mfd: wm8350-i2c: Make sure the i2c regmap functions are compiled
[linux/fpc-iii.git] / arch / s390 / kernel / ptrace.c
blobd4c5e6ba841090ff14a75b1b3c0f4267a86aff79
1 /*
2 * Ptrace user space interface.
4 * Copyright IBM Corp. 1999, 2010
5 * Author(s): Denis Joseph Barrow
6 * Martin Schwidefsky (schwidefsky@de.ibm.com)
7 */
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <linux/mm.h>
12 #include <linux/smp.h>
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>
18 #include <linux/signal.h>
19 #include <linux/elf.h>
20 #include <linux/regset.h>
21 #include <linux/tracehook.h>
22 #include <linux/seccomp.h>
23 #include <linux/compat.h>
24 #include <trace/syscall.h>
25 #include <asm/segment.h>
26 #include <asm/page.h>
27 #include <asm/pgtable.h>
28 #include <asm/pgalloc.h>
29 #include <asm/uaccess.h>
30 #include <asm/unistd.h>
31 #include <asm/switch_to.h>
32 #include "entry.h"
34 #ifdef CONFIG_COMPAT
35 #include "compat_ptrace.h"
36 #endif
38 #define CREATE_TRACE_POINTS
39 #include <trace/events/syscalls.h>
41 enum s390_regset {
42 REGSET_GENERAL,
43 REGSET_FP,
44 REGSET_LAST_BREAK,
45 REGSET_TDB,
46 REGSET_SYSTEM_CALL,
47 REGSET_GENERAL_EXTENDED,
50 void update_cr_regs(struct task_struct *task)
52 struct pt_regs *regs = task_pt_regs(task);
53 struct thread_struct *thread = &task->thread;
54 struct per_regs old, new;
56 #ifdef CONFIG_64BIT
57 /* Take care of the enable/disable of transactional execution. */
58 if (MACHINE_HAS_TE) {
59 unsigned long cr[3], cr_new[3];
61 __ctl_store(cr, 0, 2);
62 cr_new[1] = cr[1];
63 /* Set or clear transaction execution TXC bit 8. */
64 if (task->thread.per_flags & PER_FLAG_NO_TE)
65 cr_new[0] = cr[0] & ~(1UL << 55);
66 else
67 cr_new[0] = cr[0] | (1UL << 55);
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;
76 if (memcmp(&cr_new, &cr, sizeof(cr)))
77 __ctl_load(cr_new, 0, 2);
79 #endif
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;
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;
88 #ifdef CONFIG_64BIT
89 new.control |= PER_CONTROL_SUSPENSION;
90 new.control |= PER_EVENT_TRANSACTION_END;
91 #endif
92 new.start = 0;
93 new.end = PSW_ADDR_INSN;
96 /* Take care of the PER enablement bit in the PSW. */
97 if (!(new.control & PER_EVENT_MASK)) {
98 regs->psw.mask &= ~PSW_MASK_PER;
99 return;
101 regs->psw.mask |= PSW_MASK_PER;
102 __ctl_store(old, 9, 11);
103 if (memcmp(&new, &old, sizeof(struct per_regs)) != 0)
104 __ctl_load(new, 9, 11);
107 void user_enable_single_step(struct task_struct *task)
109 set_tsk_thread_flag(task, TIF_SINGLE_STEP);
110 if (task == current)
111 update_cr_regs(task);
114 void user_disable_single_step(struct task_struct *task)
116 clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
117 if (task == current)
118 update_cr_regs(task);
122 * Called by kernel/ptrace.c when detaching..
124 * Clear all debugging related fields.
126 void ptrace_disable(struct task_struct *task)
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);
132 task->thread.per_flags = 0;
135 #ifndef CONFIG_64BIT
136 # define __ADDR_MASK 3
137 #else
138 # define __ADDR_MASK 7
139 #endif
141 static inline unsigned long __peek_user_per(struct task_struct *child,
142 addr_t addr)
144 struct per_struct_kernel *dummy = NULL;
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;
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...
191 static unsigned long __peek_user(struct task_struct *child, addr_t addr)
193 struct user *dummy = NULL;
194 addr_t offset, tmp;
196 if (addr < (addr_t) &dummy->regs.acrs) {
198 * psw and gprs are stored on the stack
200 tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr);
201 if (addr == (addr_t) &dummy->regs.psw.mask)
202 /* Return a clean psw mask. */
203 tmp = psw_user_bits | (tmp & PSW_MASK_USER);
205 } else if (addr < (addr_t) &dummy->regs.orig_gpr2) {
207 * access registers are stored in the thread structure
209 offset = addr - (addr_t) &dummy->regs.acrs;
210 #ifdef CONFIG_64BIT
212 * Very special case: old & broken 64 bit gdb reading
213 * from acrs[15]. Result is a 64 bit value. Read the
214 * 32 bit acrs[15] value and shift it by 32. Sick...
216 if (addr == (addr_t) &dummy->regs.acrs[15])
217 tmp = ((unsigned long) child->thread.acrs[15]) << 32;
218 else
219 #endif
220 tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset);
222 } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
224 * orig_gpr2 is stored on the kernel stack
226 tmp = (addr_t) task_pt_regs(child)->orig_gpr2;
228 } else if (addr < (addr_t) &dummy->regs.fp_regs) {
230 * prevent reads of padding hole between
231 * orig_gpr2 and fp_regs on s390.
233 tmp = 0;
235 } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
237 * floating point regs. are stored in the thread structure
239 offset = addr - (addr_t) &dummy->regs.fp_regs;
240 tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset);
241 if (addr == (addr_t) &dummy->regs.fp_regs.fpc)
242 tmp &= (unsigned long) FPC_VALID_MASK
243 << (BITS_PER_LONG - 32);
245 } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
247 * Handle access to the per_info structure.
249 addr -= (addr_t) &dummy->regs.per_info;
250 tmp = __peek_user_per(child, addr);
252 } else
253 tmp = 0;
255 return tmp;
258 static int
259 peek_user(struct task_struct *child, addr_t addr, addr_t data)
261 addr_t tmp, mask;
264 * Stupid gdb peeks/pokes the access registers in 64 bit with
265 * an alignment of 4. Programmers from hell...
267 mask = __ADDR_MASK;
268 #ifdef CONFIG_64BIT
269 if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
270 addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
271 mask = 3;
272 #endif
273 if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
274 return -EIO;
276 tmp = __peek_user(child, addr);
277 return put_user(tmp, (addr_t __user *) data);
280 static inline void __poke_user_per(struct task_struct *child,
281 addr_t addr, addr_t data)
283 struct per_struct_kernel *dummy = NULL;
286 * There are only three fields in the per_info struct that the
287 * debugger user can write to.
288 * 1) cr9: the debugger wants to set a new PER event mask
289 * 2) starting_addr: the debugger wants to set a new starting
290 * address to use with the PER event mask.
291 * 3) ending_addr: the debugger wants to set a new ending
292 * address to use with the PER event mask.
293 * The user specified PER event mask and the start and end
294 * addresses are used only if single stepping is not in effect.
295 * Writes to any other field in per_info are ignored.
297 if (addr == (addr_t) &dummy->cr9)
298 /* PER event mask of the user specified per set. */
299 child->thread.per_user.control =
300 data & (PER_EVENT_MASK | PER_CONTROL_MASK);
301 else if (addr == (addr_t) &dummy->starting_addr)
302 /* Starting address of the user specified per set. */
303 child->thread.per_user.start = data;
304 else if (addr == (addr_t) &dummy->ending_addr)
305 /* Ending address of the user specified per set. */
306 child->thread.per_user.end = data;
310 * Write a word to the user area of a process at location addr. This
311 * operation does have an additional problem compared to peek_user.
312 * Stores to the program status word and on the floating point
313 * control register needs to get checked for validity.
315 static int __poke_user(struct task_struct *child, addr_t addr, addr_t data)
317 struct user *dummy = NULL;
318 addr_t offset;
320 if (addr < (addr_t) &dummy->regs.acrs) {
322 * psw and gprs are stored on the stack
324 if (addr == (addr_t) &dummy->regs.psw.mask &&
325 (((data^psw_user_bits) & ~PSW_MASK_USER) ||
326 (((data^psw_user_bits) & PSW_MASK_ASC) &&
327 ((data|psw_user_bits) & PSW_MASK_ASC) == PSW_MASK_ASC) ||
328 ((data & PSW_MASK_EA) && !(data & PSW_MASK_BA))))
329 /* Invalid psw mask. */
330 return -EINVAL;
331 *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data;
333 } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) {
335 * access registers are stored in the thread structure
337 offset = addr - (addr_t) &dummy->regs.acrs;
338 #ifdef CONFIG_64BIT
340 * Very special case: old & broken 64 bit gdb writing
341 * to acrs[15] with a 64 bit value. Ignore the lower
342 * half of the value and write the upper 32 bit to
343 * acrs[15]. Sick...
345 if (addr == (addr_t) &dummy->regs.acrs[15])
346 child->thread.acrs[15] = (unsigned int) (data >> 32);
347 else
348 #endif
349 *(addr_t *)((addr_t) &child->thread.acrs + offset) = data;
351 } else if (addr == (addr_t) &dummy->regs.orig_gpr2) {
353 * orig_gpr2 is stored on the kernel stack
355 task_pt_regs(child)->orig_gpr2 = data;
357 } else if (addr < (addr_t) &dummy->regs.fp_regs) {
359 * prevent writes of padding hole between
360 * orig_gpr2 and fp_regs on s390.
362 return 0;
364 } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
366 * floating point regs. are stored in the thread structure
368 if (addr == (addr_t) &dummy->regs.fp_regs.fpc &&
369 (data & ~((unsigned long) FPC_VALID_MASK
370 << (BITS_PER_LONG - 32))) != 0)
371 return -EINVAL;
372 offset = addr - (addr_t) &dummy->regs.fp_regs;
373 *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data;
375 } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) {
377 * Handle access to the per_info structure.
379 addr -= (addr_t) &dummy->regs.per_info;
380 __poke_user_per(child, addr, data);
384 return 0;
387 static int poke_user(struct task_struct *child, addr_t addr, addr_t data)
389 addr_t mask;
392 * Stupid gdb peeks/pokes the access registers in 64 bit with
393 * an alignment of 4. Programmers from hell indeed...
395 mask = __ADDR_MASK;
396 #ifdef CONFIG_64BIT
397 if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
398 addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
399 mask = 3;
400 #endif
401 if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
402 return -EIO;
404 return __poke_user(child, addr, data);
407 long arch_ptrace(struct task_struct *child, long request,
408 unsigned long addr, unsigned long data)
410 ptrace_area parea;
411 int copied, ret;
413 switch (request) {
414 case PTRACE_PEEKUSR:
415 /* read the word at location addr in the USER area. */
416 return peek_user(child, addr, data);
418 case PTRACE_POKEUSR:
419 /* write the word at location addr in the USER area */
420 return poke_user(child, addr, data);
422 case PTRACE_PEEKUSR_AREA:
423 case PTRACE_POKEUSR_AREA:
424 if (copy_from_user(&parea, (void __force __user *) addr,
425 sizeof(parea)))
426 return -EFAULT;
427 addr = parea.kernel_addr;
428 data = parea.process_addr;
429 copied = 0;
430 while (copied < parea.len) {
431 if (request == PTRACE_PEEKUSR_AREA)
432 ret = peek_user(child, addr, data);
433 else {
434 addr_t utmp;
435 if (get_user(utmp,
436 (addr_t __force __user *) data))
437 return -EFAULT;
438 ret = poke_user(child, addr, utmp);
440 if (ret)
441 return ret;
442 addr += sizeof(unsigned long);
443 data += sizeof(unsigned long);
444 copied += sizeof(unsigned long);
446 return 0;
447 case PTRACE_GET_LAST_BREAK:
448 put_user(task_thread_info(child)->last_break,
449 (unsigned long __user *) data);
450 return 0;
451 case PTRACE_ENABLE_TE:
452 if (!MACHINE_HAS_TE)
453 return -EIO;
454 child->thread.per_flags &= ~PER_FLAG_NO_TE;
455 return 0;
456 case PTRACE_DISABLE_TE:
457 if (!MACHINE_HAS_TE)
458 return -EIO;
459 child->thread.per_flags |= PER_FLAG_NO_TE;
460 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
461 return 0;
462 case PTRACE_TE_ABORT_RAND:
463 if (!MACHINE_HAS_TE || (child->thread.per_flags & PER_FLAG_NO_TE))
464 return -EIO;
465 switch (data) {
466 case 0UL:
467 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
468 break;
469 case 1UL:
470 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
471 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND_TEND;
472 break;
473 case 2UL:
474 child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
475 child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND_TEND;
476 break;
477 default:
478 return -EINVAL;
480 return 0;
481 default:
482 /* Removing high order bit from addr (only for 31 bit). */
483 addr &= PSW_ADDR_INSN;
484 return ptrace_request(child, request, addr, data);
488 #ifdef CONFIG_COMPAT
490 * Now the fun part starts... a 31 bit program running in the
491 * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
492 * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
493 * to handle, the difference to the 64 bit versions of the requests
494 * is that the access is done in multiples of 4 byte instead of
495 * 8 bytes (sizeof(unsigned long) on 31/64 bit).
496 * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
497 * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
498 * is a 31 bit program too, the content of struct user can be
499 * emulated. A 31 bit program peeking into the struct user of
500 * a 64 bit program is a no-no.
504 * Same as peek_user_per but for a 31 bit program.
506 static inline __u32 __peek_user_per_compat(struct task_struct *child,
507 addr_t addr)
509 struct compat_per_struct_kernel *dummy32 = NULL;
511 if (addr == (addr_t) &dummy32->cr9)
512 /* Control bits of the active per set. */
513 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
514 PER_EVENT_IFETCH : child->thread.per_user.control;
515 else if (addr == (addr_t) &dummy32->cr10)
516 /* Start address of the active per set. */
517 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
518 0 : child->thread.per_user.start;
519 else if (addr == (addr_t) &dummy32->cr11)
520 /* End address of the active per set. */
521 return test_thread_flag(TIF_SINGLE_STEP) ?
522 PSW32_ADDR_INSN : child->thread.per_user.end;
523 else if (addr == (addr_t) &dummy32->bits)
524 /* Single-step bit. */
525 return (__u32) test_thread_flag(TIF_SINGLE_STEP) ?
526 0x80000000 : 0;
527 else if (addr == (addr_t) &dummy32->starting_addr)
528 /* Start address of the user specified per set. */
529 return (__u32) child->thread.per_user.start;
530 else if (addr == (addr_t) &dummy32->ending_addr)
531 /* End address of the user specified per set. */
532 return (__u32) child->thread.per_user.end;
533 else if (addr == (addr_t) &dummy32->perc_atmid)
534 /* PER code, ATMID and AI of the last PER trap */
535 return (__u32) child->thread.per_event.cause << 16;
536 else if (addr == (addr_t) &dummy32->address)
537 /* Address of the last PER trap */
538 return (__u32) child->thread.per_event.address;
539 else if (addr == (addr_t) &dummy32->access_id)
540 /* Access id of the last PER trap */
541 return (__u32) child->thread.per_event.paid << 24;
542 return 0;
546 * Same as peek_user but for a 31 bit program.
548 static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
550 struct compat_user *dummy32 = NULL;
551 addr_t offset;
552 __u32 tmp;
554 if (addr < (addr_t) &dummy32->regs.acrs) {
555 struct pt_regs *regs = task_pt_regs(child);
557 * psw and gprs are stored on the stack
559 if (addr == (addr_t) &dummy32->regs.psw.mask) {
560 /* Fake a 31 bit psw mask. */
561 tmp = (__u32)(regs->psw.mask >> 32);
562 tmp = psw32_user_bits | (tmp & PSW32_MASK_USER);
563 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
564 /* Fake a 31 bit psw address. */
565 tmp = (__u32) regs->psw.addr |
566 (__u32)(regs->psw.mask & PSW_MASK_BA);
567 } else {
568 /* gpr 0-15 */
569 tmp = *(__u32 *)((addr_t) &regs->psw + addr*2 + 4);
571 } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
573 * access registers are stored in the thread structure
575 offset = addr - (addr_t) &dummy32->regs.acrs;
576 tmp = *(__u32*)((addr_t) &child->thread.acrs + offset);
578 } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
580 * orig_gpr2 is stored on the kernel stack
582 tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
584 } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
586 * prevent reads of padding hole between
587 * orig_gpr2 and fp_regs on s390.
589 tmp = 0;
591 } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
593 * floating point regs. are stored in the thread structure
595 offset = addr - (addr_t) &dummy32->regs.fp_regs;
596 tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset);
598 } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
600 * Handle access to the per_info structure.
602 addr -= (addr_t) &dummy32->regs.per_info;
603 tmp = __peek_user_per_compat(child, addr);
605 } else
606 tmp = 0;
608 return tmp;
611 static int peek_user_compat(struct task_struct *child,
612 addr_t addr, addr_t data)
614 __u32 tmp;
616 if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3)
617 return -EIO;
619 tmp = __peek_user_compat(child, addr);
620 return put_user(tmp, (__u32 __user *) data);
624 * Same as poke_user_per but for a 31 bit program.
626 static inline void __poke_user_per_compat(struct task_struct *child,
627 addr_t addr, __u32 data)
629 struct compat_per_struct_kernel *dummy32 = NULL;
631 if (addr == (addr_t) &dummy32->cr9)
632 /* PER event mask of the user specified per set. */
633 child->thread.per_user.control =
634 data & (PER_EVENT_MASK | PER_CONTROL_MASK);
635 else if (addr == (addr_t) &dummy32->starting_addr)
636 /* Starting address of the user specified per set. */
637 child->thread.per_user.start = data;
638 else if (addr == (addr_t) &dummy32->ending_addr)
639 /* Ending address of the user specified per set. */
640 child->thread.per_user.end = data;
644 * Same as poke_user but for a 31 bit program.
646 static int __poke_user_compat(struct task_struct *child,
647 addr_t addr, addr_t data)
649 struct compat_user *dummy32 = NULL;
650 __u32 tmp = (__u32) data;
651 addr_t offset;
653 if (addr < (addr_t) &dummy32->regs.acrs) {
654 struct pt_regs *regs = task_pt_regs(child);
656 * psw, gprs, acrs and orig_gpr2 are stored on the stack
658 if (addr == (addr_t) &dummy32->regs.psw.mask) {
659 /* Build a 64 bit psw mask from 31 bit mask. */
660 if (((tmp^psw32_user_bits) & ~PSW32_MASK_USER) ||
661 (((tmp^psw32_user_bits) & PSW32_MASK_ASC) &&
662 ((tmp|psw32_user_bits) & PSW32_MASK_ASC)
663 == PSW32_MASK_ASC))
664 /* Invalid psw mask. */
665 return -EINVAL;
666 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) |
667 (regs->psw.mask & PSW_MASK_BA) |
668 (__u64)(tmp & PSW32_MASK_USER) << 32;
669 } else if (addr == (addr_t) &dummy32->regs.psw.addr) {
670 /* Build a 64 bit psw address from 31 bit address. */
671 regs->psw.addr = (__u64) tmp & PSW32_ADDR_INSN;
672 /* Transfer 31 bit amode bit to psw mask. */
673 regs->psw.mask = (regs->psw.mask & ~PSW_MASK_BA) |
674 (__u64)(tmp & PSW32_ADDR_AMODE);
675 } else {
676 /* gpr 0-15 */
677 *(__u32*)((addr_t) &regs->psw + addr*2 + 4) = tmp;
679 } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) {
681 * access registers are stored in the thread structure
683 offset = addr - (addr_t) &dummy32->regs.acrs;
684 *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp;
686 } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) {
688 * orig_gpr2 is stored on the kernel stack
690 *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
692 } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
694 * prevent writess of padding hole between
695 * orig_gpr2 and fp_regs on s390.
697 return 0;
699 } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
701 * floating point regs. are stored in the thread structure
703 if (addr == (addr_t) &dummy32->regs.fp_regs.fpc &&
704 (tmp & ~FPC_VALID_MASK) != 0)
705 /* Invalid floating point control. */
706 return -EINVAL;
707 offset = addr - (addr_t) &dummy32->regs.fp_regs;
708 *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp;
710 } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) {
712 * Handle access to the per_info structure.
714 addr -= (addr_t) &dummy32->regs.per_info;
715 __poke_user_per_compat(child, addr, data);
718 return 0;
721 static int poke_user_compat(struct task_struct *child,
722 addr_t addr, addr_t data)
724 if (!is_compat_task() || (addr & 3) ||
725 addr > sizeof(struct compat_user) - 3)
726 return -EIO;
728 return __poke_user_compat(child, addr, data);
731 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
732 compat_ulong_t caddr, compat_ulong_t cdata)
734 unsigned long addr = caddr;
735 unsigned long data = cdata;
736 compat_ptrace_area parea;
737 int copied, ret;
739 switch (request) {
740 case PTRACE_PEEKUSR:
741 /* read the word at location addr in the USER area. */
742 return peek_user_compat(child, addr, data);
744 case PTRACE_POKEUSR:
745 /* write the word at location addr in the USER area */
746 return poke_user_compat(child, addr, data);
748 case PTRACE_PEEKUSR_AREA:
749 case PTRACE_POKEUSR_AREA:
750 if (copy_from_user(&parea, (void __force __user *) addr,
751 sizeof(parea)))
752 return -EFAULT;
753 addr = parea.kernel_addr;
754 data = parea.process_addr;
755 copied = 0;
756 while (copied < parea.len) {
757 if (request == PTRACE_PEEKUSR_AREA)
758 ret = peek_user_compat(child, addr, data);
759 else {
760 __u32 utmp;
761 if (get_user(utmp,
762 (__u32 __force __user *) data))
763 return -EFAULT;
764 ret = poke_user_compat(child, addr, utmp);
766 if (ret)
767 return ret;
768 addr += sizeof(unsigned int);
769 data += sizeof(unsigned int);
770 copied += sizeof(unsigned int);
772 return 0;
773 case PTRACE_GET_LAST_BREAK:
774 put_user(task_thread_info(child)->last_break,
775 (unsigned int __user *) data);
776 return 0;
778 return compat_ptrace_request(child, request, addr, data);
780 #endif
782 asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
784 long ret = 0;
786 /* Do the secure computing check first. */
787 if (secure_computing(regs->gprs[2])) {
788 /* seccomp failures shouldn't expose any additional code. */
789 ret = -1;
790 goto out;
794 * The sysc_tracesys code in entry.S stored the system
795 * call number to gprs[2].
797 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
798 (tracehook_report_syscall_entry(regs) ||
799 regs->gprs[2] >= NR_syscalls)) {
801 * Tracing decided this syscall should not happen or the
802 * debugger stored an invalid system call number. Skip
803 * the system call and the system call restart handling.
805 clear_thread_flag(TIF_SYSCALL);
806 ret = -1;
809 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
810 trace_sys_enter(regs, regs->gprs[2]);
812 audit_syscall_entry(is_compat_task() ?
813 AUDIT_ARCH_S390 : AUDIT_ARCH_S390X,
814 regs->gprs[2], regs->orig_gpr2,
815 regs->gprs[3], regs->gprs[4],
816 regs->gprs[5]);
817 out:
818 return ret ?: regs->gprs[2];
821 asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
823 audit_syscall_exit(regs);
825 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
826 trace_sys_exit(regs, regs->gprs[2]);
828 if (test_thread_flag(TIF_SYSCALL_TRACE))
829 tracehook_report_syscall_exit(regs, 0);
833 * user_regset definitions.
836 static int s390_regs_get(struct task_struct *target,
837 const struct user_regset *regset,
838 unsigned int pos, unsigned int count,
839 void *kbuf, void __user *ubuf)
841 if (target == current)
842 save_access_regs(target->thread.acrs);
844 if (kbuf) {
845 unsigned long *k = kbuf;
846 while (count > 0) {
847 *k++ = __peek_user(target, pos);
848 count -= sizeof(*k);
849 pos += sizeof(*k);
851 } else {
852 unsigned long __user *u = ubuf;
853 while (count > 0) {
854 if (__put_user(__peek_user(target, pos), u++))
855 return -EFAULT;
856 count -= sizeof(*u);
857 pos += sizeof(*u);
860 return 0;
863 static int s390_regs_set(struct task_struct *target,
864 const struct user_regset *regset,
865 unsigned int pos, unsigned int count,
866 const void *kbuf, const void __user *ubuf)
868 int rc = 0;
870 if (target == current)
871 save_access_regs(target->thread.acrs);
873 if (kbuf) {
874 const unsigned long *k = kbuf;
875 while (count > 0 && !rc) {
876 rc = __poke_user(target, pos, *k++);
877 count -= sizeof(*k);
878 pos += sizeof(*k);
880 } else {
881 const unsigned long __user *u = ubuf;
882 while (count > 0 && !rc) {
883 unsigned long word;
884 rc = __get_user(word, u++);
885 if (rc)
886 break;
887 rc = __poke_user(target, pos, word);
888 count -= sizeof(*u);
889 pos += sizeof(*u);
893 if (rc == 0 && target == current)
894 restore_access_regs(target->thread.acrs);
896 return rc;
899 static int s390_fpregs_get(struct task_struct *target,
900 const struct user_regset *regset, unsigned int pos,
901 unsigned int count, void *kbuf, void __user *ubuf)
903 if (target == current)
904 save_fp_regs(&target->thread.fp_regs);
906 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
907 &target->thread.fp_regs, 0, -1);
910 static int s390_fpregs_set(struct task_struct *target,
911 const struct user_regset *regset, unsigned int pos,
912 unsigned int count, const void *kbuf,
913 const void __user *ubuf)
915 int rc = 0;
917 if (target == current)
918 save_fp_regs(&target->thread.fp_regs);
920 /* If setting FPC, must validate it first. */
921 if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) {
922 u32 fpc[2] = { target->thread.fp_regs.fpc, 0 };
923 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &fpc,
924 0, offsetof(s390_fp_regs, fprs));
925 if (rc)
926 return rc;
927 if ((fpc[0] & ~FPC_VALID_MASK) != 0 || fpc[1] != 0)
928 return -EINVAL;
929 target->thread.fp_regs.fpc = fpc[0];
932 if (rc == 0 && count > 0)
933 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
934 target->thread.fp_regs.fprs,
935 offsetof(s390_fp_regs, fprs), -1);
937 if (rc == 0 && target == current)
938 restore_fp_regs(&target->thread.fp_regs);
940 return rc;
943 #ifdef CONFIG_64BIT
945 static int s390_last_break_get(struct task_struct *target,
946 const struct user_regset *regset,
947 unsigned int pos, unsigned int count,
948 void *kbuf, void __user *ubuf)
950 if (count > 0) {
951 if (kbuf) {
952 unsigned long *k = kbuf;
953 *k = task_thread_info(target)->last_break;
954 } else {
955 unsigned long __user *u = ubuf;
956 if (__put_user(task_thread_info(target)->last_break, u))
957 return -EFAULT;
960 return 0;
963 static int s390_last_break_set(struct task_struct *target,
964 const struct user_regset *regset,
965 unsigned int pos, unsigned int count,
966 const void *kbuf, const void __user *ubuf)
968 return 0;
971 static int s390_tdb_get(struct task_struct *target,
972 const struct user_regset *regset,
973 unsigned int pos, unsigned int count,
974 void *kbuf, void __user *ubuf)
976 struct pt_regs *regs = task_pt_regs(target);
977 unsigned char *data;
979 if (!(regs->int_code & 0x200))
980 return -ENODATA;
981 data = target->thread.trap_tdb;
982 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, data, 0, 256);
985 static int s390_tdb_set(struct task_struct *target,
986 const struct user_regset *regset,
987 unsigned int pos, unsigned int count,
988 const void *kbuf, const void __user *ubuf)
990 return 0;
993 #endif
995 static int s390_system_call_get(struct task_struct *target,
996 const struct user_regset *regset,
997 unsigned int pos, unsigned int count,
998 void *kbuf, void __user *ubuf)
1000 unsigned int *data = &task_thread_info(target)->system_call;
1001 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1002 data, 0, sizeof(unsigned int));
1005 static int s390_system_call_set(struct task_struct *target,
1006 const struct user_regset *regset,
1007 unsigned int pos, unsigned int count,
1008 const void *kbuf, const void __user *ubuf)
1010 unsigned int *data = &task_thread_info(target)->system_call;
1011 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1012 data, 0, sizeof(unsigned int));
1015 static const struct user_regset s390_regsets[] = {
1016 [REGSET_GENERAL] = {
1017 .core_note_type = NT_PRSTATUS,
1018 .n = sizeof(s390_regs) / sizeof(long),
1019 .size = sizeof(long),
1020 .align = sizeof(long),
1021 .get = s390_regs_get,
1022 .set = s390_regs_set,
1024 [REGSET_FP] = {
1025 .core_note_type = NT_PRFPREG,
1026 .n = sizeof(s390_fp_regs) / sizeof(long),
1027 .size = sizeof(long),
1028 .align = sizeof(long),
1029 .get = s390_fpregs_get,
1030 .set = s390_fpregs_set,
1032 #ifdef CONFIG_64BIT
1033 [REGSET_LAST_BREAK] = {
1034 .core_note_type = NT_S390_LAST_BREAK,
1035 .n = 1,
1036 .size = sizeof(long),
1037 .align = sizeof(long),
1038 .get = s390_last_break_get,
1039 .set = s390_last_break_set,
1041 [REGSET_TDB] = {
1042 .core_note_type = NT_S390_TDB,
1043 .n = 1,
1044 .size = 256,
1045 .align = 1,
1046 .get = s390_tdb_get,
1047 .set = s390_tdb_set,
1049 #endif
1050 [REGSET_SYSTEM_CALL] = {
1051 .core_note_type = NT_S390_SYSTEM_CALL,
1052 .n = 1,
1053 .size = sizeof(unsigned int),
1054 .align = sizeof(unsigned int),
1055 .get = s390_system_call_get,
1056 .set = s390_system_call_set,
1060 static const struct user_regset_view user_s390_view = {
1061 .name = UTS_MACHINE,
1062 .e_machine = EM_S390,
1063 .regsets = s390_regsets,
1064 .n = ARRAY_SIZE(s390_regsets)
1067 #ifdef CONFIG_COMPAT
1068 static int s390_compat_regs_get(struct task_struct *target,
1069 const struct user_regset *regset,
1070 unsigned int pos, unsigned int count,
1071 void *kbuf, void __user *ubuf)
1073 if (target == current)
1074 save_access_regs(target->thread.acrs);
1076 if (kbuf) {
1077 compat_ulong_t *k = kbuf;
1078 while (count > 0) {
1079 *k++ = __peek_user_compat(target, pos);
1080 count -= sizeof(*k);
1081 pos += sizeof(*k);
1083 } else {
1084 compat_ulong_t __user *u = ubuf;
1085 while (count > 0) {
1086 if (__put_user(__peek_user_compat(target, pos), u++))
1087 return -EFAULT;
1088 count -= sizeof(*u);
1089 pos += sizeof(*u);
1092 return 0;
1095 static int s390_compat_regs_set(struct task_struct *target,
1096 const struct user_regset *regset,
1097 unsigned int pos, unsigned int count,
1098 const void *kbuf, const void __user *ubuf)
1100 int rc = 0;
1102 if (target == current)
1103 save_access_regs(target->thread.acrs);
1105 if (kbuf) {
1106 const compat_ulong_t *k = kbuf;
1107 while (count > 0 && !rc) {
1108 rc = __poke_user_compat(target, pos, *k++);
1109 count -= sizeof(*k);
1110 pos += sizeof(*k);
1112 } else {
1113 const compat_ulong_t __user *u = ubuf;
1114 while (count > 0 && !rc) {
1115 compat_ulong_t word;
1116 rc = __get_user(word, u++);
1117 if (rc)
1118 break;
1119 rc = __poke_user_compat(target, pos, word);
1120 count -= sizeof(*u);
1121 pos += sizeof(*u);
1125 if (rc == 0 && target == current)
1126 restore_access_regs(target->thread.acrs);
1128 return rc;
1131 static int s390_compat_regs_high_get(struct task_struct *target,
1132 const struct user_regset *regset,
1133 unsigned int pos, unsigned int count,
1134 void *kbuf, void __user *ubuf)
1136 compat_ulong_t *gprs_high;
1138 gprs_high = (compat_ulong_t *)
1139 &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
1140 if (kbuf) {
1141 compat_ulong_t *k = kbuf;
1142 while (count > 0) {
1143 *k++ = *gprs_high;
1144 gprs_high += 2;
1145 count -= sizeof(*k);
1147 } else {
1148 compat_ulong_t __user *u = ubuf;
1149 while (count > 0) {
1150 if (__put_user(*gprs_high, u++))
1151 return -EFAULT;
1152 gprs_high += 2;
1153 count -= sizeof(*u);
1156 return 0;
1159 static int s390_compat_regs_high_set(struct task_struct *target,
1160 const struct user_regset *regset,
1161 unsigned int pos, unsigned int count,
1162 const void *kbuf, const void __user *ubuf)
1164 compat_ulong_t *gprs_high;
1165 int rc = 0;
1167 gprs_high = (compat_ulong_t *)
1168 &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
1169 if (kbuf) {
1170 const compat_ulong_t *k = kbuf;
1171 while (count > 0) {
1172 *gprs_high = *k++;
1173 *gprs_high += 2;
1174 count -= sizeof(*k);
1176 } else {
1177 const compat_ulong_t __user *u = ubuf;
1178 while (count > 0 && !rc) {
1179 unsigned long word;
1180 rc = __get_user(word, u++);
1181 if (rc)
1182 break;
1183 *gprs_high = word;
1184 *gprs_high += 2;
1185 count -= sizeof(*u);
1189 return rc;
1192 static int s390_compat_last_break_get(struct task_struct *target,
1193 const struct user_regset *regset,
1194 unsigned int pos, unsigned int count,
1195 void *kbuf, void __user *ubuf)
1197 compat_ulong_t last_break;
1199 if (count > 0) {
1200 last_break = task_thread_info(target)->last_break;
1201 if (kbuf) {
1202 unsigned long *k = kbuf;
1203 *k = last_break;
1204 } else {
1205 unsigned long __user *u = ubuf;
1206 if (__put_user(last_break, u))
1207 return -EFAULT;
1210 return 0;
1213 static int s390_compat_last_break_set(struct task_struct *target,
1214 const struct user_regset *regset,
1215 unsigned int pos, unsigned int count,
1216 const void *kbuf, const void __user *ubuf)
1218 return 0;
1221 static const struct user_regset s390_compat_regsets[] = {
1222 [REGSET_GENERAL] = {
1223 .core_note_type = NT_PRSTATUS,
1224 .n = sizeof(s390_compat_regs) / sizeof(compat_long_t),
1225 .size = sizeof(compat_long_t),
1226 .align = sizeof(compat_long_t),
1227 .get = s390_compat_regs_get,
1228 .set = s390_compat_regs_set,
1230 [REGSET_FP] = {
1231 .core_note_type = NT_PRFPREG,
1232 .n = sizeof(s390_fp_regs) / sizeof(compat_long_t),
1233 .size = sizeof(compat_long_t),
1234 .align = sizeof(compat_long_t),
1235 .get = s390_fpregs_get,
1236 .set = s390_fpregs_set,
1238 [REGSET_LAST_BREAK] = {
1239 .core_note_type = NT_S390_LAST_BREAK,
1240 .n = 1,
1241 .size = sizeof(long),
1242 .align = sizeof(long),
1243 .get = s390_compat_last_break_get,
1244 .set = s390_compat_last_break_set,
1246 [REGSET_TDB] = {
1247 .core_note_type = NT_S390_TDB,
1248 .n = 1,
1249 .size = 256,
1250 .align = 1,
1251 .get = s390_tdb_get,
1252 .set = s390_tdb_set,
1254 [REGSET_SYSTEM_CALL] = {
1255 .core_note_type = NT_S390_SYSTEM_CALL,
1256 .n = 1,
1257 .size = sizeof(compat_uint_t),
1258 .align = sizeof(compat_uint_t),
1259 .get = s390_system_call_get,
1260 .set = s390_system_call_set,
1262 [REGSET_GENERAL_EXTENDED] = {
1263 .core_note_type = NT_S390_HIGH_GPRS,
1264 .n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t),
1265 .size = sizeof(compat_long_t),
1266 .align = sizeof(compat_long_t),
1267 .get = s390_compat_regs_high_get,
1268 .set = s390_compat_regs_high_set,
1272 static const struct user_regset_view user_s390_compat_view = {
1273 .name = "s390",
1274 .e_machine = EM_S390,
1275 .regsets = s390_compat_regsets,
1276 .n = ARRAY_SIZE(s390_compat_regsets)
1278 #endif
1280 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
1282 #ifdef CONFIG_COMPAT
1283 if (test_tsk_thread_flag(task, TIF_31BIT))
1284 return &user_s390_compat_view;
1285 #endif
1286 return &user_s390_view;
1289 static const char *gpr_names[NUM_GPRS] = {
1290 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1291 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1294 unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset)
1296 if (offset >= NUM_GPRS)
1297 return 0;
1298 return regs->gprs[offset];
1301 int regs_query_register_offset(const char *name)
1303 unsigned long offset;
1305 if (!name || *name != 'r')
1306 return -EINVAL;
1307 if (kstrtoul(name + 1, 10, &offset))
1308 return -EINVAL;
1309 if (offset >= NUM_GPRS)
1310 return -EINVAL;
1311 return offset;
1314 const char *regs_query_register_name(unsigned int offset)
1316 if (offset >= NUM_GPRS)
1317 return NULL;
1318 return gpr_names[offset];
1321 static int regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
1323 unsigned long ksp = kernel_stack_pointer(regs);
1325 return (addr & ~(THREAD_SIZE - 1)) == (ksp & ~(THREAD_SIZE - 1));
1329 * regs_get_kernel_stack_nth() - get Nth entry of the stack
1330 * @regs:pt_regs which contains kernel stack pointer.
1331 * @n:stack entry number.
1333 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
1334 * is specifined by @regs. If the @n th entry is NOT in the kernel stack,
1335 * this returns 0.
1337 unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
1339 unsigned long addr;
1341 addr = kernel_stack_pointer(regs) + n * sizeof(long);
1342 if (!regs_within_kernel_stack(regs, addr))
1343 return 0;
1344 return *(unsigned long *)addr;