1 Subject: Backport s390 kernel components required for utrace enablement
3 From: Ananth N. Mavinakayanahalli <ananth@in.ibm.com>
7 Acked-by: John Jolly <jjolly@novell.com>
10 arch/s390/include/asm/ptrace.h | 1
11 arch/s390/include/asm/syscall.h | 80 ++++++++++++++++++++++++++++++++++++
12 arch/s390/include/asm/thread_info.h | 2
13 arch/s390/kernel/entry.S | 50 ++++++++++++++++++----
14 arch/s390/kernel/entry64.S | 42 ++++++++++++++----
15 arch/s390/kernel/ptrace.c | 75 +++++++++++++++++++++------------
16 arch/s390/kernel/signal.c | 13 +++++
17 8 files changed, 216 insertions(+), 48 deletions(-)
19 --- a/arch/s390/include/asm/ptrace.h
20 +++ b/arch/s390/include/asm/ptrace.h
21 @@ -490,6 +490,7 @@ extern void user_disable_single_step(str
23 #define user_mode(regs) (((regs)->psw.mask & PSW_MASK_PSTATE) != 0)
24 #define instruction_pointer(regs) ((regs)->psw.addr & PSW_ADDR_INSN)
25 +#define user_stack_pointer(regs)((regs)->gprs[15])
26 #define regs_return_value(regs)((regs)->gprs[2])
27 #define profile_pc(regs) instruction_pointer(regs)
28 extern void show_regs(struct pt_regs * regs);
30 +++ b/arch/s390/include/asm/syscall.h
33 + * Access to user system call parameters and results
35 + * Copyright IBM Corp. 2008
36 + * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
38 + * This program is free software; you can redistribute it and/or modify
39 + * it under the terms of the GNU General Public License (version 2 only)
40 + * as published by the Free Software Foundation.
43 +#ifndef _ASM_SYSCALL_H
44 +#define _ASM_SYSCALL_H 1
46 +#include <asm/ptrace.h>
48 +static inline long syscall_get_nr(struct task_struct *task,
49 + struct pt_regs *regs)
51 + if (regs->trap != __LC_SVC_OLD_PSW)
53 + return regs->gprs[2];
56 +static inline void syscall_rollback(struct task_struct *task,
57 + struct pt_regs *regs)
59 + regs->gprs[2] = regs->orig_gpr2;
62 +static inline long syscall_get_error(struct task_struct *task,
63 + struct pt_regs *regs)
65 + return (regs->gprs[2] >= -4096UL) ? -regs->gprs[2] : 0;
68 +static inline long syscall_get_return_value(struct task_struct *task,
69 + struct pt_regs *regs)
71 + return regs->gprs[2];
74 +static inline void syscall_set_return_value(struct task_struct *task,
75 + struct pt_regs *regs,
76 + int error, long val)
78 + regs->gprs[2] = error ? -error : val;
81 +static inline void syscall_get_arguments(struct task_struct *task,
82 + struct pt_regs *regs,
83 + unsigned int i, unsigned int n,
84 + unsigned long *args)
88 + if (test_tsk_thread_flag(task, TIF_31BIT)) {
90 + args[--n] = (u32) regs->args[0];
92 + args[n] = (u32) regs->gprs[2 + i + n];
96 + args[--n] = regs->args[0];
97 + memcpy(args, ®s->gprs[2 + i], n * sizeof(args[0]));
100 +static inline void syscall_set_arguments(struct task_struct *task,
101 + struct pt_regs *regs,
102 + unsigned int i, unsigned int n,
103 + const unsigned long *args)
107 + regs->args[0] = args[--n];
108 + memcpy(®s->gprs[2 + i], args, n * sizeof(args[0]));
111 +#endif /* _ASM_SYSCALL_H */
112 --- a/arch/s390/include/asm/thread_info.h
113 +++ b/arch/s390/include/asm/thread_info.h
114 @@ -86,6 +86,7 @@ static inline struct thread_info *curren
115 * thread information flags bit numbers
117 #define TIF_SYSCALL_TRACE 0 /* syscall trace active */
118 +#define TIF_NOTIFY_RESUME 1 /* callback before returning to user */
119 #define TIF_SIGPENDING 2 /* signal pending */
120 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
121 #define TIF_RESTART_SVC 4 /* restart svc with new svc number */
122 @@ -101,6 +102,7 @@ static inline struct thread_info *curren
123 #define TIF_FREEZE 21
125 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
126 +#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
127 #define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK)
128 #define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
129 #define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
130 --- a/arch/s390/Kconfig
131 +++ b/arch/s390/Kconfig
132 @@ -76,6 +76,7 @@ config S390
134 select HAVE_KRETPROBES
135 select HAVE_KVM if 64BIT
136 + select HAVE_ARCH_TRACEHOOK
138 source "init/Kconfig"
140 --- a/arch/s390/kernel/entry64.S
141 +++ b/arch/s390/kernel/entry64.S
142 @@ -52,9 +52,9 @@ SP_SIZE = STACK_FRAME_OVERHEAD + __
143 STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
144 STACK_SIZE = 1 << STACK_SHIFT
146 -_TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
147 +_TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
148 _TIF_MCCK_PENDING | _TIF_RESTART_SVC | _TIF_SINGLE_STEP )
149 -_TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
150 +_TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
153 #define BASED(name) name-system_call(%r13)
154 @@ -310,6 +310,8 @@ sysc_work:
156 tm __TI_flags+7(%r9),_TIF_SIGPENDING
158 + tm __TI_flags+7(%r9),_TIF_NOTIFY_RESUME
159 + jnz sysc_notify_resume
160 tm __TI_flags+7(%r9),_TIF_RESTART_SVC
162 tm __TI_flags+7(%r9),_TIF_SINGLE_STEP
163 @@ -345,6 +347,14 @@ sysc_sigpending:
167 +# _TIF_NOTIFY_RESUME is set, call do_notify_resume
170 + la %r2,SP_PTREGS(%r15) # load pt_regs
171 + larl %r14,sysc_work_loop
172 + jg do_notify_resume # call do_notify_resume
175 # _TIF_RESTART_SVC is set, set up registers and restart svc
178 @@ -367,20 +377,19 @@ sysc_singlestep:
179 jg do_single_step # branch to do_sigtrap
182 -# call syscall_trace before and after system call
183 -# special linkage: %r12 contains the return address for trace_svc
184 +# call tracehook_report_syscall_entry/tracehook_report_syscall_exit before
185 +# and after the system call
188 la %r2,SP_PTREGS(%r15) # load pt_regs
192 - brasl %r14,syscall_trace
193 + brasl %r14,do_syscall_trace_enter
195 - clg %r0,SP_R2(%r15)
198 - lg %r7,SP_R2(%r15) # strace might have changed the
199 - sll %r7,2 # system call
200 + slag %r7,%r2,2 # *4
203 lmg %r3,%r6,SP_R3(%r15)
204 @@ -391,9 +400,8 @@ sysc_tracenogo:
205 tm __TI_flags+7(%r9),(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT)
207 la %r2,SP_PTREGS(%r15) # load pt_regs
209 larl %r14,sysc_return # return point is sysc_return
211 + jg do_syscall_trace_exit
214 # a new process exits the kernel with ret_from_fork
215 @@ -672,6 +680,8 @@ io_work_loop:
217 tm __TI_flags+7(%r9),_TIF_SIGPENDING
219 + tm __TI_flags+7(%r9),_TIF_NOTIFY_RESUME
220 + jnz io_notify_resume
224 @@ -712,6 +722,18 @@ io_sigpending:
229 +# _TIF_NOTIFY_RESUME or is set, call do_notify_resume
233 + stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
234 + la %r2,SP_PTREGS(%r15) # load pt_regs
235 + brasl %r14,do_notify_resume # call do_notify_resume
236 + stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
241 * External interrupt handler routine
243 --- a/arch/s390/kernel/entry.S
244 +++ b/arch/s390/kernel/entry.S
245 @@ -49,9 +49,9 @@ SP_ILC = STACK_FRAME_OVERHEAD + __P
246 SP_TRAP = STACK_FRAME_OVERHEAD + __PT_TRAP
247 SP_SIZE = STACK_FRAME_OVERHEAD + __PT_SIZE
249 -_TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
250 +_TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
251 _TIF_MCCK_PENDING | _TIF_RESTART_SVC | _TIF_SINGLE_STEP )
252 -_TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
253 +_TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
256 STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
257 @@ -318,6 +318,8 @@ sysc_work:
258 bo BASED(sysc_reschedule)
259 tm __TI_flags+3(%r9),_TIF_SIGPENDING
260 bnz BASED(sysc_sigpending)
261 + tm __TI_flags+3(%r9),_TIF_NOTIFY_RESUME
262 + bnz BASED(sysc_notify_resume)
263 tm __TI_flags+3(%r9),_TIF_RESTART_SVC
264 bo BASED(sysc_restart)
265 tm __TI_flags+3(%r9),_TIF_SINGLE_STEP
266 @@ -356,6 +358,16 @@ sysc_sigpending:
267 b BASED(sysc_work_loop)
270 +# _TIF_NOTIFY_RESUME is set, call do_notify_resume
273 + la %r2,SP_PTREGS(%r15) # load pt_regs
274 + l %r1,BASED(.Ldo_notify_resume)
275 + la %r14,BASED(sysc_work_loop)
276 + br %r1 # call do_notify_resume
280 # _TIF_RESTART_SVC is set, set up registers and restart svc
283 @@ -378,20 +390,21 @@ sysc_singlestep:
284 br %r1 # branch to do_single_step
287 -# call trace before and after sys_call
288 +# call tracehook_report_syscall_entry/tracehook_report_syscall_exit before
289 +# and after the system call
292 - l %r1,BASED(.Ltrace)
293 + l %r1,BASED(.Ltrace_entry)
294 la %r2,SP_PTREGS(%r15) # load pt_regs
299 - clc SP_R2(4,%r15),BASED(.Lnr_syscalls)
300 + cl %r2,BASED(.Lnr_syscalls)
301 bnl BASED(sysc_tracenogo)
302 l %r8,BASED(.Lsysc_table)
303 - l %r7,SP_R2(%r15) # strace might have changed the
304 - sll %r7,2 # system call
309 lm %r3,%r6,SP_R3(%r15)
310 @@ -401,9 +414,8 @@ sysc_tracego:
312 tm __TI_flags+3(%r9),(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT)
313 bz BASED(sysc_return)
314 - l %r1,BASED(.Ltrace)
315 + l %r1,BASED(.Ltrace_exit)
316 la %r2,SP_PTREGS(%r15) # load pt_regs
318 la %r14,BASED(sysc_return)
321 @@ -666,6 +678,8 @@ io_work_loop:
322 bo BASED(io_reschedule)
323 tm __TI_flags+3(%r9),_TIF_SIGPENDING
324 bnz BASED(io_sigpending)
325 + tm __TI_flags+3(%r9),_TIF_NOTIFY_RESUME
326 + bnz BASED(io_notify_resume)
330 @@ -704,6 +718,19 @@ io_sigpending:
332 b BASED(io_work_loop)
335 +# _TIF_SIGPENDING is set, call do_signal
339 + stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
340 + la %r2,SP_PTREGS(%r15) # load pt_regs
341 + l %r1,BASED(.Ldo_notify_resume)
342 + basr %r14,%r1 # call do_signal
343 + stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
345 + b BASED(io_work_loop)
348 * External interrupt handler routine
350 @@ -1070,6 +1097,8 @@ cleanup_io_leave_insn:
351 .Ldo_IRQ: .long do_IRQ
352 .Ldo_extint: .long do_extint
353 .Ldo_signal: .long do_signal
355 + .long do_notify_resume
356 .Lhandle_per: .long do_single_step
357 .Ldo_execve: .long do_execve
358 .Lexecve_tail: .long execve_tail
359 @@ -1079,7 +1108,8 @@ cleanup_io_leave_insn:
360 .Lpreempt_schedule_irq:
361 .long preempt_schedule_irq
363 -.Ltrace: .long syscall_trace
364 +.Ltrace_entry: .long do_syscall_trace_enter
365 +.Ltrace_exit: .long do_syscall_trace_exit
366 .Lschedtail: .long schedule_tail
367 .Lsysc_table: .long sys_call_table
368 #ifdef CONFIG_TRACE_IRQFLAGS
369 --- a/arch/s390/kernel/ptrace.c
370 +++ b/arch/s390/kernel/ptrace.c
372 #include <linux/signal.h>
373 #include <linux/elf.h>
374 #include <linux/regset.h>
375 +#include <linux/tracehook.h>
377 #include <asm/segment.h>
378 #include <asm/page.h>
379 @@ -639,40 +640,58 @@ long compat_arch_ptrace(struct task_stru
384 -syscall_trace(struct pt_regs *regs, int entryexit)
385 +asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
387 - if (unlikely(current->audit_context) && entryexit)
388 - audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]), regs->gprs[2]);
390 - if (!test_thread_flag(TIF_SYSCALL_TRACE))
392 - if (!(current->ptrace & PT_PTRACED))
394 - ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
399 - * If the debuffer has set an invalid system call number,
400 - * we prepare to skip the system call restart handling.
401 + * The sysc_tracesys code in entry.S stored the system
402 + * call number to gprs[2].
404 - if (!entryexit && regs->gprs[2] >= NR_syscalls)
406 + if (is_self_ptracing(regs->gprs[2])) {
407 + struct siginfo info;
409 + memset(&info, 0, sizeof(struct siginfo));
410 + info.si_signo = SIGSYS;
411 + info.si_code = SYS_SYSCALL;
412 + info.si_errno = regs->gprs[2];
413 + info.si_addr = (void *)regs->orig_gpr2;
414 + send_sig_info(SIGSYS, &info, current);
415 + regs->gprs[2] = -1;
419 + ret = regs->gprs[2];
420 + if (test_thread_flag(TIF_SYSCALL_TRACE) &&
421 + (tracehook_report_syscall_entry(regs) ||
422 + regs->gprs[2] >= NR_syscalls)) {
424 + * Tracing decided this syscall should not happen or the
425 + * debugger stored an invalid system call number. Skip
426 + * the system call and the system call restart handling.
433 - * this isn't the same as continuing with a signal, but it will do
434 - * for normal use. strace only continues with a signal if the
435 - * stopping signal is not SIGTRAP. -brl
437 - if (current->exit_code) {
438 - send_sig(current->exit_code, current, 1);
439 - current->exit_code = 0;
442 - if (unlikely(current->audit_context) && !entryexit)
443 - audit_syscall_entry(test_thread_flag(TIF_31BIT)?AUDIT_ARCH_S390:AUDIT_ARCH_S390X,
444 - regs->gprs[2], regs->orig_gpr2, regs->gprs[3],
445 - regs->gprs[4], regs->gprs[5]);
446 + if (unlikely(current->audit_context))
447 + audit_syscall_entry(test_thread_flag(TIF_31BIT) ?
448 + AUDIT_ARCH_S390 : AUDIT_ARCH_S390X,
449 + regs->gprs[2], regs->orig_gpr2,
450 + regs->gprs[3], regs->gprs[4],
455 +asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
457 + if (unlikely(current->audit_context))
458 + audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]),
461 + if (test_thread_flag(TIF_SYSCALL_TRACE))
462 + tracehook_report_syscall_exit(regs, 0);
466 --- a/arch/s390/kernel/signal.c
467 +++ b/arch/s390/kernel/signal.c
469 #include <linux/personality.h>
470 #include <linux/binfmts.h>
471 #include <linux/syscalls.h>
472 +#include <linux/tracehook.h>
473 #include <asm/ucontext.h>
474 #include <asm/uaccess.h>
475 #include <asm/lowcore.h>
476 @@ -504,6 +505,12 @@ void do_signal(struct pt_regs *regs)
478 if (current->thread.per_info.single_step)
479 set_thread_flag(TIF_SINGLE_STEP);
482 + * Let tracing know that we've done the handler setup.
484 + tracehook_signal_handler(signr, &info, &ka, regs,
485 + test_thread_flag(TIF_SINGLE_STEP));
489 @@ -523,3 +530,9 @@ void do_signal(struct pt_regs *regs)
490 set_thread_flag(TIF_RESTART_SVC);
494 +void do_notify_resume(struct pt_regs *regs)
496 + clear_thread_flag(TIF_NOTIFY_RESUME);
497 + tracehook_notify_resume(regs);