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

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/0224f2d0971b069c678e2ff678cfc2cd1e114cfe.1567707399.git.naveen.n.rao@linux.vnet.ibm.com
arch/powerpc/include/asm/asm-prototypes.h
arch/powerpc/include/asm/ftrace.h
arch/powerpc/kernel/stacktrace.c
arch/powerpc/kernel/trace/ftrace.c
arch/powerpc/kernel/trace/ftrace_32.S
arch/powerpc/kernel/trace/ftrace_64_mprofile.S
arch/powerpc/kernel/trace/ftrace_64_pg.S

index 49196d35e3bbf5eaec297e0a6e83a2b8fa199cdb..8561498e653cb08fd604fbad535e3dc94fcff3cc 100644 (file)
@@ -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);
index 3dfb80b8656140487a5f975f08b1202f9a3974c4..f54a08a2cd70921c3ac5a8ff90587f539929a51c 100644 (file)
@@ -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 */
index 1e2276963f6d324741184af7fbaa88690b137b2e..e2a46cfed5fd1b97ca3139f52678363c5b8d5456 100644 (file)
@@ -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
index be1ca98fce5c02b3edfdd5f7cc32e9cfd6bf2ea2..7ea0ca044b6500c634f12f5d5ff3f24a0576c47b 100644 (file)
@@ -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;
index 183f608efb81a490436c248923d6b8d63c847200..e023ae59c4294c1d6c38181f5af10fe0c8983d5a 100644 (file)
@@ -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
index 74acbf16a666245ac40d95321d261d06835c65ab..f9fd5f743eba34125531452bc9d4f61b256145fa 100644 (file)
@@ -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 */
index e41a7d13c99c0d661e8e92a8018ca717ee6a107a..6708e24db0aba8c159d50c56eca6f3b419b1fe94 100644 (file)
@@ -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