ARM: ftrace: enable HAVE_FUNCTION_GRAPH_FP_TEST
authorArd Biesheuvel <ardb@kernel.org>
Tue, 25 Jan 2022 10:20:49 +0000 (11:20 +0100)
committerArd Biesheuvel <ardb@kernel.org>
Wed, 9 Feb 2022 08:12:33 +0000 (09:12 +0100)
Fix the frame pointer handling in the function graph tracer entry and
exit code so we can enable HAVE_FUNCTION_GRAPH_FP_TEST. Instead of using
FP directly (which will have different values between the entry and exit
pieces of the function graph tracer), use the value of SP at entry and
exit, as we can derive the former value from the frame pointer.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
arch/arm/include/asm/ftrace.h
arch/arm/kernel/entry-ftrace.S
arch/arm/kernel/ftrace.c

index a4dbac07e4ef05822e5aaa32ca75b8782da78d0b..b4f5fab6b04e4ddca998c1c57feef2c1fd8c5d4f 100644 (file)
@@ -2,6 +2,8 @@
 #ifndef _ASM_ARM_FTRACE
 #define _ASM_ARM_FTRACE
 
+#define HAVE_FUNCTION_GRAPH_FP_TEST
+
 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
 #define ARCH_SUPPORTS_FTRACE_OPS 1
 #endif
index 99720064a4c570d87020c24d800242ce46dd905c..bbfa0954c385ea96a1f45950f92e1ed38a1fd429 100644 (file)
@@ -247,7 +247,7 @@ ENDPROC(ftrace_graph_regs_caller)
        .globl return_to_handler
 return_to_handler:
        stmdb   sp!, {r0-r3}
-       mov     r0, fp                  @ frame pointer
+       add     r0, sp, #16             @ sp at exit of instrumented routine
        bl      ftrace_return_to_handler
        mov     lr, r0                  @ r0 has real ret addr
        ldmia   sp!, {r0-r3}
index 74d3913f5590d7dca21f9b48305372c476525d70..ea2396900c7dcbddbb13041508ab3972f2afcf84 100644 (file)
@@ -233,6 +233,11 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
        if (unlikely(atomic_read(&current->tracing_graph_pause)))
                return;
 
+       if (IS_ENABLED(CONFIG_UNWINDER_FRAME_POINTER)) {
+               /* FP points one word below parent's top of stack */
+               frame_pointer += 4;
+       }
+
        old = *parent;
        *parent = return_hooker;