Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 2 | * Ptrace user space interface. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 1999, 2010 |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 5 | * Author(s): Denis Joseph Barrow |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/sched.h> |
| 11 | #include <linux/mm.h> |
| 12 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/errno.h> |
| 14 | #include <linux/ptrace.h> |
| 15 | #include <linux/user.h> |
| 16 | #include <linux/security.h> |
| 17 | #include <linux/audit.h> |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 18 | #include <linux/signal.h> |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 19 | #include <linux/elf.h> |
| 20 | #include <linux/regset.h> |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 21 | #include <linux/tracehook.h> |
Heiko Carstens | bcf5cef | 2009-06-12 10:26:26 +0200 | [diff] [blame] | 22 | #include <linux/seccomp.h> |
Heiko Carstens | 048cd4e | 2012-02-27 10:01:52 +0100 | [diff] [blame] | 23 | #include <linux/compat.h> |
Heiko Carstens | 9bf1226 | 2009-06-12 10:26:47 +0200 | [diff] [blame] | 24 | #include <trace/syscall.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/segment.h> |
| 26 | #include <asm/page.h> |
| 27 | #include <asm/pgtable.h> |
| 28 | #include <asm/pgalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <asm/uaccess.h> |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 30 | #include <asm/unistd.h> |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 31 | #include <asm/switch_to.h> |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 32 | #include "entry.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 34 | #ifdef CONFIG_COMPAT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include "compat_ptrace.h" |
| 36 | #endif |
| 37 | |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 38 | #define CREATE_TRACE_POINTS |
| 39 | #include <trace/events/syscalls.h> |
Ingo Molnar | 5e9ad7d | 2009-08-18 10:41:57 +0200 | [diff] [blame] | 40 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 41 | enum s390_regset { |
| 42 | REGSET_GENERAL, |
| 43 | REGSET_FP, |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 44 | REGSET_LAST_BREAK, |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 45 | REGSET_TDB, |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 46 | REGSET_SYSTEM_CALL, |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 47 | REGSET_GENERAL_EXTENDED, |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 48 | }; |
| 49 | |
Michael Mueller | 64597f9 | 2013-07-02 22:58:26 +0200 | [diff] [blame] | 50 | void update_cr_regs(struct task_struct *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 52 | struct pt_regs *regs = task_pt_regs(task); |
| 53 | struct thread_struct *thread = &task->thread; |
Martin Schwidefsky | a45aff5 | 2011-10-30 15:16:07 +0100 | [diff] [blame] | 54 | struct per_regs old, new; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Heiko Carstens | 66389e8 | 2012-09-14 12:59:47 +0200 | [diff] [blame] | 56 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 57 | /* Take care of the enable/disable of transactional execution. */ |
| 58 | if (MACHINE_HAS_TE) { |
Martin Schwidefsky | c63bade | 2013-12-03 14:57:18 +0100 | [diff] [blame] | 59 | unsigned long cr, cr_new; |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 60 | |
Martin Schwidefsky | c63bade | 2013-12-03 14:57:18 +0100 | [diff] [blame] | 61 | __ctl_store(cr, 0, 0); |
Martin Schwidefsky | 0628a5f | 2013-08-27 09:56:55 +0200 | [diff] [blame] | 62 | /* Set or clear transaction execution TXC bit 8. */ |
Martin Schwidefsky | c63bade | 2013-12-03 14:57:18 +0100 | [diff] [blame] | 63 | cr_new = cr | (1UL << 55); |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 64 | if (task->thread.per_flags & PER_FLAG_NO_TE) |
Martin Schwidefsky | c63bade | 2013-12-03 14:57:18 +0100 | [diff] [blame] | 65 | cr_new &= ~(1UL << 55); |
| 66 | if (cr_new != cr) |
| 67 | __ctl_load(cr, 0, 0); |
Michael Mueller | 64597f9 | 2013-07-02 22:58:26 +0200 | [diff] [blame] | 68 | /* Set or clear transaction execution TDC bits 62 and 63. */ |
Martin Schwidefsky | c63bade | 2013-12-03 14:57:18 +0100 | [diff] [blame] | 69 | __ctl_store(cr, 2, 2); |
| 70 | cr_new = cr & ~3UL; |
Michael Mueller | 64597f9 | 2013-07-02 22:58:26 +0200 | [diff] [blame] | 71 | if (task->thread.per_flags & PER_FLAG_TE_ABORT_RAND) { |
| 72 | if (task->thread.per_flags & PER_FLAG_TE_ABORT_RAND_TEND) |
Martin Schwidefsky | c63bade | 2013-12-03 14:57:18 +0100 | [diff] [blame] | 73 | cr_new |= 1UL; |
Michael Mueller | 64597f9 | 2013-07-02 22:58:26 +0200 | [diff] [blame] | 74 | else |
Martin Schwidefsky | c63bade | 2013-12-03 14:57:18 +0100 | [diff] [blame] | 75 | cr_new |= 2UL; |
Michael Mueller | 64597f9 | 2013-07-02 22:58:26 +0200 | [diff] [blame] | 76 | } |
Martin Schwidefsky | c63bade | 2013-12-03 14:57:18 +0100 | [diff] [blame] | 77 | if (cr_new != cr) |
| 78 | __ctl_load(cr_new, 2, 2); |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 79 | } |
Heiko Carstens | 66389e8 | 2012-09-14 12:59:47 +0200 | [diff] [blame] | 80 | #endif |
Martin Schwidefsky | a45aff5 | 2011-10-30 15:16:07 +0100 | [diff] [blame] | 81 | /* Copy user specified PER registers */ |
| 82 | new.control = thread->per_user.control; |
| 83 | new.start = thread->per_user.start; |
| 84 | new.end = thread->per_user.end; |
| 85 | |
| 86 | /* merge TIF_SINGLE_STEP into user specified PER registers. */ |
| 87 | if (test_tsk_thread_flag(task, TIF_SINGLE_STEP)) { |
| 88 | new.control |= PER_EVENT_IFETCH; |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 89 | #ifdef CONFIG_64BIT |
| 90 | new.control |= PER_CONTROL_SUSPENSION; |
| 91 | new.control |= PER_EVENT_TRANSACTION_END; |
| 92 | #endif |
Martin Schwidefsky | a45aff5 | 2011-10-30 15:16:07 +0100 | [diff] [blame] | 93 | new.start = 0; |
| 94 | new.end = PSW_ADDR_INSN; |
| 95 | } |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 96 | |
| 97 | /* Take care of the PER enablement bit in the PSW. */ |
Martin Schwidefsky | a45aff5 | 2011-10-30 15:16:07 +0100 | [diff] [blame] | 98 | if (!(new.control & PER_EVENT_MASK)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | regs->psw.mask &= ~PSW_MASK_PER; |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 100 | return; |
Martin Schwidefsky | c3311c1 | 2010-01-13 20:44:25 +0100 | [diff] [blame] | 101 | } |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 102 | regs->psw.mask |= PSW_MASK_PER; |
| 103 | __ctl_store(old, 9, 11); |
Martin Schwidefsky | a45aff5 | 2011-10-30 15:16:07 +0100 | [diff] [blame] | 104 | if (memcmp(&new, &old, sizeof(struct per_regs)) != 0) |
| 105 | __ctl_load(new, 9, 11); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Roland McGrath | 0ac30be | 2008-01-26 14:11:22 +0100 | [diff] [blame] | 108 | void user_enable_single_step(struct task_struct *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 110 | set_tsk_thread_flag(task, TIF_SINGLE_STEP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Roland McGrath | 0ac30be | 2008-01-26 14:11:22 +0100 | [diff] [blame] | 113 | void user_disable_single_step(struct task_struct *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 115 | clear_tsk_thread_flag(task, TIF_SINGLE_STEP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /* |
| 119 | * Called by kernel/ptrace.c when detaching.. |
| 120 | * |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 121 | * Clear all debugging related fields. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | */ |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 123 | void ptrace_disable(struct task_struct *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 125 | memset(&task->thread.per_user, 0, sizeof(task->thread.per_user)); |
| 126 | memset(&task->thread.per_event, 0, sizeof(task->thread.per_event)); |
| 127 | clear_tsk_thread_flag(task, TIF_SINGLE_STEP); |
| 128 | clear_tsk_thread_flag(task, TIF_PER_TRAP); |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 129 | task->thread.per_flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 132 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | # define __ADDR_MASK 3 |
| 134 | #else |
| 135 | # define __ADDR_MASK 7 |
| 136 | #endif |
| 137 | |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 138 | static inline unsigned long __peek_user_per(struct task_struct *child, |
| 139 | addr_t addr) |
| 140 | { |
| 141 | struct per_struct_kernel *dummy = NULL; |
| 142 | |
| 143 | if (addr == (addr_t) &dummy->cr9) |
| 144 | /* Control bits of the active per set. */ |
| 145 | return test_thread_flag(TIF_SINGLE_STEP) ? |
| 146 | PER_EVENT_IFETCH : child->thread.per_user.control; |
| 147 | else if (addr == (addr_t) &dummy->cr10) |
| 148 | /* Start address of the active per set. */ |
| 149 | return test_thread_flag(TIF_SINGLE_STEP) ? |
| 150 | 0 : child->thread.per_user.start; |
| 151 | else if (addr == (addr_t) &dummy->cr11) |
| 152 | /* End address of the active per set. */ |
| 153 | return test_thread_flag(TIF_SINGLE_STEP) ? |
| 154 | PSW_ADDR_INSN : child->thread.per_user.end; |
| 155 | else if (addr == (addr_t) &dummy->bits) |
| 156 | /* Single-step bit. */ |
| 157 | return test_thread_flag(TIF_SINGLE_STEP) ? |
| 158 | (1UL << (BITS_PER_LONG - 1)) : 0; |
| 159 | else if (addr == (addr_t) &dummy->starting_addr) |
| 160 | /* Start address of the user specified per set. */ |
| 161 | return child->thread.per_user.start; |
| 162 | else if (addr == (addr_t) &dummy->ending_addr) |
| 163 | /* End address of the user specified per set. */ |
| 164 | return child->thread.per_user.end; |
| 165 | else if (addr == (addr_t) &dummy->perc_atmid) |
| 166 | /* PER code, ATMID and AI of the last PER trap */ |
| 167 | return (unsigned long) |
| 168 | child->thread.per_event.cause << (BITS_PER_LONG - 16); |
| 169 | else if (addr == (addr_t) &dummy->address) |
| 170 | /* Address of the last PER trap */ |
| 171 | return child->thread.per_event.address; |
| 172 | else if (addr == (addr_t) &dummy->access_id) |
| 173 | /* Access id of the last PER trap */ |
| 174 | return (unsigned long) |
| 175 | child->thread.per_event.paid << (BITS_PER_LONG - 8); |
| 176 | return 0; |
| 177 | } |
| 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | /* |
| 180 | * Read the word at offset addr from the user area of a process. The |
| 181 | * trouble here is that the information is littered over different |
| 182 | * locations. The process registers are found on the kernel stack, |
| 183 | * the floating point stuff and the trace settings are stored in |
| 184 | * the task structure. In addition the different structures in |
| 185 | * struct user contain pad bytes that should be read as zeroes. |
| 186 | * Lovely... |
| 187 | */ |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 188 | static unsigned long __peek_user(struct task_struct *child, addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
| 190 | struct user *dummy = NULL; |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 191 | addr_t offset, tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | if (addr < (addr_t) &dummy->regs.acrs) { |
| 194 | /* |
| 195 | * psw and gprs are stored on the stack |
| 196 | */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 197 | tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr); |
Heiko Carstens | 5ebf250 | 2013-10-16 09:58:01 +0200 | [diff] [blame] | 198 | if (addr == (addr_t) &dummy->regs.psw.mask) { |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 199 | /* Return a clean psw mask. */ |
Heiko Carstens | 5ebf250 | 2013-10-16 09:58:01 +0200 | [diff] [blame] | 200 | tmp &= PSW_MASK_USER | PSW_MASK_RI; |
| 201 | tmp |= PSW_USER_BITS; |
| 202 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | } else if (addr < (addr_t) &dummy->regs.orig_gpr2) { |
| 205 | /* |
| 206 | * access registers are stored in the thread structure |
| 207 | */ |
| 208 | offset = addr - (addr_t) &dummy->regs.acrs; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 209 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 210 | /* |
| 211 | * Very special case: old & broken 64 bit gdb reading |
| 212 | * from acrs[15]. Result is a 64 bit value. Read the |
| 213 | * 32 bit acrs[15] value and shift it by 32. Sick... |
| 214 | */ |
| 215 | if (addr == (addr_t) &dummy->regs.acrs[15]) |
| 216 | tmp = ((unsigned long) child->thread.acrs[15]) << 32; |
| 217 | else |
| 218 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset); |
| 220 | |
| 221 | } else if (addr == (addr_t) &dummy->regs.orig_gpr2) { |
| 222 | /* |
| 223 | * orig_gpr2 is stored on the kernel stack |
| 224 | */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 225 | tmp = (addr_t) task_pt_regs(child)->orig_gpr2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Jarod Wilson | 3d6e48f | 2008-09-09 12:38:56 +0200 | [diff] [blame] | 227 | } else if (addr < (addr_t) &dummy->regs.fp_regs) { |
| 228 | /* |
| 229 | * prevent reads of padding hole between |
| 230 | * orig_gpr2 and fp_regs on s390. |
| 231 | */ |
| 232 | tmp = 0; |
| 233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) { |
| 235 | /* |
| 236 | * floating point regs. are stored in the thread structure |
| 237 | */ |
| 238 | offset = addr - (addr_t) &dummy->regs.fp_regs; |
| 239 | tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset); |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 240 | if (addr == (addr_t) &dummy->regs.fp_regs.fpc) |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 241 | tmp <<= BITS_PER_LONG - 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
| 243 | } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) { |
| 244 | /* |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 245 | * Handle access to the per_info structure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | */ |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 247 | addr -= (addr_t) &dummy->regs.per_info; |
| 248 | tmp = __peek_user_per(child, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
| 250 | } else |
| 251 | tmp = 0; |
| 252 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 253 | return tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | static int |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 257 | peek_user(struct task_struct *child, addr_t addr, addr_t data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 259 | addr_t tmp, mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
| 261 | /* |
| 262 | * Stupid gdb peeks/pokes the access registers in 64 bit with |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 263 | * an alignment of 4. Programmers from hell... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | */ |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 265 | mask = __ADDR_MASK; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 266 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 547e3ce | 2008-12-25 13:39:00 +0100 | [diff] [blame] | 267 | if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs && |
| 268 | addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2) |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 269 | mask = 3; |
| 270 | #endif |
| 271 | if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | return -EIO; |
| 273 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 274 | tmp = __peek_user(child, addr); |
| 275 | return put_user(tmp, (addr_t __user *) data); |
| 276 | } |
| 277 | |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 278 | static inline void __poke_user_per(struct task_struct *child, |
| 279 | addr_t addr, addr_t data) |
| 280 | { |
| 281 | struct per_struct_kernel *dummy = NULL; |
| 282 | |
| 283 | /* |
| 284 | * There are only three fields in the per_info struct that the |
| 285 | * debugger user can write to. |
| 286 | * 1) cr9: the debugger wants to set a new PER event mask |
| 287 | * 2) starting_addr: the debugger wants to set a new starting |
| 288 | * address to use with the PER event mask. |
| 289 | * 3) ending_addr: the debugger wants to set a new ending |
| 290 | * address to use with the PER event mask. |
| 291 | * The user specified PER event mask and the start and end |
| 292 | * addresses are used only if single stepping is not in effect. |
| 293 | * Writes to any other field in per_info are ignored. |
| 294 | */ |
| 295 | if (addr == (addr_t) &dummy->cr9) |
| 296 | /* PER event mask of the user specified per set. */ |
| 297 | child->thread.per_user.control = |
| 298 | data & (PER_EVENT_MASK | PER_CONTROL_MASK); |
| 299 | else if (addr == (addr_t) &dummy->starting_addr) |
| 300 | /* Starting address of the user specified per set. */ |
| 301 | child->thread.per_user.start = data; |
| 302 | else if (addr == (addr_t) &dummy->ending_addr) |
| 303 | /* Ending address of the user specified per set. */ |
| 304 | child->thread.per_user.end = data; |
| 305 | } |
| 306 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 307 | /* |
| 308 | * Write a word to the user area of a process at location addr. This |
| 309 | * operation does have an additional problem compared to peek_user. |
| 310 | * Stores to the program status word and on the floating point |
| 311 | * control register needs to get checked for validity. |
| 312 | */ |
| 313 | static int __poke_user(struct task_struct *child, addr_t addr, addr_t data) |
| 314 | { |
| 315 | struct user *dummy = NULL; |
Martin Schwidefsky | d4e81b3 | 2011-10-30 15:16:51 +0100 | [diff] [blame] | 316 | addr_t offset; |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | if (addr < (addr_t) &dummy->regs.acrs) { |
| 319 | /* |
| 320 | * psw and gprs are stored on the stack |
| 321 | */ |
Heiko Carstens | 5ebf250 | 2013-10-16 09:58:01 +0200 | [diff] [blame] | 322 | if (addr == (addr_t) &dummy->regs.psw.mask) { |
| 323 | unsigned long mask = PSW_MASK_USER; |
| 324 | |
| 325 | mask |= is_ri_task(child) ? PSW_MASK_RI : 0; |
| 326 | if ((data & ~mask) != PSW_USER_BITS) |
| 327 | return -EINVAL; |
| 328 | if ((data & PSW_MASK_EA) && !(data & PSW_MASK_BA)) |
| 329 | return -EINVAL; |
| 330 | } |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 331 | *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
| 333 | } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) { |
| 334 | /* |
| 335 | * access registers are stored in the thread structure |
| 336 | */ |
| 337 | offset = addr - (addr_t) &dummy->regs.acrs; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 338 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 339 | /* |
| 340 | * Very special case: old & broken 64 bit gdb writing |
| 341 | * to acrs[15] with a 64 bit value. Ignore the lower |
| 342 | * half of the value and write the upper 32 bit to |
| 343 | * acrs[15]. Sick... |
| 344 | */ |
| 345 | if (addr == (addr_t) &dummy->regs.acrs[15]) |
| 346 | child->thread.acrs[15] = (unsigned int) (data >> 32); |
| 347 | else |
| 348 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | *(addr_t *)((addr_t) &child->thread.acrs + offset) = data; |
| 350 | |
| 351 | } else if (addr == (addr_t) &dummy->regs.orig_gpr2) { |
| 352 | /* |
| 353 | * orig_gpr2 is stored on the kernel stack |
| 354 | */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 355 | task_pt_regs(child)->orig_gpr2 = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Jarod Wilson | 3d6e48f | 2008-09-09 12:38:56 +0200 | [diff] [blame] | 357 | } else if (addr < (addr_t) &dummy->regs.fp_regs) { |
| 358 | /* |
| 359 | * prevent writes of padding hole between |
| 360 | * orig_gpr2 and fp_regs on s390. |
| 361 | */ |
| 362 | return 0; |
| 363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) { |
| 365 | /* |
| 366 | * floating point regs. are stored in the thread structure |
| 367 | */ |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 368 | if (addr == (addr_t) &dummy->regs.fp_regs.fpc) |
| 369 | if ((unsigned int) data != 0 || |
| 370 | test_fp_ctl(data >> (BITS_PER_LONG - 32))) |
| 371 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | offset = addr - (addr_t) &dummy->regs.fp_regs; |
| 373 | *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data; |
| 374 | |
| 375 | } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) { |
| 376 | /* |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 377 | * Handle access to the per_info structure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | */ |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 379 | addr -= (addr_t) &dummy->regs.per_info; |
| 380 | __poke_user_per(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
| 382 | } |
| 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | return 0; |
| 385 | } |
| 386 | |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 387 | static int poke_user(struct task_struct *child, addr_t addr, addr_t data) |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 388 | { |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 389 | addr_t mask; |
| 390 | |
| 391 | /* |
| 392 | * Stupid gdb peeks/pokes the access registers in 64 bit with |
| 393 | * an alignment of 4. Programmers from hell indeed... |
| 394 | */ |
| 395 | mask = __ADDR_MASK; |
| 396 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 547e3ce | 2008-12-25 13:39:00 +0100 | [diff] [blame] | 397 | if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs && |
| 398 | addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2) |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 399 | mask = 3; |
| 400 | #endif |
| 401 | if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK) |
| 402 | return -EIO; |
| 403 | |
| 404 | return __poke_user(child, addr, data); |
| 405 | } |
| 406 | |
Namhyung Kim | 9b05a69 | 2010-10-27 15:33:47 -0700 | [diff] [blame] | 407 | long arch_ptrace(struct task_struct *child, long request, |
| 408 | unsigned long addr, unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | ptrace_area parea; |
| 411 | int copied, ret; |
| 412 | |
| 413 | switch (request) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | case PTRACE_PEEKUSR: |
| 415 | /* read the word at location addr in the USER area. */ |
| 416 | return peek_user(child, addr, data); |
| 417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | case PTRACE_POKEUSR: |
| 419 | /* write the word at location addr in the USER area */ |
| 420 | return poke_user(child, addr, data); |
| 421 | |
| 422 | case PTRACE_PEEKUSR_AREA: |
| 423 | case PTRACE_POKEUSR_AREA: |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 424 | if (copy_from_user(&parea, (void __force __user *) addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | sizeof(parea))) |
| 426 | return -EFAULT; |
| 427 | addr = parea.kernel_addr; |
| 428 | data = parea.process_addr; |
| 429 | copied = 0; |
| 430 | while (copied < parea.len) { |
| 431 | if (request == PTRACE_PEEKUSR_AREA) |
| 432 | ret = peek_user(child, addr, data); |
| 433 | else { |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 434 | addr_t utmp; |
| 435 | if (get_user(utmp, |
| 436 | (addr_t __force __user *) data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | return -EFAULT; |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 438 | ret = poke_user(child, addr, utmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | } |
| 440 | if (ret) |
| 441 | return ret; |
| 442 | addr += sizeof(unsigned long); |
| 443 | data += sizeof(unsigned long); |
| 444 | copied += sizeof(unsigned long); |
| 445 | } |
| 446 | return 0; |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 447 | case PTRACE_GET_LAST_BREAK: |
| 448 | put_user(task_thread_info(child)->last_break, |
| 449 | (unsigned long __user *) data); |
| 450 | return 0; |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 451 | case PTRACE_ENABLE_TE: |
| 452 | if (!MACHINE_HAS_TE) |
| 453 | return -EIO; |
| 454 | child->thread.per_flags &= ~PER_FLAG_NO_TE; |
| 455 | return 0; |
| 456 | case PTRACE_DISABLE_TE: |
| 457 | if (!MACHINE_HAS_TE) |
| 458 | return -EIO; |
| 459 | child->thread.per_flags |= PER_FLAG_NO_TE; |
Michael Mueller | 64597f9 | 2013-07-02 22:58:26 +0200 | [diff] [blame] | 460 | child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND; |
| 461 | return 0; |
| 462 | case PTRACE_TE_ABORT_RAND: |
| 463 | if (!MACHINE_HAS_TE || (child->thread.per_flags & PER_FLAG_NO_TE)) |
| 464 | return -EIO; |
| 465 | switch (data) { |
| 466 | case 0UL: |
| 467 | child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND; |
| 468 | break; |
| 469 | case 1UL: |
| 470 | child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND; |
| 471 | child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND_TEND; |
| 472 | break; |
| 473 | case 2UL: |
| 474 | child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND; |
| 475 | child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND_TEND; |
| 476 | break; |
| 477 | default: |
| 478 | return -EINVAL; |
| 479 | } |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 480 | return 0; |
Christian Borntraeger | 07805ac | 2009-09-22 22:58:48 +0200 | [diff] [blame] | 481 | default: |
| 482 | /* Removing high order bit from addr (only for 31 bit). */ |
| 483 | addr &= PSW_ADDR_INSN; |
| 484 | return ptrace_request(child, request, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 488 | #ifdef CONFIG_COMPAT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | /* |
| 490 | * Now the fun part starts... a 31 bit program running in the |
| 491 | * 31 bit emulation tracing another program. PTRACE_PEEKTEXT, |
| 492 | * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy |
| 493 | * to handle, the difference to the 64 bit versions of the requests |
| 494 | * is that the access is done in multiples of 4 byte instead of |
| 495 | * 8 bytes (sizeof(unsigned long) on 31/64 bit). |
| 496 | * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA, |
| 497 | * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program |
| 498 | * is a 31 bit program too, the content of struct user can be |
| 499 | * emulated. A 31 bit program peeking into the struct user of |
| 500 | * a 64 bit program is a no-no. |
| 501 | */ |
| 502 | |
| 503 | /* |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 504 | * Same as peek_user_per but for a 31 bit program. |
| 505 | */ |
| 506 | static inline __u32 __peek_user_per_compat(struct task_struct *child, |
| 507 | addr_t addr) |
| 508 | { |
| 509 | struct compat_per_struct_kernel *dummy32 = NULL; |
| 510 | |
| 511 | if (addr == (addr_t) &dummy32->cr9) |
| 512 | /* Control bits of the active per set. */ |
| 513 | return (__u32) test_thread_flag(TIF_SINGLE_STEP) ? |
| 514 | PER_EVENT_IFETCH : child->thread.per_user.control; |
| 515 | else if (addr == (addr_t) &dummy32->cr10) |
| 516 | /* Start address of the active per set. */ |
| 517 | return (__u32) test_thread_flag(TIF_SINGLE_STEP) ? |
| 518 | 0 : child->thread.per_user.start; |
| 519 | else if (addr == (addr_t) &dummy32->cr11) |
| 520 | /* End address of the active per set. */ |
| 521 | return test_thread_flag(TIF_SINGLE_STEP) ? |
| 522 | PSW32_ADDR_INSN : child->thread.per_user.end; |
| 523 | else if (addr == (addr_t) &dummy32->bits) |
| 524 | /* Single-step bit. */ |
| 525 | return (__u32) test_thread_flag(TIF_SINGLE_STEP) ? |
| 526 | 0x80000000 : 0; |
| 527 | else if (addr == (addr_t) &dummy32->starting_addr) |
| 528 | /* Start address of the user specified per set. */ |
| 529 | return (__u32) child->thread.per_user.start; |
| 530 | else if (addr == (addr_t) &dummy32->ending_addr) |
| 531 | /* End address of the user specified per set. */ |
| 532 | return (__u32) child->thread.per_user.end; |
| 533 | else if (addr == (addr_t) &dummy32->perc_atmid) |
| 534 | /* PER code, ATMID and AI of the last PER trap */ |
| 535 | return (__u32) child->thread.per_event.cause << 16; |
| 536 | else if (addr == (addr_t) &dummy32->address) |
| 537 | /* Address of the last PER trap */ |
| 538 | return (__u32) child->thread.per_event.address; |
| 539 | else if (addr == (addr_t) &dummy32->access_id) |
| 540 | /* Access id of the last PER trap */ |
| 541 | return (__u32) child->thread.per_event.paid << 24; |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | * Same as peek_user but for a 31 bit program. |
| 547 | */ |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 548 | static u32 __peek_user_compat(struct task_struct *child, addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | { |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 550 | struct compat_user *dummy32 = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | addr_t offset; |
| 552 | __u32 tmp; |
| 553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | if (addr < (addr_t) &dummy32->regs.acrs) { |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 555 | struct pt_regs *regs = task_pt_regs(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | /* |
| 557 | * psw and gprs are stored on the stack |
| 558 | */ |
| 559 | if (addr == (addr_t) &dummy32->regs.psw.mask) { |
| 560 | /* Fake a 31 bit psw mask. */ |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 561 | tmp = (__u32)(regs->psw.mask >> 32); |
Heiko Carstens | 5ebf250 | 2013-10-16 09:58:01 +0200 | [diff] [blame] | 562 | tmp &= PSW32_MASK_USER | PSW32_MASK_RI; |
Heiko Carstens | f26946d | 2013-10-16 14:17:29 +0200 | [diff] [blame] | 563 | tmp |= PSW32_USER_BITS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | } else if (addr == (addr_t) &dummy32->regs.psw.addr) { |
| 565 | /* Fake a 31 bit psw address. */ |
Martin Schwidefsky | d4e81b3 | 2011-10-30 15:16:51 +0100 | [diff] [blame] | 566 | tmp = (__u32) regs->psw.addr | |
| 567 | (__u32)(regs->psw.mask & PSW_MASK_BA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } else { |
| 569 | /* gpr 0-15 */ |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 570 | tmp = *(__u32 *)((addr_t) ®s->psw + addr*2 + 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } |
| 572 | } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) { |
| 573 | /* |
| 574 | * access registers are stored in the thread structure |
| 575 | */ |
| 576 | offset = addr - (addr_t) &dummy32->regs.acrs; |
| 577 | tmp = *(__u32*)((addr_t) &child->thread.acrs + offset); |
| 578 | |
| 579 | } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) { |
| 580 | /* |
| 581 | * orig_gpr2 is stored on the kernel stack |
| 582 | */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 583 | tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
Jarod Wilson | 3d6e48f | 2008-09-09 12:38:56 +0200 | [diff] [blame] | 585 | } else if (addr < (addr_t) &dummy32->regs.fp_regs) { |
| 586 | /* |
| 587 | * prevent reads of padding hole between |
| 588 | * orig_gpr2 and fp_regs on s390. |
| 589 | */ |
| 590 | tmp = 0; |
| 591 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) { |
| 593 | /* |
| 594 | * floating point regs. are stored in the thread structure |
| 595 | */ |
| 596 | offset = addr - (addr_t) &dummy32->regs.fp_regs; |
| 597 | tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset); |
| 598 | |
| 599 | } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) { |
| 600 | /* |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 601 | * Handle access to the per_info structure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | */ |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 603 | addr -= (addr_t) &dummy32->regs.per_info; |
| 604 | tmp = __peek_user_per_compat(child, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
| 606 | } else |
| 607 | tmp = 0; |
| 608 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 609 | return tmp; |
| 610 | } |
| 611 | |
| 612 | static int peek_user_compat(struct task_struct *child, |
| 613 | addr_t addr, addr_t data) |
| 614 | { |
| 615 | __u32 tmp; |
| 616 | |
Heiko Carstens | 7757591 | 2009-06-12 10:26:25 +0200 | [diff] [blame] | 617 | if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3) |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 618 | return -EIO; |
| 619 | |
| 620 | tmp = __peek_user_compat(child, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | return put_user(tmp, (__u32 __user *) data); |
| 622 | } |
| 623 | |
| 624 | /* |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 625 | * Same as poke_user_per but for a 31 bit program. |
| 626 | */ |
| 627 | static inline void __poke_user_per_compat(struct task_struct *child, |
| 628 | addr_t addr, __u32 data) |
| 629 | { |
| 630 | struct compat_per_struct_kernel *dummy32 = NULL; |
| 631 | |
| 632 | if (addr == (addr_t) &dummy32->cr9) |
| 633 | /* PER event mask of the user specified per set. */ |
| 634 | child->thread.per_user.control = |
| 635 | data & (PER_EVENT_MASK | PER_CONTROL_MASK); |
| 636 | else if (addr == (addr_t) &dummy32->starting_addr) |
| 637 | /* Starting address of the user specified per set. */ |
| 638 | child->thread.per_user.start = data; |
| 639 | else if (addr == (addr_t) &dummy32->ending_addr) |
| 640 | /* Ending address of the user specified per set. */ |
| 641 | child->thread.per_user.end = data; |
| 642 | } |
| 643 | |
| 644 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | * Same as poke_user but for a 31 bit program. |
| 646 | */ |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 647 | static int __poke_user_compat(struct task_struct *child, |
| 648 | addr_t addr, addr_t data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | { |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 650 | struct compat_user *dummy32 = NULL; |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 651 | __u32 tmp = (__u32) data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | addr_t offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
| 654 | if (addr < (addr_t) &dummy32->regs.acrs) { |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 655 | struct pt_regs *regs = task_pt_regs(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | /* |
| 657 | * psw, gprs, acrs and orig_gpr2 are stored on the stack |
| 658 | */ |
| 659 | if (addr == (addr_t) &dummy32->regs.psw.mask) { |
Heiko Carstens | 5ebf250 | 2013-10-16 09:58:01 +0200 | [diff] [blame] | 660 | __u32 mask = PSW32_MASK_USER; |
| 661 | |
| 662 | mask |= is_ri_task(child) ? PSW32_MASK_RI : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | /* Build a 64 bit psw mask from 31 bit mask. */ |
Heiko Carstens | f26946d | 2013-10-16 14:17:29 +0200 | [diff] [blame] | 664 | if ((tmp & ~mask) != PSW32_USER_BITS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | /* Invalid psw mask. */ |
| 666 | return -EINVAL; |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 667 | regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) | |
Martin Schwidefsky | d4e81b3 | 2011-10-30 15:16:51 +0100 | [diff] [blame] | 668 | (regs->psw.mask & PSW_MASK_BA) | |
Heiko Carstens | 5ebf250 | 2013-10-16 09:58:01 +0200 | [diff] [blame] | 669 | (__u64)(tmp & mask) << 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | } else if (addr == (addr_t) &dummy32->regs.psw.addr) { |
| 671 | /* Build a 64 bit psw address from 31 bit address. */ |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 672 | regs->psw.addr = (__u64) tmp & PSW32_ADDR_INSN; |
Martin Schwidefsky | d4e81b3 | 2011-10-30 15:16:51 +0100 | [diff] [blame] | 673 | /* Transfer 31 bit amode bit to psw mask. */ |
| 674 | regs->psw.mask = (regs->psw.mask & ~PSW_MASK_BA) | |
| 675 | (__u64)(tmp & PSW32_ADDR_AMODE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | } else { |
| 677 | /* gpr 0-15 */ |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 678 | *(__u32*)((addr_t) ®s->psw + addr*2 + 4) = tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
| 680 | } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) { |
| 681 | /* |
| 682 | * access registers are stored in the thread structure |
| 683 | */ |
| 684 | offset = addr - (addr_t) &dummy32->regs.acrs; |
| 685 | *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp; |
| 686 | |
| 687 | } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) { |
| 688 | /* |
| 689 | * orig_gpr2 is stored on the kernel stack |
| 690 | */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 691 | *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
Jarod Wilson | 3d6e48f | 2008-09-09 12:38:56 +0200 | [diff] [blame] | 693 | } else if (addr < (addr_t) &dummy32->regs.fp_regs) { |
| 694 | /* |
| 695 | * prevent writess of padding hole between |
| 696 | * orig_gpr2 and fp_regs on s390. |
| 697 | */ |
| 698 | return 0; |
| 699 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) { |
| 701 | /* |
| 702 | * floating point regs. are stored in the thread structure |
| 703 | */ |
| 704 | if (addr == (addr_t) &dummy32->regs.fp_regs.fpc && |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 705 | test_fp_ctl(tmp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | return -EINVAL; |
| 707 | offset = addr - (addr_t) &dummy32->regs.fp_regs; |
| 708 | *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp; |
| 709 | |
| 710 | } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) { |
| 711 | /* |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 712 | * Handle access to the per_info structure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | */ |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 714 | addr -= (addr_t) &dummy32->regs.per_info; |
| 715 | __poke_user_per_compat(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | return 0; |
| 719 | } |
| 720 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 721 | static int poke_user_compat(struct task_struct *child, |
| 722 | addr_t addr, addr_t data) |
| 723 | { |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 724 | if (!is_compat_task() || (addr & 3) || |
| 725 | addr > sizeof(struct compat_user) - 3) |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 726 | return -EIO; |
| 727 | |
| 728 | return __poke_user_compat(child, addr, data); |
| 729 | } |
| 730 | |
Roland McGrath | b499d76 | 2008-05-07 09:22:57 +0200 | [diff] [blame] | 731 | long compat_arch_ptrace(struct task_struct *child, compat_long_t request, |
| 732 | compat_ulong_t caddr, compat_ulong_t cdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | { |
Roland McGrath | b499d76 | 2008-05-07 09:22:57 +0200 | [diff] [blame] | 734 | unsigned long addr = caddr; |
| 735 | unsigned long data = cdata; |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 736 | compat_ptrace_area parea; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | int copied, ret; |
| 738 | |
| 739 | switch (request) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | case PTRACE_PEEKUSR: |
| 741 | /* read the word at location addr in the USER area. */ |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 742 | return peek_user_compat(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | case PTRACE_POKEUSR: |
| 745 | /* write the word at location addr in the USER area */ |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 746 | return poke_user_compat(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
| 748 | case PTRACE_PEEKUSR_AREA: |
| 749 | case PTRACE_POKEUSR_AREA: |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 750 | if (copy_from_user(&parea, (void __force __user *) addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | sizeof(parea))) |
| 752 | return -EFAULT; |
| 753 | addr = parea.kernel_addr; |
| 754 | data = parea.process_addr; |
| 755 | copied = 0; |
| 756 | while (copied < parea.len) { |
| 757 | if (request == PTRACE_PEEKUSR_AREA) |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 758 | ret = peek_user_compat(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | else { |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 760 | __u32 utmp; |
| 761 | if (get_user(utmp, |
| 762 | (__u32 __force __user *) data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | return -EFAULT; |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 764 | ret = poke_user_compat(child, addr, utmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | } |
| 766 | if (ret) |
| 767 | return ret; |
| 768 | addr += sizeof(unsigned int); |
| 769 | data += sizeof(unsigned int); |
| 770 | copied += sizeof(unsigned int); |
| 771 | } |
| 772 | return 0; |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 773 | case PTRACE_GET_LAST_BREAK: |
| 774 | put_user(task_thread_info(child)->last_break, |
| 775 | (unsigned int __user *) data); |
| 776 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | } |
Roland McGrath | b499d76 | 2008-05-07 09:22:57 +0200 | [diff] [blame] | 778 | return compat_ptrace_request(child, request, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | } |
| 780 | #endif |
| 781 | |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 782 | asmlinkage long do_syscall_trace_enter(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | { |
Gerald Schaefer | 545c174 | 2010-05-12 09:32:12 +0200 | [diff] [blame] | 784 | long ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
Heiko Carstens | bcf5cef | 2009-06-12 10:26:26 +0200 | [diff] [blame] | 786 | /* Do the secure computing check first. */ |
Heiko Carstens | c63cb46 | 2012-07-31 15:37:13 +0200 | [diff] [blame] | 787 | if (secure_computing(regs->gprs[2])) { |
| 788 | /* seccomp failures shouldn't expose any additional code. */ |
| 789 | ret = -1; |
| 790 | goto out; |
| 791 | } |
Heiko Carstens | bcf5cef | 2009-06-12 10:26:26 +0200 | [diff] [blame] | 792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | /* |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 794 | * The sysc_tracesys code in entry.S stored the system |
| 795 | * call number to gprs[2]. |
Bodo Stroesser | c5c3a6d | 2005-06-04 15:43:32 -0700 | [diff] [blame] | 796 | */ |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 797 | if (test_thread_flag(TIF_SYSCALL_TRACE) && |
| 798 | (tracehook_report_syscall_entry(regs) || |
| 799 | regs->gprs[2] >= NR_syscalls)) { |
| 800 | /* |
| 801 | * Tracing decided this syscall should not happen or the |
| 802 | * debugger stored an invalid system call number. Skip |
| 803 | * the system call and the system call restart handling. |
| 804 | */ |
Martin Schwidefsky | b6ef5bb | 2011-10-30 15:16:49 +0100 | [diff] [blame] | 805 | clear_thread_flag(TIF_SYSCALL); |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 806 | ret = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | } |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 808 | |
Josh Stone | 6670000 | 2009-08-24 14:43:11 -0700 | [diff] [blame] | 809 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 810 | trace_sys_enter(regs, regs->gprs[2]); |
Heiko Carstens | 9bf1226 | 2009-06-12 10:26:47 +0200 | [diff] [blame] | 811 | |
Eric Paris | b05d844 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 812 | audit_syscall_entry(is_compat_task() ? |
| 813 | AUDIT_ARCH_S390 : AUDIT_ARCH_S390X, |
| 814 | regs->gprs[2], regs->orig_gpr2, |
| 815 | regs->gprs[3], regs->gprs[4], |
| 816 | regs->gprs[5]); |
Heiko Carstens | c63cb46 | 2012-07-31 15:37:13 +0200 | [diff] [blame] | 817 | out: |
Gerald Schaefer | 545c174 | 2010-05-12 09:32:12 +0200 | [diff] [blame] | 818 | return ret ?: regs->gprs[2]; |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | asmlinkage void do_syscall_trace_exit(struct pt_regs *regs) |
| 822 | { |
Eric Paris | d7e7528 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 823 | audit_syscall_exit(regs); |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 824 | |
Josh Stone | 6670000 | 2009-08-24 14:43:11 -0700 | [diff] [blame] | 825 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 826 | trace_sys_exit(regs, regs->gprs[2]); |
Heiko Carstens | 9bf1226 | 2009-06-12 10:26:47 +0200 | [diff] [blame] | 827 | |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 828 | if (test_thread_flag(TIF_SYSCALL_TRACE)) |
| 829 | tracehook_report_syscall_exit(regs, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | } |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 831 | |
| 832 | /* |
| 833 | * user_regset definitions. |
| 834 | */ |
| 835 | |
| 836 | static int s390_regs_get(struct task_struct *target, |
| 837 | const struct user_regset *regset, |
| 838 | unsigned int pos, unsigned int count, |
| 839 | void *kbuf, void __user *ubuf) |
| 840 | { |
| 841 | if (target == current) |
| 842 | save_access_regs(target->thread.acrs); |
| 843 | |
| 844 | if (kbuf) { |
| 845 | unsigned long *k = kbuf; |
| 846 | while (count > 0) { |
| 847 | *k++ = __peek_user(target, pos); |
| 848 | count -= sizeof(*k); |
| 849 | pos += sizeof(*k); |
| 850 | } |
| 851 | } else { |
| 852 | unsigned long __user *u = ubuf; |
| 853 | while (count > 0) { |
| 854 | if (__put_user(__peek_user(target, pos), u++)) |
| 855 | return -EFAULT; |
| 856 | count -= sizeof(*u); |
| 857 | pos += sizeof(*u); |
| 858 | } |
| 859 | } |
| 860 | return 0; |
| 861 | } |
| 862 | |
| 863 | static int s390_regs_set(struct task_struct *target, |
| 864 | const struct user_regset *regset, |
| 865 | unsigned int pos, unsigned int count, |
| 866 | const void *kbuf, const void __user *ubuf) |
| 867 | { |
| 868 | int rc = 0; |
| 869 | |
| 870 | if (target == current) |
| 871 | save_access_regs(target->thread.acrs); |
| 872 | |
| 873 | if (kbuf) { |
| 874 | const unsigned long *k = kbuf; |
| 875 | while (count > 0 && !rc) { |
| 876 | rc = __poke_user(target, pos, *k++); |
| 877 | count -= sizeof(*k); |
| 878 | pos += sizeof(*k); |
| 879 | } |
| 880 | } else { |
| 881 | const unsigned long __user *u = ubuf; |
| 882 | while (count > 0 && !rc) { |
| 883 | unsigned long word; |
| 884 | rc = __get_user(word, u++); |
| 885 | if (rc) |
| 886 | break; |
| 887 | rc = __poke_user(target, pos, word); |
| 888 | count -= sizeof(*u); |
| 889 | pos += sizeof(*u); |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | if (rc == 0 && target == current) |
| 894 | restore_access_regs(target->thread.acrs); |
| 895 | |
| 896 | return rc; |
| 897 | } |
| 898 | |
| 899 | static int s390_fpregs_get(struct task_struct *target, |
| 900 | const struct user_regset *regset, unsigned int pos, |
| 901 | unsigned int count, void *kbuf, void __user *ubuf) |
| 902 | { |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 903 | if (target == current) { |
| 904 | save_fp_ctl(&target->thread.fp_regs.fpc); |
| 905 | save_fp_regs(target->thread.fp_regs.fprs); |
| 906 | } |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 907 | |
| 908 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 909 | &target->thread.fp_regs, 0, -1); |
| 910 | } |
| 911 | |
| 912 | static int s390_fpregs_set(struct task_struct *target, |
| 913 | const struct user_regset *regset, unsigned int pos, |
| 914 | unsigned int count, const void *kbuf, |
| 915 | const void __user *ubuf) |
| 916 | { |
| 917 | int rc = 0; |
| 918 | |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 919 | if (target == current) { |
| 920 | save_fp_ctl(&target->thread.fp_regs.fpc); |
| 921 | save_fp_regs(target->thread.fp_regs.fprs); |
| 922 | } |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 923 | |
| 924 | /* If setting FPC, must validate it first. */ |
| 925 | if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) { |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 926 | u32 ufpc[2] = { target->thread.fp_regs.fpc, 0 }; |
| 927 | rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ufpc, |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 928 | 0, offsetof(s390_fp_regs, fprs)); |
| 929 | if (rc) |
| 930 | return rc; |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 931 | if (ufpc[1] != 0 || test_fp_ctl(ufpc[0])) |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 932 | return -EINVAL; |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 933 | target->thread.fp_regs.fpc = ufpc[0]; |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | if (rc == 0 && count > 0) |
| 937 | rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 938 | target->thread.fp_regs.fprs, |
| 939 | offsetof(s390_fp_regs, fprs), -1); |
| 940 | |
Martin Schwidefsky | 4725c86 | 2013-10-15 16:08:34 +0200 | [diff] [blame] | 941 | if (rc == 0 && target == current) { |
| 942 | restore_fp_ctl(&target->thread.fp_regs.fpc); |
| 943 | restore_fp_regs(target->thread.fp_regs.fprs); |
| 944 | } |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 945 | |
| 946 | return rc; |
| 947 | } |
| 948 | |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 949 | #ifdef CONFIG_64BIT |
| 950 | |
| 951 | static int s390_last_break_get(struct task_struct *target, |
| 952 | const struct user_regset *regset, |
| 953 | unsigned int pos, unsigned int count, |
| 954 | void *kbuf, void __user *ubuf) |
| 955 | { |
| 956 | if (count > 0) { |
| 957 | if (kbuf) { |
| 958 | unsigned long *k = kbuf; |
| 959 | *k = task_thread_info(target)->last_break; |
| 960 | } else { |
| 961 | unsigned long __user *u = ubuf; |
| 962 | if (__put_user(task_thread_info(target)->last_break, u)) |
| 963 | return -EFAULT; |
| 964 | } |
| 965 | } |
| 966 | return 0; |
| 967 | } |
| 968 | |
Martin Schwidefsky | b934069 | 2011-12-01 13:32:17 +0100 | [diff] [blame] | 969 | static int s390_last_break_set(struct task_struct *target, |
| 970 | const struct user_regset *regset, |
| 971 | unsigned int pos, unsigned int count, |
| 972 | const void *kbuf, const void __user *ubuf) |
| 973 | { |
| 974 | return 0; |
| 975 | } |
| 976 | |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 977 | static int s390_tdb_get(struct task_struct *target, |
| 978 | const struct user_regset *regset, |
| 979 | unsigned int pos, unsigned int count, |
| 980 | void *kbuf, void __user *ubuf) |
| 981 | { |
| 982 | struct pt_regs *regs = task_pt_regs(target); |
| 983 | unsigned char *data; |
| 984 | |
| 985 | if (!(regs->int_code & 0x200)) |
| 986 | return -ENODATA; |
| 987 | data = target->thread.trap_tdb; |
| 988 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, data, 0, 256); |
| 989 | } |
| 990 | |
| 991 | static int s390_tdb_set(struct task_struct *target, |
| 992 | const struct user_regset *regset, |
| 993 | unsigned int pos, unsigned int count, |
| 994 | const void *kbuf, const void __user *ubuf) |
| 995 | { |
| 996 | return 0; |
| 997 | } |
| 998 | |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 999 | #endif |
| 1000 | |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 1001 | static int s390_system_call_get(struct task_struct *target, |
| 1002 | const struct user_regset *regset, |
| 1003 | unsigned int pos, unsigned int count, |
| 1004 | void *kbuf, void __user *ubuf) |
| 1005 | { |
| 1006 | unsigned int *data = &task_thread_info(target)->system_call; |
| 1007 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 1008 | data, 0, sizeof(unsigned int)); |
| 1009 | } |
| 1010 | |
| 1011 | static int s390_system_call_set(struct task_struct *target, |
| 1012 | const struct user_regset *regset, |
| 1013 | unsigned int pos, unsigned int count, |
| 1014 | const void *kbuf, const void __user *ubuf) |
| 1015 | { |
| 1016 | unsigned int *data = &task_thread_info(target)->system_call; |
| 1017 | return user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 1018 | data, 0, sizeof(unsigned int)); |
| 1019 | } |
| 1020 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 1021 | static const struct user_regset s390_regsets[] = { |
| 1022 | [REGSET_GENERAL] = { |
| 1023 | .core_note_type = NT_PRSTATUS, |
| 1024 | .n = sizeof(s390_regs) / sizeof(long), |
| 1025 | .size = sizeof(long), |
| 1026 | .align = sizeof(long), |
| 1027 | .get = s390_regs_get, |
| 1028 | .set = s390_regs_set, |
| 1029 | }, |
| 1030 | [REGSET_FP] = { |
| 1031 | .core_note_type = NT_PRFPREG, |
| 1032 | .n = sizeof(s390_fp_regs) / sizeof(long), |
| 1033 | .size = sizeof(long), |
| 1034 | .align = sizeof(long), |
| 1035 | .get = s390_fpregs_get, |
| 1036 | .set = s390_fpregs_set, |
| 1037 | }, |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 1038 | #ifdef CONFIG_64BIT |
| 1039 | [REGSET_LAST_BREAK] = { |
| 1040 | .core_note_type = NT_S390_LAST_BREAK, |
| 1041 | .n = 1, |
| 1042 | .size = sizeof(long), |
| 1043 | .align = sizeof(long), |
| 1044 | .get = s390_last_break_get, |
Martin Schwidefsky | b934069 | 2011-12-01 13:32:17 +0100 | [diff] [blame] | 1045 | .set = s390_last_break_set, |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 1046 | }, |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 1047 | [REGSET_TDB] = { |
| 1048 | .core_note_type = NT_S390_TDB, |
| 1049 | .n = 1, |
| 1050 | .size = 256, |
| 1051 | .align = 1, |
| 1052 | .get = s390_tdb_get, |
| 1053 | .set = s390_tdb_set, |
| 1054 | }, |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 1055 | #endif |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 1056 | [REGSET_SYSTEM_CALL] = { |
| 1057 | .core_note_type = NT_S390_SYSTEM_CALL, |
| 1058 | .n = 1, |
| 1059 | .size = sizeof(unsigned int), |
| 1060 | .align = sizeof(unsigned int), |
| 1061 | .get = s390_system_call_get, |
| 1062 | .set = s390_system_call_set, |
| 1063 | }, |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 1064 | }; |
| 1065 | |
| 1066 | static const struct user_regset_view user_s390_view = { |
| 1067 | .name = UTS_MACHINE, |
| 1068 | .e_machine = EM_S390, |
| 1069 | .regsets = s390_regsets, |
| 1070 | .n = ARRAY_SIZE(s390_regsets) |
| 1071 | }; |
| 1072 | |
| 1073 | #ifdef CONFIG_COMPAT |
| 1074 | static int s390_compat_regs_get(struct task_struct *target, |
| 1075 | const struct user_regset *regset, |
| 1076 | unsigned int pos, unsigned int count, |
| 1077 | void *kbuf, void __user *ubuf) |
| 1078 | { |
| 1079 | if (target == current) |
| 1080 | save_access_regs(target->thread.acrs); |
| 1081 | |
| 1082 | if (kbuf) { |
| 1083 | compat_ulong_t *k = kbuf; |
| 1084 | while (count > 0) { |
| 1085 | *k++ = __peek_user_compat(target, pos); |
| 1086 | count -= sizeof(*k); |
| 1087 | pos += sizeof(*k); |
| 1088 | } |
| 1089 | } else { |
| 1090 | compat_ulong_t __user *u = ubuf; |
| 1091 | while (count > 0) { |
| 1092 | if (__put_user(__peek_user_compat(target, pos), u++)) |
| 1093 | return -EFAULT; |
| 1094 | count -= sizeof(*u); |
| 1095 | pos += sizeof(*u); |
| 1096 | } |
| 1097 | } |
| 1098 | return 0; |
| 1099 | } |
| 1100 | |
| 1101 | static int s390_compat_regs_set(struct task_struct *target, |
| 1102 | const struct user_regset *regset, |
| 1103 | unsigned int pos, unsigned int count, |
| 1104 | const void *kbuf, const void __user *ubuf) |
| 1105 | { |
| 1106 | int rc = 0; |
| 1107 | |
| 1108 | if (target == current) |
| 1109 | save_access_regs(target->thread.acrs); |
| 1110 | |
| 1111 | if (kbuf) { |
| 1112 | const compat_ulong_t *k = kbuf; |
| 1113 | while (count > 0 && !rc) { |
| 1114 | rc = __poke_user_compat(target, pos, *k++); |
| 1115 | count -= sizeof(*k); |
| 1116 | pos += sizeof(*k); |
| 1117 | } |
| 1118 | } else { |
| 1119 | const compat_ulong_t __user *u = ubuf; |
| 1120 | while (count > 0 && !rc) { |
| 1121 | compat_ulong_t word; |
| 1122 | rc = __get_user(word, u++); |
| 1123 | if (rc) |
| 1124 | break; |
| 1125 | rc = __poke_user_compat(target, pos, word); |
| 1126 | count -= sizeof(*u); |
| 1127 | pos += sizeof(*u); |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | if (rc == 0 && target == current) |
| 1132 | restore_access_regs(target->thread.acrs); |
| 1133 | |
| 1134 | return rc; |
| 1135 | } |
| 1136 | |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 1137 | static int s390_compat_regs_high_get(struct task_struct *target, |
| 1138 | const struct user_regset *regset, |
| 1139 | unsigned int pos, unsigned int count, |
| 1140 | void *kbuf, void __user *ubuf) |
| 1141 | { |
| 1142 | compat_ulong_t *gprs_high; |
| 1143 | |
| 1144 | gprs_high = (compat_ulong_t *) |
| 1145 | &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)]; |
| 1146 | if (kbuf) { |
| 1147 | compat_ulong_t *k = kbuf; |
| 1148 | while (count > 0) { |
| 1149 | *k++ = *gprs_high; |
| 1150 | gprs_high += 2; |
| 1151 | count -= sizeof(*k); |
| 1152 | } |
| 1153 | } else { |
| 1154 | compat_ulong_t __user *u = ubuf; |
| 1155 | while (count > 0) { |
| 1156 | if (__put_user(*gprs_high, u++)) |
| 1157 | return -EFAULT; |
| 1158 | gprs_high += 2; |
| 1159 | count -= sizeof(*u); |
| 1160 | } |
| 1161 | } |
| 1162 | return 0; |
| 1163 | } |
| 1164 | |
| 1165 | static int s390_compat_regs_high_set(struct task_struct *target, |
| 1166 | const struct user_regset *regset, |
| 1167 | unsigned int pos, unsigned int count, |
| 1168 | const void *kbuf, const void __user *ubuf) |
| 1169 | { |
| 1170 | compat_ulong_t *gprs_high; |
| 1171 | int rc = 0; |
| 1172 | |
| 1173 | gprs_high = (compat_ulong_t *) |
| 1174 | &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)]; |
| 1175 | if (kbuf) { |
| 1176 | const compat_ulong_t *k = kbuf; |
| 1177 | while (count > 0) { |
| 1178 | *gprs_high = *k++; |
| 1179 | *gprs_high += 2; |
| 1180 | count -= sizeof(*k); |
| 1181 | } |
| 1182 | } else { |
| 1183 | const compat_ulong_t __user *u = ubuf; |
| 1184 | while (count > 0 && !rc) { |
| 1185 | unsigned long word; |
| 1186 | rc = __get_user(word, u++); |
| 1187 | if (rc) |
| 1188 | break; |
| 1189 | *gprs_high = word; |
| 1190 | *gprs_high += 2; |
| 1191 | count -= sizeof(*u); |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | return rc; |
| 1196 | } |
| 1197 | |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 1198 | static int s390_compat_last_break_get(struct task_struct *target, |
| 1199 | const struct user_regset *regset, |
| 1200 | unsigned int pos, unsigned int count, |
| 1201 | void *kbuf, void __user *ubuf) |
| 1202 | { |
| 1203 | compat_ulong_t last_break; |
| 1204 | |
| 1205 | if (count > 0) { |
| 1206 | last_break = task_thread_info(target)->last_break; |
| 1207 | if (kbuf) { |
| 1208 | unsigned long *k = kbuf; |
| 1209 | *k = last_break; |
| 1210 | } else { |
| 1211 | unsigned long __user *u = ubuf; |
| 1212 | if (__put_user(last_break, u)) |
| 1213 | return -EFAULT; |
| 1214 | } |
| 1215 | } |
| 1216 | return 0; |
| 1217 | } |
| 1218 | |
Martin Schwidefsky | b934069 | 2011-12-01 13:32:17 +0100 | [diff] [blame] | 1219 | static int s390_compat_last_break_set(struct task_struct *target, |
| 1220 | const struct user_regset *regset, |
| 1221 | unsigned int pos, unsigned int count, |
| 1222 | const void *kbuf, const void __user *ubuf) |
| 1223 | { |
| 1224 | return 0; |
| 1225 | } |
| 1226 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 1227 | static const struct user_regset s390_compat_regsets[] = { |
| 1228 | [REGSET_GENERAL] = { |
| 1229 | .core_note_type = NT_PRSTATUS, |
| 1230 | .n = sizeof(s390_compat_regs) / sizeof(compat_long_t), |
| 1231 | .size = sizeof(compat_long_t), |
| 1232 | .align = sizeof(compat_long_t), |
| 1233 | .get = s390_compat_regs_get, |
| 1234 | .set = s390_compat_regs_set, |
| 1235 | }, |
| 1236 | [REGSET_FP] = { |
| 1237 | .core_note_type = NT_PRFPREG, |
| 1238 | .n = sizeof(s390_fp_regs) / sizeof(compat_long_t), |
| 1239 | .size = sizeof(compat_long_t), |
| 1240 | .align = sizeof(compat_long_t), |
| 1241 | .get = s390_fpregs_get, |
| 1242 | .set = s390_fpregs_set, |
| 1243 | }, |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 1244 | [REGSET_LAST_BREAK] = { |
| 1245 | .core_note_type = NT_S390_LAST_BREAK, |
| 1246 | .n = 1, |
| 1247 | .size = sizeof(long), |
| 1248 | .align = sizeof(long), |
| 1249 | .get = s390_compat_last_break_get, |
Martin Schwidefsky | b934069 | 2011-12-01 13:32:17 +0100 | [diff] [blame] | 1250 | .set = s390_compat_last_break_set, |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 1251 | }, |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 1252 | [REGSET_TDB] = { |
| 1253 | .core_note_type = NT_S390_TDB, |
| 1254 | .n = 1, |
| 1255 | .size = 256, |
| 1256 | .align = 1, |
| 1257 | .get = s390_tdb_get, |
| 1258 | .set = s390_tdb_set, |
| 1259 | }, |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 1260 | [REGSET_SYSTEM_CALL] = { |
| 1261 | .core_note_type = NT_S390_SYSTEM_CALL, |
| 1262 | .n = 1, |
| 1263 | .size = sizeof(compat_uint_t), |
| 1264 | .align = sizeof(compat_uint_t), |
| 1265 | .get = s390_system_call_get, |
| 1266 | .set = s390_system_call_set, |
| 1267 | }, |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 1268 | [REGSET_GENERAL_EXTENDED] = { |
Martin Schwidefsky | 622e99b | 2009-12-18 17:43:20 +0100 | [diff] [blame] | 1269 | .core_note_type = NT_S390_HIGH_GPRS, |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 1270 | .n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t), |
| 1271 | .size = sizeof(compat_long_t), |
| 1272 | .align = sizeof(compat_long_t), |
| 1273 | .get = s390_compat_regs_high_get, |
| 1274 | .set = s390_compat_regs_high_set, |
| 1275 | }, |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 1276 | }; |
| 1277 | |
| 1278 | static const struct user_regset_view user_s390_compat_view = { |
| 1279 | .name = "s390", |
| 1280 | .e_machine = EM_S390, |
| 1281 | .regsets = s390_compat_regsets, |
| 1282 | .n = ARRAY_SIZE(s390_compat_regsets) |
| 1283 | }; |
| 1284 | #endif |
| 1285 | |
| 1286 | const struct user_regset_view *task_user_regset_view(struct task_struct *task) |
| 1287 | { |
| 1288 | #ifdef CONFIG_COMPAT |
| 1289 | if (test_tsk_thread_flag(task, TIF_31BIT)) |
| 1290 | return &user_s390_compat_view; |
| 1291 | #endif |
| 1292 | return &user_s390_view; |
| 1293 | } |
Heiko Carstens | 952974ac6 | 2010-02-12 13:38:40 +0100 | [diff] [blame] | 1294 | |
| 1295 | static const char *gpr_names[NUM_GPRS] = { |
| 1296 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 1297 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 1298 | }; |
| 1299 | |
| 1300 | unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset) |
| 1301 | { |
| 1302 | if (offset >= NUM_GPRS) |
| 1303 | return 0; |
| 1304 | return regs->gprs[offset]; |
| 1305 | } |
| 1306 | |
| 1307 | int regs_query_register_offset(const char *name) |
| 1308 | { |
| 1309 | unsigned long offset; |
| 1310 | |
| 1311 | if (!name || *name != 'r') |
| 1312 | return -EINVAL; |
Heiko Carstens | 958d907 | 2013-07-22 06:43:57 +0200 | [diff] [blame] | 1313 | if (kstrtoul(name + 1, 10, &offset)) |
Heiko Carstens | 952974ac6 | 2010-02-12 13:38:40 +0100 | [diff] [blame] | 1314 | return -EINVAL; |
| 1315 | if (offset >= NUM_GPRS) |
| 1316 | return -EINVAL; |
| 1317 | return offset; |
| 1318 | } |
| 1319 | |
| 1320 | const char *regs_query_register_name(unsigned int offset) |
| 1321 | { |
| 1322 | if (offset >= NUM_GPRS) |
| 1323 | return NULL; |
| 1324 | return gpr_names[offset]; |
| 1325 | } |
| 1326 | |
| 1327 | static int regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr) |
| 1328 | { |
| 1329 | unsigned long ksp = kernel_stack_pointer(regs); |
| 1330 | |
| 1331 | return (addr & ~(THREAD_SIZE - 1)) == (ksp & ~(THREAD_SIZE - 1)); |
| 1332 | } |
| 1333 | |
| 1334 | /** |
| 1335 | * regs_get_kernel_stack_nth() - get Nth entry of the stack |
| 1336 | * @regs:pt_regs which contains kernel stack pointer. |
| 1337 | * @n:stack entry number. |
| 1338 | * |
| 1339 | * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which |
| 1340 | * is specifined by @regs. If the @n th entry is NOT in the kernel stack, |
| 1341 | * this returns 0. |
| 1342 | */ |
| 1343 | unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n) |
| 1344 | { |
| 1345 | unsigned long addr; |
| 1346 | |
| 1347 | addr = kernel_stack_pointer(regs) + n * sizeof(long); |
| 1348 | if (!regs_within_kernel_stack(regs, addr)) |
| 1349 | return 0; |
| 1350 | return *(unsigned long *)addr; |
| 1351 | } |