arch/arm/Kconfig | 1 + arch/arm/kernel/entry-ftrace.S | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-)
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 <pengdonglin@sangfor.com.cn>
Signed-off-by: Richard Weinberger <richard@nod.at>
---
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.pengdonglin@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
Unsolicited thread intervention: Richard if you use ftrace on ARM a lot, have you looked into patchable function entry as described by Mark Rutland for ARM64 in this talk? https://www.youtube.com/watch?v=p9cqUTF4I0w (Described at 19:12 into the talk.) I think it would be neat if we could do this on ARM32 as well but I do not know how hard it would be. Yours, Linus Walleij
On Mon, Aug 18, 2025 at 12:40 PM Richard Weinberger <richard@nod.at> wrote: > 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 <pengdonglin@sangfor.com.cn> > Signed-off-by: Richard Weinberger <richard@nod.at> LGTM Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Can you put this patch into Russell's patch tracker? https://www.armlinux.org.uk/developer/patches/ Yours, Linus Walleij
----- Ursprüngliche Mail ----- > Von: "Linus Walleij" <linus.walleij@linaro.org> > Can you put this patch into Russell's patch tracker? > https://www.armlinux.org.uk/developer/patches/ So far I had no success doing so. Whenever I add the patch, I get back to the patch add form without an error message or such. Thanks, //richard
----- Ursprüngliche Mail ----- > Von: "richard" <richard@nod.at> >> Can you put this patch into Russell's patch tracker? >> https://www.armlinux.org.uk/developer/patches/ > > So far I had no success doing so. > Whenever I add the patch, I get back to the patch add form without > an error message or such. Worked. :-) It took just some time until patchd's mail arrived. Thanks, //richard
© 2016 - 2025 Red Hat, Inc.