Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2025 ChinaTelecom */
3#include <vmlinux.h>
4#include <bpf/bpf_helpers.h>
5#include <bpf/bpf_tracing.h>
6
7char _license[] SEC("license") = "GPL";
8
9__u64 test1_entry_result = 0;
10__u64 test1_exit_result = 0;
11
12SEC("fsession/bpf_fentry_test1")
13int BPF_PROG(test1, int a, int ret)
14{
15 bool is_exit = bpf_session_is_return(ctx);
16
17 if (!is_exit) {
18 test1_entry_result = a == 1 && ret == 0;
19 return 0;
20 }
21
22 test1_exit_result = a == 1 && ret == 2;
23 return 0;
24}
25
26__u64 test2_entry_result = 0;
27__u64 test2_exit_result = 0;
28
29SEC("fsession/bpf_fentry_test3")
30int BPF_PROG(test2, char a, int b, __u64 c, int ret)
31{
32 bool is_exit = bpf_session_is_return(ctx);
33
34 if (!is_exit) {
35 test2_entry_result = a == 4 && b == 5 && c == 6 && ret == 0;
36 return 0;
37 }
38
39 test2_exit_result = a == 4 && b == 5 && c == 6 && ret == 15;
40 return 0;
41}
42
43__u64 test3_entry_result = 0;
44__u64 test3_exit_result = 0;
45
46SEC("fsession/bpf_fentry_test4")
47int BPF_PROG(test3, void *a, char b, int c, __u64 d, int ret)
48{
49 bool is_exit = bpf_session_is_return(ctx);
50
51 if (!is_exit) {
52 test3_entry_result = a == (void *)7 && b == 8 && c == 9 && d == 10 && ret == 0;
53 return 0;
54 }
55
56 test3_exit_result = a == (void *)7 && b == 8 && c == 9 && d == 10 && ret == 34;
57 return 0;
58}
59
60__u64 test4_entry_result = 0;
61__u64 test4_exit_result = 0;
62
63SEC("fsession/bpf_fentry_test5")
64int BPF_PROG(test4, __u64 a, void *b, short c, int d, __u64 e, int ret)
65{
66 bool is_exit = bpf_session_is_return(ctx);
67
68 if (!is_exit) {
69 test4_entry_result = a == 11 && b == (void *)12 && c == 13 && d == 14 &&
70 e == 15 && ret == 0;
71 return 0;
72 }
73
74 test4_exit_result = a == 11 && b == (void *)12 && c == 13 && d == 14 &&
75 e == 15 && ret == 65;
76 return 0;
77}
78
79__u64 test5_entry_result = 0;
80__u64 test5_exit_result = 0;
81
82SEC("fsession/bpf_fentry_test7")
83int BPF_PROG(test5, struct bpf_fentry_test_t *arg, int ret)
84{
85 bool is_exit = bpf_session_is_return(ctx);
86
87 if (!is_exit) {
88 if (!arg)
89 test5_entry_result = ret == 0;
90 return 0;
91 }
92
93 if (!arg)
94 test5_exit_result = 1;
95 return 0;
96}
97
98__u64 test6_entry_result = 0;
99__u64 test6_exit_result = 0;
100SEC("fsession/bpf_fentry_test1")
101int BPF_PROG(test6, int a)
102{
103 __u64 addr = bpf_get_func_ip(ctx);
104
105 if (bpf_session_is_return(ctx))
106 test6_exit_result = (const void *) addr == &bpf_fentry_test1;
107 else
108 test6_entry_result = (const void *) addr == &bpf_fentry_test1;
109 return 0;
110}
111
112__u64 test7_entry_ok = 0;
113__u64 test7_exit_ok = 0;
114SEC("fsession/bpf_fentry_test1")
115int BPF_PROG(test7, int a)
116{
117 volatile __u64 *cookie = bpf_session_cookie(ctx);
118
119 if (!bpf_session_is_return(ctx)) {
120 *cookie = 0xAAAABBBBCCCCDDDDull;
121 test7_entry_ok = *cookie == 0xAAAABBBBCCCCDDDDull;
122 return 0;
123 }
124
125 test7_exit_ok = *cookie == 0xAAAABBBBCCCCDDDDull;
126 return 0;
127}
128
129__u64 test8_entry_ok = 0;
130__u64 test8_exit_ok = 0;
131
132SEC("fsession/bpf_fentry_test1")
133int BPF_PROG(test8, int a)
134{
135 volatile __u64 *cookie = bpf_session_cookie(ctx);
136
137 if (!bpf_session_is_return(ctx)) {
138 *cookie = 0x1111222233334444ull;
139 test8_entry_ok = *cookie == 0x1111222233334444ull;
140 return 0;
141 }
142
143 test8_exit_ok = *cookie == 0x1111222233334444ull;
144 return 0;
145}
146
147__u64 test9_entry_result = 0;
148__u64 test9_exit_result = 0;
149
150SEC("fsession/bpf_fentry_test1")
151int BPF_PROG(test9, int a, int ret)
152{
153 __u64 *cookie = bpf_session_cookie(ctx);
154
155 if (!bpf_session_is_return(ctx)) {
156 test9_entry_result = a == 1 && ret == 0;
157 *cookie = 0x123456ULL;
158 return 0;
159 }
160
161 test9_exit_result = a == 1 && ret == 2 && *cookie == 0x123456ULL;
162 return 0;
163}
164
165__u64 test10_result = 0;
166SEC("fexit/bpf_fentry_test1")
167int BPF_PROG(test10, int a, int ret)
168{
169 test10_result = a == 1 && ret == 2;
170 return 0;
171}
172
173__u64 test11_result = 0;
174SEC("fentry/bpf_fentry_test1")
175int BPF_PROG(test11, int a)
176{
177 test11_result = a == 1;
178 return 0;
179}