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