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 #if __has_attribute(btf_type_tag) 30 #define __arena_tag __attribute__((btf_type_tag("arena"))) 31 #else 32 #define __arena_tag 33 #endif 34 35 struct bpf_iter_testmod_seq; 36 37 struct prog_test_pass1 { 38 int x0; 39 struct { 40 int x1; 41 struct { 42 int x2; 43 struct { 44 int x3; 45 }; 46 }; 47 }; 48 }; 49 50 struct prog_test_pass2 { 51 int len; 52 short arr1[4]; 53 struct { 54 char arr2[4]; 55 unsigned long arr3[8]; 56 } x; 57 }; 58 59 struct prog_test_big_arg { 60 __u64 a; 61 __u64 b; 62 }; 63 64 struct prog_test_pair_arg { /* 16 bytes: two argument registers */ 65 __u64 lo; 66 __u64 hi; 67 }; 68 69 #ifdef __SIZEOF_INT128__ 70 struct prog_test_i128_arg { /* 16 bytes, aligned to 16 like its member */ 71 __int128 v; 72 }; 73 #endif 74 75 struct prog_test_ptr_arg { /* 16 bytes, but holds a pointer */ 76 void *p; 77 __u64 x; 78 }; 79 80 struct prog_test_ret_pair { /* 16 bytes: R0:R2 */ 81 __u64 lo; 82 __u64 hi; 83 }; 84 85 struct prog_test_ret_ii { /* 8 bytes: R0 only */ 86 int a; 87 int b; 88 }; 89 90 struct prog_test_ret_ptr { /* 16 bytes: contains a pointer */ 91 void *p; 92 __u64 tag; 93 }; 94 95 struct prog_test_ret_arena { /* 16 bytes: two arena pointers */ 96 void __arena_tag *a; 97 void __arena_tag *b; 98 }; 99 100 struct prog_test_ret_arena_mixed { /* 16 bytes: an arena pointer and a scalar */ 101 void __arena_tag *p; 102 __u64 tag; 103 }; 104 105 struct prog_test_ret_arena_untagged { /* 16 bytes: 'b' lacks the arena tag */ 106 void __arena_tag *a; 107 void *b; 108 }; 109 110 union prog_test_ret_arena_union { /* 8 bytes: 'b' lacks the arena tag */ 111 void __arena_tag *a; 112 void *b; 113 }; 114 115 struct prog_test_ret_nested { /* 16 bytes: the pointer hides one level down */ 116 struct { 117 void *p; 118 } in; 119 __u64 tag; 120 }; 121 122 struct prog_test_ret_ptr_arr { /* 16 bytes: an array of pointers */ 123 void *p[2]; 124 }; 125 126 struct prog_test_ret_arr_struct { /* 16 bytes: the pointer is under an array of structs */ 127 struct { 128 struct { 129 void *p; 130 } in2; 131 } in1[2]; 132 }; 133 134 struct prog_test_ret_arr2d { /* 16 bytes: a two dimensional array of structs */ 135 struct { 136 void *p; 137 } a[1][2]; 138 }; 139 140 struct prog_test_ret_deep { /* 8 bytes, but nested past the 4-level walk limit */ 141 struct { 142 struct { 143 struct { 144 struct { 145 __u64 v; 146 } l4; 147 } l3; 148 } l2; 149 } l1; 150 }; 151 152 struct prog_test_ret_big { /* 24 bytes: too large for R0:R2 */ 153 __u64 a; 154 __u64 b; 155 __u64 c; 156 }; 157 158 struct prog_test_fail1 { 159 void *p; 160 int x; 161 }; 162 163 struct prog_test_fail2 { 164 int x8; 165 struct prog_test_pass1 x; 166 }; 167 168 struct prog_test_fail3 { 169 int len; 170 char arr1[2]; 171 char arr2[]; 172 }; 173 174 struct init_sock_args { 175 int af; 176 int type; 177 }; 178 179 struct addr_args { 180 char addr[sizeof(struct __kernel_sockaddr_storage)]; 181 int addrlen; 182 }; 183 184 struct sendmsg_args { 185 struct addr_args addr; 186 char msg[10]; 187 int msglen; 188 }; 189 190 struct bpf_testmod_ctx { 191 struct callback_head rcu; 192 refcount_t usage; 193 }; 194 195 struct prog_test_ref_kfunc * 196 bpf_kfunc_call_test_acquire(unsigned long *scalar_ptr) __ksym; 197 void bpf_kfunc_call_test_release(struct prog_test_ref_kfunc *p) __ksym; 198 void bpf_kfunc_call_test_ref(struct prog_test_ref_kfunc *p) __ksym; 199 200 void bpf_kfunc_call_test_mem_len_pass1(void *mem, int len) __ksym; 201 __u64 bpf_kfunc_arena_arg_test(__u64 *val__arena) __ksym; 202 __u64 bpf_kfunc_arena_cap_test(__u64 *val__arena) __ksym; 203 __u64 bpf_kfunc_arena_cap_nullable_test(__u64 *val__arena__nullable) __ksym; 204 __u64 bpf_kfunc_arena_args5_test(__u64 *a__arena, __u64 *b__arena, 205 __u64 *c__arena, __u64 *d__arena, 206 __u64 *e__arena__nullable) __ksym; 207 __u64 bpf_kfunc_arena_stack_arg_test(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e, 208 __u64 *f__arena) __ksym; 209 __u64 bpf_kfunc_arena_mixed_test(__u64 *a__arena, __u64 *b__arena__nullable) __ksym; 210 int *bpf_kfunc_call_test_get_rdwr_mem(struct prog_test_ref_kfunc *p, const int rdwr_buf_size) __ksym; 211 int *bpf_kfunc_call_test_get_rdonly_mem(struct prog_test_ref_kfunc *p, const int rdonly_buf_size) __ksym; 212 int *bpf_kfunc_call_test_acq_rdonly_mem(struct prog_test_ref_kfunc *p, const int rdonly_buf_size) __ksym; 213 void bpf_kfunc_call_int_mem_release(int *p) __ksym; 214 215 /* The bpf_kfunc_call_test_static_unused_arg is defined as static, 216 * but bpf program compilation needs to see it as global symbol. 217 */ 218 #ifndef __KERNEL__ 219 u32 bpf_kfunc_call_test_static_unused_arg(u32 arg, u32 unused) __ksym; 220 #endif 221 222 void bpf_testmod_test_mod_kfunc(int i) __ksym; 223 int bpf_testmod_ops3_call_test_arena(__u64 *ptr__arena) __ksym; 224 int bpf_testmod_ops3_call_test_arena_nullable(__u64 *ptr__arena__nullable) __ksym; 225 int bpf_testmod_ops3_call_test_arena_stack(__u64 *ptr__arena) __ksym; 226 int bpf_testmod_ops3_call_test_arena_multislot(__u64 *ptr__arena) __ksym; 227 int bpf_testmod_ops3_call_test_arena_member(__u64 *ptr__arena) __ksym; 228 int bpf_testmod_ops3_call_test_nullable(void) __ksym; 229 230 __u64 bpf_kfunc_call_test1(struct sock *sk, __u32 a, __u64 b, 231 __u32 c, __u64 d) __ksym; 232 int bpf_kfunc_call_test2(struct sock *sk, __u32 a, __u32 b) __ksym; 233 struct sock *bpf_kfunc_call_test3(struct sock *sk) __ksym; 234 long bpf_kfunc_call_test4(signed char a, short b, int c, long d) __ksym; 235 int bpf_kfunc_call_test5(__u8 a, __u16 b, __u32 c) __ksym; 236 #ifdef __SIZEOF_INT128__ 237 __int128 bpf_kfunc_call_test_i128(__u64 a, __u64 b) __ksym; 238 #endif 239 struct prog_test_ret_pair bpf_kfunc_call_test_ret_pair(__u64 a, __u64 b) __ksym; 240 struct prog_test_ret_pair bpf_kfunc_call_test_ret_fastcall(__u64 a, __u64 b) __ksym; 241 struct prog_test_ret_ii bpf_kfunc_call_test_ret_ii(int a, int b) __ksym; 242 __u64 bpf_kfunc_call_test_pair_arg(__u64 a, struct prog_test_pair_arg s, __u64 b) __ksym; 243 #ifdef __SIZEOF_INT128__ 244 __u64 bpf_kfunc_call_test_i128_arg(__u64 a, __u64 b, __int128 v) __ksym; 245 __u64 bpf_kfunc_call_test_i128_arg_odd(__u64 a, __int128 v, __u64 b) __ksym; 246 __u64 bpf_kfunc_call_test_i128_arg_odd_many(__u64 a, __int128 v, __u64 b, __u64 c, 247 __u64 d, __u64 e, __u64 f, __int128 w) __ksym; 248 __u64 bpf_kfunc_call_test_i128_arg_stack_hole(__u64 a, __u64 b, __u64 c, __u64 d, 249 __u64 e, struct prog_test_pair_arg s, 250 __u64 f, __u64 g, 251 struct prog_test_i128_arg w) __ksym; 252 __u64 bpf_kfunc_call_test_i128_arg_pad(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e, 253 __u64 f, __u64 g, __int128 v) __ksym; 254 #endif 255 __u64 bpf_kfunc_call_test_pair_arg_nofit(__u64 a, __u64 b, __u64 c, __u64 d, 256 struct prog_test_pair_arg s) __ksym; 257 __u64 bpf_kfunc_call_test_pair_arg_tail(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e, 258 struct prog_test_pair_arg s, __u64 f) __ksym; 259 __u64 bpf_kfunc_call_test_pair_arg_split8(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e, 260 __u64 f, __u64 g, 261 struct prog_test_pair_arg s) __ksym; 262 __u64 bpf_kfunc_call_test_ptr_arg(struct prog_test_ptr_arg s) __ksym; 263 __u64 bpf_kfunc_call_test_pair_arena_arg(__u64 a, __u64 b, __u64 c, 264 struct prog_test_pair_arg s, 265 __u64 *f__arena) __ksym; 266 struct prog_test_ret_ptr bpf_kfunc_call_test_ret_ptr(__u64 tag) __ksym; 267 struct prog_test_ret_nested bpf_kfunc_call_test_ret_nested(__u64 tag) __ksym; 268 struct prog_test_ret_ptr_arr bpf_kfunc_call_test_ret_ptr_arr(void) __ksym; 269 struct prog_test_ret_arr_struct bpf_kfunc_call_test_ret_arr_struct(void) __ksym; 270 struct prog_test_ret_arr2d bpf_kfunc_call_test_ret_arr2d(void) __ksym; 271 struct prog_test_ret_arena bpf_kfunc_call_test_ret_arena(__u64 addr) __ksym; 272 struct prog_test_ret_arena_mixed bpf_kfunc_call_test_ret_arena_mixed(__u64 addr) __ksym; 273 struct prog_test_ret_arena_untagged bpf_kfunc_call_test_ret_arena_untagged(__u64 addr) __ksym; 274 union prog_test_ret_arena_union bpf_kfunc_call_test_ret_arena_union(__u64 addr) __ksym; 275 struct prog_test_ret_deep bpf_kfunc_call_test_ret_deep(__u64 v) __ksym; 276 struct prog_test_ret_big bpf_kfunc_call_test_ret_big(void) __ksym; 277 __u64 bpf_kfunc_call_stack_arg(__u64 a, __u64 b, __u64 c, __u64 d, 278 __u64 e, __u64 f, __u64 g, __u64 h, 279 __u64 i, __u64 j) __ksym; 280 __u64 bpf_kfunc_call_stack_arg_ptr(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e, 281 __u64 f, __u64 g, __u64 h, __u64 i, 282 struct prog_test_pass1 *p) __ksym; 283 __u64 bpf_kfunc_call_stack_arg_mix(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e, 284 __u64 f, __u64 g, 285 struct prog_test_pass1 *p, __u64 h, 286 struct prog_test_pass1 *q) __ksym; 287 __u64 bpf_kfunc_call_stack_arg_dynptr(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e, 288 __u64 f, __u64 g, __u64 h, __u64 i, 289 struct bpf_dynptr *ptr) __ksym; 290 __u64 bpf_kfunc_call_stack_arg_mem(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e, 291 void *mem, int mem__sz) __ksym; 292 __u64 bpf_kfunc_call_stack_arg_iter(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e, 293 __u64 f, __u64 g, __u64 h, __u64 i, 294 struct bpf_iter_testmod_seq *it__iter) __ksym; 295 __u64 bpf_kfunc_call_stack_arg_const_str(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e, 296 __u64 f, __u64 g, __u64 h, __u64 i, 297 const char *str__str) __ksym; 298 __u64 bpf_kfunc_call_stack_arg_timer(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e, 299 __u64 f, __u64 g, __u64 h, __u64 i, 300 struct bpf_timer *timer) __ksym; 301 __u64 bpf_kfunc_call_stack_arg_big(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e, 302 struct prog_test_big_arg s) __ksym; 303 304 void bpf_kfunc_call_test_pass_ctx(struct __sk_buff *skb) __ksym; 305 void bpf_kfunc_call_test_pass1(struct prog_test_pass1 *p) __ksym; 306 void bpf_kfunc_call_test_pass2(struct prog_test_pass2 *p) __ksym; 307 void bpf_kfunc_test_uninit_struct(struct prog_test_pass1 *out__uninit) __ksym; 308 void bpf_kfunc_test_uninit_mem(void *out__uninit, __u32 out__sz) __ksym; 309 void bpf_kfunc_test_uninit_partial(void *out__uninit, __u32 out__sz) __ksym; 310 int bpf_kfunc_test_uninit_alias(int *out__uninit, const int *in) __ksym; 311 void bpf_kfunc_test_uninit_multi(int *a__uninit, void *b__uninit, __u32 b__sz) __ksym; 312 void bpf_kfunc_test_uninit_pair(struct prog_test_pair_arg p, int *out__uninit) __ksym; 313 void bpf_kfunc_test_uninit_stack(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e, 314 int *out__uninit) __ksym; 315 void bpf_kfunc_call_test_mem_len_fail2(__u64 *mem, int len) __ksym; 316 317 void bpf_kfunc_call_test_destructive(void) __ksym; 318 void bpf_kfunc_call_test_sleepable(void) __ksym; 319 int bpf_kfunc_call_test_call_rcu_tasks_trace(int *done) __ksym; 320 321 void bpf_kfunc_call_test_offset(struct prog_test_ref_kfunc *p); 322 struct prog_test_member *bpf_kfunc_call_memb_acquire(void); 323 void bpf_kfunc_call_memb1_release(struct prog_test_member1 *p); 324 void bpf_kfunc_call_test_fail1(struct prog_test_fail1 *p); 325 void bpf_kfunc_call_test_fail2(struct prog_test_fail2 *p); 326 void bpf_kfunc_call_test_fail3(struct prog_test_fail3 *p); 327 void bpf_kfunc_call_test_mem_len_fail1(void *mem, int len); 328 329 void bpf_kfunc_common_test(void) __ksym; 330 331 int bpf_kfunc_init_sock(struct init_sock_args *args) __ksym; 332 void bpf_kfunc_close_sock(void) __ksym; 333 int bpf_kfunc_call_kernel_connect(struct addr_args *args) __ksym; 334 int bpf_kfunc_call_kernel_bind(struct addr_args *args) __ksym; 335 int bpf_kfunc_call_kernel_listen(void) __ksym; 336 int bpf_kfunc_call_kernel_sendmsg(struct sendmsg_args *args) __ksym; 337 int bpf_kfunc_call_sock_sendmsg(struct sendmsg_args *args) __ksym; 338 int bpf_kfunc_call_kernel_getsockname(struct addr_args *args) __ksym; 339 int bpf_kfunc_call_kernel_getpeername(struct addr_args *args) __ksym; 340 341 void bpf_kfunc_dynptr_test(struct bpf_dynptr *ptr, struct bpf_dynptr *ptr__nullable) __ksym; 342 343 struct bpf_testmod_ctx *bpf_testmod_ctx_create(int *err) __ksym; 344 void bpf_testmod_ctx_release(struct bpf_testmod_ctx *ctx) __ksym; 345 346 struct sk_buff *bpf_kfunc_nested_acquire_nonzero_offset_test(struct sk_buff_head *ptr) __ksym; 347 struct sk_buff *bpf_kfunc_nested_acquire_zero_offset_test(struct sock_common *ptr) __ksym; 348 void bpf_kfunc_nested_release_test(struct sk_buff *ptr) __ksym; 349 350 struct st_ops_args; 351 int bpf_kfunc_st_ops_test_prologue(struct st_ops_args *args) __ksym; 352 int bpf_kfunc_st_ops_test_epilogue(struct st_ops_args *args) __ksym; 353 int bpf_kfunc_st_ops_test_pro_epilogue(struct st_ops_args *args) __ksym; 354 int bpf_kfunc_st_ops_inc10(struct st_ops_args *args) __ksym; 355 356 void bpf_kfunc_trusted_vma_test(struct vm_area_struct *ptr) __ksym; 357 void bpf_kfunc_trusted_task_test(struct task_struct *ptr) __ksym; 358 struct task_struct *bpf_kfunc_trusted_null_test(void) __ksym; 359 void bpf_kfunc_trusted_nullable_test(struct task_struct *ptr__nullable) __ksym; 360 void bpf_kfunc_trusted_num_test(int *ptr) __ksym; 361 void bpf_kfunc_rcu_task_test(struct task_struct *ptr) __ksym; 362 struct task_struct *bpf_kfunc_ret_rcu_test(void) __ksym; 363 int *bpf_kfunc_ret_rcu_test_nostruct(int rdonly_buf_size) __ksym; 364 365 #ifndef __KERNEL__ 366 extern int bpf_kfunc_multi_st_ops_test_1(struct st_ops_args *args, u32 id) __weak __ksym; 367 extern int bpf_kfunc_multi_st_ops_test_1_assoc(struct st_ops_args *args) __weak __ksym; 368 #endif 369 370 struct prog_test_member *bpf_kfunc_get_default_trusted_ptr_test(void) __ksym; 371 void bpf_kfunc_put_default_trusted_ptr_test(struct prog_test_member *trusted_ptr) __ksym; 372 373 void bpf_testmod_test_hardirq_fn(void); 374 void bpf_testmod_test_softirq_fn(void); 375 void bpf_kfunc_trigger_ctx_check(void) __ksym; 376 377 #endif /* _BPF_TESTMOD_KFUNC_H */ 378