Enable support for ftrace's funcgraph-retval feature by capturing r0-r3
and fp.
Since ARM does not provide its own __arch_ftrace_regs structure,
we instead populate pt_regs with the registers required by ftrace.

Cc: Donglin Peng <[email protected]>
Signed-off-by: Richard Weinberger <[email protected]>
---
I noticed that funcgraph-retval is not available on ARM.
There was a patch [0] to enable the feature, but it never made it
upstream. Since then, the infrastructure around
CONFIG_FUNCTION_GRAPH_RETVAL has changed, so I have
reimplemented the original patch.

Donglin Peng, your change also captured the link register, but it
seems it was never used. Therefore, I skipped storing LR.

Thanks,
//richard

[0]: 
https://lore.kernel.org/all/c61eb9290c3e817d4d70c429c0e987e3ec51a3c4.1680954589.git.pengdong...@sangfor.com.cn/
---
 arch/arm/Kconfig               |  1 +
 arch/arm/kernel/entry-ftrace.S | 18 ++++++++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index b1f3df39ed406..ba84c6f7f5f7a 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -108,6 +108,7 @@ config ARM
        select HAVE_GUP_FAST if ARM_LPAE
        select HAVE_FUNCTION_ERROR_INJECTION
        select HAVE_FUNCTION_GRAPH_TRACER
+       select HAVE_FUNCTION_GRAPH_FREGS
        select HAVE_FUNCTION_TRACER if !XIP_KERNEL
        select HAVE_GCC_PLUGINS
        select HAVE_HW_BREAKPOINT if PERF_EVENTS && (CPU_V6 || CPU_V6K || 
CPU_V7)
diff --git a/arch/arm/kernel/entry-ftrace.S b/arch/arm/kernel/entry-ftrace.S
index bc598e3d8dd23..e24ee559af81d 100644
--- a/arch/arm/kernel/entry-ftrace.S
+++ b/arch/arm/kernel/entry-ftrace.S
@@ -257,11 +257,21 @@ ENDPROC(ftrace_graph_regs_caller)
 
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 ENTRY(return_to_handler)
-       stmdb   sp!, {r0-r3}
-       add     r0, sp, #16             @ sp at exit of instrumented routine
+       mov     ip, sp                          @ sp at exit of instrumented 
routine
+       sub     sp, #PT_REGS_SIZE
+       str     r0, [sp, #S_R0]
+       str     r1, [sp, #S_R1]
+       str     r2, [sp, #S_R2]
+       str     r3, [sp, #S_R3]
+       str     ip, [sp, #S_FP]
+       mov     r0, sp
        bl      ftrace_return_to_handler
-       mov     lr, r0                  @ r0 has real ret addr
-       ldmia   sp!, {r0-r3}
+       mov     lr, r0                          @ r0 has real ret addr
+       ldr     r3, [sp, #S_R3]
+       ldr     r2, [sp, #S_R2]
+       ldr     r1, [sp, #S_R1]
+       ldr     r0, [sp, #S_R0]
+       add     sp, sp, #PT_REGS_SIZE           @ restore stack pointer
        ret     lr
 ENDPROC(return_to_handler)
 #endif
-- 
2.50.1


Reply via email to