summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2024-11-08 14:45:39 +0100
committerAndrii Nakryiko <andrii@kernel.org>2024-11-11 08:18:12 -0800
commit8bcb9c62f0689402e90886d3b65fc649d7c600d7 (patch)
tree66ad2532894085af5eb8b923d22c24127dd18f44 /tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c
parentf6b45e352f0f822bc0bb01b14829ac8f3158d056 (diff)
downloadlinux-8bcb9c62f0689402e90886d3b65fc649d7c600d7.tar.gz
linux-8bcb9c62f0689402e90886d3b65fc649d7c600d7.tar.bz2
linux-8bcb9c62f0689402e90886d3b65fc649d7c600d7.zip
selftests/bpf: Add uprobe session recursive test
Adding uprobe session test that verifies the cookie value is stored properly when single uprobe-ed function is executed recursively. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20241108134544.480660-9-jolsa@kernel.org
Diffstat (limited to 'tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c')
-rw-r--r--tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c b/tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c
new file mode 100644
index 000000000000..8fbcd69fae22
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+#include <stdbool.h>
+#include "bpf_kfuncs.h"
+#include "bpf_misc.h"
+
+char _license[] SEC("license") = "GPL";
+
+int pid = 0;
+
+int idx_entry = 0;
+int idx_return = 0;
+
+__u64 test_uprobe_cookie_entry[6];
+__u64 test_uprobe_cookie_return[3];
+
+static int check_cookie(void)
+{
+ __u64 *cookie = bpf_session_cookie();
+
+ if (bpf_session_is_return()) {
+ if (idx_return >= ARRAY_SIZE(test_uprobe_cookie_return))
+ return 1;
+ test_uprobe_cookie_return[idx_return++] = *cookie;
+ return 0;
+ }
+
+ if (idx_entry >= ARRAY_SIZE(test_uprobe_cookie_entry))
+ return 1;
+ *cookie = test_uprobe_cookie_entry[idx_entry];
+ return idx_entry++ % 2;
+}
+
+
+SEC("uprobe.session//proc/self/exe:uprobe_session_recursive")
+int uprobe_recursive(struct pt_regs *ctx)
+{
+ if (bpf_get_current_pid_tgid() >> 32 != pid)
+ return 1;
+
+ return check_cookie();
+}