Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Add uprobe session single consumer test

Testing that the session ret_handler bypass works on single
uprobe with multiple consumers, each with different session
ignore return value.

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-12-jolsa@kernel.org

authored by

Jiri Olsa and committed by
Andrii Nakryiko
c574bcd6 504d21d9

+77
+33
tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
··· 9 9 #include "uprobe_multi_consumers.skel.h" 10 10 #include "uprobe_multi_pid_filter.skel.h" 11 11 #include "uprobe_multi_session.skel.h" 12 + #include "uprobe_multi_session_single.skel.h" 12 13 #include "uprobe_multi_session_cookie.skel.h" 13 14 #include "uprobe_multi_session_recursive.skel.h" 14 15 #include "uprobe_multi_verifier.skel.h" ··· 1072 1071 uprobe_multi_session__destroy(skel); 1073 1072 } 1074 1073 1074 + static void test_session_single_skel_api(void) 1075 + { 1076 + struct uprobe_multi_session_single *skel = NULL; 1077 + LIBBPF_OPTS(bpf_kprobe_multi_opts, opts); 1078 + int err; 1079 + 1080 + skel = uprobe_multi_session_single__open_and_load(); 1081 + if (!ASSERT_OK_PTR(skel, "uprobe_multi_session_single__open_and_load")) 1082 + goto cleanup; 1083 + 1084 + skel->bss->pid = getpid(); 1085 + 1086 + err = uprobe_multi_session_single__attach(skel); 1087 + if (!ASSERT_OK(err, "uprobe_multi_session_single__attach")) 1088 + goto cleanup; 1089 + 1090 + uprobe_multi_func_1(); 1091 + 1092 + /* 1093 + * We expect consumer 0 and 2 to trigger just entry handler (value 1) 1094 + * and consumer 1 to hit both (value 2). 1095 + */ 1096 + ASSERT_EQ(skel->bss->uprobe_session_result[0], 1, "uprobe_session_result_0"); 1097 + ASSERT_EQ(skel->bss->uprobe_session_result[1], 2, "uprobe_session_result_1"); 1098 + ASSERT_EQ(skel->bss->uprobe_session_result[2], 1, "uprobe_session_result_2"); 1099 + 1100 + cleanup: 1101 + uprobe_multi_session_single__destroy(skel); 1102 + } 1103 + 1075 1104 static void test_session_cookie_skel_api(void) 1076 1105 { 1077 1106 struct uprobe_multi_session_cookie *skel = NULL; ··· 1276 1245 test_pid_filter_process(true); 1277 1246 if (test__start_subtest("session")) 1278 1247 test_session_skel_api(); 1248 + if (test__start_subtest("session_single")) 1249 + test_session_single_skel_api(); 1279 1250 if (test__start_subtest("session_cookie")) 1280 1251 test_session_cookie_skel_api(); 1281 1252 if (test__start_subtest("session_cookie_recursive"))
+44
tools/testing/selftests/bpf/progs/uprobe_multi_session_single.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include <linux/bpf.h> 3 + #include <bpf/bpf_helpers.h> 4 + #include <bpf/bpf_tracing.h> 5 + #include <stdbool.h> 6 + #include "bpf_kfuncs.h" 7 + #include "bpf_misc.h" 8 + 9 + char _license[] SEC("license") = "GPL"; 10 + 11 + __u64 uprobe_session_result[3] = {}; 12 + int pid = 0; 13 + 14 + static int uprobe_multi_check(void *ctx, int idx) 15 + { 16 + if (bpf_get_current_pid_tgid() >> 32 != pid) 17 + return 1; 18 + 19 + uprobe_session_result[idx]++; 20 + 21 + /* only consumer 1 executes return probe */ 22 + if (idx == 0 || idx == 2) 23 + return 1; 24 + 25 + return 0; 26 + } 27 + 28 + SEC("uprobe.session//proc/self/exe:uprobe_multi_func_1") 29 + int uprobe_0(struct pt_regs *ctx) 30 + { 31 + return uprobe_multi_check(ctx, 0); 32 + } 33 + 34 + SEC("uprobe.session//proc/self/exe:uprobe_multi_func_1") 35 + int uprobe_1(struct pt_regs *ctx) 36 + { 37 + return uprobe_multi_check(ctx, 1); 38 + } 39 + 40 + SEC("uprobe.session//proc/self/exe:uprobe_multi_func_1") 41 + int uprobe_2(struct pt_regs *ctx) 42 + { 43 + return uprobe_multi_check(ctx, 2); 44 + }