Skip to content

Commit 45f7a0d

Browse files
author
Vasily Gorbik
committed
s390/ftrace: generate traced function stack frame
Currently backtrace from ftraced function does not contain ftraced function itself. e.g. for "path_openat": arch_stack_walk+0x15c/0x2d8 stack_trace_save+0x50/0x68 stack_trace_call+0x15e/0x3d8 ftrace_graph_caller+0x0/0x1c <-- ftrace code do_filp_open+0x7c/0xe8 <-- ftraced function caller do_open_execat+0x76/0x1b8 open_exec+0x52/0x78 load_elf_binary+0x180/0x1160 search_binary_handler+0x8e/0x288 load_script+0x2a8/0x2b8 search_binary_handler+0x8e/0x288 __do_execve_file.isra.39+0x6fa/0xb40 __s390x_sys_execve+0x56/0x68 system_call+0xdc/0x2d8 Ftraced function is expected in the backtrace by ftrace kselftests, which are now failing. It would also be nice to have it for clarity reasons. "ftrace_caller" itself is called without stack frame allocated for it and does not store its caller (ftraced function). Instead it simply allocates a stack frame for "ftrace_trace_function" and sets backchain to point to ftraced function stack frame (which contains ftraced function caller in saved r14). To fix this issue make "ftrace_caller" allocate a stack frame for itself just to store ftraced function for the stack unwinder. As a result backtrace looks like the following: arch_stack_walk+0x15c/0x2d8 stack_trace_save+0x50/0x68 stack_trace_call+0x15e/0x3d8 ftrace_graph_caller+0x0/0x1c <-- ftrace code path_openat+0x6/0xd60 <-- ftraced function do_filp_open+0x7c/0xe8 <-- ftraced function caller do_open_execat+0x76/0x1b8 open_exec+0x52/0x78 load_elf_binary+0x180/0x1160 search_binary_handler+0x8e/0x288 load_script+0x2a8/0x2b8 search_binary_handler+0x8e/0x288 __do_execve_file.isra.39+0x6fa/0xb40 __s390x_sys_execve+0x56/0x68 system_call+0xdc/0x2d8 Reported-by: Sven Schnelle <[email protected]> Tested-by: Sven Schnelle <[email protected]> Reviewed-by: Heiko Carstens <[email protected]> Signed-off-by: Vasily Gorbik <[email protected]>
1 parent 253b3c4 commit 45f7a0d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

arch/s390/kernel/mcount.S

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ ENDPROC(ftrace_stub)
2626
#define STACK_PTREGS (STACK_FRAME_OVERHEAD)
2727
#define STACK_PTREGS_GPRS (STACK_PTREGS + __PT_GPRS)
2828
#define STACK_PTREGS_PSW (STACK_PTREGS + __PT_PSW)
29+
#ifdef __PACK_STACK
30+
/* allocate just enough for r14, r15 and backchain */
31+
#define TRACED_FUNC_FRAME_SIZE 24
32+
#else
33+
#define TRACED_FUNC_FRAME_SIZE STACK_FRAME_OVERHEAD
34+
#endif
2935

3036
ENTRY(_mcount)
3137
BR_EX %r14
@@ -39,9 +45,16 @@ ENTRY(ftrace_caller)
3945
#if !(defined(CC_USING_HOTPATCH) || defined(CC_USING_NOP_MCOUNT))
4046
aghi %r0,MCOUNT_RETURN_FIXUP
4147
#endif
42-
aghi %r15,-STACK_FRAME_SIZE
48+
# allocate stack frame for ftrace_caller to contain traced function
49+
aghi %r15,-TRACED_FUNC_FRAME_SIZE
4350
stg %r1,__SF_BACKCHAIN(%r15)
51+
stg %r0,(__SF_GPRS+8*8)(%r15)
52+
stg %r15,(__SF_GPRS+9*8)(%r15)
53+
# allocate pt_regs and stack frame for ftrace_trace_function
54+
aghi %r15,-STACK_FRAME_SIZE
4455
stg %r1,(STACK_PTREGS_GPRS+15*8)(%r15)
56+
aghi %r1,-TRACED_FUNC_FRAME_SIZE
57+
stg %r1,__SF_BACKCHAIN(%r15)
4558
stg %r0,(STACK_PTREGS_PSW+8)(%r15)
4659
stmg %r2,%r14,(STACK_PTREGS_GPRS+2*8)(%r15)
4760
#ifdef CONFIG_HAVE_MARCH_Z196_FEATURES

0 commit comments

Comments
 (0)