Skip to content

Bpf/tracing multi ci#11005

Draft
olsajiri wants to merge 17 commits intokernel-patches:bpf-next_basefrom
olsajiri:bpf/tracing_multi_ci
Draft

Bpf/tracing multi ci#11005
olsajiri wants to merge 17 commits intokernel-patches:bpf-next_basefrom
olsajiri:bpf/tracing_multi_ci

Conversation

@olsajiri
Copy link
Contributor

No description provided.

@kernel-patches-daemon-bpf kernel-patches-daemon-bpf bot force-pushed the bpf-next_base branch 4 times, most recently from 2294d0a to 254af9f Compare February 11, 2026 20:32
@olsajiri olsajiri force-pushed the bpf/tracing_multi_ci branch 2 times, most recently from 4483170 to f0c9e60 Compare February 11, 2026 21:59
@olsajiri olsajiri force-pushed the bpf/tracing_multi_ci branch from f0c9e60 to 04b0321 Compare February 12, 2026 12:48
@kernel-patches-daemon-bpf kernel-patches-daemon-bpf bot force-pushed the bpf-next_base branch 6 times, most recently from a4a9811 to 2650068 Compare February 13, 2026 22:49
@olsajiri olsajiri force-pushed the bpf/tracing_multi_ci branch from 04b0321 to cb52425 Compare February 14, 2026 23:42
Adding external ftrace_hash_count function that replaces hash_count
function, so we can get hash count outside of ftrace object.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
@olsajiri olsajiri force-pushed the bpf/tracing_multi_ci branch 10 times, most recently from d00fa97 to e1dd74a Compare February 17, 2026 13:59
Removing the mutex_is_locked in bpf_trampoline_put,
because we removed the mutex from bpf_trampoline.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
In following changes we will need to change ftrace direct attachment
logic. In order to do that adding struct bpf_trampoline_ops object
that defines 3 callbacks that follow ftrace attachment functions:

   register_fentry
   unregister_fentry
   modify_fentry

The new struct bpf_trampoline_ops object is passed as an argument to
__bpf_trampoline_link_prog function.

At the moment the default trampoline_ops is set to the current ftrace
direct attachment functions, so there's no change for current code.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Add struct bpf_struct_ops_tramp_link for struct_ops link, to follow
the code of all the other users of bpf_tramp_link object.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Adding struct bpf_tramp_node to decouple the link out of the trampoline
attachment info.

At the moment the object for attaching bpf program to the trampoline is
'struct bpf_tramp_link':

  struct bpf_tramp_link {
       struct bpf_link link;
       struct hlist_node tramp_hlist;
       u64 cookie;
  }

The link holds the bpf_prog pointer and forces one link - one program
binding logic. In following changes we want to attach program to multiple
trampolines but have just one bpf_link object.

Splitting struct bpf_tramp_link into:

  struct bpf_tramp_link {
       struct bpf_link link;
       struct bpf_tramp_node node;
  };

  struct bpf_tramp_node {
       struct bpf_link *link;
       struct hlist_node tramp_hlist;
       u64 cookie;
  };

where 'struct bpf_tramp_link' defines standard single trampoline link,
and 'struct bpf_tramp_node' is the attachment trampoline object. This
will allow us to define link for multiple trampolines, like:

  struct bpf_tracing_multi_link {
       struct bpf_link link;
       ...
       int nodes_cnt;
       struct bpf_tracing_multi_node nodes[] __counted_by(nodes_cnt);
  };

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Adding new attach type to identify multi tracing attachment:
  BPF_TRACE_FENTRY_MULTI
  BPF_TRACE_FEXIT_MULTI

Programs with such attach type will use specific link attachment
interface coming in following changes.

This was suggested by Andrii some (long) time ago and turned out
to be easier than having special program flag for that.

Bpf programs with such types have 'bpf_multi_func' function set
as their attach_btf_id.

Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
@olsajiri olsajiri force-pushed the bpf/tracing_multi_ci branch 2 times, most recently from dd9ff24 to 8d3fa89 Compare February 17, 2026 22:12
Adding bpf_trampoline_multi_attach/detach functions that allows
to attach/detach multi tracing trampoline.

The attachment is defined with bpf_program and array of BTF ids
of functions to attach the bpf program to.

The attachment will allocate or use currently existing trampoline
for function to attach and link it with the bpf program.

The attach works as follows:
- we get all the needed trampolines
- lock them and add the bpf program to each (__bpf_trampoline_link_prog)
- the trampoline_multi_ops passed in __bpf_trampoline_link_prog gather needed
  ftrace_hash ip->trampoline data
- we call update_ftrace_direct_add/mod to update needed locations
- we unlock all the trampolines

The detach works as follows:
- we lock all the needed trampolines
- remove the program from each (__bpf_trampoline_unlink_prog)
- the trampoline_multi_ops passed in __bpf_trampoline_link_prog gather needed
  ftrace_hash ip->trampoline data
- we call update_ftrace_direct_del/mod to update needed locations
- we unlock and put all the trampolines

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Adding new link to allow to attach program to multiple function
BTF IDs. The link is represented by struct bpf_tracing_multi_link.

To configure the link, new fields are added to bpf_attr::link_create
to pass array of BTF IDs;

  struct {
      __aligned_u64   btf_ids;        /* addresses to attach */
      __u32           btf_ids_cnt;    /* addresses count */
  } tracing_multi;

Each BTF ID represents function (BTF_KIND_FUNC) that the link will
attach bpf program to.

We use previously added bpf_trampoline_multi_attach/detach functions
to attach/detach the link.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Adding new interface function to attach programs with tracing
multi link:

  bpf_program__attach_tracing_multi(const struct bpf_program *prog,
                                    const char *pattern,
                                    const struct bpf_tracing_multi_opts *opts);

The program is attach to functions specified by pattern or by
btf IDs specified in bpf_tracing_multi_opts object.

Adding support for new sections to attach programs with above
functions:

   fentry.multi/pattern
   fexit.multi/pattern

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
@olsajiri olsajiri force-pushed the bpf/tracing_multi_ci branch from 8d3fa89 to 6ab54fc Compare February 18, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant