Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
5e9a2692 | 2 | * Ptrace user space interface. |
1da177e4 | 3 | * |
a53c8fab | 4 | * Copyright IBM Corp. 1999, 2010 |
5e9a2692 | 5 | * Author(s): Denis Joseph Barrow |
1da177e4 | 6 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
1da177e4 LT |
7 | */ |
8 | ||
9 | #include <linux/kernel.h> | |
10 | #include <linux/sched.h> | |
11 | #include <linux/mm.h> | |
12 | #include <linux/smp.h> | |
1da177e4 LT |
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> | |
7ed20e1a | 18 | #include <linux/signal.h> |
63506c41 MS |
19 | #include <linux/elf.h> |
20 | #include <linux/regset.h> | |
753c4dd6 | 21 | #include <linux/tracehook.h> |
bcf5cef7 | 22 | #include <linux/seccomp.h> |
048cd4e5 | 23 | #include <linux/compat.h> |
9bf1226b | 24 | #include <trace/syscall.h> |
1da177e4 LT |
25 | #include <asm/segment.h> |
26 | #include <asm/page.h> | |
27 | #include <asm/pgtable.h> | |
28 | #include <asm/pgalloc.h> | |
1da177e4 | 29 | #include <asm/uaccess.h> |
778959db | 30 | #include <asm/unistd.h> |
a0616cde | 31 | #include <asm/switch_to.h> |
a806170e | 32 | #include "entry.h" |
1da177e4 | 33 | |
347a8dc3 | 34 | #ifdef CONFIG_COMPAT |
1da177e4 LT |
35 | #include "compat_ptrace.h" |
36 | #endif | |
37 | ||
1c569f02 JS |
38 | #define CREATE_TRACE_POINTS |
39 | #include <trace/events/syscalls.h> | |
5e9ad7df | 40 | |
63506c41 MS |
41 | enum s390_regset { |
42 | REGSET_GENERAL, | |
43 | REGSET_FP, | |
86f2552b | 44 | REGSET_LAST_BREAK, |
d35339a4 | 45 | REGSET_TDB, |
20b40a79 | 46 | REGSET_SYSTEM_CALL, |
ea2a4d3a | 47 | REGSET_GENERAL_EXTENDED, |
63506c41 MS |
48 | }; |
49 | ||
64597f9d | 50 | void update_cr_regs(struct task_struct *task) |
1da177e4 | 51 | { |
5e9a2692 MS |
52 | struct pt_regs *regs = task_pt_regs(task); |
53 | struct thread_struct *thread = &task->thread; | |
a45aff52 | 54 | struct per_regs old, new; |
5e9a2692 | 55 | |
66389e85 | 56 | #ifdef CONFIG_64BIT |
d35339a4 MS |
57 | /* Take care of the enable/disable of transactional execution. */ |
58 | if (MACHINE_HAS_TE) { | |
64597f9d | 59 | unsigned long cr[3], cr_new[3]; |
d35339a4 | 60 | |
64597f9d MM |
61 | __ctl_store(cr, 0, 2); |
62 | cr_new[1] = cr[1]; | |
0628a5fb | 63 | /* Set or clear transaction execution TXC bit 8. */ |
d35339a4 | 64 | if (task->thread.per_flags & PER_FLAG_NO_TE) |
0628a5fb | 65 | cr_new[0] = cr[0] & ~(1UL << 55); |
d35339a4 | 66 | else |
0628a5fb | 67 | cr_new[0] = cr[0] | (1UL << 55); |
64597f9d MM |
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); | |
d35339a4 | 78 | } |
66389e85 | 79 | #endif |
a45aff52 MS |
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; | |
d35339a4 MS |
88 | #ifdef CONFIG_64BIT |
89 | new.control |= PER_CONTROL_SUSPENSION; | |
90 | new.control |= PER_EVENT_TRANSACTION_END; | |
91 | #endif | |
a45aff52 MS |
92 | new.start = 0; |
93 | new.end = PSW_ADDR_INSN; | |
94 | } | |
5e9a2692 MS |
95 | |
96 | /* Take care of the PER enablement bit in the PSW. */ | |
a45aff52 | 97 | if (!(new.control & PER_EVENT_MASK)) { |
1da177e4 | 98 | regs->psw.mask &= ~PSW_MASK_PER; |
5e9a2692 | 99 | return; |
c3311c13 | 100 | } |
5e9a2692 MS |
101 | regs->psw.mask |= PSW_MASK_PER; |
102 | __ctl_store(old, 9, 11); | |
a45aff52 MS |
103 | if (memcmp(&new, &old, sizeof(struct per_regs)) != 0) |
104 | __ctl_load(new, 9, 11); | |
1da177e4 LT |
105 | } |
106 | ||
0ac30be4 | 107 | void user_enable_single_step(struct task_struct *task) |
1da177e4 | 108 | { |
5e9a2692 MS |
109 | set_tsk_thread_flag(task, TIF_SINGLE_STEP); |
110 | if (task == current) | |
64597f9d | 111 | update_cr_regs(task); |
1da177e4 LT |
112 | } |
113 | ||
0ac30be4 | 114 | void user_disable_single_step(struct task_struct *task) |
1da177e4 | 115 | { |
5e9a2692 MS |
116 | clear_tsk_thread_flag(task, TIF_SINGLE_STEP); |
117 | if (task == current) | |
64597f9d | 118 | update_cr_regs(task); |
1da177e4 LT |
119 | } |
120 | ||
121 | /* | |
122 | * Called by kernel/ptrace.c when detaching.. | |
123 | * | |
5e9a2692 | 124 | * Clear all debugging related fields. |
1da177e4 | 125 | */ |
5e9a2692 | 126 | void ptrace_disable(struct task_struct *task) |
1da177e4 | 127 | { |
5e9a2692 MS |
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); | |
d35339a4 | 132 | task->thread.per_flags = 0; |
1da177e4 LT |
133 | } |
134 | ||
347a8dc3 | 135 | #ifndef CONFIG_64BIT |
1da177e4 LT |
136 | # define __ADDR_MASK 3 |
137 | #else | |
138 | # define __ADDR_MASK 7 | |
139 | #endif | |
140 | ||
5e9a2692 MS |
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 | ||
1da177e4 LT |
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 | */ | |
63506c41 | 191 | static unsigned long __peek_user(struct task_struct *child, addr_t addr) |
1da177e4 LT |
192 | { |
193 | struct user *dummy = NULL; | |
63506c41 | 194 | addr_t offset, tmp; |
1da177e4 LT |
195 | |
196 | if (addr < (addr_t) &dummy->regs.acrs) { | |
197 | /* | |
198 | * psw and gprs are stored on the stack | |
199 | */ | |
c7584fb6 | 200 | tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr); |
5ebf250d | 201 | if (addr == (addr_t) &dummy->regs.psw.mask) { |
b50511e4 | 202 | /* Return a clean psw mask. */ |
5ebf250d HC |
203 | tmp &= PSW_MASK_USER | PSW_MASK_RI; |
204 | tmp |= PSW_USER_BITS; | |
205 | } | |
1da177e4 LT |
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; | |
347a8dc3 | 212 | #ifdef CONFIG_64BIT |
778959db MS |
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 | |
1da177e4 LT |
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 | */ | |
c7584fb6 | 228 | tmp = (addr_t) task_pt_regs(child)->orig_gpr2; |
1da177e4 | 229 | |
3d6e48f4 JW |
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 | ||
1da177e4 LT |
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); | |
778959db | 243 | if (addr == (addr_t) &dummy->regs.fp_regs.fpc) |
4725c860 | 244 | tmp <<= BITS_PER_LONG - 32; |
1da177e4 LT |
245 | |
246 | } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) { | |
247 | /* | |
5e9a2692 | 248 | * Handle access to the per_info structure. |
1da177e4 | 249 | */ |
5e9a2692 MS |
250 | addr -= (addr_t) &dummy->regs.per_info; |
251 | tmp = __peek_user_per(child, addr); | |
1da177e4 LT |
252 | |
253 | } else | |
254 | tmp = 0; | |
255 | ||
63506c41 | 256 | return tmp; |
1da177e4 LT |
257 | } |
258 | ||
1da177e4 | 259 | static int |
63506c41 | 260 | peek_user(struct task_struct *child, addr_t addr, addr_t data) |
1da177e4 | 261 | { |
63506c41 | 262 | addr_t tmp, mask; |
1da177e4 LT |
263 | |
264 | /* | |
265 | * Stupid gdb peeks/pokes the access registers in 64 bit with | |
63506c41 | 266 | * an alignment of 4. Programmers from hell... |
1da177e4 | 267 | */ |
778959db | 268 | mask = __ADDR_MASK; |
347a8dc3 | 269 | #ifdef CONFIG_64BIT |
547e3cec MS |
270 | if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs && |
271 | addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2) | |
778959db MS |
272 | mask = 3; |
273 | #endif | |
274 | if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK) | |
1da177e4 LT |
275 | return -EIO; |
276 | ||
63506c41 MS |
277 | tmp = __peek_user(child, addr); |
278 | return put_user(tmp, (addr_t __user *) data); | |
279 | } | |
280 | ||
5e9a2692 MS |
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 | ||
63506c41 MS |
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; | |
d4e81b35 | 319 | addr_t offset; |
63506c41 | 320 | |
1da177e4 LT |
321 | if (addr < (addr_t) &dummy->regs.acrs) { |
322 | /* | |
323 | * psw and gprs are stored on the stack | |
324 | */ | |
5ebf250d HC |
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 | } | |
c7584fb6 | 334 | *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data; |
1da177e4 LT |
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; | |
347a8dc3 | 341 | #ifdef CONFIG_64BIT |
778959db MS |
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 | |
1da177e4 LT |
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 | */ | |
c7584fb6 | 358 | task_pt_regs(child)->orig_gpr2 = data; |
1da177e4 | 359 | |
3d6e48f4 JW |
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 | ||
1da177e4 LT |
367 | } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) { |
368 | /* | |
369 | * floating point regs. are stored in the thread structure | |
370 | */ | |
4725c860 MS |
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; | |
1da177e4 LT |
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 | /* | |
5e9a2692 | 380 | * Handle access to the per_info structure. |
1da177e4 | 381 | */ |
5e9a2692 MS |
382 | addr -= (addr_t) &dummy->regs.per_info; |
383 | __poke_user_per(child, addr, data); | |
1da177e4 LT |
384 | |
385 | } | |
386 | ||
1da177e4 LT |
387 | return 0; |
388 | } | |
389 | ||
5e9a2692 | 390 | static int poke_user(struct task_struct *child, addr_t addr, addr_t data) |
63506c41 | 391 | { |
63506c41 MS |
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 | |
547e3cec MS |
400 | if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs && |
401 | addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2) | |
63506c41 MS |
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 | ||
9b05a69e NK |
410 | long arch_ptrace(struct task_struct *child, long request, |
411 | unsigned long addr, unsigned long data) | |
1da177e4 | 412 | { |
1da177e4 LT |
413 | ptrace_area parea; |
414 | int copied, ret; | |
415 | ||
416 | switch (request) { | |
1da177e4 LT |
417 | case PTRACE_PEEKUSR: |
418 | /* read the word at location addr in the USER area. */ | |
419 | return peek_user(child, addr, data); | |
420 | ||
1da177e4 LT |
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: | |
2b67fc46 | 427 | if (copy_from_user(&parea, (void __force __user *) addr, |
1da177e4 LT |
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 { | |
2b67fc46 HC |
437 | addr_t utmp; |
438 | if (get_user(utmp, | |
439 | (addr_t __force __user *) data)) | |
1da177e4 | 440 | return -EFAULT; |
2b67fc46 | 441 | ret = poke_user(child, addr, utmp); |
1da177e4 LT |
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; | |
86f2552b MS |
450 | case PTRACE_GET_LAST_BREAK: |
451 | put_user(task_thread_info(child)->last_break, | |
452 | (unsigned long __user *) data); | |
453 | return 0; | |
d35339a4 MS |
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; | |
64597f9d MM |
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 | } | |
d35339a4 | 483 | return 0; |
07805ac8 CB |
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); | |
1da177e4 | 488 | } |
1da177e4 LT |
489 | } |
490 | ||
347a8dc3 | 491 | #ifdef CONFIG_COMPAT |
1da177e4 LT |
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 | ||
5e9a2692 MS |
506 | /* |
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 | ||
1da177e4 LT |
548 | /* |
549 | * Same as peek_user but for a 31 bit program. | |
550 | */ | |
63506c41 | 551 | static u32 __peek_user_compat(struct task_struct *child, addr_t addr) |
1da177e4 | 552 | { |
5e9a2692 | 553 | struct compat_user *dummy32 = NULL; |
1da177e4 LT |
554 | addr_t offset; |
555 | __u32 tmp; | |
556 | ||
1da177e4 | 557 | if (addr < (addr_t) &dummy32->regs.acrs) { |
b50511e4 | 558 | struct pt_regs *regs = task_pt_regs(child); |
1da177e4 LT |
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. */ | |
b50511e4 | 564 | tmp = (__u32)(regs->psw.mask >> 32); |
5ebf250d | 565 | tmp &= PSW32_MASK_USER | PSW32_MASK_RI; |
f26946d7 | 566 | tmp |= PSW32_USER_BITS; |
1da177e4 LT |
567 | } else if (addr == (addr_t) &dummy32->regs.psw.addr) { |
568 | /* Fake a 31 bit psw address. */ | |
d4e81b35 MS |
569 | tmp = (__u32) regs->psw.addr | |
570 | (__u32)(regs->psw.mask & PSW_MASK_BA); | |
1da177e4 LT |
571 | } else { |
572 | /* gpr 0-15 */ | |
b50511e4 | 573 | tmp = *(__u32 *)((addr_t) ®s->psw + addr*2 + 4); |
1da177e4 LT |
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 | */ | |
c7584fb6 | 586 | tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4); |
1da177e4 | 587 | |
3d6e48f4 JW |
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 | ||
1da177e4 LT |
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 | /* | |
5e9a2692 | 604 | * Handle access to the per_info structure. |
1da177e4 | 605 | */ |
5e9a2692 MS |
606 | addr -= (addr_t) &dummy32->regs.per_info; |
607 | tmp = __peek_user_per_compat(child, addr); | |
1da177e4 LT |
608 | |
609 | } else | |
610 | tmp = 0; | |
611 | ||
63506c41 MS |
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 | ||
7757591a | 620 | if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3) |
63506c41 MS |
621 | return -EIO; |
622 | ||
623 | tmp = __peek_user_compat(child, addr); | |
1da177e4 LT |
624 | return put_user(tmp, (__u32 __user *) data); |
625 | } | |
626 | ||
5e9a2692 MS |
627 | /* |
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 | ||
1da177e4 LT |
647 | /* |
648 | * Same as poke_user but for a 31 bit program. | |
649 | */ | |
63506c41 MS |
650 | static int __poke_user_compat(struct task_struct *child, |
651 | addr_t addr, addr_t data) | |
1da177e4 | 652 | { |
5e9a2692 | 653 | struct compat_user *dummy32 = NULL; |
63506c41 | 654 | __u32 tmp = (__u32) data; |
1da177e4 | 655 | addr_t offset; |
1da177e4 LT |
656 | |
657 | if (addr < (addr_t) &dummy32->regs.acrs) { | |
b50511e4 | 658 | struct pt_regs *regs = task_pt_regs(child); |
1da177e4 LT |
659 | /* |
660 | * psw, gprs, acrs and orig_gpr2 are stored on the stack | |
661 | */ | |
662 | if (addr == (addr_t) &dummy32->regs.psw.mask) { | |
5ebf250d HC |
663 | __u32 mask = PSW32_MASK_USER; |
664 | ||
665 | mask |= is_ri_task(child) ? PSW32_MASK_RI : 0; | |
1da177e4 | 666 | /* Build a 64 bit psw mask from 31 bit mask. */ |
f26946d7 | 667 | if ((tmp & ~mask) != PSW32_USER_BITS) |
1da177e4 LT |
668 | /* Invalid psw mask. */ |
669 | return -EINVAL; | |
b50511e4 | 670 | regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) | |
d4e81b35 | 671 | (regs->psw.mask & PSW_MASK_BA) | |
5ebf250d | 672 | (__u64)(tmp & mask) << 32; |
1da177e4 LT |
673 | } else if (addr == (addr_t) &dummy32->regs.psw.addr) { |
674 | /* Build a 64 bit psw address from 31 bit address. */ | |
b50511e4 | 675 | regs->psw.addr = (__u64) tmp & PSW32_ADDR_INSN; |
d4e81b35 MS |
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); | |
1da177e4 LT |
679 | } else { |
680 | /* gpr 0-15 */ | |
b50511e4 | 681 | *(__u32*)((addr_t) ®s->psw + addr*2 + 4) = tmp; |
1da177e4 LT |
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 | */ | |
c7584fb6 | 694 | *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp; |
1da177e4 | 695 | |
3d6e48f4 JW |
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 | ||
1da177e4 LT |
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 && | |
4725c860 | 708 | test_fp_ctl(tmp)) |
1da177e4 LT |
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 | /* | |
5e9a2692 | 715 | * Handle access to the per_info structure. |
1da177e4 | 716 | */ |
5e9a2692 MS |
717 | addr -= (addr_t) &dummy32->regs.per_info; |
718 | __poke_user_per_compat(child, addr, data); | |
1da177e4 LT |
719 | } |
720 | ||
1da177e4 LT |
721 | return 0; |
722 | } | |
723 | ||
63506c41 MS |
724 | static int poke_user_compat(struct task_struct *child, |
725 | addr_t addr, addr_t data) | |
726 | { | |
5e9a2692 MS |
727 | if (!is_compat_task() || (addr & 3) || |
728 | addr > sizeof(struct compat_user) - 3) | |
63506c41 MS |
729 | return -EIO; |
730 | ||
731 | return __poke_user_compat(child, addr, data); | |
732 | } | |
733 | ||
b499d76b RM |
734 | long compat_arch_ptrace(struct task_struct *child, compat_long_t request, |
735 | compat_ulong_t caddr, compat_ulong_t cdata) | |
1da177e4 | 736 | { |
b499d76b RM |
737 | unsigned long addr = caddr; |
738 | unsigned long data = cdata; | |
5e9a2692 | 739 | compat_ptrace_area parea; |
1da177e4 LT |
740 | int copied, ret; |
741 | ||
742 | switch (request) { | |
1da177e4 LT |
743 | case PTRACE_PEEKUSR: |
744 | /* read the word at location addr in the USER area. */ | |
63506c41 | 745 | return peek_user_compat(child, addr, data); |
1da177e4 | 746 | |
1da177e4 LT |
747 | case PTRACE_POKEUSR: |
748 | /* write the word at location addr in the USER area */ | |
63506c41 | 749 | return poke_user_compat(child, addr, data); |
1da177e4 LT |
750 | |
751 | case PTRACE_PEEKUSR_AREA: | |
752 | case PTRACE_POKEUSR_AREA: | |
2b67fc46 | 753 | if (copy_from_user(&parea, (void __force __user *) addr, |
1da177e4 LT |
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) | |
63506c41 | 761 | ret = peek_user_compat(child, addr, data); |
1da177e4 | 762 | else { |
2b67fc46 HC |
763 | __u32 utmp; |
764 | if (get_user(utmp, | |
765 | (__u32 __force __user *) data)) | |
1da177e4 | 766 | return -EFAULT; |
63506c41 | 767 | ret = poke_user_compat(child, addr, utmp); |
1da177e4 LT |
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; | |
86f2552b MS |
776 | case PTRACE_GET_LAST_BREAK: |
777 | put_user(task_thread_info(child)->last_break, | |
778 | (unsigned int __user *) data); | |
779 | return 0; | |
1da177e4 | 780 | } |
b499d76b | 781 | return compat_ptrace_request(child, request, addr, data); |
1da177e4 LT |
782 | } |
783 | #endif | |
784 | ||
753c4dd6 | 785 | asmlinkage long do_syscall_trace_enter(struct pt_regs *regs) |
1da177e4 | 786 | { |
545c174d | 787 | long ret = 0; |
1da177e4 | 788 | |
bcf5cef7 | 789 | /* Do the secure computing check first. */ |
c63cb468 HC |
790 | if (secure_computing(regs->gprs[2])) { |
791 | /* seccomp failures shouldn't expose any additional code. */ | |
792 | ret = -1; | |
793 | goto out; | |
794 | } | |
bcf5cef7 | 795 | |
c5c3a6d8 | 796 | /* |
753c4dd6 MS |
797 | * The sysc_tracesys code in entry.S stored the system |
798 | * call number to gprs[2]. | |
c5c3a6d8 | 799 | */ |
753c4dd6 MS |
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 | */ | |
b6ef5bb3 | 808 | clear_thread_flag(TIF_SYSCALL); |
753c4dd6 | 809 | ret = -1; |
1da177e4 | 810 | } |
753c4dd6 | 811 | |
66700001 | 812 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
1c569f02 | 813 | trace_sys_enter(regs, regs->gprs[2]); |
9bf1226b | 814 | |
b05d8447 EP |
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]); | |
c63cb468 | 820 | out: |
545c174d | 821 | return ret ?: regs->gprs[2]; |
753c4dd6 MS |
822 | } |
823 | ||
824 | asmlinkage void do_syscall_trace_exit(struct pt_regs *regs) | |
825 | { | |
d7e7528b | 826 | audit_syscall_exit(regs); |
753c4dd6 | 827 | |
66700001 | 828 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
1c569f02 | 829 | trace_sys_exit(regs, regs->gprs[2]); |
9bf1226b | 830 | |
753c4dd6 MS |
831 | if (test_thread_flag(TIF_SYSCALL_TRACE)) |
832 | tracehook_report_syscall_exit(regs, 0); | |
1da177e4 | 833 | } |
63506c41 MS |
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 | { | |
4725c860 MS |
906 | if (target == current) { |
907 | save_fp_ctl(&target->thread.fp_regs.fpc); | |
908 | save_fp_regs(target->thread.fp_regs.fprs); | |
909 | } | |
63506c41 MS |
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 | ||
4725c860 MS |
922 | if (target == current) { |
923 | save_fp_ctl(&target->thread.fp_regs.fpc); | |
924 | save_fp_regs(target->thread.fp_regs.fprs); | |
925 | } | |
63506c41 MS |
926 | |
927 | /* If setting FPC, must validate it first. */ | |
928 | if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) { | |
4725c860 MS |
929 | u32 ufpc[2] = { target->thread.fp_regs.fpc, 0 }; |
930 | rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ufpc, | |
63506c41 MS |
931 | 0, offsetof(s390_fp_regs, fprs)); |
932 | if (rc) | |
933 | return rc; | |
4725c860 | 934 | if (ufpc[1] != 0 || test_fp_ctl(ufpc[0])) |
63506c41 | 935 | return -EINVAL; |
4725c860 | 936 | target->thread.fp_regs.fpc = ufpc[0]; |
63506c41 MS |
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 | ||
4725c860 MS |
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 | } | |
63506c41 MS |
948 | |
949 | return rc; | |
950 | } | |
951 | ||
86f2552b MS |
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 | ||
b934069c MS |
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 | ||
d35339a4 MS |
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 | ||
86f2552b MS |
1002 | #endif |
1003 | ||
20b40a79 MS |
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 | ||
63506c41 MS |
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 | }, | |
86f2552b MS |
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, | |
b934069c | 1048 | .set = s390_last_break_set, |
86f2552b | 1049 | }, |
d35339a4 MS |
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 | }, | |
86f2552b | 1058 | #endif |
20b40a79 MS |
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 | }, | |
63506c41 MS |
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 | ||
ea2a4d3a HC |
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 | ||
86f2552b MS |
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 | ||
b934069c MS |
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 | ||
63506c41 MS |
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 | }, | |
86f2552b MS |
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, | |
b934069c | 1253 | .set = s390_compat_last_break_set, |
86f2552b | 1254 | }, |
d35339a4 MS |
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 | }, | |
20b40a79 MS |
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 | }, | |
ea2a4d3a | 1271 | [REGSET_GENERAL_EXTENDED] = { |
622e99bf | 1272 | .core_note_type = NT_S390_HIGH_GPRS, |
ea2a4d3a HC |
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 | }, | |
63506c41 MS |
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 | } | |
952974ac HC |
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; | |
958d9072 | 1316 | if (kstrtoul(name + 1, 10, &offset)) |
952974ac HC |
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 | } |