* [PATCH bpf-next v2 0/2] bpf: Fix WARNING in bpf_trampoline_multi_detach
@ 2026-07-11 12:48 Leon Hwang
2026-07-11 12:48 ` [PATCH bpf-next v2 1/2] bpf: Mark tracing_multi trampolines as ftrace managed Leon Hwang
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Leon Hwang @ 2026-07-11 12:48 UTC (permalink / raw)
To: bpf
Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
Emil Tsalapatis, Shuah Khan, Leon Hwang, linux-kernel,
linux-kselftest, kernel-patches-bot
Since tracing_multi link does not set ftrace_managed, it would fail to
release the tracing_multi link when attaching tracing_multi link and
then attaching fentry link.
[ 3.714215] WARNING: kernel/bpf/trampoline.c:1727 at bpf_trampoline_multi_detach+0x20b/0x240, CPU#1: test_progs/97
...
[ 3.733170] bpf_tracing_multi_link_release+0x14/0x30
[ 3.733890] bpf_link_free+0x58/0x130
[ 3.734414] bpf_link_release+0x23/0x30
Fix it by setting 'ftrace_managed = true' in register_fentry_multi().
Note: the reason of targeting bpf-next tree is I'm planning to add
tracing_multi link support for bpf progs, that would rely on the fix and
have code conflict with the test.
Changes:
v1 -> v2:
* Collect Acked-by from Jiri, thanks.
* Check arg using tracing_multi_arg_check() in bpf prog in test.
(per Sashiko)
* v1: https://lore.kernel.org/bpf/20260710144734.78203-1-leon.hwang@linux.dev/
Leon Hwang (2):
bpf: Mark tracing_multi trampolines as ftrace managed
selftests/bpf: Test fentry link after tracing_multi link
kernel/bpf/trampoline.c | 1 +
.../selftests/bpf/prog_tests/tracing_multi.c | 69 +++++++++++++++++++
.../progs/tracing_multi_intersect_attach.c | 8 +++
3 files changed, 78 insertions(+)
--
2.55.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH bpf-next v2 1/2] bpf: Mark tracing_multi trampolines as ftrace managed 2026-07-11 12:48 [PATCH bpf-next v2 0/2] bpf: Fix WARNING in bpf_trampoline_multi_detach Leon Hwang @ 2026-07-11 12:48 ` Leon Hwang 2026-07-11 12:48 ` [PATCH bpf-next v2 2/2] selftests/bpf: Test fentry link after tracing_multi link Leon Hwang 2026-07-12 0:00 ` [PATCH bpf-next v2 0/2] bpf: Fix WARNING in bpf_trampoline_multi_detach patchwork-bot+netdevbpf 2 siblings, 0 replies; 5+ messages in thread From: Leon Hwang @ 2026-07-11 12:48 UTC (permalink / raw) To: bpf Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend, Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan, Leon Hwang, linux-kernel, linux-kselftest, kernel-patches-bot Since tracing_multi link does not set ftrace_managed, it would fail to release the tracing_multi link when attaching tracing_multi link and then attaching fentry link. [ 3.714215] WARNING: kernel/bpf/trampoline.c:1727 at bpf_trampoline_multi_detach+0x20b/0x240, CPU#1: test_progs/97 ... [ 3.733170] bpf_tracing_multi_link_release+0x14/0x30 [ 3.733890] bpf_link_free+0x58/0x130 [ 3.734414] bpf_link_release+0x23/0x30 Fix it by setting 'ftrace_managed = true' in register_fentry_multi(). Fixes: aef4dfa790b2 ("bpf: Add bpf_trampoline_multi_attach/detach functions") Acked-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Leon Hwang <leon.hwang@linux.dev> --- kernel/bpf/trampoline.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c index 1a721fc4bef5..6eadf64f7ec9 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -1536,6 +1536,7 @@ static int register_fentry_multi(struct bpf_trampoline *tr, struct bpf_tramp_ima if (bpf_trampoline_use_jmp(tr->flags)) addr = ftrace_jmp_set(addr); + tr->func.ftrace_managed = true; ftrace_hash_add(data->reg, data->entry, ip, addr); tr->cur_image = im; return 0; -- 2.55.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH bpf-next v2 2/2] selftests/bpf: Test fentry link after tracing_multi link 2026-07-11 12:48 [PATCH bpf-next v2 0/2] bpf: Fix WARNING in bpf_trampoline_multi_detach Leon Hwang 2026-07-11 12:48 ` [PATCH bpf-next v2 1/2] bpf: Mark tracing_multi trampolines as ftrace managed Leon Hwang @ 2026-07-11 12:48 ` Leon Hwang 2026-07-11 20:36 ` Jiri Olsa 2026-07-12 0:00 ` [PATCH bpf-next v2 0/2] bpf: Fix WARNING in bpf_trampoline_multi_detach patchwork-bot+netdevbpf 2 siblings, 1 reply; 5+ messages in thread From: Leon Hwang @ 2026-07-11 12:48 UTC (permalink / raw) To: bpf Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend, Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan, Leon Hwang, linux-kernel, linux-kselftest, kernel-patches-bot Verify that there's no any issue to attach tracing_multi link, then attach fentry link. Assisted-by: Codex:gpt-5.6-sol Signed-off-by: Leon Hwang <leon.hwang@linux.dev> --- .../selftests/bpf/prog_tests/tracing_multi.c | 69 +++++++++++++++++++ .../progs/tracing_multi_intersect_attach.c | 8 +++ 2 files changed, 77 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c index f02ffc7f41d7..0aa9532a05cf 100644 --- a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c +++ b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c @@ -460,6 +460,73 @@ static void test_intersect(void) tracing_multi_intersect__destroy(skel); } +static void test_fentry_after_multi(void) +{ + static const char * const funcs[] = { + "bpf_fentry_test1", + }; + struct bpf_link *fentry_link = NULL, *multi_link = NULL; + struct tracing_multi_intersect *skel = NULL; + LIBBPF_OPTS(bpf_tracing_multi_opts, opts); + LIBBPF_OPTS(bpf_test_run_opts, topts); + __u32 *ids = NULL; + int err; + + skel = tracing_multi_intersect__open_and_load(); + if (!ASSERT_OK_PTR(skel, "tracing_multi_intersect__open_and_load")) + return; + + skel->bss->pid = getpid(); + + ids = get_ids(funcs, ARRAY_SIZE(funcs), NULL); + if (!ASSERT_OK_PTR(ids, "get_ids")) + goto cleanup; + + opts.ids = ids; + opts.cnt = ARRAY_SIZE(funcs); + multi_link = bpf_program__attach_tracing_multi(skel->progs.fentry_1, NULL, &opts); + if (!ASSERT_OK_PTR(multi_link, "attach_multi")) + goto cleanup; + + fentry_link = bpf_program__attach(skel->progs.fentry); + if (!ASSERT_OK_PTR(fentry_link, "attach_fentry")) + goto cleanup; + + err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.fentry_1), &topts); + if (!ASSERT_OK(err, "test_run")) + goto cleanup; + ASSERT_EQ(skel->bss->test_result_fentry_1, 1, "multi_fentry"); + ASSERT_EQ(skel->bss->test_result_fentry, 1, "fentry"); + + err = bpf_link__destroy(fentry_link); + fentry_link = NULL; + if (!ASSERT_OK(err, "destroy_fentry")) + goto cleanup; + + err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.fentry_1), &topts); + if (!ASSERT_OK(err, "test_run_multi")) + goto cleanup; + ASSERT_EQ(skel->bss->test_result_fentry_1, 2, "multi_fentry_only"); + ASSERT_EQ(skel->bss->test_result_fentry, 1, "fentry_detached"); + + err = bpf_link__destroy(multi_link); + multi_link = NULL; + if (!ASSERT_OK(err, "destroy_multi")) + goto cleanup; + + err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.fentry_1), &topts); + if (!ASSERT_OK(err, "test_run_detached")) + goto cleanup; + ASSERT_EQ(skel->bss->test_result_fentry_1, 2, "multi_fentry_detached"); + ASSERT_EQ(skel->bss->test_result_fentry, 1, "fentry_still_detached"); + +cleanup: + bpf_link__destroy(fentry_link); + bpf_link__destroy(multi_link); + free(ids); + tracing_multi_intersect__destroy(skel); +} + static void test_session(void) { LIBBPF_OPTS(bpf_test_run_opts, topts); @@ -957,4 +1024,6 @@ void test_tracing_multi_test(void) if (test__start_subtest("attach_api_fails")) test_attach_api_fails(); RUN_TESTS(tracing_multi_verifier); + if (test__start_subtest("fentry_after_multi")) + test_fentry_after_multi(); } diff --git a/tools/testing/selftests/bpf/progs/tracing_multi_intersect_attach.c b/tools/testing/selftests/bpf/progs/tracing_multi_intersect_attach.c index cd5be0bb6ffd..5b0af8f4c62f 100644 --- a/tools/testing/selftests/bpf/progs/tracing_multi_intersect_attach.c +++ b/tools/testing/selftests/bpf/progs/tracing_multi_intersect_attach.c @@ -11,6 +11,14 @@ __u64 test_result_fentry_1 = 0; __u64 test_result_fentry_2 = 0; __u64 test_result_fexit_1 = 0; __u64 test_result_fexit_2 = 0; +__u64 test_result_fentry = 0; + +SEC("fentry/bpf_fentry_test1") +int BPF_PROG(fentry) +{ + tracing_multi_arg_check(ctx, &test_result_fentry, false); + return 0; +} SEC("fentry.multi") int BPF_PROG(fentry_1) -- 2.55.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next v2 2/2] selftests/bpf: Test fentry link after tracing_multi link 2026-07-11 12:48 ` [PATCH bpf-next v2 2/2] selftests/bpf: Test fentry link after tracing_multi link Leon Hwang @ 2026-07-11 20:36 ` Jiri Olsa 0 siblings, 0 replies; 5+ messages in thread From: Jiri Olsa @ 2026-07-11 20:36 UTC (permalink / raw) To: Leon Hwang Cc: bpf, Alexei Starovoitov, Daniel Borkmann, John Fastabend, Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau, Song Liu, Yonghong Song, Emil Tsalapatis, Shuah Khan, linux-kernel, linux-kselftest, kernel-patches-bot On Sat, Jul 11, 2026 at 08:48:22PM +0800, Leon Hwang wrote: > Verify that there's no any issue to attach tracing_multi link, then attach > fentry link. > > Assisted-by: Codex:gpt-5.6-sol > Signed-off-by: Leon Hwang <leon.hwang@linux.dev> Acked-by: Jiri Olsa <jolsa@kernel.org> thanks, jirka > --- > .../selftests/bpf/prog_tests/tracing_multi.c | 69 +++++++++++++++++++ > .../progs/tracing_multi_intersect_attach.c | 8 +++ > 2 files changed, 77 insertions(+) > > diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c > index f02ffc7f41d7..0aa9532a05cf 100644 > --- a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c > +++ b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c > @@ -460,6 +460,73 @@ static void test_intersect(void) > tracing_multi_intersect__destroy(skel); > } > > +static void test_fentry_after_multi(void) > +{ > + static const char * const funcs[] = { > + "bpf_fentry_test1", > + }; > + struct bpf_link *fentry_link = NULL, *multi_link = NULL; > + struct tracing_multi_intersect *skel = NULL; > + LIBBPF_OPTS(bpf_tracing_multi_opts, opts); > + LIBBPF_OPTS(bpf_test_run_opts, topts); > + __u32 *ids = NULL; > + int err; > + > + skel = tracing_multi_intersect__open_and_load(); > + if (!ASSERT_OK_PTR(skel, "tracing_multi_intersect__open_and_load")) > + return; > + > + skel->bss->pid = getpid(); > + > + ids = get_ids(funcs, ARRAY_SIZE(funcs), NULL); > + if (!ASSERT_OK_PTR(ids, "get_ids")) > + goto cleanup; > + > + opts.ids = ids; > + opts.cnt = ARRAY_SIZE(funcs); > + multi_link = bpf_program__attach_tracing_multi(skel->progs.fentry_1, NULL, &opts); > + if (!ASSERT_OK_PTR(multi_link, "attach_multi")) > + goto cleanup; > + > + fentry_link = bpf_program__attach(skel->progs.fentry); > + if (!ASSERT_OK_PTR(fentry_link, "attach_fentry")) > + goto cleanup; > + > + err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.fentry_1), &topts); > + if (!ASSERT_OK(err, "test_run")) > + goto cleanup; > + ASSERT_EQ(skel->bss->test_result_fentry_1, 1, "multi_fentry"); > + ASSERT_EQ(skel->bss->test_result_fentry, 1, "fentry"); > + > + err = bpf_link__destroy(fentry_link); > + fentry_link = NULL; > + if (!ASSERT_OK(err, "destroy_fentry")) > + goto cleanup; > + > + err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.fentry_1), &topts); > + if (!ASSERT_OK(err, "test_run_multi")) > + goto cleanup; > + ASSERT_EQ(skel->bss->test_result_fentry_1, 2, "multi_fentry_only"); > + ASSERT_EQ(skel->bss->test_result_fentry, 1, "fentry_detached"); > + > + err = bpf_link__destroy(multi_link); > + multi_link = NULL; > + if (!ASSERT_OK(err, "destroy_multi")) > + goto cleanup; > + > + err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.fentry_1), &topts); > + if (!ASSERT_OK(err, "test_run_detached")) > + goto cleanup; > + ASSERT_EQ(skel->bss->test_result_fentry_1, 2, "multi_fentry_detached"); > + ASSERT_EQ(skel->bss->test_result_fentry, 1, "fentry_still_detached"); > + > +cleanup: > + bpf_link__destroy(fentry_link); > + bpf_link__destroy(multi_link); > + free(ids); > + tracing_multi_intersect__destroy(skel); > +} > + > static void test_session(void) > { > LIBBPF_OPTS(bpf_test_run_opts, topts); > @@ -957,4 +1024,6 @@ void test_tracing_multi_test(void) > if (test__start_subtest("attach_api_fails")) > test_attach_api_fails(); > RUN_TESTS(tracing_multi_verifier); > + if (test__start_subtest("fentry_after_multi")) > + test_fentry_after_multi(); > } > diff --git a/tools/testing/selftests/bpf/progs/tracing_multi_intersect_attach.c b/tools/testing/selftests/bpf/progs/tracing_multi_intersect_attach.c > index cd5be0bb6ffd..5b0af8f4c62f 100644 > --- a/tools/testing/selftests/bpf/progs/tracing_multi_intersect_attach.c > +++ b/tools/testing/selftests/bpf/progs/tracing_multi_intersect_attach.c > @@ -11,6 +11,14 @@ __u64 test_result_fentry_1 = 0; > __u64 test_result_fentry_2 = 0; > __u64 test_result_fexit_1 = 0; > __u64 test_result_fexit_2 = 0; > +__u64 test_result_fentry = 0; > + > +SEC("fentry/bpf_fentry_test1") > +int BPF_PROG(fentry) > +{ > + tracing_multi_arg_check(ctx, &test_result_fentry, false); > + return 0; > +} > > SEC("fentry.multi") > int BPF_PROG(fentry_1) > -- > 2.55.0 > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next v2 0/2] bpf: Fix WARNING in bpf_trampoline_multi_detach 2026-07-11 12:48 [PATCH bpf-next v2 0/2] bpf: Fix WARNING in bpf_trampoline_multi_detach Leon Hwang 2026-07-11 12:48 ` [PATCH bpf-next v2 1/2] bpf: Mark tracing_multi trampolines as ftrace managed Leon Hwang 2026-07-11 12:48 ` [PATCH bpf-next v2 2/2] selftests/bpf: Test fentry link after tracing_multi link Leon Hwang @ 2026-07-12 0:00 ` patchwork-bot+netdevbpf 2 siblings, 0 replies; 5+ messages in thread From: patchwork-bot+netdevbpf @ 2026-07-12 0:00 UTC (permalink / raw) To: Leon Hwang Cc: bpf, ast, daniel, john.fastabend, andrii, eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil, shuah, linux-kernel, linux-kselftest, kernel-patches-bot Hello: This series was applied to bpf/bpf-next.git (master) by Kumar Kartikeya Dwivedi <memxor@gmail.com>: On Sat, 11 Jul 2026 20:48:20 +0800 you wrote: > Since tracing_multi link does not set ftrace_managed, it would fail to > release the tracing_multi link when attaching tracing_multi link and > then attaching fentry link. > > [ 3.714215] WARNING: kernel/bpf/trampoline.c:1727 at bpf_trampoline_multi_detach+0x20b/0x240, CPU#1: test_progs/97 > ... > [ 3.733170] bpf_tracing_multi_link_release+0x14/0x30 > [ 3.733890] bpf_link_free+0x58/0x130 > [ 3.734414] bpf_link_release+0x23/0x30 > > [...] Here is the summary with links: - [bpf-next,v2,1/2] bpf: Mark tracing_multi trampolines as ftrace managed https://git.kernel.org/bpf/bpf-next/c/30bdd6d1384d - [bpf-next,v2,2/2] selftests/bpf: Test fentry link after tracing_multi link https://git.kernel.org/bpf/bpf-next/c/539d3edf8e53 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] 5+ messages in thread
end of thread, other threads:[~2026-07-12 0:00 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-07-11 12:48 [PATCH bpf-next v2 0/2] bpf: Fix WARNING in bpf_trampoline_multi_detach Leon Hwang 2026-07-11 12:48 ` [PATCH bpf-next v2 1/2] bpf: Mark tracing_multi trampolines as ftrace managed Leon Hwang 2026-07-11 12:48 ` [PATCH bpf-next v2 2/2] selftests/bpf: Test fentry link after tracing_multi link Leon Hwang 2026-07-11 20:36 ` Jiri Olsa 2026-07-12 0:00 ` [PATCH bpf-next v2 0/2] bpf: Fix WARNING in bpf_trampoline_multi_detach 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