[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250902143504.1224726-7-jolsa@kernel.org>
Date: Tue, 2 Sep 2025 16:34:59 +0200
From: Jiri Olsa <jolsa@...nel.org>
To: Oleg Nesterov <oleg@...hat.com>,
Masami Hiramatsu <mhiramat@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Andrii Nakryiko <andrii@...nel.org>
Cc: bpf@...r.kernel.org,
linux-kernel@...r.kernel.org,
linux-trace-kernel@...r.kernel.org,
x86@...nel.org,
Song Liu <songliubraving@...com>,
Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
Hao Luo <haoluo@...gle.com>,
Steven Rostedt <rostedt@...dmis.org>,
Ingo Molnar <mingo@...nel.org>
Subject: [PATCH perf/core 06/11] libbpf: Add support to attach unique uprobe_multi uprobe
Adding support to attach unique uprobe multi by adding the 'unique'
bool flag to struct bpf_uprobe_multi_opts.
Also adding "uprobe.unique[.s]" auto load sections to create
uprobe_multi unique uprobe.
Signed-off-by: Jiri Olsa <jolsa@...nel.org>
---
tools/lib/bpf/libbpf.c | 7 ++++++-
tools/lib/bpf/libbpf.h | 4 +++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 8f5a81b672e1..1f613a5f95b6 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -9525,6 +9525,8 @@ static const struct bpf_sec_def section_defs[] = {
SEC_DEF("uprobe.multi+", KPROBE, BPF_TRACE_UPROBE_MULTI, SEC_NONE, attach_uprobe_multi),
SEC_DEF("uretprobe.multi+", KPROBE, BPF_TRACE_UPROBE_MULTI, SEC_NONE, attach_uprobe_multi),
SEC_DEF("uprobe.session+", KPROBE, BPF_TRACE_UPROBE_SESSION, SEC_NONE, attach_uprobe_multi),
+ SEC_DEF("uprobe.unique+", KPROBE, BPF_TRACE_UPROBE_MULTI, SEC_NONE, attach_uprobe_multi),
+ SEC_DEF("uprobe.unique.s+", KPROBE, BPF_TRACE_UPROBE_MULTI, SEC_SLEEPABLE, attach_uprobe_multi),
SEC_DEF("uprobe.multi.s+", KPROBE, BPF_TRACE_UPROBE_MULTI, SEC_SLEEPABLE, attach_uprobe_multi),
SEC_DEF("uretprobe.multi.s+", KPROBE, BPF_TRACE_UPROBE_MULTI, SEC_SLEEPABLE, attach_uprobe_multi),
SEC_DEF("uprobe.session.s+", KPROBE, BPF_TRACE_UPROBE_SESSION, SEC_SLEEPABLE, attach_uprobe_multi),
@@ -11880,6 +11882,7 @@ static int attach_uprobe_multi(const struct bpf_program *prog, long cookie, stru
case 3:
opts.session = str_has_pfx(probe_type, "uprobe.session");
opts.retprobe = str_has_pfx(probe_type, "uretprobe.multi");
+ opts.unique = str_has_pfx(probe_type, "uprobe.unique");
*link = bpf_program__attach_uprobe_multi(prog, -1, binary_path, func_name, &opts);
ret = libbpf_get_error(*link);
@@ -12116,10 +12119,10 @@ bpf_program__attach_uprobe_multi(const struct bpf_program *prog,
LIBBPF_OPTS(bpf_link_create_opts, lopts);
unsigned long *resolved_offsets = NULL;
enum bpf_attach_type attach_type;
+ bool retprobe, session, unique;
int err = 0, link_fd, prog_fd;
struct bpf_link *link = NULL;
char full_path[PATH_MAX];
- bool retprobe, session;
const __u64 *cookies;
const char **syms;
size_t cnt;
@@ -12141,6 +12144,7 @@ bpf_program__attach_uprobe_multi(const struct bpf_program *prog,
cnt = OPTS_GET(opts, cnt, 0);
retprobe = OPTS_GET(opts, retprobe, false);
session = OPTS_GET(opts, session, false);
+ unique = OPTS_GET(opts, unique, false);
/*
* User can specify 2 mutually exclusive set of inputs:
@@ -12203,6 +12207,7 @@ bpf_program__attach_uprobe_multi(const struct bpf_program *prog,
lopts.uprobe_multi.cookies = cookies;
lopts.uprobe_multi.cnt = cnt;
lopts.uprobe_multi.flags = retprobe ? BPF_F_UPROBE_MULTI_RETURN : 0;
+ lopts.uprobe_multi.flags |= unique ? BPF_F_UPROBE_MULTI_UNIQUE : 0;
if (pid == 0)
pid = getpid();
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 455a957cb702..13a10299331b 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -596,10 +596,12 @@ struct bpf_uprobe_multi_opts {
bool retprobe;
/* create session kprobes */
bool session;
+ /* create unique uprobe */
+ bool unique;
size_t :0;
};
-#define bpf_uprobe_multi_opts__last_field session
+#define bpf_uprobe_multi_opts__last_field unique
/**
* @brief **bpf_program__attach_uprobe_multi()** attaches a BPF program
--
2.51.0
Powered by blists - more mailing lists