xref: /linux/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h (revision 12e896b9794bbd88f56aeac2a5807ae8d4bb5ad8)
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 int *bpf_kfunc_call_test_get_rdwr_mem(struct prog_test_ref_kfunc *p, const int rdwr_buf_size) __ksym;
102 int *bpf_kfunc_call_test_get_rdonly_mem(struct prog_test_ref_kfunc *p, const int rdonly_buf_size) __ksym;
103 int *bpf_kfunc_call_test_acq_rdonly_mem(struct prog_test_ref_kfunc *p, const int rdonly_buf_size) __ksym;
104 void bpf_kfunc_call_int_mem_release(int *p) __ksym;
105 
106 /* The bpf_kfunc_call_test_static_unused_arg is defined as static,
107  * but bpf program compilation needs to see it as global symbol.
108  */
109 #ifndef __KERNEL__
110 u32 bpf_kfunc_call_test_static_unused_arg(u32 arg, u32 unused) __ksym;
111 #endif
112 
113 void bpf_testmod_test_mod_kfunc(int i) __ksym;
114 
115 __u64 bpf_kfunc_call_test1(struct sock *sk, __u32 a, __u64 b,
116 				__u32 c, __u64 d) __ksym;
117 int bpf_kfunc_call_test2(struct sock *sk, __u32 a, __u32 b) __ksym;
118 struct sock *bpf_kfunc_call_test3(struct sock *sk) __ksym;
119 long bpf_kfunc_call_test4(signed char a, short b, int c, long d) __ksym;
120 int bpf_kfunc_call_test5(__u8 a, __u16 b, __u32 c) __ksym;
121 __u64 bpf_kfunc_call_stack_arg(__u64 a, __u64 b, __u64 c, __u64 d,
122 			       __u64 e, __u64 f, __u64 g, __u64 h) __ksym;
123 __u64 bpf_kfunc_call_stack_arg_ptr(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
124 				   struct prog_test_pass1 *p) __ksym;
125 __u64 bpf_kfunc_call_stack_arg_mix(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
126 				   struct prog_test_pass1 *p, __u64 f,
127 				   struct prog_test_pass1 *q) __ksym;
128 __u64 bpf_kfunc_call_stack_arg_dynptr(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
129 				      struct bpf_dynptr *ptr) __ksym;
130 __u64 bpf_kfunc_call_stack_arg_mem(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
131 				   void *mem, int mem__sz) __ksym;
132 __u64 bpf_kfunc_call_stack_arg_iter(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
133 				    struct bpf_iter_testmod_seq *it__iter) __ksym;
134 __u64 bpf_kfunc_call_stack_arg_const_str(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
135 					 const char *str__str) __ksym;
136 __u64 bpf_kfunc_call_stack_arg_timer(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
137 				     struct bpf_timer *timer) __ksym;
138 __u64 bpf_kfunc_call_stack_arg_big(__u64 a, __u64 b, __u64 c, __u64 d, __u64 e,
139 				   struct prog_test_big_arg s) __ksym;
140 
141 void bpf_kfunc_call_test_pass_ctx(struct __sk_buff *skb) __ksym;
142 void bpf_kfunc_call_test_pass1(struct prog_test_pass1 *p) __ksym;
143 void bpf_kfunc_call_test_pass2(struct prog_test_pass2 *p) __ksym;
144 void bpf_kfunc_call_test_mem_len_fail2(__u64 *mem, int len) __ksym;
145 
146 void bpf_kfunc_call_test_destructive(void) __ksym;
147 void bpf_kfunc_call_test_sleepable(void) __ksym;
148 int bpf_kfunc_call_test_call_rcu_tasks_trace(int *done) __ksym;
149 
150 void bpf_kfunc_call_test_offset(struct prog_test_ref_kfunc *p);
151 struct prog_test_member *bpf_kfunc_call_memb_acquire(void);
152 void bpf_kfunc_call_memb1_release(struct prog_test_member1 *p);
153 void bpf_kfunc_call_test_fail1(struct prog_test_fail1 *p);
154 void bpf_kfunc_call_test_fail2(struct prog_test_fail2 *p);
155 void bpf_kfunc_call_test_fail3(struct prog_test_fail3 *p);
156 void bpf_kfunc_call_test_mem_len_fail1(void *mem, int len);
157 
158 void bpf_kfunc_common_test(void) __ksym;
159 
160 int bpf_kfunc_init_sock(struct init_sock_args *args) __ksym;
161 void bpf_kfunc_close_sock(void) __ksym;
162 int bpf_kfunc_call_kernel_connect(struct addr_args *args) __ksym;
163 int bpf_kfunc_call_kernel_bind(struct addr_args *args) __ksym;
164 int bpf_kfunc_call_kernel_listen(void) __ksym;
165 int bpf_kfunc_call_kernel_sendmsg(struct sendmsg_args *args) __ksym;
166 int bpf_kfunc_call_sock_sendmsg(struct sendmsg_args *args) __ksym;
167 int bpf_kfunc_call_kernel_getsockname(struct addr_args *args) __ksym;
168 int bpf_kfunc_call_kernel_getpeername(struct addr_args *args) __ksym;
169 
170 void bpf_kfunc_dynptr_test(struct bpf_dynptr *ptr, struct bpf_dynptr *ptr__nullable) __ksym;
171 
172 struct bpf_testmod_ctx *bpf_testmod_ctx_create(int *err) __ksym;
173 void bpf_testmod_ctx_release(struct bpf_testmod_ctx *ctx) __ksym;
174 
175 struct sk_buff *bpf_kfunc_nested_acquire_nonzero_offset_test(struct sk_buff_head *ptr) __ksym;
176 struct sk_buff *bpf_kfunc_nested_acquire_zero_offset_test(struct sock_common *ptr) __ksym;
177 void bpf_kfunc_nested_release_test(struct sk_buff *ptr) __ksym;
178 
179 struct st_ops_args;
180 int bpf_kfunc_st_ops_test_prologue(struct st_ops_args *args) __ksym;
181 int bpf_kfunc_st_ops_test_epilogue(struct st_ops_args *args) __ksym;
182 int bpf_kfunc_st_ops_test_pro_epilogue(struct st_ops_args *args) __ksym;
183 int bpf_kfunc_st_ops_inc10(struct st_ops_args *args) __ksym;
184 
185 void bpf_kfunc_trusted_vma_test(struct vm_area_struct *ptr) __ksym;
186 void bpf_kfunc_trusted_task_test(struct task_struct *ptr) __ksym;
187 void bpf_kfunc_trusted_num_test(int *ptr) __ksym;
188 void bpf_kfunc_rcu_task_test(struct task_struct *ptr) __ksym;
189 struct task_struct *bpf_kfunc_ret_rcu_test(void) __ksym;
190 int *bpf_kfunc_ret_rcu_test_nostruct(int rdonly_buf_size) __ksym;
191 
192 #ifndef __KERNEL__
193 extern int bpf_kfunc_multi_st_ops_test_1(struct st_ops_args *args, u32 id) __weak __ksym;
194 extern int bpf_kfunc_multi_st_ops_test_1_assoc(struct st_ops_args *args) __weak __ksym;
195 #endif
196 
197 struct prog_test_member *bpf_kfunc_get_default_trusted_ptr_test(void) __ksym;
198 void bpf_kfunc_put_default_trusted_ptr_test(struct prog_test_member *trusted_ptr) __ksym;
199 
200 void bpf_testmod_test_hardirq_fn(void);
201 void bpf_testmod_test_softirq_fn(void);
202 void bpf_kfunc_trigger_ctx_check(void) __ksym;
203 
204 #endif /* _BPF_TESTMOD_KFUNC_H */
205