mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH bpf-next v2] selftests/bpf: port test_ftrace.sh to test_progs
@ 2026-11-04  9:59 Alexis Lothoré (eBPF Foundation)
  2026-11-04 11:40 ` Jiri Olsa
  2026-11-04 18:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Alexis Lothoré (eBPF Foundation) @ 2026-11-04  9:59 UTC (permalink / raw)
  To: ebpf, Bastien Curutchet, Thomas Petazzoni
  Cc: Alexis Lothoré (eBPF Foundation),
	Andrii Nakryiko, Eduard Zingerman, Ihor Solodrai,
	Alexei Starovoitov, Daniel Borkmann, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Shuah Khan, linux-kernel, bpf, linux-kselftest

Commit ff205766dbbe ("ftrace: Fix function_graph tracer interaction with
BPF trampoline") made sure that trampolines generated for tracing
programs did not collide with the function graph when we are returning
from the hooked function. The series bringing this commit also came with
a new test ensuring that the kernel does not crash when executing BPF
programs handled by trampolines while the function graph trace is
enabled, but this test is a standalone shell script, hence not executed
in CI.

Convert the script to the test_progs runner so it can be executed
automatically by the CI infrastructure. There are two main options to
port this test:
  - just enable ftrace during some existing trampoline-related tests
    (eg: fentry/fexit tests)
  - create a dedicated, minimal test with function graph

The new test adopts the latter approach, with a smaller scope to keep
execution time reasonable, while reusing an existing
fentry/fexit/fmod_ret test. Despite the few asserts in the new test, the
actual goal is to make sure that the kernel does not crash because of
some incorrect stack frame skipping when both the function graph and
tracing programs are running.

ftrace is configured through a dedicated ftrace instance which is
dropped at the end of the test.

With the new test integrated into test_progs, drop test_ftrace.sh.

Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
---
Hello,
this is v2 of a small series aiming to port the test_ftrace.sh script
(testing that trampolines and function graph behave correctly when both
are enabled) into the test_progs framework. The test is heavily
simplified following Alexei's review and suggestions.
---
Changes in v2:
- use a ftrace instance rather than global ftrace
- drop fgraph filters
- drop custom ftrace helpers in favor of direct manipulation in test
- drop custom bpf prog, reuse test_modify_return directly
- move test in existing test file (modify_return.c)
- make the test parallel (drop serial_)
- Link to v1: https://patch.msgid.link/20261030-ftrace_in_test_progs-v1-0-aa50c5dd1ccc@bootlin.com

To: Andrii Nakryiko <andrii@kernel.org>
To: Eduard Zingerman <eddyz87@gmail.com>
To: Ihor Solodrai <ihor.solodrai@linux.dev>
To: Alexei Starovoitov <ast@kernel.org>
To: Daniel Borkmann <daniel@iogearbox.net>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: Martin KaFai Lau <martin.lau@linux.dev>
To: Song Liu <song@kernel.org>
To: Yonghong Song <yonghong.song@linux.dev>
To: Jiri Olsa <jolsa@kernel.org>
To: Emil Tsalapatis <emil@etsalapatis.com>
To: Shuah Khan <shuah@kernel.org>
Cc: ebpf@linuxfoundation.org
Cc: Bastien Curutchet <bastien.curutchet@bootlin.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: linux-kernel@vger.kernel.org
Cc: bpf@vger.kernel.org
Cc: linux-kselftest@vger.kernel.org
---
 .../selftests/bpf/prog_tests/modify_return.c       | 32 ++++++++++++++++
 tools/testing/selftests/bpf/test_ftrace.sh         | 44 ----------------------
 2 files changed, 32 insertions(+), 44 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/modify_return.c b/tools/testing/selftests/bpf/prog_tests/modify_return.c
index 4661d77ebdfc..15681b49f86f 100644
--- a/tools/testing/selftests/bpf/prog_tests/modify_return.c
+++ b/tools/testing/selftests/bpf/prog_tests/modify_return.c
@@ -11,6 +11,10 @@
 #define LOWER(x) ((x) & 0xffff)
 #define UPPER(x) ((x) >> 16)
 
+#define MAX_INSTANCE_PATH_LEN	128
+#define TRACEFS_DEFAULT		"/sys/kernel/tracing"
+#define TRACEFS_IN_DEBUGFS	"/sys/kernel/debug/tracing"
+#define TRACE_FTRACE_DEFAULT	TRACEFS_DEFAULT "/trace"
 
 static void run_test(__u32 input_retval, __u16 want_side_effect, __s16 want_ret)
 {
@@ -61,3 +65,31 @@ void test_modify_return(void)
 		 0 /* want_side_effect */,
 		 -EINVAL * 2 /* want_ret */);
 }
+
+void test_modify_return_graph(void)
+{
+	char instance[MAX_INSTANCE_PATH_LEN];
+	char *ftrace_dir;
+	int ret;
+
+	ftrace_dir = access(TRACE_FTRACE_DEFAULT, F_OK) ? TRACEFS_IN_DEBUGFS :
+							  TRACEFS_DEFAULT;
+
+	ret = snprintf(instance, MAX_INSTANCE_PATH_LEN,
+		       "%s/instances/bpf-XXXXXX", ftrace_dir);
+	if (ret < 0)
+		return;
+
+	if (!ASSERT_OK_PTR(mkdtemp(instance), "mkdtemp"))
+		return;
+
+	SYS(out, "echo 'bpf_modify_return_test*' > %s/set_ftrace_filter",
+	    instance);
+	SYS(out, "echo function_graph > %s/current_tracer", instance);
+
+	test_modify_return();
+
+	SYS(out, "grep -q bpf_modify_return_test2 %s/trace", instance);
+out:
+	ASSERT_OK(rmdir(instance), "rmdir");
+}
diff --git a/tools/testing/selftests/bpf/test_ftrace.sh b/tools/testing/selftests/bpf/test_ftrace.sh
deleted file mode 100755
index f5109eb0e951..000000000000
--- a/tools/testing/selftests/bpf/test_ftrace.sh
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/bin/bash
-
-if [[ -e /sys/kernel/tracing/trace ]]; then
-    TR=/sys/kernel/tracing/
-else
-    TR=/sys/kernel/debug/tracing/
-fi
-
-clear_trace() { # reset trace output
-    echo > $TR/trace
-}
-
-disable_tracing() { # stop trace recording
-    echo 0 > $TR/tracing_on
-}
-
-enable_tracing() { # start trace recording
-    echo 1 > $TR/tracing_on
-}
-
-reset_tracer() { # reset the current tracer
-    echo nop > $TR/current_tracer
-}
-
-disable_tracing
-clear_trace
-
-echo "" > $TR/set_ftrace_filter
-echo '*printk* *console* *wake* *serial* *lock*' > $TR/set_ftrace_notrace
-
-echo "bpf_prog_test*" > $TR/set_graph_function
-echo "" > $TR/set_graph_notrace
-
-echo function_graph > $TR/current_tracer
-
-enable_tracing
-./test_progs -t fentry
-./test_progs -t fexit
-disable_tracing
-clear_trace
-
-reset_tracer
-
-exit 0

---
base-commit: b0e67f50519538b1b4c6364edc7811f482703f75
change-id: 20261027-ftrace_in_test_progs-d5f70a2330ac

Best regards,
--  
Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>


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

* Re: [PATCH bpf-next v2] selftests/bpf: port test_ftrace.sh to test_progs
  2026-11-04  9:59 [PATCH bpf-next v2] selftests/bpf: port test_ftrace.sh to test_progs Alexis Lothoré (eBPF Foundation)
@ 2026-11-04 11:40 ` Jiri Olsa
  2026-11-04 18:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Olsa @ 2026-11-04 11:40 UTC (permalink / raw)
  To: Alexis Lothoré (eBPF Foundation)
  Cc: ebpf, Bastien Curutchet, Thomas Petazzoni, Andrii Nakryiko,
	Eduard Zingerman, Ihor Solodrai, Alexei Starovoitov,
	Daniel Borkmann, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Emil Tsalapatis, Shuah Khan,
	linux-kernel, bpf, linux-kselftest

On Wed, Nov 04, 2026 at 10:59:33AM +0100, Alexis Lothoré (eBPF Foundation) wrote:
> Commit ff205766dbbe ("ftrace: Fix function_graph tracer interaction with
> BPF trampoline") made sure that trampolines generated for tracing
> programs did not collide with the function graph when we are returning
> from the hooked function. The series bringing this commit also came with
> a new test ensuring that the kernel does not crash when executing BPF
> programs handled by trampolines while the function graph trace is
> enabled, but this test is a standalone shell script, hence not executed
> in CI.
> 
> Convert the script to the test_progs runner so it can be executed
> automatically by the CI infrastructure. There are two main options to
> port this test:
>   - just enable ftrace during some existing trampoline-related tests
>     (eg: fentry/fexit tests)
>   - create a dedicated, minimal test with function graph
> 
> The new test adopts the latter approach, with a smaller scope to keep
> execution time reasonable, while reusing an existing
> fentry/fexit/fmod_ret test. Despite the few asserts in the new test, the
> actual goal is to make sure that the kernel does not crash because of
> some incorrect stack frame skipping when both the function graph and
> tracing programs are running.
> 
> ftrace is configured through a dedicated ftrace instance which is
> dropped at the end of the test.
> 
> With the new test integrated into test_progs, drop test_ftrace.sh.
> 
> Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
> ---
> Hello,
> this is v2 of a small series aiming to port the test_ftrace.sh script
> (testing that trampolines and function graph behave correctly when both
> are enabled) into the test_progs framework. The test is heavily
> simplified following Alexei's review and suggestions.
> ---
> Changes in v2:
> - use a ftrace instance rather than global ftrace
> - drop fgraph filters
> - drop custom ftrace helpers in favor of direct manipulation in test
> - drop custom bpf prog, reuse test_modify_return directly
> - move test in existing test file (modify_return.c)
> - make the test parallel (drop serial_)
> - Link to v1: https://patch.msgid.link/20261030-ftrace_in_test_progs-v1-0-aa50c5dd1ccc@bootlin.com

lgtm, it might be worth to add something like this also for
tracing-multi (maybe also kprobe-multi) and run some tests
with function or function_graph enabled

Reviewed-by: Jiri Olsa <jolsa@kernel.org>

jirka

SNIP

> +void test_modify_return_graph(void)
> +{
> +	char instance[MAX_INSTANCE_PATH_LEN];
> +	char *ftrace_dir;
> +	int ret;
> +
> +	ftrace_dir = access(TRACE_FTRACE_DEFAULT, F_OK) ? TRACEFS_IN_DEBUGFS :
> +							  TRACEFS_DEFAULT;
> +
> +	ret = snprintf(instance, MAX_INSTANCE_PATH_LEN,
> +		       "%s/instances/bpf-XXXXXX", ftrace_dir);
> +	if (ret < 0)
> +		return;
> +
> +	if (!ASSERT_OK_PTR(mkdtemp(instance), "mkdtemp"))
> +		return;
> +
> +	SYS(out, "echo 'bpf_modify_return_test*' > %s/set_ftrace_filter",
> +	    instance);

nit, no need for new line

> +	SYS(out, "echo function_graph > %s/current_tracer", instance);
> +
> +	test_modify_return();
> +
> +	SYS(out, "grep -q bpf_modify_return_test2 %s/trace", instance);
> +out:
> +	ASSERT_OK(rmdir(instance), "rmdir");
> +}
> diff --git a/tools/testing/selftests/bpf/test_ftrace.sh b/tools/testing/selftests/bpf/test_ftrace.sh
> deleted file mode 100755
> index f5109eb0e951..000000000000
> --- a/tools/testing/selftests/bpf/test_ftrace.sh
> +++ /dev/null
> @@ -1,44 +0,0 @@
> -#!/bin/bash
> -
> -if [[ -e /sys/kernel/tracing/trace ]]; then
> -    TR=/sys/kernel/tracing/
> -else
> -    TR=/sys/kernel/debug/tracing/
> -fi
> -
> -clear_trace() { # reset trace output
> -    echo > $TR/trace
> -}
> -
> -disable_tracing() { # stop trace recording
> -    echo 0 > $TR/tracing_on
> -}
> -
> -enable_tracing() { # start trace recording
> -    echo 1 > $TR/tracing_on
> -}
> -
> -reset_tracer() { # reset the current tracer
> -    echo nop > $TR/current_tracer
> -}
> -
> -disable_tracing
> -clear_trace
> -
> -echo "" > $TR/set_ftrace_filter
> -echo '*printk* *console* *wake* *serial* *lock*' > $TR/set_ftrace_notrace
> -
> -echo "bpf_prog_test*" > $TR/set_graph_function
> -echo "" > $TR/set_graph_notrace
> -
> -echo function_graph > $TR/current_tracer
> -
> -enable_tracing
> -./test_progs -t fentry
> -./test_progs -t fexit
> -disable_tracing
> -clear_trace
> -
> -reset_tracer
> -
> -exit 0
> 
> ---
> base-commit: b0e67f50519538b1b4c6364edc7811f482703f75
> change-id: 20261027-ftrace_in_test_progs-d5f70a2330ac
> 
> Best regards,
> --  
> Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
> 

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

* Re: [PATCH bpf-next v2] selftests/bpf: port test_ftrace.sh to test_progs
  2026-11-04  9:59 [PATCH bpf-next v2] selftests/bpf: port test_ftrace.sh to test_progs Alexis Lothoré (eBPF Foundation)
  2026-11-04 11:40 ` Jiri Olsa
@ 2026-11-04 18:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-11-04 18:10 UTC (permalink / raw)
  To: =?utf-8?q?Alexis_Lothor=C3=A9_=28eBPF_Foundation=29_=3Calexis=2Elothore=40bo?=,
	=?utf-8?q?otlin=2Ecom=3E?=
  Cc: ebpf, bastien.curutchet, thomas.petazzoni, andrii, eddyz87,
	ihor.solodrai, ast, daniel, memxor, martin.lau, song,
	yonghong.song, jolsa, emil, shuah, linux-kernel, bpf,
	linux-kselftest

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Wed, 04 Nov 2026 10:59:33 +0100 you wrote:
> Commit ff205766dbbe ("ftrace: Fix function_graph tracer interaction with
> BPF trampoline") made sure that trampolines generated for tracing
> programs did not collide with the function graph when we are returning
> from the hooked function. The series bringing this commit also came with
> a new test ensuring that the kernel does not crash when executing BPF
> programs handled by trampolines while the function graph trace is
> enabled, but this test is a standalone shell script, hence not executed
> in CI.
> 
> [...]

Here is the summary with links:
  - [bpf-next,v2] selftests/bpf: port test_ftrace.sh to test_progs
    https://git.kernel.org/bpf/bpf-next/c/77ac1105bf1d

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-11-04 18:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04  9:59 [PATCH bpf-next v2] selftests/bpf: port test_ftrace.sh to test_progs Alexis Lothoré (eBPF Foundation)
2026-11-04 11:40 ` Jiri Olsa
2026-11-04 18:10 ` patchwork-bot+netdevbpf

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®