xref: /linux/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod_kfunc.h (revision 8e07e0e3964ca4e23ce7b68e2096fe660a888942)
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 prog_test_pass1 {
30 	int x0;
31 	struct {
32 		int x1;
33 		struct {
34 			int x2;
35 			struct {
36 				int x3;
37 			};
38 		};
39 	};
40 };
41 
42 struct prog_test_pass2 {
43 	int len;
44 	short arr1[4];
45 	struct {
46 		char arr2[4];
47 		unsigned long arr3[8];
48 	} x;
49 };
50 
51 struct prog_test_fail1 {
52 	void *p;
53 	int x;
54 };
55 
56 struct prog_test_fail2 {
57 	int x8;
58 	struct prog_test_pass1 x;
59 };
60 
61 struct prog_test_fail3 {
62 	int len;
63 	char arr1[2];
64 	char arr2[];
65 };
66 
67 struct prog_test_ref_kfunc *
68 bpf_kfunc_call_test_acquire(unsigned long *scalar_ptr) __ksym;
69 void bpf_kfunc_call_test_release(struct prog_test_ref_kfunc *p) __ksym;
70 void bpf_kfunc_call_test_ref(struct prog_test_ref_kfunc *p) __ksym;
71 
72 void bpf_kfunc_call_test_mem_len_pass1(void *mem, int len) __ksym;
73 int *bpf_kfunc_call_test_get_rdwr_mem(struct prog_test_ref_kfunc *p, const int rdwr_buf_size) __ksym;
74 int *bpf_kfunc_call_test_get_rdonly_mem(struct prog_test_ref_kfunc *p, const int rdonly_buf_size) __ksym;
75 int *bpf_kfunc_call_test_acq_rdonly_mem(struct prog_test_ref_kfunc *p, const int rdonly_buf_size) __ksym;
76 void bpf_kfunc_call_int_mem_release(int *p) __ksym;
77 
78 /* The bpf_kfunc_call_test_static_unused_arg is defined as static,
79  * but bpf program compilation needs to see it as global symbol.
80  */
81 #ifndef __KERNEL__
82 u32 bpf_kfunc_call_test_static_unused_arg(u32 arg, u32 unused) __ksym;
83 #endif
84 
85 void bpf_testmod_test_mod_kfunc(int i) __ksym;
86 
87 __u64 bpf_kfunc_call_test1(struct sock *sk, __u32 a, __u64 b,
88 				__u32 c, __u64 d) __ksym;
89 int bpf_kfunc_call_test2(struct sock *sk, __u32 a, __u32 b) __ksym;
90 struct sock *bpf_kfunc_call_test3(struct sock *sk) __ksym;
91 long bpf_kfunc_call_test4(signed char a, short b, int c, long d) __ksym;
92 
93 void bpf_kfunc_call_test_pass_ctx(struct __sk_buff *skb) __ksym;
94 void bpf_kfunc_call_test_pass1(struct prog_test_pass1 *p) __ksym;
95 void bpf_kfunc_call_test_pass2(struct prog_test_pass2 *p) __ksym;
96 void bpf_kfunc_call_test_mem_len_fail2(__u64 *mem, int len) __ksym;
97 
98 void bpf_kfunc_call_test_destructive(void) __ksym;
99 
100 void bpf_kfunc_call_test_offset(struct prog_test_ref_kfunc *p);
101 struct prog_test_member *bpf_kfunc_call_memb_acquire(void);
102 void bpf_kfunc_call_memb1_release(struct prog_test_member1 *p);
103 void bpf_kfunc_call_test_fail1(struct prog_test_fail1 *p);
104 void bpf_kfunc_call_test_fail2(struct prog_test_fail2 *p);
105 void bpf_kfunc_call_test_fail3(struct prog_test_fail3 *p);
106 void bpf_kfunc_call_test_mem_len_fail1(void *mem, int len);
107 
108 void bpf_kfunc_common_test(void) __ksym;
109 #endif /* _BPF_TESTMOD_KFUNC_H */
110