xref: /linux/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h (revision 9d19ca5d0e8b4a3f4b2eaa14e86a25f1c93ff35b)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef _BPF_TESTMOD_KFUNC_H
4 #define _BPF_TESTMOD_KFUNC_H
5 
6 #ifndef __KERNEL__
7 #include <vmlinux.h>
8 #include <bpf/bpf_helpers.h>
9 #else
10 #define __ksym
11 struct prog_test_member1 {
12 	int a;
13 };
14 
15 struct prog_test_member {
16 	struct prog_test_member1 m;
17 	int c;
18 };
19 
20 struct prog_test_ref_kfunc {
21 	int a;
22 	int b;
23 	struct prog_test_member memb;
24 	struct prog_test_ref_kfunc *next;
25 	refcount_t cnt;
26 };
27 #endif
28 
29 struct bpf_iter_testmod_seq;
30 
31 struct prog_test_pass1 {
32 	int x0;
33 	struct {
34 		int x1;
35 		struct {
36 			int x2;
37 			struct {
38 				int x3;
39 			};
40 		};
41 	};
42 };
43 
44 struct prog_test_pass2 {
45 	int len;
46 	short arr1[4];
47 	struct {
48 		char arr2[4];
49 		unsigned long arr3[8];
50 	} x;
51 };
52 
53 struct prog_test_big_arg {
54 	__u64 a;
55 	__u64 b;
56 };
57 
58 struct prog_test_fail1 {
59 	void *p;
60 	int x;
61 };
62 
63 struct prog_test_fail2 {
64 	int x8;
65 	struct prog_test_pass1 x;
66 };
67 
68 struct prog_test_fail3 {
69 	int len;
70 	char arr1[2];
71 	char arr2[];
72 };
73 
74 struct init_sock_args {
75 	int af;
76 	int type;
77 };
78 
79 struct addr_args {
80 	char addr[sizeof(struct __kernel_sockaddr_storage)];
81 	int addrlen;
82 };
83 
84 struct sendmsg_args {
85 	struct addr_args addr;
86 	char msg[10];
87 	int msglen;
88 };
89 
90 struct bpf_testmod_ctx {
91 	struct callback_head	rcu;
92 	refcount_t		usage;
93 };
94 
95 struct prog_test_ref_kfunc *
96 bpf_kfunc_call_test_acquire(unsigned long *scalar_ptr) __ksym;
97 void bpf_kfunc_call_test_release(struct prog_test_ref_kfunc *p) __ksym;
98 void bpf_kfunc_call_test_ref(struct prog_test_ref_kfunc *p) __ksym;
99 
100 void bpf_kfunc_call_test_mem_len_pass1(void *mem, int len) __ksym;
101 __u64 bpf_kfunc_arena_arg_test(__u64 *val__arena) __ksym;
102 __u64 bpf_kfunc_arena_cap_test(__u64 *val__arena) __ksym;
103 __u64 bpf_kfunc_arena_cap_nullable_test(__u64 *val__arena__nullable) __ksym;
104 __u64 bpf_kfunc_arena_args5_test(__u64 *a__arena, __u64 *b__arena,
105 				 __u64 *c__arena, __u64 *d__arena,
106 				 __u64 *e__arena__nullable) __ksym;
107 __u64 bpf_kfunc_arena_stack_arg_test(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
108 				     __u64 *f__arena) __ksym;
109 __u64 bpf_kfunc_arena_mixed_test(__u64 *a__arena, __u64 *b__arena__nullable) __ksym;
110 int *bpf_kfunc_call_test_get_rdwr_mem(struct prog_test_ref_kfunc *p, const int rdwr_buf_size) __ksym;
111 int *bpf_kfunc_call_test_get_rdonly_mem(struct prog_test_ref_kfunc *p, const int rdonly_buf_size) __ksym;
112 int *bpf_kfunc_call_test_acq_rdonly_mem(struct prog_test_ref_kfunc *p, const int rdonly_buf_size) __ksym;
113 void bpf_kfunc_call_int_mem_release(int *p) __ksym;
114 
115 /* The bpf_kfunc_call_test_static_unused_arg is defined as static,
116  * but bpf program compilation needs to see it as global symbol.
117  */
118 #ifndef __KERNEL__
119 u32 bpf_kfunc_call_test_static_unused_arg(u32 arg, u32 unused) __ksym;
120 #endif
121 
122 void bpf_testmod_test_mod_kfunc(int i) __ksym;
123 int bpf_testmod_ops3_call_test_arena(__u64 *ptr__arena) __ksym;
124 int bpf_testmod_ops3_call_test_arena_nullable(__u64 *ptr__arena__nullable) __ksym;
125 int bpf_testmod_ops3_call_test_arena_stack(__u64 *ptr__arena) __ksym;
126 int bpf_testmod_ops3_call_test_arena_multislot(__u64 *ptr__arena) __ksym;
127 
128 __u64 bpf_kfunc_call_test1(struct sock *sk, __u32 a, __u64 b,
129 				__u32 c, __u64 d) __ksym;
130 int bpf_kfunc_call_test2(struct sock *sk, __u32 a, __u32 b) __ksym;
131 struct sock *bpf_kfunc_call_test3(struct sock *sk) __ksym;
132 long bpf_kfunc_call_test4(signed char a, short b, int c, long d) __ksym;
133 int bpf_kfunc_call_test5(__u8 a, __u16 b, __u32 c) __ksym;
134 __u64 bpf_kfunc_call_stack_arg(__u64 a, __u64 b, __u64 c, __u64 d,
135 			       __u64 e, __u64 f, __u64 g, __u64 h,
136 			       __u64 i, __u64 j) __ksym;
137 __u64 bpf_kfunc_call_stack_arg_ptr(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
138 				   __u64 f, __u64 g, __u64 h, __u64 i,
139 				   struct prog_test_pass1 *p) __ksym;
140 __u64 bpf_kfunc_call_stack_arg_mix(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
141 				   __u64 f, __u64 g,
142 				   struct prog_test_pass1 *p, __u64 h,
143 				   struct prog_test_pass1 *q) __ksym;
144 __u64 bpf_kfunc_call_stack_arg_dynptr(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
145 				      __u64 f, __u64 g, __u64 h, __u64 i,
146 				      struct bpf_dynptr *ptr) __ksym;
147 __u64 bpf_kfunc_call_stack_arg_mem(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
148 				   void *mem, int mem__sz) __ksym;
149 __u64 bpf_kfunc_call_stack_arg_iter(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
150 				    __u64 f, __u64 g, __u64 h, __u64 i,
151 				    struct bpf_iter_testmod_seq *it__iter) __ksym;
152 __u64 bpf_kfunc_call_stack_arg_const_str(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
153 					 __u64 f, __u64 g, __u64 h, __u64 i,
154 					 const char *str__str) __ksym;
155 __u64 bpf_kfunc_call_stack_arg_timer(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
156 				     __u64 f, __u64 g, __u64 h, __u64 i,
157 				     struct bpf_timer *timer) __ksym;
158 __u64 bpf_kfunc_call_stack_arg_big(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
159 				   struct prog_test_big_arg s) __ksym;
160 
161 void bpf_kfunc_call_test_pass_ctx(struct __sk_buff *skb) __ksym;
162 void bpf_kfunc_call_test_pass1(struct prog_test_pass1 *p) __ksym;
163 void bpf_kfunc_call_test_pass2(struct prog_test_pass2 *p) __ksym;
164 void bpf_kfunc_call_test_mem_len_fail2(__u64 *mem, int len) __ksym;
165 
166 void bpf_kfunc_call_test_destructive(void) __ksym;
167 void bpf_kfunc_call_test_sleepable(void) __ksym;
168 int bpf_kfunc_call_test_call_rcu_tasks_trace(int *done) __ksym;
169 
170 void bpf_kfunc_call_test_offset(struct prog_test_ref_kfunc *p);
171 struct prog_test_member *bpf_kfunc_call_memb_acquire(void);
172 void bpf_kfunc_call_memb1_release(struct prog_test_member1 *p);
173 void bpf_kfunc_call_test_fail1(struct prog_test_fail1 *p);
174 void bpf_kfunc_call_test_fail2(struct prog_test_fail2 *p);
175 void bpf_kfunc_call_test_fail3(struct prog_test_fail3 *p);
176 void bpf_kfunc_call_test_mem_len_fail1(void *mem, int len);
177 
178 void bpf_kfunc_common_test(void) __ksym;
179 
180 int bpf_kfunc_init_sock(struct init_sock_args *args) __ksym;
181 void bpf_kfunc_close_sock(void) __ksym;
182 int bpf_kfunc_call_kernel_connect(struct addr_args *args) __ksym;
183 int bpf_kfunc_call_kernel_bind(struct addr_args *args) __ksym;
184 int bpf_kfunc_call_kernel_listen(void) __ksym;
185 int bpf_kfunc_call_kernel_sendmsg(struct sendmsg_args *args) __ksym;
186 int bpf_kfunc_call_sock_sendmsg(struct sendmsg_args *args) __ksym;
187 int bpf_kfunc_call_kernel_getsockname(struct addr_args *args) __ksym;
188 int bpf_kfunc_call_kernel_getpeername(struct addr_args *args) __ksym;
189 
190 void bpf_kfunc_dynptr_test(struct bpf_dynptr *ptr, struct bpf_dynptr *ptr__nullable) __ksym;
191 
192 struct bpf_testmod_ctx *bpf_testmod_ctx_create(int *err) __ksym;
193 void bpf_testmod_ctx_release(struct bpf_testmod_ctx *ctx) __ksym;
194 
195 struct sk_buff *bpf_kfunc_nested_acquire_nonzero_offset_test(struct sk_buff_head *ptr) __ksym;
196 struct sk_buff *bpf_kfunc_nested_acquire_zero_offset_test(struct sock_common *ptr) __ksym;
197 void bpf_kfunc_nested_release_test(struct sk_buff *ptr) __ksym;
198 
199 struct st_ops_args;
200 int bpf_kfunc_st_ops_test_prologue(struct st_ops_args *args) __ksym;
201 int bpf_kfunc_st_ops_test_epilogue(struct st_ops_args *args) __ksym;
202 int bpf_kfunc_st_ops_test_pro_epilogue(struct st_ops_args *args) __ksym;
203 int bpf_kfunc_st_ops_inc10(struct st_ops_args *args) __ksym;
204 
205 void bpf_kfunc_trusted_vma_test(struct vm_area_struct *ptr) __ksym;
206 void bpf_kfunc_trusted_task_test(struct task_struct *ptr) __ksym;
207 void bpf_kfunc_trusted_num_test(int *ptr) __ksym;
208 void bpf_kfunc_rcu_task_test(struct task_struct *ptr) __ksym;
209 struct task_struct *bpf_kfunc_ret_rcu_test(void) __ksym;
210 int *bpf_kfunc_ret_rcu_test_nostruct(int rdonly_buf_size) __ksym;
211 
212 #ifndef __KERNEL__
213 extern int bpf_kfunc_multi_st_ops_test_1(struct st_ops_args *args, u32 id) __weak __ksym;
214 extern int bpf_kfunc_multi_st_ops_test_1_assoc(struct st_ops_args *args) __weak __ksym;
215 #endif
216 
217 struct prog_test_member *bpf_kfunc_get_default_trusted_ptr_test(void) __ksym;
218 void bpf_kfunc_put_default_trusted_ptr_test(struct prog_test_member *trusted_ptr) __ksym;
219 
220 void bpf_testmod_test_hardirq_fn(void);
221 void bpf_testmod_test_softirq_fn(void);
222 void bpf_kfunc_trigger_ctx_check(void) __ksym;
223 
224 #endif /* _BPF_TESTMOD_KFUNC_H */
225