powerpc: Use ftrace_graph_ret_addr() when unwinding
authorNaveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Thu, 5 Sep 2019 18:20:30 +0000 (23:50 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 18 Sep 2019 02:24:55 +0000 (12:24 +1000)
With 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)

Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/dc89c9a887121342d9c7819482c3dabdece2a323.1567707399.git.naveen.n.rao@linux.vnet.ibm.com
arch/powerpc/kernel/process.c

index 24621e7e5033444bd68336d9d29fc247fdd566f0..f289bdd2b562c342086ee8bfaf849495d8cbcf46 100644 (file)
@@ -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)");