diff mbox series

[v7,25/36] arm64: ftrace: Enable HAVE_FUNCTION_GRAPH_FREGS

Message ID 170723232647.502590.10808588686838195094.stgit@devnote2 (mailing list archive)
State Not Applicable
Headers show
Series tracing: fprobe: function_graph: Multi-function graph and fprobe on fgraph | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-13 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-15 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 fail Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 fail Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-18 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 fail Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 fail Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-31 fail Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-32 fail Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-38 fail Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 fail Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-40 fail Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-42 success Logs for x86_64-llvm-18 / veristat
netdev/series_format fail Series longer than 15 patches (and no cover letter)
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 3 maintainers not CCed: catalin.marinas@arm.com will@kernel.org linux-arm-kernel@lists.infradead.org
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch warning WARNING: line length of 86 exceeds 80 columns WARNING: line length of 89 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Masami Hiramatsu (Google) Feb. 6, 2024, 3:12 p.m. UTC
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Enable CONFIG_HAVE_FUNCTION_GRAPH_FREGS on arm64. Note that this
depends on HAVE_DYNAMIC_FTRACE_WITH_ARGS which is enabled if the
compiler supports "-fpatchable-function-entry=2". If not, it
continue to use ftrace_ret_regs.

Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 Changes in v3:
   - Newly added.
---
 arch/arm64/Kconfig               |    2 ++
 arch/arm64/include/asm/ftrace.h  |    6 ++++++
 arch/arm64/kernel/entry-ftrace.S |   28 ++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+)

Comments

Steven Rostedt Feb. 15, 2024, 4:10 p.m. UTC | #1
On Wed,  7 Feb 2024 00:12:06 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:

> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> 
> Enable CONFIG_HAVE_FUNCTION_GRAPH_FREGS on arm64. Note that this
> depends on HAVE_DYNAMIC_FTRACE_WITH_ARGS which is enabled if the
> compiler supports "-fpatchable-function-entry=2". If not, it
> continue to use ftrace_ret_regs.
> 
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> ---
>  Changes in v3:
>    - Newly added.
> ---
>  arch/arm64/Kconfig               |    2 ++
>  arch/arm64/include/asm/ftrace.h  |    6 ++++++
>  arch/arm64/kernel/entry-ftrace.S |   28 ++++++++++++++++++++++++++++
>  3 files changed, 36 insertions(+)
> 
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index aa7c1d435139..34becd41ae66 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -194,6 +194,8 @@ config ARM64
>  	select HAVE_DYNAMIC_FTRACE
>  	select HAVE_DYNAMIC_FTRACE_WITH_ARGS \
>  		if $(cc-option,-fpatchable-function-entry=2)
> +	select HAVE_FUNCTION_GRAPH_FREGS \
> +		if HAVE_DYNAMIC_FTRACE_WITH_ARGS
>  	select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS \
>  		if DYNAMIC_FTRACE_WITH_ARGS && DYNAMIC_FTRACE_WITH_CALL_OPS
>  	select HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS \
> diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h
> index ab158196480c..efd5dbf74dd6 100644
> --- a/arch/arm64/include/asm/ftrace.h
> +++ b/arch/arm64/include/asm/ftrace.h
> @@ -131,6 +131,12 @@ ftrace_regs_set_return_value(struct ftrace_regs *fregs,
>  	fregs->regs[0] = ret;
>  }
>  
> +static __always_inline unsigned long
> +ftrace_regs_get_frame_pointer(struct ftrace_regs *fregs)
> +{
> +	return fregs->fp;
> +}
> +
>  static __always_inline void
>  ftrace_override_function_with_return(struct ftrace_regs *fregs)
>  {
> diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
> index f0c16640ef21..d87ccdb9e678 100644
> --- a/arch/arm64/kernel/entry-ftrace.S
> +++ b/arch/arm64/kernel/entry-ftrace.S
> @@ -328,6 +328,33 @@ SYM_FUNC_END(ftrace_stub_graph)
>   * Run ftrace_return_to_handler() before going back to parent.
>   * @fp is checked against the value passed by ftrace_graph_caller().
>   */
> +#ifdef CONFIG_HAVE_FUNCTION_GRAPH_FREGS
> +SYM_CODE_START(return_to_handler)
> +	/* save ftrace_regs except for PC */
> +	sub	sp, sp, #FREGS_SIZE
> +	stp	x0, x1, [sp, #FREGS_X0]
> +	stp	x2, x3, [sp, #FREGS_X2]
> +	stp	x4, x5, [sp, #FREGS_X4]
> +	stp	x6, x7, [sp, #FREGS_X6]
> +	str	x8,     [sp, #FREGS_X8]
> +	str	x29, [sp, #FREGS_FP]
> +	str	x9,  [sp, #FREGS_LR]
> +	str	x10, [sp, #FREGS_SP]

Here too. The above is just garbage.

Let's not fill in garbarge registers. The above is useless on return of a
function. Heck, adding zeros is better than this. But really, we need to
have ftrace regs to have some kind of flag that can state what it holds.
Right now I see three states:

 1 - holds all regs and pt_regs can be retrieved
 2 - only holds function entry regs (parameters and stack)
 3 - only holds function exit regs (return value and stack)

Don't save anything else unless needed.

-- Steve

> +
> +	mov	x0, sp
> +	bl	ftrace_return_to_handler	// addr = ftrace_return_to_hander(fregs);
> +	mov	x30, x0				// restore the original return address
> +
> +	/* restore return value regs */
> +	ldp x0, x1, [sp, #FREGS_X0]
> +	ldp x2, x3, [sp, #FREGS_X2]
> +	ldp x4, x5, [sp, #FREGS_X4]
> +	ldp x6, x7, [sp, #FREGS_X6]
> +	add sp, sp, #FREGS_SIZE
> +
> +	ret
> +SYM_CODE_END(return_to_handler)
> +#else /* !CONFIG_HAVE_FUNCTION_GRAPH_FREGS */
>  SYM_CODE_START(return_to_handler)
>  	/* save return value regs */
>  	sub sp, sp, #FGRET_REGS_SIZE
> @@ -350,4 +377,5 @@ SYM_CODE_START(return_to_handler)
>  
>  	ret
>  SYM_CODE_END(return_to_handler)
> +#endif /* CONFIG_HAVE_FUNCTION_GRAPH_FREGS */
>  #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
Masami Hiramatsu (Google) Feb. 16, 2024, 12:49 p.m. UTC | #2
On Thu, 15 Feb 2024 11:10:21 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Wed,  7 Feb 2024 00:12:06 +0900
> "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> 
> > From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> > 
> > Enable CONFIG_HAVE_FUNCTION_GRAPH_FREGS on arm64. Note that this
> > depends on HAVE_DYNAMIC_FTRACE_WITH_ARGS which is enabled if the
> > compiler supports "-fpatchable-function-entry=2". If not, it
> > continue to use ftrace_ret_regs.
> > 
> > Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> > ---
> >  Changes in v3:
> >    - Newly added.
> > ---
> >  arch/arm64/Kconfig               |    2 ++
> >  arch/arm64/include/asm/ftrace.h  |    6 ++++++
> >  arch/arm64/kernel/entry-ftrace.S |   28 ++++++++++++++++++++++++++++
> >  3 files changed, 36 insertions(+)
> > 
> > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> > index aa7c1d435139..34becd41ae66 100644
> > --- a/arch/arm64/Kconfig
> > +++ b/arch/arm64/Kconfig
> > @@ -194,6 +194,8 @@ config ARM64
> >  	select HAVE_DYNAMIC_FTRACE
> >  	select HAVE_DYNAMIC_FTRACE_WITH_ARGS \
> >  		if $(cc-option,-fpatchable-function-entry=2)
> > +	select HAVE_FUNCTION_GRAPH_FREGS \
> > +		if HAVE_DYNAMIC_FTRACE_WITH_ARGS
> >  	select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS \
> >  		if DYNAMIC_FTRACE_WITH_ARGS && DYNAMIC_FTRACE_WITH_CALL_OPS
> >  	select HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS \
> > diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h
> > index ab158196480c..efd5dbf74dd6 100644
> > --- a/arch/arm64/include/asm/ftrace.h
> > +++ b/arch/arm64/include/asm/ftrace.h
> > @@ -131,6 +131,12 @@ ftrace_regs_set_return_value(struct ftrace_regs *fregs,
> >  	fregs->regs[0] = ret;
> >  }
> >  
> > +static __always_inline unsigned long
> > +ftrace_regs_get_frame_pointer(struct ftrace_regs *fregs)
> > +{
> > +	return fregs->fp;
> > +}
> > +
> >  static __always_inline void
> >  ftrace_override_function_with_return(struct ftrace_regs *fregs)
> >  {
> > diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
> > index f0c16640ef21..d87ccdb9e678 100644
> > --- a/arch/arm64/kernel/entry-ftrace.S
> > +++ b/arch/arm64/kernel/entry-ftrace.S
> > @@ -328,6 +328,33 @@ SYM_FUNC_END(ftrace_stub_graph)
> >   * Run ftrace_return_to_handler() before going back to parent.
> >   * @fp is checked against the value passed by ftrace_graph_caller().
> >   */
> > +#ifdef CONFIG_HAVE_FUNCTION_GRAPH_FREGS
> > +SYM_CODE_START(return_to_handler)
> > +	/* save ftrace_regs except for PC */
> > +	sub	sp, sp, #FREGS_SIZE
> > +	stp	x0, x1, [sp, #FREGS_X0]
> > +	stp	x2, x3, [sp, #FREGS_X2]
> > +	stp	x4, x5, [sp, #FREGS_X4]
> > +	stp	x6, x7, [sp, #FREGS_X6]
> > +	str	x8,     [sp, #FREGS_X8]
> > +	str	x29, [sp, #FREGS_FP]
> > +	str	x9,  [sp, #FREGS_LR]
> > +	str	x10, [sp, #FREGS_SP]
> 
> Here too. The above is just garbage.
> 
> Let's not fill in garbarge registers. The above is useless on return of a
> function. Heck, adding zeros is better than this. But really, we need to
> have ftrace regs to have some kind of flag that can state what it holds.
> Right now I see three states:
> 
>  1 - holds all regs and pt_regs can be retrieved
>  2 - only holds function entry regs (parameters and stack)
>  3 - only holds function exit regs (return value and stack)
> 
> Don't save anything else unless needed.

OK, it is reasonable to save the registers depending on the context.

Thanks,

> 
> -- Steve
> 
> > +
> > +	mov	x0, sp
> > +	bl	ftrace_return_to_handler	// addr = ftrace_return_to_hander(fregs);
> > +	mov	x30, x0				// restore the original return address
> > +
> > +	/* restore return value regs */
> > +	ldp x0, x1, [sp, #FREGS_X0]
> > +	ldp x2, x3, [sp, #FREGS_X2]
> > +	ldp x4, x5, [sp, #FREGS_X4]
> > +	ldp x6, x7, [sp, #FREGS_X6]
> > +	add sp, sp, #FREGS_SIZE
> > +
> > +	ret
> > +SYM_CODE_END(return_to_handler)
> > +#else /* !CONFIG_HAVE_FUNCTION_GRAPH_FREGS */
> >  SYM_CODE_START(return_to_handler)
> >  	/* save return value regs */
> >  	sub sp, sp, #FGRET_REGS_SIZE
> > @@ -350,4 +377,5 @@ SYM_CODE_START(return_to_handler)
> >  
> >  	ret
> >  SYM_CODE_END(return_to_handler)
> > +#endif /* CONFIG_HAVE_FUNCTION_GRAPH_FREGS */
> >  #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
>
diff mbox series

Patch

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index aa7c1d435139..34becd41ae66 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -194,6 +194,8 @@  config ARM64
 	select HAVE_DYNAMIC_FTRACE
 	select HAVE_DYNAMIC_FTRACE_WITH_ARGS \
 		if $(cc-option,-fpatchable-function-entry=2)
+	select HAVE_FUNCTION_GRAPH_FREGS \
+		if HAVE_DYNAMIC_FTRACE_WITH_ARGS
 	select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS \
 		if DYNAMIC_FTRACE_WITH_ARGS && DYNAMIC_FTRACE_WITH_CALL_OPS
 	select HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS \
diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h
index ab158196480c..efd5dbf74dd6 100644
--- a/arch/arm64/include/asm/ftrace.h
+++ b/arch/arm64/include/asm/ftrace.h
@@ -131,6 +131,12 @@  ftrace_regs_set_return_value(struct ftrace_regs *fregs,
 	fregs->regs[0] = ret;
 }
 
+static __always_inline unsigned long
+ftrace_regs_get_frame_pointer(struct ftrace_regs *fregs)
+{
+	return fregs->fp;
+}
+
 static __always_inline void
 ftrace_override_function_with_return(struct ftrace_regs *fregs)
 {
diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
index f0c16640ef21..d87ccdb9e678 100644
--- a/arch/arm64/kernel/entry-ftrace.S
+++ b/arch/arm64/kernel/entry-ftrace.S
@@ -328,6 +328,33 @@  SYM_FUNC_END(ftrace_stub_graph)
  * Run ftrace_return_to_handler() before going back to parent.
  * @fp is checked against the value passed by ftrace_graph_caller().
  */
+#ifdef CONFIG_HAVE_FUNCTION_GRAPH_FREGS
+SYM_CODE_START(return_to_handler)
+	/* save ftrace_regs except for PC */
+	sub	sp, sp, #FREGS_SIZE
+	stp	x0, x1, [sp, #FREGS_X0]
+	stp	x2, x3, [sp, #FREGS_X2]
+	stp	x4, x5, [sp, #FREGS_X4]
+	stp	x6, x7, [sp, #FREGS_X6]
+	str	x8,     [sp, #FREGS_X8]
+	str	x29, [sp, #FREGS_FP]
+	str	x9,  [sp, #FREGS_LR]
+	str	x10, [sp, #FREGS_SP]
+
+	mov	x0, sp
+	bl	ftrace_return_to_handler	// addr = ftrace_return_to_hander(fregs);
+	mov	x30, x0				// restore the original return address
+
+	/* restore return value regs */
+	ldp x0, x1, [sp, #FREGS_X0]
+	ldp x2, x3, [sp, #FREGS_X2]
+	ldp x4, x5, [sp, #FREGS_X4]
+	ldp x6, x7, [sp, #FREGS_X6]
+	add sp, sp, #FREGS_SIZE
+
+	ret
+SYM_CODE_END(return_to_handler)
+#else /* !CONFIG_HAVE_FUNCTION_GRAPH_FREGS */
 SYM_CODE_START(return_to_handler)
 	/* save return value regs */
 	sub sp, sp, #FGRET_REGS_SIZE
@@ -350,4 +377,5 @@  SYM_CODE_START(return_to_handler)
 
 	ret
 SYM_CODE_END(return_to_handler)
+#endif /* CONFIG_HAVE_FUNCTION_GRAPH_FREGS */
 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */