powerpc/ftrace: Enable HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
cover powerpc/ftrace: Enable HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
Enable HAVE_FUNCTION_GRAPH_RET_ADDR_PTR for more robust stack unwinding when function graph tracer is in use. Convert powerpc show_stack() to use ftrace_graph_ret_addr() for better stack unwinding.
- Naveen
Naveen N. Rao (3):
ftrace: Look up the address of return_to_handler() using helpers powerpc/ftrace: Enable HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
powerpc: Use ftrace_graph_ret_addr() when unwinding
arch/powerpc/include/asm/asm-prototypes.h | 3 ++- arch/powerpc/include/asm/ftrace.h | 2 ++ arch/powerpc/kernel/process.c | 19 ++++++------------- arch/powerpc/kernel/stacktrace.c | 2 +- arch/powerpc/kernel/trace/ftrace.c | 5 +++-- arch/powerpc/kernel/trace/ftrace_32.S | 1 + .../powerpc/kernel/trace/ftrace_64_mprofile.S | 1 + arch/powerpc/kernel/trace/ftrace_64_pg.S | 1 + kernel/trace/fgraph.c | 4 ++-- 9 files changed, 19 insertions(+), 19 deletions(-)
Signature · 1 line
2.23.0
PATCH 1/3 ftrace: Look up the address of return_to_handler() using helpers
This ensures that we use the right address on architectures that use function descriptors.
--- kernel/trace/fgraph.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/fgraph.c +2 -2
@@ -276,7 +276,7 @@ unsigned long ftrace_graph_ret_addr(struct task_struct *task, int *idx,int index = task->curr_ret_stack;int i; -if (ret != (unsigned long )return_to_handler) +if (ret != (unsigned long )dereference_kernel_function_descriptor (return_to_handler))return ret;if (index <0 )
@@ -294,7 +294,7 @@ unsigned long ftrace_graph_ret_addr(struct task_struct *task, int *idx, {int task_idx; -if (ret != (unsigned long )return_to_handler) +if (ret != (unsigned long )dereference_kernel_function_descriptor (return_to_handler))return ret; task_idx = task->curr_ret_stack;
Signature · 1 line
2.23.0
Re: [PATCH 1/3] ftrace: Look up the address of return_to_handler() using helpers
Quoted 4 lines · Naveen N. Rao
This ensures that we use the right address on architectures that use function descriptors.
Signed-off-by Naveen N. Rao <[email protected]>
Series applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/a3db31ff6ce31f5a544a66b61613a098029031cc
cheers
PATCH 2/3 powerpc/ftrace: Enable HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
In reply to Naveen N. RaoThis associates entries in the ftrace_ret_stack with corresponding stack frames, enabling more robust stack unwinding. Also update the only user of ftrace_graph_ret_addr() to pass the stack pointer.
--- arch/powerpc/include/asm/asm-prototypes.h | 3 ++- arch/powerpc/include/asm/ftrace.h | 2 ++ arch/powerpc/kernel/stacktrace.c | 2 +- arch/powerpc/kernel/trace/ftrace.c | 5 +++-- arch/powerpc/kernel/trace/ftrace_32.S | 1 + arch/powerpc/kernel/trace/ftrace_64_mprofile.S | 1 + arch/powerpc/kernel/trace/ftrace_64_pg.S | 1 + 7 files changed, 11 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/asm-prototypes.h +2 -1
@@ -134,7 +134,8 @@ extern int __ucmpdi2(u64, u64);/* tracing */ void _mcount (void ); -unsigned long prepare_ftrace_return (unsigned long parent,unsigned long ip); +unsigned long prepare_ftrace_return (unsigned long parent,unsigned long ip, +unsigned long sp);void pnv_power9_force_smt4_catch (void );void pnv_power9_force_smt4_release (void );
arch/powerpc/include/asm/ftrace.h +2 -0
@@ -8,6 +8,8 @@#define MCOUNT_ADDR ((unsigned long)(_mcount))#define MCOUNT_INSN_SIZE 4/* sizeof mcount call */ +#define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR +#ifdef __ASSEMBLY__/* Based off of objdump optput from glibc */
arch/powerpc/kernel/stacktrace.c +1 -1
@@ -182,7 +182,7 @@ static int __save_stack_trace_tsk_reliable(struct task_struct *tsk,* FIXME: IMHO these tests do not belong in * arch-dependent code, they are generic. */ - ip =ftrace_graph_ret_addr (tsk, &graph_idx, ip,NULL ); + ip =ftrace_graph_ret_addr (tsk, &graph_idx, ip, stack);#ifdef CONFIG_KPROBES /* * Mark stacktraces with kretprobed functions on them
arch/powerpc/kernel/trace/ftrace.c +3 -2
@@ -944,7 +944,8 @@ int ftrace_disable_ftrace_graph_caller(void)* Hook the return address and push it in the stack of return addrs * in current thread info. Return the address we want to divert to. */ -unsigned long prepare_ftrace_return (unsigned long parent,unsigned long ip) +unsigned long prepare_ftrace_return (unsigned long parent,unsigned long ip, +unsigned long sp) {unsigned long return_hooker;
@@ -956,7 +957,7 @@ unsigned long prepare_ftrace_return(unsigned long parent, unsigned long ip) return_hooker =ppc_function_entry (return_to_handler); -if (!function_graph_enter (parent, ip,0 ,NULL )) +if (!function_graph_enter (parent, ip,0 , (unsigned long *)sp)) parent = return_hooker; out:return parent;
arch/powerpc/kernel/trace/ftrace_32.S +1 -0
@@ -50,6 +50,7 @@ _GLOBAL(ftrace_stub) #ifdef CONFIG_FUNCTION_GRAPH_TRACER _GLOBAL(ftrace_graph_caller) + addi r5, r1, 48 /* load r4 with local address */ lwz r4, 44(r1) subi r4, r4, MCOUNT_INSN_SIZE
arch/powerpc/kernel/trace/ftrace_64_mprofile.S +1 -0
@@ -294,6 +294,7 @@ _GLOBAL(ftrace_graph_caller) std r2, 24(r1) ld r2, PACATOC(r13) /* get kernel TOC in r2 */ + addi r5, r1, 112 mfctr r4 /* ftrace_caller has moved local addr here */ std r4, 40(r1) mflr r3 /* ftrace_caller has restored LR from stack */
arch/powerpc/kernel/trace/ftrace_64_pg.S +1 -0
@@ -41,6 +41,7 @@ _GLOBAL(ftrace_stub) #ifdef CONFIG_FUNCTION_GRAPH_TRACER _GLOBAL(ftrace_graph_caller) + addi r5, r1, 112 /* load r4 with local address */ ld r4, 128(r1) subi r4, r4, MCOUNT_INSN_SIZE
Signature · 1 line
2.23.0
PATCH 3/3 powerpc: Use ftrace_graph_ret_addr() when unwinding
In reply to Naveen N. RaoWith support for HAVE_FUNCTION_GRAPH_RET_ADDR_PTR, ftrace_graph_ret_addr() provides more robust unwinding when function graph is in use. Update show_stack() to use the same.
With dump_stack() added to sysrq_sysctl_handler(), before this patch:
root@(none):/sys/kernel/debug/tracing# cat /proc/sys/kernel/sysrq CPU: 0 PID: 218 Comm: cat Not tainted 5.3.0-rc7-00868-g8453ad4a078c-dirty #20 Call Trace: [c0000000d1e13c30] [c00000000006ab98] return_to_handler+0x0/0x40 (dump_stack+0xe8/0x164) (unreliable) [c0000000d1e13c80] [c000000000145680] sysrq_sysctl_handler+0x48/0xb8 [c0000000d1e13cd0] [c00000000006ab98] return_to_handler+0x0/0x40 (proc_sys_call_handler+0x274/0x2a0) [c0000000d1e13d60] [c00000000006ab98] return_to_handler+0x0/0x40 (return_to_handler+0x0/0x40) [c0000000d1e13d80] [c00000000006ab98] return_to_handler+0x0/0x40 (__vfs_read+0x3c/0x70) [c0000000d1e13dd0] [c00000000006ab98] return_to_handler+0x0/0x40 (vfs_read+0xb8/0x1b0) [c0000000d1e13e20] [c00000000006ab98] return_to_handler+0x0/0x40 (ksys_read+0x7c/0x140)
After this patch:
Call Trace: [c0000000d1e33c30] [c00000000006ab58] return_to_handler+0x0/0x40 (dump_stack+0xe8/0x164) (unreliable) [c0000000d1e33c80] [c000000000145680] sysrq_sysctl_handler+0x48/0xb8 [c0000000d1e33cd0] [c00000000006ab58] return_to_handler+0x0/0x40 (proc_sys_call_handler+0x274/0x2a0) [c0000000d1e33d60] [c00000000006ab58] return_to_handler+0x0/0x40 (__vfs_read+0x3c/0x70) [c0000000d1e33d80] [c00000000006ab58] return_to_handler+0x0/0x40 (vfs_read+0xb8/0x1b0) [c0000000d1e33dd0] [c00000000006ab58] return_to_handler+0x0/0x40 (ksys_read+0x7c/0x140) [c0000000d1e33e20] [c00000000006ab58] return_to_handler+0x0/0x40 (system_call+0x5c/0x68)
--- arch/powerpc/kernel/process.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
arch/powerpc/kernel/process.c +6 -13
@@ -2047,10 +2047,8 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)int count =0 ;int firstframe =1 ;#ifdef CONFIG_FUNCTION_GRAPH_TRACER -struct ftrace_ret_stack *ret_stack; -extern void return_to_handler (void ); -unsigned long rth = (unsigned long )return_to_handler; -int curr_frame =0 ; +unsigned long ret_addr; +int ftrace_idx =0 ;#endif if (tsk ==NULL )
@@ -2079,15 +2077,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)if (!firstframe || ip != lr) {printk ("[" REG "] [" REG "] %pS" , sp, ip, (void *)ip);#ifdef CONFIG_FUNCTION_GRAPH_TRACER -if ((ip == rth) && curr_frame >=0 ) { - ret_stack =ftrace_graph_get_ret_stack (current, - curr_frame++); -if (ret_stack) -pr_cont (" (%pS)" , - (void *)ret_stack->ret); -else - curr_frame =-1 ; - } + ret_addr =ftrace_graph_ret_addr (current, + &ftrace_idx, ip, stack); +if (ret_addr != ip) +pr_cont (" (%pS)" , (void *)ret_addr);#endif if (firstframe)pr_cont (" (unreliable)" );
Signature · 1 line
2.23.0
Naveen N. Rao's on September 6, 2019 4:20 am:
Quoted 3 lines
Enable
HAVE_FUNCTION_GRAPH_RET_ADDR_PTRfor more robust stack unwinding when function graph tracer is in use. Convert powerpcshow_stack()to useftrace_graph_ret_addr()for better stack unwinding.
This series improved my case of a WARN_ON triggering in trace_graph_return, the last return_to_handler entry in the stack dump has the caller in parenthesis rather than return_to_handler.
It gives the caller, it would be nice if it could output the actual function being traced, and then continue the caller. But at least this is a significant improvement. Thanks for the quick turnaround.