From: Jiri Olsa <jolsa@kernel.org>
To: Oleg Nesterov <oleg@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>
Cc: bpf@vger.kernel.org, Martin KaFai Lau <kafai@fb.com>,
Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@chromium.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: [PATCHv6 bpf-next 15/16] selftests/bpf: Add uprobe sessions to consumer test
Date: Thu, 10 Oct 2024 22:09:56 +0200 [thread overview]
Message-ID: <20241010200957.2750179-16-jolsa@kernel.org> (raw)
In-Reply-To: <20241010200957.2750179-1-jolsa@kernel.org>
Adding uprobe session consumers to the consumer test,
so we get the session into the test mix.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
.../bpf/prog_tests/uprobe_multi_test.c | 63 +++++++++++++++----
.../bpf/progs/uprobe_multi_consumers.c | 16 ++++-
2 files changed, 66 insertions(+), 13 deletions(-)
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 2effe4d693b4..df9314309bc3 100644
--- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
@@ -761,6 +761,10 @@ get_program(struct uprobe_multi_consumers *skel, int prog)
return skel->progs.uprobe_0;
case 1:
return skel->progs.uprobe_1;
+ case 2:
+ return skel->progs.uprobe_2;
+ case 3:
+ return skel->progs.uprobe_3;
default:
ASSERT_FAIL("get_program");
return NULL;
@@ -775,6 +779,10 @@ get_link(struct uprobe_multi_consumers *skel, int link)
return &skel->links.uprobe_0;
case 1:
return &skel->links.uprobe_1;
+ case 2:
+ return &skel->links.uprobe_2;
+ case 3:
+ return &skel->links.uprobe_3;
default:
ASSERT_FAIL("get_link");
return NULL;
@@ -793,8 +801,11 @@ static int uprobe_attach(struct uprobe_multi_consumers *skel, int idx)
/*
* bit/prog: 0 uprobe entry
* bit/prog: 1 uprobe return
+ * bit/prog: 2 uprobe session without return
+ * bit/prog: 3 uprobe session with return
*/
opts.retprobe = idx == 1;
+ opts.session = idx == 2 || idx == 3;
*link = bpf_program__attach_uprobe_multi(prog, 0, "/proc/self/exe",
"uprobe_consumer_test",
@@ -824,7 +835,7 @@ uprobe_consumer_test(struct uprobe_multi_consumers *skel,
int idx;
/* detach uprobe for each unset programs in 'before' state ... */
- for (idx = 0; idx < 1; idx++) {
+ for (idx = 0; idx < 4; idx++) {
if (test_bit(idx, before) && !test_bit(idx, after))
uprobe_detach(skel, idx);
}
@@ -847,7 +858,7 @@ static int consumer_test(struct uprobe_multi_consumers *skel,
printf("consumer_test before %lu after %lu\n", before, after);
/* 'before' is each, we attach uprobe for every set idx */
- for (idx = 0; idx < 1; idx++) {
+ for (idx = 0; idx < 4; idx++) {
if (test_bit(idx, before)) {
if (!ASSERT_OK(uprobe_attach(skel, idx), "uprobe_attach_before"))
goto cleanup;
@@ -858,11 +869,13 @@ static int consumer_test(struct uprobe_multi_consumers *skel,
if (!ASSERT_EQ(err, 0, "uprobe_consumer_test"))
goto cleanup;
- for (idx = 0; idx < 1; idx++) {
+ for (idx = 0; idx < 4; idx++) {
+ unsigned long had_uretprobes;
const char *fmt = "BUG";
__u64 val = 0;
- if (idx == 0) {
+ switch (idx) {
+ case 0:
/*
* uprobe entry
* +1 if define in 'before'
@@ -870,18 +883,42 @@ static int consumer_test(struct uprobe_multi_consumers *skel,
if (test_bit(idx, before))
val++;
fmt = "prog 0: uprobe";
- } else {
+ break;
+ case 1:
/*
* to trigger uretprobe consumer, the uretprobe needs to be installed,
* which means one of the 'return' uprobes was alive when probe was hit:
*
- * idxs: 2/3 uprobe return in 'installed' mask
+ * idxs: 1/2 uprobe return in 'installed' mask
*/
- unsigned long had_uretprobes = before & 0b10; /* is uretprobe installed */
+ had_uretprobes = before & 0b0110; /* is uretprobe installed */
if (had_uretprobes && test_bit(idx, after))
val++;
fmt = "prog 1: uretprobe";
+ break;
+ case 2:
+ /*
+ * session with return
+ * +1 if defined in 'before'
+ * +1 if defined in 'after'
+ */
+ if (test_bit(idx, before)) {
+ val++;
+ if (test_bit(idx, after))
+ val++;
+ }
+ fmt = "prog 2 : session with return";
+ break;
+ case 3:
+ /*
+ * session without return
+ * +1 if defined in 'before'
+ */
+ if (test_bit(idx, before))
+ val++;
+ fmt = "prog 3 : session with NO return";
+ break;
}
if (!ASSERT_EQ(skel->bss->uprobe_result[idx], val, fmt))
@@ -892,7 +929,7 @@ static int consumer_test(struct uprobe_multi_consumers *skel,
ret = 0;
cleanup:
- for (idx = 0; idx < 1; idx++)
+ for (idx = 0; idx < 4; idx++)
uprobe_detach(skel, idx);
return ret;
}
@@ -912,9 +949,11 @@ static void test_consumers(void)
*
* - 1 uprobe entry consumer
* - 1 uprobe exit consumer
+ * - 1 uprobe session with return
+ * - 1 uprobe session without return
*
- * The test uses 2 uprobes attached on single function, but that
- * translates into single uprobe with 2 consumers in kernel.
+ * The test uses 4 uprobes attached on single function, but that
+ * translates into single uprobe with 4 consumers in kernel.
*
* The before/after values present the state of attached consumers
* before and after the probed function:
@@ -943,8 +982,8 @@ static void test_consumers(void)
* before/after bits.
*/
- for (before = 0; before < 4; before++) {
- for (after = 0; after < 4; after++)
+ for (before = 0; before < 16; before++) {
+ for (after = 0; after < 16; after++)
if (consumer_test(skel, before, after))
goto out;
}
diff --git a/tools/testing/selftests/bpf/progs/uprobe_multi_consumers.c b/tools/testing/selftests/bpf/progs/uprobe_multi_consumers.c
index 1c64d7263911..93752bb5690b 100644
--- a/tools/testing/selftests/bpf/progs/uprobe_multi_consumers.c
+++ b/tools/testing/selftests/bpf/progs/uprobe_multi_consumers.c
@@ -8,7 +8,7 @@
char _license[] SEC("license") = "GPL";
-__u64 uprobe_result[2];
+__u64 uprobe_result[4];
SEC("uprobe.multi")
int uprobe_0(struct pt_regs *ctx)
@@ -23,3 +23,17 @@ int uprobe_1(struct pt_regs *ctx)
uprobe_result[1]++;
return 0;
}
+
+SEC("uprobe.session")
+int uprobe_2(struct pt_regs *ctx)
+{
+ uprobe_result[2]++;
+ return 0;
+}
+
+SEC("uprobe.session")
+int uprobe_3(struct pt_regs *ctx)
+{
+ uprobe_result[3]++;
+ return 1;
+}
--
2.46.2
next prev parent reply other threads:[~2024-10-10 20:13 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-10 20:09 [PATCHv6 bpf-next,perf/core 00/16] uprobe, bpf: Add session support Jiri Olsa
2024-10-10 20:09 ` [PATCHv6 perf/core 01/16] uprobe: Add data pointer to consumer handlers Jiri Olsa
2024-10-15 22:24 ` Masami Hiramatsu
2024-10-16 6:41 ` Jiri Olsa
2024-10-10 20:09 ` [PATCHv6 perf/core 02/16] uprobe: Add support for session consumer Jiri Olsa
2024-10-11 11:27 ` Oleg Nesterov
2024-10-16 0:07 ` Masami Hiramatsu
2024-10-10 20:09 ` [PATCHv6 bpf-next 03/16] bpf: Allow return values 0 and 1 for kprobe session Jiri Olsa
2024-10-11 2:19 ` Andrii Nakryiko
2024-10-10 20:09 ` [PATCHv6 bpf-next 04/16] bpf: Force uprobe bpf program to always return 0 Jiri Olsa
2024-10-11 2:20 ` Andrii Nakryiko
2024-10-10 20:09 ` [PATCHv6 bpf-next 05/16] bpf: Add support for uprobe multi session attach Jiri Olsa
2024-10-10 20:09 ` [PATCHv6 bpf-next 06/16] bpf: Add support for uprobe multi session context Jiri Olsa
2024-10-10 20:09 ` [PATCHv6 bpf-next 07/16] libbpf: Add support for uprobe multi session attach Jiri Olsa
2024-10-11 2:21 ` Andrii Nakryiko
2024-10-10 20:09 ` [PATCHv6 bpf-next 08/16] selftests/bpf: Add uprobe session test Jiri Olsa
2024-10-11 2:22 ` Andrii Nakryiko
2024-10-10 20:09 ` [PATCHv6 bpf-next 09/16] selftests/bpf: Add uprobe session cookie test Jiri Olsa
2024-10-10 20:09 ` [PATCHv6 bpf-next 10/16] selftests/bpf: Add uprobe session recursive test Jiri Olsa
2024-10-10 20:09 ` [PATCHv6 bpf-next 11/16] selftests/bpf: Add uprobe session verifier test for return value Jiri Olsa
2024-10-11 2:23 ` Andrii Nakryiko
2024-10-10 20:09 ` [PATCHv6 bpf-next 12/16] selftests/bpf: Add kprobe " Jiri Olsa
2024-10-11 2:24 ` Andrii Nakryiko
2024-10-10 20:09 ` [PATCHv6 bpf-next 13/16] selftests/bpf: Add uprobe session single consumer test Jiri Olsa
2024-10-11 2:25 ` Andrii Nakryiko
2024-10-11 11:33 ` Jiri Olsa
2024-10-10 20:09 ` [PATCHv6 bpf-next 14/16] selftests/bpf: Scale down uprobe multi " Jiri Olsa
2024-10-11 2:27 ` Andrii Nakryiko
2024-10-11 11:36 ` Jiri Olsa
2024-10-10 20:09 ` Jiri Olsa [this message]
2024-10-11 2:30 ` [PATCHv6 bpf-next 15/16] selftests/bpf: Add uprobe sessions to " Andrii Nakryiko
2024-10-11 11:36 ` Jiri Olsa
2024-10-10 20:09 ` [PATCHv6 bpf-next 16/16] selftests/bpf: Add threads " Jiri Olsa
2024-10-11 2:35 ` Andrii Nakryiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241010200957.2750179-16-jolsa@kernel.org \
--to=jolsa@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sdf@fomichev.me \
--cc=songliubraving@fb.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox