[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250902143504.1224726-11-jolsa@kernel.org>
Date: Tue, 2 Sep 2025 16:35:03 +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 10/11] selftests/bpf: Add uprobe multi unique attach test
Adding test to check the unique uprobe attchment together
with not-unique uprobe on top of uprobe_multi link.
Signed-off-by: Jiri Olsa <jolsa@...nel.org>
---
.../bpf/prog_tests/uprobe_multi_test.c | 99 +++++++++++++++++++
.../selftests/bpf/progs/uprobe_multi_unique.c | 34 +++++++
2 files changed, 133 insertions(+)
create mode 100644 tools/testing/selftests/bpf/progs/uprobe_multi_unique.c
diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
index 4630a6c65c3c..1043bc4387e8 100644
--- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
@@ -14,6 +14,7 @@
#include "uprobe_multi_session_cookie.skel.h"
#include "uprobe_multi_session_recursive.skel.h"
#include "uprobe_multi_verifier.skel.h"
+#include "uprobe_multi_unique.skel.h"
#include "bpf/libbpf_internal.h"
#include "testing_helpers.h"
#include "../sdt.h"
@@ -1477,12 +1478,110 @@ static void unique_regs_ip(void)
uprobe_multi__destroy(skel);
}
+static void unique_attach(void)
+{
+ LIBBPF_OPTS(bpf_uprobe_multi_opts, opts,
+ .unique = true,
+ );
+ struct bpf_link *link_1, *link_2 = NULL;
+ struct bpf_program *prog_1, *prog_2;
+ struct uprobe_multi_unique *skel;
+
+ skel = uprobe_multi_unique__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "uprobe_multi_unique__open_and_load"))
+ return;
+
+ skel->bss->my_pid = getpid();
+
+ prog_1 = skel->progs.test1;
+ prog_2 = skel->progs.test2;
+
+ /* not-unique and unique */
+ link_1 = bpf_program__attach_uprobe_multi(prog_1, -1, "/proc/self/exe",
+ "uprobe_multi_func_1",
+ NULL);
+ if (!ASSERT_OK_PTR(link_1, "bpf_program__attach_uprobe_multi"))
+ goto cleanup;
+
+ link_2 = bpf_program__attach_uprobe_multi(prog_2, -1, "/proc/self/exe",
+ "uprobe_multi_func_1",
+ &opts);
+ if (!ASSERT_ERR_PTR(link_2, "bpf_program__attach_uprobe_multi")) {
+ bpf_link__destroy(link_2);
+ goto cleanup;
+ }
+
+ bpf_link__destroy(link_1);
+
+ /* unique and unique */
+ link_1 = bpf_program__attach_uprobe_multi(prog_1, -1, "/proc/self/exe",
+ "uprobe_multi_func_1",
+ &opts);
+ if (!ASSERT_OK_PTR(link_1, "bpf_program__attach_uprobe_multi"))
+ goto cleanup;
+
+ link_2 = bpf_program__attach_uprobe_multi(prog_2, -1, "/proc/self/exe",
+ "uprobe_multi_func_1",
+ &opts);
+ if (!ASSERT_ERR_PTR(link_2, "bpf_program__attach_uprobe_multi")) {
+ bpf_link__destroy(link_2);
+ goto cleanup;
+ }
+
+ bpf_link__destroy(link_1);
+
+ /* unique and not-unique */
+ link_1 = bpf_program__attach_uprobe_multi(prog_1, -1, "/proc/self/exe",
+ "uprobe_multi_func_1",
+ &opts);
+ if (!ASSERT_OK_PTR(link_1, "bpf_program__attach_uprobe_multi"))
+ goto cleanup;
+
+ link_2 = bpf_program__attach_uprobe_multi(prog_2, -1, "/proc/self/exe",
+ "uprobe_multi_func_1",
+ NULL);
+ if (!ASSERT_ERR_PTR(link_2, "bpf_program__attach_uprobe_multi")) {
+ bpf_link__destroy(link_2);
+ goto cleanup;
+ }
+
+ bpf_link__destroy(link_1);
+
+ /* not-unique and not-unique */
+ link_1 = bpf_program__attach_uprobe_multi(prog_1, -1, "/proc/self/exe",
+ "uprobe_multi_func_1",
+ NULL);
+ if (!ASSERT_OK_PTR(link_1, "bpf_program__attach_uprobe_multi"))
+ goto cleanup;
+
+ link_2 = bpf_program__attach_uprobe_multi(prog_2, -1, "/proc/self/exe",
+ "uprobe_multi_func_1",
+ NULL);
+ if (!ASSERT_OK_PTR(link_2, "bpf_program__attach_uprobe_multi")) {
+ bpf_link__destroy(link_1);
+ goto cleanup;
+ }
+
+ uprobe_multi_func_1();
+
+ ASSERT_EQ(skel->bss->test1_result, 1, "test1_result");
+ ASSERT_EQ(skel->bss->test2_result, 1, "test2_result");
+
+ bpf_link__destroy(link_1);
+ bpf_link__destroy(link_2);
+
+cleanup:
+ uprobe_multi_unique__destroy(skel);
+}
+
static void test_unique(void)
{
if (test__start_subtest("unique_regs_common"))
unique_regs_common();
if (test__start_subtest("unique_regs_ip"))
unique_regs_ip();
+ if (test__start_subtest("unique_attach"))
+ unique_attach();
}
#else
static void test_unique(void) { }
diff --git a/tools/testing/selftests/bpf/progs/uprobe_multi_unique.c b/tools/testing/selftests/bpf/progs/uprobe_multi_unique.c
new file mode 100644
index 000000000000..e31e17bd85ea
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/uprobe_multi_unique.c
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+pid_t my_pid = 0;
+
+int test1_result = 0;
+int test2_result = 0;
+
+SEC("uprobe.multi")
+int BPF_UPROBE(test1)
+{
+ pid_t pid = bpf_get_current_pid_tgid() >> 32;
+
+ if (pid != my_pid)
+ return 0;
+
+ test1_result = 1;
+ return 0;
+}
+
+SEC("uprobe.multi")
+int BPF_UPROBE(test2)
+{
+ pid_t pid = bpf_get_current_pid_tgid() >> 32;
+
+ if (pid != my_pid)
+ return 0;
+
+ test2_result = 1;
+ return 0;
+}
--
2.51.0
Powered by blists - more mailing lists