libbpf: Add bpf_link_create support for multi kprobes
authorJiri Olsa <jolsa@kernel.org>
Wed, 16 Mar 2022 12:24:14 +0000 (13:24 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 18 Mar 2022 03:17:19 +0000 (20:17 -0700)
Adding new kprobe_multi struct to bpf_link_create_opts object
to pass multiple kprobe data to link_create attr uapi.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20220316122419.933957-9-jolsa@kernel.org
tools/lib/bpf/bpf.c
tools/lib/bpf/bpf.h

index f69ce3a013859aaa5c74fb784635dd7cba49c310..cf27251adb92ed876ec9dafc7047cac152ceb868 100644 (file)
@@ -854,6 +854,15 @@ int bpf_link_create(int prog_fd, int target_fd,
                if (!OPTS_ZEROED(opts, perf_event))
                        return libbpf_err(-EINVAL);
                break;
+       case BPF_TRACE_KPROBE_MULTI:
+               attr.link_create.kprobe_multi.flags = OPTS_GET(opts, kprobe_multi.flags, 0);
+               attr.link_create.kprobe_multi.cnt = OPTS_GET(opts, kprobe_multi.cnt, 0);
+               attr.link_create.kprobe_multi.syms = ptr_to_u64(OPTS_GET(opts, kprobe_multi.syms, 0));
+               attr.link_create.kprobe_multi.addrs = ptr_to_u64(OPTS_GET(opts, kprobe_multi.addrs, 0));
+               attr.link_create.kprobe_multi.cookies = ptr_to_u64(OPTS_GET(opts, kprobe_multi.cookies, 0));
+               if (!OPTS_ZEROED(opts, kprobe_multi))
+                       return libbpf_err(-EINVAL);
+               break;
        default:
                if (!OPTS_ZEROED(opts, flags))
                        return libbpf_err(-EINVAL);
index 5253cb4a4c0a6f31a6ea42fe6c5254cfa245c1ea..f4b4afb6d4ba754be0cc01a49c58410ff7c977fa 100644 (file)
@@ -413,10 +413,17 @@ struct bpf_link_create_opts {
                struct {
                        __u64 bpf_cookie;
                } perf_event;
+               struct {
+                       __u32 flags;
+                       __u32 cnt;
+                       const char **syms;
+                       const unsigned long *addrs;
+                       const __u64 *cookies;
+               } kprobe_multi;
        };
        size_t :0;
 };
-#define bpf_link_create_opts__last_field perf_event
+#define bpf_link_create_opts__last_field kprobe_multi.cookies
 
 LIBBPF_API int bpf_link_create(int prog_fd, int target_fd,
                               enum bpf_attach_type attach_type,