linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ARM: ftrace: Implement HAVE_FUNCTION_GRAPH_FREGS
@ 2025-08-18 10:39 Richard Weinberger
  2025-08-20  7:20 ` Linus Walleij
  2025-08-20  7:26 ` Linus Walleij
  0 siblings, 2 replies; 5+ messages in thread
From: Richard Weinberger @ 2025-08-18 10:39 UTC (permalink / raw)
  To: linux, rostedt, mhiramat, mark.rutland
  Cc: ardb, ebiggers, nathan, linus.walleij, dave, ruanjinjie,
	liuyuntao12, linux-arm-kernel, linux-kernel, linux-trace-kernel,
	Richard Weinberger, Donglin Peng

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] ARM: ftrace: Implement HAVE_FUNCTION_GRAPH_FREGS
  2025-08-18 10:39 [PATCH] ARM: ftrace: Implement HAVE_FUNCTION_GRAPH_FREGS Richard Weinberger
@ 2025-08-20  7:20 ` Linus Walleij
  2025-08-20  8:11   ` Richard Weinberger
  2025-08-20  7:26 ` Linus Walleij
  1 sibling, 1 reply; 5+ messages in thread
From: Linus Walleij @ 2025-08-20  7:20 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: linux, rostedt, mhiramat, mark.rutland, ardb, ebiggers, nathan,
	dave, ruanjinjie, liuyuntao12, linux-arm-kernel, linux-kernel,
	linux-trace-kernel, Donglin Peng

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ARM: ftrace: Implement HAVE_FUNCTION_GRAPH_FREGS
  2025-08-18 10:39 [PATCH] ARM: ftrace: Implement HAVE_FUNCTION_GRAPH_FREGS Richard Weinberger
  2025-08-20  7:20 ` Linus Walleij
@ 2025-08-20  7:26 ` Linus Walleij
  1 sibling, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2025-08-20  7:26 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: linux, rostedt, mhiramat, mark.rutland, ardb, ebiggers, nathan,
	dave, ruanjinjie, liuyuntao12, linux-arm-kernel, linux-kernel,
	linux-trace-kernel, Donglin Peng

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ARM: ftrace: Implement HAVE_FUNCTION_GRAPH_FREGS
  2025-08-20  7:20 ` Linus Walleij
@ 2025-08-20  8:11   ` Richard Weinberger
  2025-08-20  8:30     ` Richard Weinberger
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Weinberger @ 2025-08-20  8:11 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Russell King, Steven Rostedt, mhiramat, Mark Rutland, ardb,
	Eric Biggers, Nathan Chancellor, dave, ruanjinjie, liuyuntao12,
	linux-arm-kernel, linux-kernel, linux-trace-kernel, Donglin Peng

----- 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ARM: ftrace: Implement HAVE_FUNCTION_GRAPH_FREGS
  2025-08-20  8:11   ` Richard Weinberger
@ 2025-08-20  8:30     ` Richard Weinberger
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Weinberger @ 2025-08-20  8:30 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Russell King, Steven Rostedt, mhiramat, Mark Rutland, ardb,
	Eric Biggers, Nathan Chancellor, dave, ruanjinjie, liuyuntao12,
	linux-arm-kernel, linux-kernel, linux-trace-kernel, Donglin Peng

----- 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-08-20  8:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-18 10:39 [PATCH] ARM: ftrace: Implement HAVE_FUNCTION_GRAPH_FREGS Richard Weinberger
2025-08-20  7:20 ` Linus Walleij
2025-08-20  8:11   ` Richard Weinberger
2025-08-20  8:30     ` Richard Weinberger
2025-08-20  7:26 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).