Re: [PATCHv2 bpf-next 10/24] libbpf: Add bpf_link_create support for multi uprobes

Andrii Nakryiko
2023-06-23T20:40:58Z

On Tue, Jun 20, 2023 at 1:37 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> Adding new uprobe_multi struct to bpf_link_create_opts object
> to pass multiple uprobe data to link_create attr uapi.
>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> tools/lib/bpf/bpf.c | 11 +++++++++++
> tools/lib/bpf/bpf.h | 11 ++++++++++-
> 2 files changed, 21 insertions(+), 1 deletion(-)
>

LGTM

Acked-by: Andrii Nakryiko <andrii@kernel.org>

> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> index ed86b37d8024..0fd35c91f50c 100644
> --- a/tools/lib/bpf/bpf.c
> +++ b/tools/lib/bpf/bpf.c
> @@ -733,6 +733,17 @@ int bpf_link_create(int prog_fd, int target_fd,
> if (!OPTS_ZEROED(opts, kprobe_multi))
> return libbpf_err(-EINVAL);
> break;
> + case BPF_TRACE_UPROBE_MULTI:
> + attr.link_create.uprobe_multi.flags = OPTS_GET(opts, uprobe_multi.flags, 0);
> + attr.link_create.uprobe_multi.cnt = OPTS_GET(opts, uprobe_multi.cnt, 0);
> + attr.link_create.uprobe_multi.path = ptr_to_u64(OPTS_GET(opts, uprobe_multi.path, 0));
> + attr.link_create.uprobe_multi.offsets = ptr_to_u64(OPTS_GET(opts, uprobe_multi.offsets, 0));
> + attr.link_create.uprobe_multi.ref_ctr_offsets = ptr_to_u64(OPTS_GET(opts, uprobe_multi.ref_ctr_offsets, 0));
> + attr.link_create.uprobe_multi.cookies = ptr_to_u64(OPTS_GET(opts, uprobe_multi.cookies, 0));
> + attr.link_create.uprobe_multi.pid = OPTS_GET(opts, uprobe_multi.pid, 0);
> + if (!OPTS_ZEROED(opts, uprobe_multi))
> + return libbpf_err(-EINVAL);
> + break;
> case BPF_TRACE_FENTRY:
> case BPF_TRACE_FEXIT:
> case BPF_MODIFY_RETURN:
> diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
> index 9aa0ee473754..82979b4f2769 100644
> --- a/tools/lib/bpf/bpf.h
> +++ b/tools/lib/bpf/bpf.h
> @@ -346,13 +346,22 @@ struct bpf_link_create_opts {
> const unsigned long *addrs;
> const __u64 *cookies;
> } kprobe_multi;
> + struct {
> + __u32 flags;
> + __u32 cnt;
> + const char *path;
> + const unsigned long *offsets;
> + const unsigned long *ref_ctr_offsets;
> + const __u64 *cookies;
> + __u32 pid;
> + } uprobe_multi;
> struct {
> __u64 cookie;
> } tracing;
> };
> size_t :0;
> };
> -#define bpf_link_create_opts__last_field kprobe_multi.cookies
> +#define bpf_link_create_opts__last_field uprobe_multi.pid
>
> LIBBPF_API int bpf_link_create(int prog_fd, int target_fd,
> enum bpf_attach_type attach_type,
> --
> 2.41.0
>