xref: /linux/tools/testing/selftests/bpf/progs/tracing_multi_session_attach.c (revision 68f4e480b089abae26fbab0c38c3df3cbac3d79d)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <vmlinux.h>
3 #include <bpf/bpf_helpers.h>
4 #include <bpf/bpf_tracing.h>
5 
6 char _license[] SEC("license") = "GPL";
7 
8 __hidden extern int tracing_multi_arg_check(__u64 *ctx, __u64 *test_result, bool is_return);
9 
10 __u64 test_result_fentry = 0;
11 __u64 test_result_fexit = 0;
12 
13 SEC("fsession.multi/bpf_fentry_test*")
14 int BPF_PROG(test_session_1)
15 {
16 	volatile __u64 *cookie = bpf_session_cookie(ctx);
17 
18 	if (bpf_session_is_return(ctx)) {
19 		if (tracing_multi_arg_check(ctx, &test_result_fexit, true))
20 			return 0;
21 		/* extra count for test_result_fexit cookie */
22 		test_result_fexit += *cookie == 0xbeafbeafbeafbeaf;
23 	} else {
24 		if (tracing_multi_arg_check(ctx, &test_result_fentry, false))
25 			return 0;
26 		*cookie = 0xbeafbeafbeafbeaf;
27 	}
28 	return 0;
29 }
30 
31 SEC("fsession.multi.s/bpf_fentry_test1")
32 int BPF_PROG(test_fsession_s)
33 {
34 	volatile __u64 *cookie = bpf_session_cookie(ctx);
35 
36 	if (bpf_session_is_return(ctx)) {
37 		if (tracing_multi_arg_check(ctx, &test_result_fexit, true))
38 			return 0;
39 		/* extra count for test_result_fexit cookie */
40 		test_result_fexit += *cookie == 0xbeafbeafbeafbeaf;
41 	} else {
42 		if (tracing_multi_arg_check(ctx, &test_result_fentry, false))
43 			return 0;
44 		*cookie = 0xbeafbeafbeafbeaf;
45 	}
46 	return 0;
47 }
48 
49 SEC("fsession.multi/bpf_testmod:bpf_testmod_fentry_test*")
50 int BPF_PROG(test_session_2)
51 {
52 	volatile __u64 *cookie = bpf_session_cookie(ctx);
53 
54 	if (bpf_session_is_return(ctx)) {
55 		if (tracing_multi_arg_check(ctx, &test_result_fexit, true))
56 			return 0;
57 		/* extra count for test_result_fexit cookie */
58 		test_result_fexit += *cookie == 0xbeafbeafbeafbeaf;
59 	} else {
60 		if (tracing_multi_arg_check(ctx, &test_result_fentry, false))
61 			return 0;
62 		*cookie = 0xbeafbeafbeafbeaf;
63 	}
64 	return 0;
65 }
66