Re: [PATCH bpf-next v2 01/21] bpf: Initialize ftrace_managed in bpf_trampoline_get()
From: Jiri Olsa
Date: Wed Oct 14 2026 - 17:43:36 EST
On Mon, Oct 12, 2026 at 11:40:03PM +0800, Leon Hwang wrote:
> A trampoline managed by ftrace is determined by its target, that said
> ftrace_managed is already known when the trampoline is initialized. so,
> set 'ftrace_managed = tr->ip != 0' in bpf_trampoline_get() instead of
> relying on the first regular or tracing_multi attachment to set it.
>
> This makes the backend selection independent of attachment order and keeps
> the registration callbacks focused on installing the trampoline.
>
> No functional change intended.
>
> Signed-off-by: Leon Hwang <leon.hwang@xxxxxxxxx>
Acked-by: Jiri Olsa <jolsa@xxxxxxxxxx>
jirka
> ---
> kernel/bpf/trampoline.c | 11 ++---------
> 1 file changed, 2 insertions(+), 9 deletions(-)
>
> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
> index 24edb59238f3..17f2a8133f61 100644
> --- a/kernel/bpf/trampoline.c
> +++ b/kernel/bpf/trampoline.c
> @@ -475,18 +475,11 @@ static int register_fentry(struct bpf_trampoline *tr, struct bpf_tramp_image *im
> void *data __maybe_unused)
> {
> void *new_addr = im->image;
> - void *ip = tr->func.addr;
> - unsigned long faddr;
> int ret;
>
> - faddr = ftrace_location((unsigned long)ip);
> - if (faddr) {
> + if (tr->func.ftrace_managed) {
> if (!tr->fops)
> return -ENOTSUPP;
> - tr->func.ftrace_managed = true;
> - }
> -
> - if (tr->func.ftrace_managed) {
> ret = direct_ops_add(tr, new_addr);
> } else {
> ret = bpf_trampoline_update_fentry(tr, 0, NULL, new_addr);
> @@ -1286,6 +1279,7 @@ struct bpf_trampoline *bpf_trampoline_get(u64 key,
>
> memcpy(&tr->func.model, &tgt_info->fmodel, sizeof(tgt_info->fmodel));
> tr->func.addr = (void *)tgt_info->tgt_addr;
> + tr->func.ftrace_managed = tr->ip != 0;
> out:
> trampoline_unlock(tr);
> return tr;
> @@ -1649,7 +1643,6 @@ 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
>