mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Venkat <venkat88@linux.ibm.com>
To: Aditya Bodkhe <adityab1@linux.ibm.com>
Cc: linuxppc-dev@lists.ozlabs.org,
	LKML <linux-kernel@vger.kernel.org>,
	linux-trace-kernel@vger.kernel.org, maddy@linux.ibm.com,
	Michael Ellerman <mpe@ellerman.id.au>,
	npiggin@gmail.com, christophe.leroy@csgroup.eu,
	rostedt@goodmis.org, mhiramat@kernel.org, mark.rutland@arm.com
Subject: Re: [PATCH v2 1/2] powerpc/ftrace: support CONFIG_FUNCTION_GRAPH_RETVAL
Date: Mon, 4 Aug 2025 12:40:03 +0530	[thread overview]
Message-ID: <401DC39A-0A74-467F-AE01-68B164BEDCF6@linux.ibm.com> (raw)
In-Reply-To: <20250722085648.1640-1-adityab1@linux.ibm.com>



> On 22 Jul 2025, at 2:26 PM, Aditya Bodkhe <adityab1@linux.ibm.com> wrote:
> 
> 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.
> 
> Signed-off-by: Aditya Bodkhe <adityab1@linux.ibm.com>
> ---
> 
> Changelog:
> 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.
> 
> 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(-)
> 
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index c3e0cc83f120..9163521bc4b9 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -250,6 +250,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 if GCC_VERSION >= 50200   # plugin support on gcc <= 5.1 is buggy on PPC
> diff --git a/arch/powerpc/include/asm/ftrace.h b/arch/powerpc/include/asm/ftrace.h
> index 82da7c7a1d12..6ffc9c9cf4e3 100644
> --- a/arch/powerpc/include/asm/ftrace.h
> +++ b/arch/powerpc/include/asm/ftrace.h
> @@ -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)
> diff --git a/arch/powerpc/kernel/trace/ftrace_entry.S b/arch/powerpc/kernel/trace/ftrace_entry.S
> index 3565c67fc638..3da14d8271d9 100644
> --- a/arch/powerpc/kernel/trace/ftrace_entry.S
> +++ b/arch/powerpc/kernel/trace/ftrace_entry.S
> @@ -409,23 +409,31 @@ EXPORT_SYMBOL(_mcount)
> _GLOBAL(return_to_handler)
> /* need to save return values */
> #ifdef CONFIG_PPC64
> - std r4,  -32(r1)
> - std r3,  -24(r1)
> + stdu r1, -SWITCH_FRAME_SIZE(r1)
> + std r4, GPR4(r1)
> + std r3, GPR3(r1)
> + /* Save previous stack pointer (r1) */
> + addi r3, r1, SWITCH_FRAME_SIZE
> + std r3, GPR1(r1)
> /* save TOC */
> - std r2,  -16(r1)
> - std r31, -8(r1)
> + std r2, 24(r1)
> + std r31, 32(r1)
> mr r31, r1
> - stdu r1, -112(r1)
> -
> + /* pass ftrace_regs/pt_regs to ftrace_return_to_handler */
> + addi r3, r1, STACK_INT_FRAME_REGS
> /*
> * We might be called from a module.
> * Switch to our TOC to run inside the core kernel.
> */
> LOAD_PACA_TOC()
> #else
> - stwu r1, -16(r1)
> - stw r3, 8(r1)
> - stw r4, 12(r1)
> + stwu r1, -SWITCH_FRAME_SIZE(r1)
> + stw r4, GPR4(r1)
> + stw r3, GPR3(r1)
> + addi r3, r1, SWITCH_FRAME_SIZE
> + stw r3, GPR1(r1)
> + /* pass ftrace_regs/pt_regs to ftrace_return_to_handler */
> + addi r3, r1, STACK_INT_FRAME_REGS
> #endif
> 
> 
> bl ftrace_return_to_handler
> @@ -435,15 +443,15 @@ _GLOBAL(return_to_handler)
> mtlr r3
> 
> #ifdef CONFIG_PPC64
> - ld r1, 0(r1)
> - ld r4,  -32(r1)
> - ld r3,  -24(r1)
> - ld r2,  -16(r1)
> - ld r31, -8(r1)
> + ld r4,  GPR4(r1)
> + ld r3,  GPR3(r1)
> + ld r2,  24(r1)
> + ld r31, 32(r1)
> + ld r1,  0(r1)
> #else
> - lwz r3, 8(r1)
> - lwz r4, 12(r1)
> - addi r1, r1, 16
> + lwz r3, GPR3(r1)
> + lwz r4, GPR4(r1)
> + addi r1, r1, SWITCH_FRAME_SIZE
> #endif
> 
> /* Jump back to real return address */
> -- 
> 2.50.0
> 


<Resending to the right thread>

Tested this patch by applying on top of mainline. Build and boot is successful. Also ran ftrace selftest, intended test passed and no new failures/errors introduced with this patch. Hence,

Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>

Regards,
Venkat.


  parent reply	other threads:[~2025-08-04  7:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-22  8:56 Aditya Bodkhe
2025-07-22  8:56 ` [PATCH v2 2/2] powerpc/fprobe: fix updated fprobe for function-graph tracer Aditya Bodkhe
2025-07-26 14:15   ` Hari Bathini
2025-08-04  7:12   ` Venkat
2025-08-04  7:10 ` Venkat [this message]
2025-08-04 14:19 ` [PATCH v2 1/2] powerpc/ftrace: support CONFIG_FUNCTION_GRAPH_RETVAL Christophe Leroy
2025-07-23  5:26 Venkat

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=401DC39A-0A74-467F-AE01-68B164BEDCF6@linux.ibm.com \
    --to=venkat88@linux.ibm.com \
    --cc=adityab1@linux.ibm.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mark.rutland@arm.com \
    --cc=mhiramat@kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®