Commit | Line | Data |
---|---|---|
99c55f7d AS |
1 | /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com |
2 | * | |
3 | * This program is free software; you can redistribute it and/or | |
4 | * modify it under the terms of version 2 of the GNU General Public | |
5 | * License as published by the Free Software Foundation. | |
6 | */ | |
7 | #ifndef _LINUX_BPF_H | |
8 | #define _LINUX_BPF_H 1 | |
9 | ||
10 | #include <uapi/linux/bpf.h> | |
74451e66 | 11 | |
99c55f7d | 12 | #include <linux/workqueue.h> |
db20fd2b | 13 | #include <linux/file.h> |
b121d1e7 | 14 | #include <linux/percpu.h> |
002245cc | 15 | #include <linux/err.h> |
74451e66 | 16 | #include <linux/rbtree_latch.h> |
d6e1e46f | 17 | #include <linux/numa.h> |
ab3f0063 | 18 | #include <linux/wait.h> |
99c55f7d | 19 | |
3b1efb19 | 20 | struct perf_event; |
174a79ff | 21 | struct bpf_prog; |
99c55f7d AS |
22 | struct bpf_map; |
23 | ||
24 | /* map is generic key/value storage optionally accesible by eBPF programs */ | |
25 | struct bpf_map_ops { | |
26 | /* funcs callable from userspace (via syscall) */ | |
27 | struct bpf_map *(*map_alloc)(union bpf_attr *attr); | |
61d1b6a4 DB |
28 | void (*map_release)(struct bpf_map *map, struct file *map_file); |
29 | void (*map_free)(struct bpf_map *map); | |
db20fd2b AS |
30 | int (*map_get_next_key)(struct bpf_map *map, void *key, void *next_key); |
31 | ||
32 | /* funcs callable from userspace and from eBPF programs */ | |
33 | void *(*map_lookup_elem)(struct bpf_map *map, void *key); | |
3274f520 | 34 | int (*map_update_elem)(struct bpf_map *map, void *key, void *value, u64 flags); |
db20fd2b | 35 | int (*map_delete_elem)(struct bpf_map *map, void *key); |
2a36f0b9 WN |
36 | |
37 | /* funcs called by prog_array and perf_event_array map */ | |
d056a788 DB |
38 | void *(*map_fd_get_ptr)(struct bpf_map *map, struct file *map_file, |
39 | int fd); | |
40 | void (*map_fd_put_ptr)(void *ptr); | |
81ed18ab | 41 | u32 (*map_gen_lookup)(struct bpf_map *map, struct bpf_insn *insn_buf); |
14dc6f04 | 42 | u32 (*map_fd_sys_lookup_elem)(void *ptr); |
99c55f7d AS |
43 | }; |
44 | ||
45 | struct bpf_map { | |
46 | atomic_t refcnt; | |
47 | enum bpf_map_type map_type; | |
48 | u32 key_size; | |
49 | u32 value_size; | |
50 | u32 max_entries; | |
6c905981 | 51 | u32 map_flags; |
aaac3ba9 | 52 | u32 pages; |
f3f1c054 | 53 | u32 id; |
96eabe7a | 54 | int numa_node; |
aaac3ba9 | 55 | struct user_struct *user; |
a2c83fff | 56 | const struct bpf_map_ops *ops; |
99c55f7d | 57 | struct work_struct work; |
c9da161c | 58 | atomic_t usercnt; |
56f668df | 59 | struct bpf_map *inner_map_meta; |
067cae47 | 60 | char name[BPF_OBJ_NAME_LEN]; |
afdb09c7 CF |
61 | #ifdef CONFIG_SECURITY |
62 | void *security; | |
63 | #endif | |
99c55f7d AS |
64 | }; |
65 | ||
17a52670 AS |
66 | /* function argument constraints */ |
67 | enum bpf_arg_type { | |
80f1d68c | 68 | ARG_DONTCARE = 0, /* unused argument in helper function */ |
17a52670 AS |
69 | |
70 | /* the following constraints used to prototype | |
71 | * bpf_map_lookup/update/delete_elem() functions | |
72 | */ | |
73 | ARG_CONST_MAP_PTR, /* const argument used as pointer to bpf_map */ | |
74 | ARG_PTR_TO_MAP_KEY, /* pointer to stack used as map key */ | |
75 | ARG_PTR_TO_MAP_VALUE, /* pointer to stack used as map value */ | |
76 | ||
77 | /* the following constraints used to prototype bpf_memcmp() and other | |
78 | * functions that access data on eBPF program stack | |
79 | */ | |
39f19ebb | 80 | ARG_PTR_TO_MEM, /* pointer to valid memory (stack, packet, map value) */ |
db1ac496 | 81 | ARG_PTR_TO_MEM_OR_NULL, /* pointer to valid memory or NULL */ |
39f19ebb AS |
82 | ARG_PTR_TO_UNINIT_MEM, /* pointer to memory does not need to be initialized, |
83 | * helper function must fill all bytes or clear | |
84 | * them in error case. | |
435faee1 DB |
85 | */ |
86 | ||
39f19ebb AS |
87 | ARG_CONST_SIZE, /* number of bytes accessed from memory */ |
88 | ARG_CONST_SIZE_OR_ZERO, /* number of bytes accessed from memory or 0 */ | |
80f1d68c | 89 | |
608cd71a | 90 | ARG_PTR_TO_CTX, /* pointer to context */ |
80f1d68c | 91 | ARG_ANYTHING, /* any (initialized) argument is ok */ |
17a52670 AS |
92 | }; |
93 | ||
94 | /* type of values returned from helper functions */ | |
95 | enum bpf_return_type { | |
96 | RET_INTEGER, /* function returns integer */ | |
97 | RET_VOID, /* function doesn't return anything */ | |
98 | RET_PTR_TO_MAP_VALUE_OR_NULL, /* returns a pointer to map elem value or NULL */ | |
99 | }; | |
100 | ||
09756af4 AS |
101 | /* eBPF function prototype used by verifier to allow BPF_CALLs from eBPF programs |
102 | * to in-kernel helper functions and for adjusting imm32 field in BPF_CALL | |
103 | * instructions after verifying | |
104 | */ | |
105 | struct bpf_func_proto { | |
106 | u64 (*func)(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5); | |
107 | bool gpl_only; | |
36bbef52 | 108 | bool pkt_access; |
17a52670 AS |
109 | enum bpf_return_type ret_type; |
110 | enum bpf_arg_type arg1_type; | |
111 | enum bpf_arg_type arg2_type; | |
112 | enum bpf_arg_type arg3_type; | |
113 | enum bpf_arg_type arg4_type; | |
114 | enum bpf_arg_type arg5_type; | |
115 | }; | |
116 | ||
117 | /* bpf_context is intentionally undefined structure. Pointer to bpf_context is | |
118 | * the first argument to eBPF programs. | |
119 | * For socket filters: 'struct bpf_context *' == 'struct sk_buff *' | |
120 | */ | |
121 | struct bpf_context; | |
122 | ||
123 | enum bpf_access_type { | |
124 | BPF_READ = 1, | |
125 | BPF_WRITE = 2 | |
09756af4 AS |
126 | }; |
127 | ||
19de99f7 | 128 | /* types of values stored in eBPF registers */ |
f1174f77 EC |
129 | /* Pointer types represent: |
130 | * pointer | |
131 | * pointer + imm | |
132 | * pointer + (u16) var | |
133 | * pointer + (u16) var + imm | |
134 | * if (range > 0) then [ptr, ptr + range - off) is safe to access | |
135 | * if (id > 0) means that some 'var' was added | |
136 | * if (off > 0) means that 'imm' was added | |
137 | */ | |
19de99f7 AS |
138 | enum bpf_reg_type { |
139 | NOT_INIT = 0, /* nothing was written into register */ | |
f1174f77 | 140 | SCALAR_VALUE, /* reg doesn't contain a valid pointer */ |
19de99f7 AS |
141 | PTR_TO_CTX, /* reg points to bpf_context */ |
142 | CONST_PTR_TO_MAP, /* reg points to struct bpf_map */ | |
143 | PTR_TO_MAP_VALUE, /* reg points to map element value */ | |
144 | PTR_TO_MAP_VALUE_OR_NULL,/* points to map elem value or NULL */ | |
f1174f77 | 145 | PTR_TO_STACK, /* reg == frame_pointer + offset */ |
de8f3a83 | 146 | PTR_TO_PACKET_META, /* skb->data - meta_len */ |
f1174f77 | 147 | PTR_TO_PACKET, /* reg points to skb->data */ |
19de99f7 AS |
148 | PTR_TO_PACKET_END, /* skb->data + headlen */ |
149 | }; | |
150 | ||
23994631 YS |
151 | /* The information passed from prog-specific *_is_valid_access |
152 | * back to the verifier. | |
153 | */ | |
154 | struct bpf_insn_access_aux { | |
155 | enum bpf_reg_type reg_type; | |
156 | int ctx_field_size; | |
23994631 YS |
157 | }; |
158 | ||
f96da094 DB |
159 | static inline void |
160 | bpf_ctx_record_field_size(struct bpf_insn_access_aux *aux, u32 size) | |
161 | { | |
162 | aux->ctx_field_size = size; | |
163 | } | |
164 | ||
7de16e3a JK |
165 | struct bpf_prog_ops { |
166 | int (*test_run)(struct bpf_prog *prog, const union bpf_attr *kattr, | |
167 | union bpf_attr __user *uattr); | |
168 | }; | |
169 | ||
09756af4 AS |
170 | struct bpf_verifier_ops { |
171 | /* return eBPF function prototype for verification */ | |
172 | const struct bpf_func_proto *(*get_func_proto)(enum bpf_func_id func_id); | |
17a52670 AS |
173 | |
174 | /* return true if 'size' wide access at offset 'off' within bpf_context | |
175 | * with 'type' (read or write) is allowed | |
176 | */ | |
19de99f7 | 177 | bool (*is_valid_access)(int off, int size, enum bpf_access_type type, |
23994631 | 178 | struct bpf_insn_access_aux *info); |
36bbef52 DB |
179 | int (*gen_prologue)(struct bpf_insn *insn, bool direct_write, |
180 | const struct bpf_prog *prog); | |
6b8cc1d1 DB |
181 | u32 (*convert_ctx_access)(enum bpf_access_type type, |
182 | const struct bpf_insn *src, | |
183 | struct bpf_insn *dst, | |
f96da094 | 184 | struct bpf_prog *prog, u32 *target_size); |
09756af4 AS |
185 | }; |
186 | ||
ab3f0063 JK |
187 | struct bpf_dev_offload { |
188 | struct bpf_prog *prog; | |
189 | struct net_device *netdev; | |
190 | void *dev_priv; | |
191 | struct list_head offloads; | |
192 | bool dev_state; | |
193 | bool verifier_running; | |
194 | wait_queue_head_t verifier_done; | |
195 | }; | |
196 | ||
09756af4 AS |
197 | struct bpf_prog_aux { |
198 | atomic_t refcnt; | |
24701ece | 199 | u32 used_map_cnt; |
32bbe007 | 200 | u32 max_ctx_offset; |
8726679a | 201 | u32 stack_depth; |
dc4bb0e2 | 202 | u32 id; |
74451e66 DB |
203 | struct latch_tree_node ksym_tnode; |
204 | struct list_head ksym_lnode; | |
7de16e3a | 205 | const struct bpf_prog_ops *ops; |
09756af4 | 206 | struct bpf_map **used_maps; |
09756af4 | 207 | struct bpf_prog *prog; |
aaac3ba9 | 208 | struct user_struct *user; |
cb4d2b3f | 209 | u64 load_time; /* ns since boottime */ |
067cae47 | 210 | char name[BPF_OBJ_NAME_LEN]; |
afdb09c7 CF |
211 | #ifdef CONFIG_SECURITY |
212 | void *security; | |
213 | #endif | |
ab3f0063 | 214 | struct bpf_dev_offload *offload; |
abf2e7d6 AS |
215 | union { |
216 | struct work_struct work; | |
217 | struct rcu_head rcu; | |
218 | }; | |
09756af4 AS |
219 | }; |
220 | ||
04fd61ab AS |
221 | struct bpf_array { |
222 | struct bpf_map map; | |
223 | u32 elem_size; | |
224 | /* 'ownership' of prog_array is claimed by the first program that | |
225 | * is going to use this map or by the first program which FD is stored | |
226 | * in the map to make sure that all callers and callees have the same | |
227 | * prog_type and JITed flag | |
228 | */ | |
229 | enum bpf_prog_type owner_prog_type; | |
230 | bool owner_jited; | |
231 | union { | |
232 | char value[0] __aligned(8); | |
2a36f0b9 | 233 | void *ptrs[0] __aligned(8); |
a10423b8 | 234 | void __percpu *pptrs[0] __aligned(8); |
04fd61ab AS |
235 | }; |
236 | }; | |
3b1efb19 | 237 | |
04fd61ab AS |
238 | #define MAX_TAIL_CALL_CNT 32 |
239 | ||
3b1efb19 DB |
240 | struct bpf_event_entry { |
241 | struct perf_event *event; | |
242 | struct file *perf_file; | |
243 | struct file *map_file; | |
244 | struct rcu_head rcu; | |
245 | }; | |
246 | ||
04fd61ab | 247 | bool bpf_prog_array_compatible(struct bpf_array *array, const struct bpf_prog *fp); |
f1f7714e | 248 | int bpf_prog_calc_tag(struct bpf_prog *fp); |
bd570ff9 | 249 | |
0756ea3e | 250 | const struct bpf_func_proto *bpf_get_trace_printk_proto(void); |
555c8a86 DB |
251 | |
252 | typedef unsigned long (*bpf_ctx_copy_t)(void *dst, const void *src, | |
aa7145c1 | 253 | unsigned long off, unsigned long len); |
555c8a86 DB |
254 | |
255 | u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size, | |
256 | void *ctx, u64 ctx_size, bpf_ctx_copy_t ctx_copy); | |
04fd61ab | 257 | |
1cf1cae9 AS |
258 | int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr, |
259 | union bpf_attr __user *uattr); | |
260 | int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr, | |
261 | union bpf_attr __user *uattr); | |
262 | ||
324bda9e AS |
263 | /* an array of programs to be executed under rcu_lock. |
264 | * | |
265 | * Typical usage: | |
266 | * ret = BPF_PROG_RUN_ARRAY(&bpf_prog_array, ctx, BPF_PROG_RUN); | |
267 | * | |
268 | * the structure returned by bpf_prog_array_alloc() should be populated | |
269 | * with program pointers and the last pointer must be NULL. | |
270 | * The user has to keep refcnt on the program and make sure the program | |
271 | * is removed from the array before bpf_prog_put(). | |
272 | * The 'struct bpf_prog_array *' should only be replaced with xchg() | |
273 | * since other cpus are walking the array of pointers in parallel. | |
274 | */ | |
275 | struct bpf_prog_array { | |
276 | struct rcu_head rcu; | |
277 | struct bpf_prog *progs[0]; | |
278 | }; | |
279 | ||
280 | struct bpf_prog_array __rcu *bpf_prog_array_alloc(u32 prog_cnt, gfp_t flags); | |
281 | void bpf_prog_array_free(struct bpf_prog_array __rcu *progs); | |
468e2f64 AS |
282 | int bpf_prog_array_length(struct bpf_prog_array __rcu *progs); |
283 | int bpf_prog_array_copy_to_user(struct bpf_prog_array __rcu *progs, | |
284 | __u32 __user *prog_ids, u32 cnt); | |
324bda9e | 285 | |
e87c6bc3 YS |
286 | void bpf_prog_array_delete_safe(struct bpf_prog_array __rcu *progs, |
287 | struct bpf_prog *old_prog); | |
f371b304 YS |
288 | int bpf_prog_array_copy_info(struct bpf_prog_array __rcu *array, |
289 | __u32 __user *prog_ids, u32 request_cnt, | |
290 | __u32 __user *prog_cnt); | |
e87c6bc3 YS |
291 | int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array, |
292 | struct bpf_prog *exclude_prog, | |
293 | struct bpf_prog *include_prog, | |
294 | struct bpf_prog_array **new_array); | |
295 | ||
296 | #define __BPF_PROG_RUN_ARRAY(array, ctx, func, check_non_null) \ | |
324bda9e | 297 | ({ \ |
e87c6bc3 YS |
298 | struct bpf_prog **_prog, *__prog; \ |
299 | struct bpf_prog_array *_array; \ | |
324bda9e AS |
300 | u32 _ret = 1; \ |
301 | rcu_read_lock(); \ | |
e87c6bc3 YS |
302 | _array = rcu_dereference(array); \ |
303 | if (unlikely(check_non_null && !_array))\ | |
304 | goto _out; \ | |
305 | _prog = _array->progs; \ | |
306 | while ((__prog = READ_ONCE(*_prog))) { \ | |
307 | _ret &= func(__prog, ctx); \ | |
308 | _prog++; \ | |
309 | } \ | |
310 | _out: \ | |
324bda9e AS |
311 | rcu_read_unlock(); \ |
312 | _ret; \ | |
313 | }) | |
314 | ||
e87c6bc3 YS |
315 | #define BPF_PROG_RUN_ARRAY(array, ctx, func) \ |
316 | __BPF_PROG_RUN_ARRAY(array, ctx, func, false) | |
317 | ||
318 | #define BPF_PROG_RUN_ARRAY_CHECK(array, ctx, func) \ | |
319 | __BPF_PROG_RUN_ARRAY(array, ctx, func, true) | |
320 | ||
89aa0758 | 321 | #ifdef CONFIG_BPF_SYSCALL |
b121d1e7 AS |
322 | DECLARE_PER_CPU(int, bpf_prog_active); |
323 | ||
f66e448c CF |
324 | extern const struct file_operations bpf_map_fops; |
325 | extern const struct file_operations bpf_prog_fops; | |
326 | ||
7de16e3a JK |
327 | #define BPF_PROG_TYPE(_id, _name) \ |
328 | extern const struct bpf_prog_ops _name ## _prog_ops; \ | |
329 | extern const struct bpf_verifier_ops _name ## _verifier_ops; | |
40077e0c JB |
330 | #define BPF_MAP_TYPE(_id, _ops) \ |
331 | extern const struct bpf_map_ops _ops; | |
be9370a7 JB |
332 | #include <linux/bpf_types.h> |
333 | #undef BPF_PROG_TYPE | |
40077e0c | 334 | #undef BPF_MAP_TYPE |
0fc174de | 335 | |
ab3f0063 | 336 | extern const struct bpf_prog_ops bpf_offload_prog_ops; |
4f9218aa JK |
337 | extern const struct bpf_verifier_ops tc_cls_act_analyzer_ops; |
338 | extern const struct bpf_verifier_ops xdp_analyzer_ops; | |
339 | ||
0fc174de | 340 | struct bpf_prog *bpf_prog_get(u32 ufd); |
248f346f | 341 | struct bpf_prog *bpf_prog_get_type_dev(u32 ufd, enum bpf_prog_type type, |
288b3de5 | 342 | bool attach_drv); |
6d67942d | 343 | struct bpf_prog * __must_check bpf_prog_add(struct bpf_prog *prog, int i); |
c540594f | 344 | void bpf_prog_sub(struct bpf_prog *prog, int i); |
6d67942d | 345 | struct bpf_prog * __must_check bpf_prog_inc(struct bpf_prog *prog); |
a6f6df69 | 346 | struct bpf_prog * __must_check bpf_prog_inc_not_zero(struct bpf_prog *prog); |
61e021f3 | 347 | void bpf_prog_put(struct bpf_prog *prog); |
5ccb071e DB |
348 | int __bpf_prog_charge(struct user_struct *user, u32 pages); |
349 | void __bpf_prog_uncharge(struct user_struct *user, u32 pages); | |
61e021f3 | 350 | |
c9da161c | 351 | struct bpf_map *bpf_map_get_with_uref(u32 ufd); |
c2101297 | 352 | struct bpf_map *__bpf_map_get(struct fd f); |
6d67942d | 353 | struct bpf_map * __must_check bpf_map_inc(struct bpf_map *map, bool uref); |
c9da161c | 354 | void bpf_map_put_with_uref(struct bpf_map *map); |
61e021f3 | 355 | void bpf_map_put(struct bpf_map *map); |
6c905981 | 356 | int bpf_map_precharge_memlock(u32 pages); |
96eabe7a | 357 | void *bpf_map_area_alloc(size_t size, int numa_node); |
d407bd25 | 358 | void bpf_map_area_free(void *base); |
61e021f3 | 359 | |
1be7f75d AS |
360 | extern int sysctl_unprivileged_bpf_disabled; |
361 | ||
6e71b04a | 362 | int bpf_map_new_fd(struct bpf_map *map, int flags); |
b2197755 DB |
363 | int bpf_prog_new_fd(struct bpf_prog *prog); |
364 | ||
365 | int bpf_obj_pin_user(u32 ufd, const char __user *pathname); | |
6e71b04a | 366 | int bpf_obj_get_user(const char __user *pathname, int flags); |
b2197755 | 367 | |
15a07b33 AS |
368 | int bpf_percpu_hash_copy(struct bpf_map *map, void *key, void *value); |
369 | int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value); | |
370 | int bpf_percpu_hash_update(struct bpf_map *map, void *key, void *value, | |
371 | u64 flags); | |
372 | int bpf_percpu_array_update(struct bpf_map *map, void *key, void *value, | |
373 | u64 flags); | |
d056a788 | 374 | |
557c0c6e | 375 | int bpf_stackmap_copy(struct bpf_map *map, void *key, void *value); |
15a07b33 | 376 | |
d056a788 DB |
377 | int bpf_fd_array_map_update_elem(struct bpf_map *map, struct file *map_file, |
378 | void *key, void *value, u64 map_flags); | |
14dc6f04 | 379 | int bpf_fd_array_map_lookup_elem(struct bpf_map *map, void *key, u32 *value); |
d056a788 | 380 | void bpf_fd_array_map_clear(struct bpf_map *map); |
bcc6b1b7 MKL |
381 | int bpf_fd_htab_map_update_elem(struct bpf_map *map, struct file *map_file, |
382 | void *key, void *value, u64 map_flags); | |
14dc6f04 | 383 | int bpf_fd_htab_map_lookup_elem(struct bpf_map *map, void *key, u32 *value); |
d056a788 | 384 | |
6e71b04a CF |
385 | int bpf_get_file_flag(int flags); |
386 | ||
15a07b33 AS |
387 | /* memcpy that is used with 8-byte aligned pointers, power-of-8 size and |
388 | * forced to use 'long' read/writes to try to atomically copy long counters. | |
389 | * Best-effort only. No barriers here, since it _will_ race with concurrent | |
390 | * updates from BPF programs. Called from bpf syscall and mostly used with | |
391 | * size 8 or 16 bytes, so ask compiler to inline it. | |
392 | */ | |
393 | static inline void bpf_long_memcpy(void *dst, const void *src, u32 size) | |
394 | { | |
395 | const long *lsrc = src; | |
396 | long *ldst = dst; | |
397 | ||
398 | size /= sizeof(long); | |
399 | while (size--) | |
400 | *ldst++ = *lsrc++; | |
401 | } | |
402 | ||
61e021f3 | 403 | /* verify correctness of eBPF program */ |
9bac3d6d | 404 | int bpf_check(struct bpf_prog **fp, union bpf_attr *attr); |
1ea47e01 | 405 | void bpf_patch_call_args(struct bpf_insn *insn, u32 stack_depth); |
46f55cff JF |
406 | |
407 | /* Map specifics */ | |
408 | struct net_device *__dev_map_lookup_elem(struct bpf_map *map, u32 key); | |
409 | void __dev_map_insert_ctx(struct bpf_map *map, u32 index); | |
410 | void __dev_map_flush(struct bpf_map *map); | |
411 | ||
9c270af3 JDB |
412 | struct bpf_cpu_map_entry *__cpu_map_lookup_elem(struct bpf_map *map, u32 key); |
413 | void __cpu_map_insert_ctx(struct bpf_map *map, u32 index); | |
414 | void __cpu_map_flush(struct bpf_map *map); | |
415 | struct xdp_buff; | |
416 | int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_buff *xdp, | |
417 | struct net_device *dev_rx); | |
418 | ||
96eabe7a MKL |
419 | /* Return map's numa specified by userspace */ |
420 | static inline int bpf_map_attr_numa_node(const union bpf_attr *attr) | |
421 | { | |
422 | return (attr->map_flags & BPF_F_NUMA_NODE) ? | |
423 | attr->numa_node : NUMA_NO_NODE; | |
424 | } | |
425 | ||
9c270af3 | 426 | #else /* !CONFIG_BPF_SYSCALL */ |
0fc174de DB |
427 | static inline struct bpf_prog *bpf_prog_get(u32 ufd) |
428 | { | |
429 | return ERR_PTR(-EOPNOTSUPP); | |
430 | } | |
431 | ||
248f346f JK |
432 | static inline struct bpf_prog *bpf_prog_get_type_dev(u32 ufd, |
433 | enum bpf_prog_type type, | |
288b3de5 | 434 | bool attach_drv) |
248f346f JK |
435 | { |
436 | return ERR_PTR(-EOPNOTSUPP); | |
437 | } | |
438 | ||
6d67942d DB |
439 | static inline struct bpf_prog * __must_check bpf_prog_add(struct bpf_prog *prog, |
440 | int i) | |
cc2e0b3f BB |
441 | { |
442 | return ERR_PTR(-EOPNOTSUPP); | |
443 | } | |
113214be | 444 | |
c540594f DB |
445 | static inline void bpf_prog_sub(struct bpf_prog *prog, int i) |
446 | { | |
447 | } | |
448 | ||
0fc174de DB |
449 | static inline void bpf_prog_put(struct bpf_prog *prog) |
450 | { | |
451 | } | |
6d67942d DB |
452 | |
453 | static inline struct bpf_prog * __must_check bpf_prog_inc(struct bpf_prog *prog) | |
aa6a5f3c AS |
454 | { |
455 | return ERR_PTR(-EOPNOTSUPP); | |
456 | } | |
5ccb071e | 457 | |
a6f6df69 JF |
458 | static inline struct bpf_prog *__must_check |
459 | bpf_prog_inc_not_zero(struct bpf_prog *prog) | |
460 | { | |
461 | return ERR_PTR(-EOPNOTSUPP); | |
462 | } | |
463 | ||
5ccb071e DB |
464 | static inline int __bpf_prog_charge(struct user_struct *user, u32 pages) |
465 | { | |
466 | return 0; | |
467 | } | |
468 | ||
469 | static inline void __bpf_prog_uncharge(struct user_struct *user, u32 pages) | |
470 | { | |
471 | } | |
46f55cff | 472 | |
6e71b04a | 473 | static inline int bpf_obj_get_user(const char __user *pathname, int flags) |
98589a09 SL |
474 | { |
475 | return -EOPNOTSUPP; | |
476 | } | |
477 | ||
46f55cff JF |
478 | static inline struct net_device *__dev_map_lookup_elem(struct bpf_map *map, |
479 | u32 key) | |
480 | { | |
481 | return NULL; | |
482 | } | |
483 | ||
484 | static inline void __dev_map_insert_ctx(struct bpf_map *map, u32 index) | |
485 | { | |
486 | } | |
487 | ||
488 | static inline void __dev_map_flush(struct bpf_map *map) | |
489 | { | |
490 | } | |
9c270af3 JDB |
491 | |
492 | static inline | |
493 | struct bpf_cpu_map_entry *__cpu_map_lookup_elem(struct bpf_map *map, u32 key) | |
494 | { | |
495 | return NULL; | |
496 | } | |
497 | ||
498 | static inline void __cpu_map_insert_ctx(struct bpf_map *map, u32 index) | |
499 | { | |
500 | } | |
501 | ||
502 | static inline void __cpu_map_flush(struct bpf_map *map) | |
503 | { | |
504 | } | |
505 | ||
506 | struct xdp_buff; | |
507 | static inline int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu, | |
508 | struct xdp_buff *xdp, | |
509 | struct net_device *dev_rx) | |
510 | { | |
511 | return 0; | |
512 | } | |
61e021f3 | 513 | #endif /* CONFIG_BPF_SYSCALL */ |
09756af4 | 514 | |
479321e9 JK |
515 | static inline struct bpf_prog *bpf_prog_get_type(u32 ufd, |
516 | enum bpf_prog_type type) | |
517 | { | |
518 | return bpf_prog_get_type_dev(ufd, type, false); | |
519 | } | |
520 | ||
ab3f0063 JK |
521 | int bpf_prog_offload_compile(struct bpf_prog *prog); |
522 | void bpf_prog_offload_destroy(struct bpf_prog *prog); | |
523 | ||
524 | #if defined(CONFIG_NET) && defined(CONFIG_BPF_SYSCALL) | |
525 | int bpf_prog_offload_init(struct bpf_prog *prog, union bpf_attr *attr); | |
526 | ||
527 | static inline bool bpf_prog_is_dev_bound(struct bpf_prog_aux *aux) | |
528 | { | |
529 | return aux->offload; | |
530 | } | |
531 | #else | |
532 | static inline int bpf_prog_offload_init(struct bpf_prog *prog, | |
533 | union bpf_attr *attr) | |
534 | { | |
535 | return -EOPNOTSUPP; | |
536 | } | |
537 | ||
538 | static inline bool bpf_prog_is_dev_bound(struct bpf_prog_aux *aux) | |
539 | { | |
540 | return false; | |
541 | } | |
542 | #endif /* CONFIG_NET && CONFIG_BPF_SYSCALL */ | |
543 | ||
6bdc9c4c JF |
544 | #if defined(CONFIG_STREAM_PARSER) && defined(CONFIG_BPF_SYSCALL) |
545 | struct sock *__sock_map_lookup_elem(struct bpf_map *map, u32 key); | |
5a67da2a | 546 | int sock_map_prog(struct bpf_map *map, struct bpf_prog *prog, u32 type); |
6bdc9c4c JF |
547 | #else |
548 | static inline struct sock *__sock_map_lookup_elem(struct bpf_map *map, u32 key) | |
549 | { | |
550 | return NULL; | |
551 | } | |
464bc0fd | 552 | |
5a67da2a JF |
553 | static inline int sock_map_prog(struct bpf_map *map, |
554 | struct bpf_prog *prog, | |
555 | u32 type) | |
464bc0fd JF |
556 | { |
557 | return -EOPNOTSUPP; | |
558 | } | |
6bdc9c4c JF |
559 | #endif |
560 | ||
d0003ec0 | 561 | /* verifier prototypes for helper functions called from eBPF programs */ |
a2c83fff DB |
562 | extern const struct bpf_func_proto bpf_map_lookup_elem_proto; |
563 | extern const struct bpf_func_proto bpf_map_update_elem_proto; | |
564 | extern const struct bpf_func_proto bpf_map_delete_elem_proto; | |
d0003ec0 | 565 | |
03e69b50 | 566 | extern const struct bpf_func_proto bpf_get_prandom_u32_proto; |
c04167ce | 567 | extern const struct bpf_func_proto bpf_get_smp_processor_id_proto; |
2d0e30c3 | 568 | extern const struct bpf_func_proto bpf_get_numa_node_id_proto; |
04fd61ab | 569 | extern const struct bpf_func_proto bpf_tail_call_proto; |
17ca8cbf | 570 | extern const struct bpf_func_proto bpf_ktime_get_ns_proto; |
ffeedafb AS |
571 | extern const struct bpf_func_proto bpf_get_current_pid_tgid_proto; |
572 | extern const struct bpf_func_proto bpf_get_current_uid_gid_proto; | |
573 | extern const struct bpf_func_proto bpf_get_current_comm_proto; | |
4e10df9a AS |
574 | extern const struct bpf_func_proto bpf_skb_vlan_push_proto; |
575 | extern const struct bpf_func_proto bpf_skb_vlan_pop_proto; | |
d5a3b1f6 | 576 | extern const struct bpf_func_proto bpf_get_stackid_proto; |
174a79ff | 577 | extern const struct bpf_func_proto bpf_sock_map_update_proto; |
03e69b50 | 578 | |
3ad00405 DB |
579 | /* Shared helpers among cBPF and eBPF. */ |
580 | void bpf_user_rnd_init_once(void); | |
581 | u64 bpf_user_rnd_u32(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5); | |
582 | ||
92ace999 JB |
583 | #if defined(__KERNEL__) && !defined(__ASSEMBLY__) |
584 | #ifdef CONFIG_BPF_KPROBE_OVERRIDE | |
585 | #define BPF_ALLOW_ERROR_INJECTION(fname) \ | |
586 | static unsigned long __used \ | |
587 | __attribute__((__section__("_kprobe_error_inject_list"))) \ | |
588 | _eil_addr_##fname = (unsigned long)fname; | |
589 | #else | |
590 | #define BPF_ALLOW_ERROR_INJECTION(fname) | |
591 | #endif | |
592 | #endif | |
593 | ||
99c55f7d | 594 | #endif /* _LINUX_BPF_H */ |