Skip to contentSkip to conversation

powerpc/ftrace: support CONFIG_FUNCTION_GRAPH_RETVAL

PATCH Applied Aditya Bodkhe 2 participants 3 messages Sep 16, 2025 – Sep 22, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 powerpc/ftrace: support CONFIG_FUNCTION_GRAPH_RETVAL

commit a1be9ccc57f0 ("function_graph: Support recording and printing the return value of function") introduced support for function graph return value tracing.

Additionally, commit a3ed4157b7d8 ("fgraph: Replace fgraph_ret_regs with ftrace_regs") further refactored and optimized the implementation, making struct fgraph_ret_regs unnecessary.

This patch enables the above modifications for powerpc all, ensuring that function graph return value tracing is available on this architecture.

In this patch we have redefined two functions:
- 'ftrace_regs_get_return_value()' - the existing implementation on ppc returns -ve of return value based on some conditions not relevant to our patch.
- 'ftrace_regs_get_frame_pointer()' - always returns 0 in current code .

We also allocate stack space to equivalent of 'SWITCH_FRAME_SIZE', allowing us to directly use predefined offsets like 'GPR3' and 'GPR4' this keeps code clean and consistent with already defined offsets .

After this patch, v6.14+ kernel can also be built with FPROBE on powerpc but there are a few other build and runtime dependencies for FPROBE to work properly. The next patch addresses them.

---

Changelog:
v3 -> v4:
- commit a41de5ccff85 ("arch/powerpc: Remove support for older GCC and binutils") which is already part of -next has removed the check for GCC_VERSION in Kconfig which is causing error for git am when applying v3. So rebased it to powerpc -next as v4

v3:https://lore.kernel.org/all/[email protected]/

v2 -> v3:
- Rebase on Linux 6.17-rc4

v2:https://lore.kernel.org/all/[email protected]/

v1 -> v2:
- Added explanation for redefining ftrace_regs_get_return_value() and ftrace_regs_get_frame_pointer()
- Explained why stack space equivalent to 'SWITCH_FRAME_SIZE' is allocated.

v1:https://lore.kernel.org/all/[email protected]/

---
 arch/powerpc/Kconfig                     |  1 +
 arch/powerpc/include/asm/ftrace.h        | 15 +++++++++
 arch/powerpc/kernel/trace/ftrace_entry.S | 42 ++++++++++++++----------
 3 files changed, 41 insertions(+), 17 deletions(-)
arch/powerpc/Kconfig +1 -0
index ba9750c8e0cd..449404d3932b 100644
@@ -246,6 +246,7 @@ config PPC
 	select HAVE_FUNCTION_ARG_ACCESS_API
 	select HAVE_FUNCTION_DESCRIPTORS	if PPC64_ELF_ABI_V1
 	select HAVE_FUNCTION_ERROR_INJECTION
+	select HAVE_FUNCTION_GRAPH_FREGS
 	select HAVE_FUNCTION_GRAPH_TRACER
 	select HAVE_FUNCTION_TRACER		if !COMPILE_TEST && (PPC64 || (PPC32 && CC_IS_GCC))
 	select HAVE_GCC_PLUGINS
arch/powerpc/include/asm/ftrace.h +15 -0
index bd61a230b19d..5984eaa75ce8 100644
@@ -50,6 +50,21 @@ static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *
 		asm volatile("mfmsr %0" : "=r" ((_regs)->msr));	\
 	} while (0)
 
+#undef ftrace_regs_get_return_value
+static __always_inline unsigned long
+ftrace_regs_get_return_value(const struct ftrace_regs *fregs)
+{
+	return arch_ftrace_regs(fregs)->regs.gpr[3];
+}
+#define ftrace_regs_get_return_value ftrace_regs_get_return_value
+
+#undef ftrace_regs_get_frame_pointer
+static __always_inline unsigned long
+ftrace_regs_get_frame_pointer(const struct ftrace_regs *fregs)
+{
+	return arch_ftrace_regs(fregs)->regs.gpr[1];
+}
+
 static __always_inline void
 ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,
 				    unsigned long ip)
arch/powerpc/kernel/trace/ftrace_entry.S +25 -17

63 lines not on this page · raw message

Signature · 1 line
2.51.0
#1 lore raw

PATCH v4 2/2 powerpc/fprobe: fix updated fprobe for function-graph tracer

From: Hari Bathini <[email protected]>

Since commit 4346ba160409 ("fprobe: Rewrite fprobe on function-graph tracer"), FPROBE depends on HAVE_FUNCTION_GRAPH_FREGS. With previous patch adding HAVE_FUNCTION_GRAPH_FREGS for powerpc, FPROBE can be enabled on powerpc. But with the commit b5fa903b7f7c ("fprobe: Add fprobe_header encoding feature"), asm/fprobe.h header is needed to define arch dependent encode/decode macros. The fprobe header MSB pattern on powerpc is not 0xf. So, define FPROBE_HEADER_MSB_PATTERN expected on powerpc.

Also, commit 762abbc0d09f ("fprobe: Use ftrace_regs in fprobe exit handler") introduced HAVE_FTRACE_REGS_HAVING_PT_REGS for archs that have pt_regs in ftrace_regs. Advertise that on powerpc to reuse common definitions like ftrace_partial_regs().

---
 arch/powerpc/Kconfig              |  1 +
 arch/powerpc/include/asm/fprobe.h | 12 ++++++++++++
 2 files changed, 13 insertions(+)
 create mode 100644 arch/powerpc/include/asm/fprobe.h
arch/powerpc/Kconfig +1 -0
index 449404d3932b..325c1171894d 100644
@@ -243,6 +243,7 @@ config PPC
 	select HAVE_EFFICIENT_UNALIGNED_ACCESS
 	select HAVE_GUP_FAST
 	select HAVE_FTRACE_GRAPH_FUNC
+	select HAVE_FTRACE_REGS_HAVING_PT_REGS
 	select HAVE_FUNCTION_ARG_ACCESS_API
 	select HAVE_FUNCTION_DESCRIPTORS	if PPC64_ELF_ABI_V1
 	select HAVE_FUNCTION_ERROR_INJECTION
arch/powerpc/include/asm/fprobe.h new file +12 -0
new file mode 100644
index 000000000000..d64bc28fb3d3
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_PPC_FPROBE_H
+#define _ASM_PPC_FPROBE_H
+
+#include <asm-generic/fprobe.h>
+
+#ifdef CONFIG_64BIT
+#undef FPROBE_HEADER_MSB_PATTERN
+#define FPROBE_HEADER_MSB_PATTERN	(PAGE_OFFSET & ~FPROBE_HEADER_MSB_MASK)
+#endif
+
+#endif /* _ASM_PPC_FPROBE_H */
Signature · 1 line
2.51.0
maintainer Applied
#2 lore raw
In reply to Aditya Bodkhe
Quoted 9 lines · Aditya Bodkhe

commit a1be9ccc57f0 ("function_graph: Support recording and printing the return value of function") introduced support for function graph return value tracing.

Additionally, commit a3ed4157b7d8 ("fgraph: Replace fgraph_ret_regs with ftrace_regs") further refactored and optimized the implementation, making struct fgraph_ret_regs unnecessary.

[...]

Applied to powerpc/next.

[1/2] powerpc/ftrace: support CONFIG_FUNCTION_GRAPH_RETVAL

      https://git.kernel.org/powerpc/c/d733f18a6da6fb719450d5122162556d785ed580
[2/2] powerpc/fprobe: fix updated fprobe for function-graph tracer
      https://git.kernel.org/powerpc/c/7cec88bfdd33434d62d4d5ba664127fa175b50e7

Thanks