Re: [PATCH bpf-next 1/2] bpf: Mark tracing_multi trampolines as ftrace managed

From: Jiri Olsa

Date: Fri Jul 10 2026 - 18:15:45 EST


On Fri, Jul 10, 2026 at 10:47:33PM +0800, Leon Hwang 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
>
> Fix it by setting 'ftrace_managed = true' in register_fentry_multi().
>
> Fixes: aef4dfa790b2 ("bpf: Add bpf_trampoline_multi_attach/detach functions")
> Signed-off-by: Leon Hwang <leon.hwang@xxxxxxxxx>
> ---
> 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;

I wonder we could set tr->func.ftrace_managed early in bpf_trampoline_get,
but we could do that as follow up

Acked-by: Jiri Olsa <jolsa@xxxxxxxxxx>

thanks,
jirka


> ftrace_hash_add(data->reg, data->entry, ip, addr);
> tr->cur_image = im;
> return 0;
> --
> 2.55.0
>