1
2
3
4#ifndef _LINUX_BPF_H
5#define _LINUX_BPF_H 1
6
7#include <uapi/linux/bpf.h>
8
9#include <linux/workqueue.h>
10#include <linux/file.h>
11#include <linux/percpu.h>
12#include <linux/err.h>
13#include <linux/rbtree_latch.h>
14#include <linux/numa.h>
15#include <linux/mm_types.h>
16#include <linux/wait.h>
17#include <linux/u64_stats_sync.h>
18#include <linux/refcount.h>
19#include <linux/mutex.h>
20#include <linux/module.h>
21#include <linux/kallsyms.h>
22#include <linux/capability.h>
23#include <linux/sched/mm.h>
24#include <linux/slab.h>
25#include <linux/percpu-refcount.h>
26
27struct bpf_verifier_env;
28struct bpf_verifier_log;
29struct perf_event;
30struct bpf_prog;
31struct bpf_prog_aux;
32struct bpf_map;
33struct sock;
34struct seq_file;
35struct btf;
36struct btf_type;
37struct exception_table_entry;
38struct seq_operations;
39struct bpf_iter_aux_info;
40struct bpf_local_storage;
41struct bpf_local_storage_map;
42struct kobject;
43struct mem_cgroup;
44
45extern struct idr btf_idr;
46extern spinlock_t btf_idr_lock;
47extern struct kobject *btf_kobj;
48
49typedef int (*bpf_iter_init_seq_priv_t)(void *private_data,
50 struct bpf_iter_aux_info *aux);
51typedef void (*bpf_iter_fini_seq_priv_t)(void *private_data);
52struct bpf_iter_seq_info {
53 const struct seq_operations *seq_ops;
54 bpf_iter_init_seq_priv_t init_seq_private;
55 bpf_iter_fini_seq_priv_t fini_seq_private;
56 u32 seq_priv_size;
57};
58
59
60struct bpf_map_ops {
61
62 int (*map_alloc_check)(union bpf_attr *attr);
63 struct bpf_map *(*map_alloc)(union bpf_attr *attr);
64 void (*map_release)(struct bpf_map *map, struct file *map_file);
65 void (*map_free)(struct bpf_map *map);
66 int (*map_get_next_key)(struct bpf_map *map, void *key, void *next_key);
67 void (*map_release_uref)(struct bpf_map *map);
68 RH_KABI_BROKEN_INSERT(void *(*map_lookup_elem_sys_only)(struct bpf_map *map, void *key))
69 RH_KABI_BROKEN_INSERT(int (*map_lookup_batch)(struct bpf_map *map, const union bpf_attr *attr, union bpf_attr __user *uattr))
70 RH_KABI_BROKEN_INSERT(int (*map_lookup_and_delete_batch)(struct bpf_map *map, const union bpf_attr *attr, union bpf_attr __user *uattr))
71 RH_KABI_BROKEN_INSERT(int (*map_update_batch)(struct bpf_map *map, const union bpf_attr *attr, union bpf_attr __user *uattr))
72 RH_KABI_BROKEN_INSERT(int (*map_delete_batch)(struct bpf_map *map, const union bpf_attr *attr, union bpf_attr __user *uattr))
73
74
75 void *(*map_lookup_elem)(struct bpf_map *map, void *key);
76 int (*map_update_elem)(struct bpf_map *map, void *key, void *value, u64 flags);
77 int (*map_delete_elem)(struct bpf_map *map, void *key);
78
79 RH_KABI_BROKEN_INSERT_BLOCK(
80 int (*map_push_elem)(struct bpf_map *map, void *value, u64 flags);
81 int (*map_pop_elem)(struct bpf_map *map, void *value);
82 int (*map_peek_elem)(struct bpf_map *map, void *value);
83 )
84
85
86 void *(*map_fd_get_ptr)(struct bpf_map *map, struct file *map_file,
87 int fd);
88 void (*map_fd_put_ptr)(void *ptr);
89 RH_KABI_BROKEN_REPLACE(
90 u32 (*map_gen_lookup)(struct bpf_map *map, struct bpf_insn *insn_buf),
91 int (*map_gen_lookup)(struct bpf_map *map, struct bpf_insn *insn_buf)
92 )
93 u32 (*map_fd_sys_lookup_elem)(void *ptr);
94 void (*map_seq_show_elem)(struct bpf_map *map, void *key,
95 struct seq_file *m);
96 RH_KABI_BROKEN_REMOVE(int (*map_check_btf)(const struct bpf_map *map, const struct btf *btf,
97 u32 key_type_id, u32 value_type_id))
98 RH_KABI_BROKEN_INSERT_BLOCK(
99 int (*map_check_btf)(const struct bpf_map *map,
100 const struct btf *btf,
101 const struct btf_type *key_type,
102 const struct btf_type *value_type);
103
104
105 int (*map_poke_track)(struct bpf_map *map, struct bpf_prog_aux *aux);
106 void (*map_poke_untrack)(struct bpf_map *map, struct bpf_prog_aux *aux);
107 void (*map_poke_run)(struct bpf_map *map, u32 key, struct bpf_prog *old,
108 struct bpf_prog *new);
109
110
111 int (*map_direct_value_addr)(const struct bpf_map *map,
112 u64 *imm, u32 off);
113 int (*map_direct_value_meta)(const struct bpf_map *map,
114 u64 imm, u32 *off);
115 int (*map_mmap)(struct bpf_map *map, struct vm_area_struct *vma);
116 __poll_t (*map_poll)(struct bpf_map *map, struct file *filp,
117 struct poll_table_struct *pts);
118
119
120 int (*map_local_storage_charge)(struct bpf_local_storage_map *smap,
121 void *owner, u32 size);
122 void (*map_local_storage_uncharge)(struct bpf_local_storage_map *smap,
123 void *owner, u32 size);
124 struct bpf_local_storage __rcu ** (*map_owner_storage_ptr)(void *owner);
125
126
127
128
129
130
131
132
133
134
135 bool (*map_meta_equal)(const struct bpf_map *meta0,
136 const struct bpf_map *meta1);
137
138
139 const char * const map_btf_name;
140 int *map_btf_id;
141
142 const struct bpf_iter_seq_info *iter_seq_info;
143 )
144};
145
146struct bpf_map {
147
148
149
150 const struct bpf_map_ops *ops ____cacheline_aligned;
151 struct bpf_map *inner_map_meta;
152#ifdef CONFIG_SECURITY
153 void *security;
154#endif
155 enum bpf_map_type map_type;
156 u32 key_size;
157 u32 value_size;
158 u32 max_entries;
159 u32 map_flags;
160 RH_KABI_BROKEN_REMOVE(u32 pages)
161 RH_KABI_BROKEN_INSERT(int spin_lock_off)
162 u32 id;
163 int numa_node;
164 u32 btf_key_type_id;
165 u32 btf_value_type_id;
166 struct btf *btf;
167#ifdef CONFIG_MEMCG_KMEM
168 RH_KABI_BROKEN_INSERT(struct mem_cgroup *memcg)
169#endif
170 RH_KABI_BROKEN_INSERT(char name[BPF_OBJ_NAME_LEN])
171 RH_KABI_BROKEN_INSERT(u32 btf_vmlinux_value_type_id)
172 RH_KABI_REPLACE(bool unpriv_array, bool bypass_spec_v1)
173 RH_KABI_FILL_HOLE(bool frozen)
174
175
176
177
178
179 RH_KABI_BROKEN_REMOVE_BLOCK(
180 struct user_struct *user ____cacheline_aligned;
181 atomic_t refcnt;
182 )
183 RH_KABI_BROKEN_INSERT(atomic64_t refcnt ____cacheline_aligned)
184 RH_KABI_BROKEN_REPLACE(atomic_t usercnt, atomic64_t usercnt)
185 struct work_struct work;
186 RH_KABI_BROKEN_REMOVE(char name[BPF_OBJ_NAME_LEN])
187 RH_KABI_BROKEN_INSERT(struct mutex freeze_mutex)
188 RH_KABI_BROKEN_INSERT(u64 writecnt)
189};
190
191static inline bool map_value_has_spin_lock(const struct bpf_map *map)
192{
193 return map->spin_lock_off >= 0;
194}
195
196static inline void check_and_init_map_lock(struct bpf_map *map, void *dst)
197{
198 if (likely(!map_value_has_spin_lock(map)))
199 return;
200 *(struct bpf_spin_lock *)(dst + map->spin_lock_off) =
201 (struct bpf_spin_lock){};
202}
203
204
205static inline void copy_map_value(struct bpf_map *map, void *dst, void *src)
206{
207 if (unlikely(map_value_has_spin_lock(map))) {
208 u32 off = map->spin_lock_off;
209
210 memcpy(dst, src, off);
211 memcpy(dst + off + sizeof(struct bpf_spin_lock),
212 src + off + sizeof(struct bpf_spin_lock),
213 map->value_size - off - sizeof(struct bpf_spin_lock));
214 } else {
215 memcpy(dst, src, map->value_size);
216 }
217}
218void copy_map_value_locked(struct bpf_map *map, void *dst, void *src,
219 bool lock_src);
220int bpf_obj_name_cpy(char *dst, const char *src, unsigned int size);
221
222struct bpf_offload_dev;
223struct bpf_offloaded_map;
224
225struct bpf_map_dev_ops {
226 int (*map_get_next_key)(struct bpf_offloaded_map *map,
227 void *key, void *next_key);
228 int (*map_lookup_elem)(struct bpf_offloaded_map *map,
229 void *key, void *value);
230 int (*map_update_elem)(struct bpf_offloaded_map *map,
231 void *key, void *value, u64 flags);
232 int (*map_delete_elem)(struct bpf_offloaded_map *map, void *key);
233};
234
235struct bpf_offloaded_map {
236 struct bpf_map map;
237 struct net_device *netdev;
238 const struct bpf_map_dev_ops *dev_ops;
239 void *dev_priv;
240 struct list_head offloads;
241};
242
243static inline struct bpf_offloaded_map *map_to_offmap(struct bpf_map *map)
244{
245 return container_of(map, struct bpf_offloaded_map, map);
246}
247
248static inline bool bpf_map_offload_neutral(const struct bpf_map *map)
249{
250 return map->map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY;
251}
252
253static inline bool bpf_map_support_seq_show(const struct bpf_map *map)
254{
255 return (map->btf_value_type_id || map->btf_vmlinux_value_type_id) &&
256 map->ops->map_seq_show_elem;
257}
258
259int map_check_no_btf(const struct bpf_map *map,
260 const struct btf *btf,
261 const struct btf_type *key_type,
262 const struct btf_type *value_type);
263
264bool bpf_map_meta_equal(const struct bpf_map *meta0,
265 const struct bpf_map *meta1);
266
267extern const struct bpf_map_ops bpf_map_offload_ops;
268
269
270enum bpf_arg_type {
271 ARG_DONTCARE = 0,
272
273
274
275
276 ARG_CONST_MAP_PTR,
277 ARG_PTR_TO_MAP_KEY,
278 ARG_PTR_TO_MAP_VALUE,
279 ARG_PTR_TO_UNINIT_MAP_VALUE,
280 ARG_PTR_TO_MAP_VALUE_OR_NULL,
281
282
283
284
285 ARG_PTR_TO_MEM,
286 ARG_PTR_TO_MEM_OR_NULL,
287 ARG_PTR_TO_UNINIT_MEM,
288
289
290
291
292 ARG_CONST_SIZE,
293 ARG_CONST_SIZE_OR_ZERO,
294
295 ARG_PTR_TO_CTX,
296 ARG_PTR_TO_CTX_OR_NULL,
297 ARG_ANYTHING,
298 ARG_PTR_TO_SPIN_LOCK,
299 ARG_PTR_TO_SOCK_COMMON,
300 ARG_PTR_TO_INT,
301 ARG_PTR_TO_LONG,
302 ARG_PTR_TO_SOCKET,
303 ARG_PTR_TO_SOCKET_OR_NULL,
304 ARG_PTR_TO_BTF_ID,
305 ARG_PTR_TO_ALLOC_MEM,
306 ARG_PTR_TO_ALLOC_MEM_OR_NULL,
307 ARG_CONST_ALLOC_SIZE_OR_ZERO,
308 ARG_PTR_TO_BTF_ID_SOCK_COMMON,
309 ARG_PTR_TO_PERCPU_BTF_ID,
310 __BPF_ARG_TYPE_MAX,
311};
312
313
314enum bpf_return_type {
315 RET_INTEGER,
316 RET_VOID,
317 RET_PTR_TO_MAP_VALUE,
318 RET_PTR_TO_MAP_VALUE_OR_NULL,
319 RET_PTR_TO_SOCKET_OR_NULL,
320 RET_PTR_TO_TCP_SOCK_OR_NULL,
321 RET_PTR_TO_SOCK_COMMON_OR_NULL,
322 RET_PTR_TO_ALLOC_MEM_OR_NULL,
323 RET_PTR_TO_BTF_ID_OR_NULL,
324 RET_PTR_TO_MEM_OR_BTF_ID_OR_NULL,
325 RET_PTR_TO_MEM_OR_BTF_ID,
326 RET_PTR_TO_BTF_ID,
327};
328
329
330
331
332
333struct bpf_func_proto {
334 u64 (*func)(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
335 bool gpl_only;
336 bool pkt_access;
337 enum bpf_return_type ret_type;
338 union {
339 struct {
340 enum bpf_arg_type arg1_type;
341 enum bpf_arg_type arg2_type;
342 enum bpf_arg_type arg3_type;
343 enum bpf_arg_type arg4_type;
344 enum bpf_arg_type arg5_type;
345 };
346 enum bpf_arg_type arg_type[5];
347 };
348 union {
349 struct {
350 u32 *arg1_btf_id;
351 u32 *arg2_btf_id;
352 u32 *arg3_btf_id;
353 u32 *arg4_btf_id;
354 u32 *arg5_btf_id;
355 };
356 u32 *arg_btf_id[5];
357 };
358 int *ret_btf_id;
359 bool (*allowed)(const struct bpf_prog *prog);
360};
361
362
363
364
365
366struct bpf_context;
367
368enum bpf_access_type {
369 BPF_READ = 1,
370 BPF_WRITE = 2
371};
372
373
374
375
376
377
378
379
380
381
382
383enum bpf_reg_type {
384 NOT_INIT = 0,
385 SCALAR_VALUE,
386 PTR_TO_CTX,
387 CONST_PTR_TO_MAP,
388 PTR_TO_MAP_VALUE,
389 PTR_TO_MAP_VALUE_OR_NULL,
390 PTR_TO_STACK,
391 PTR_TO_PACKET_META,
392 PTR_TO_PACKET,
393 PTR_TO_PACKET_END,
394 PTR_TO_FLOW_KEYS,
395 PTR_TO_SOCKET,
396 PTR_TO_SOCKET_OR_NULL,
397 PTR_TO_SOCK_COMMON,
398 PTR_TO_SOCK_COMMON_OR_NULL,
399 PTR_TO_TCP_SOCK,
400 PTR_TO_TCP_SOCK_OR_NULL,
401 PTR_TO_TP_BUFFER,
402 PTR_TO_XDP_SOCK,
403
404
405
406
407
408
409
410
411
412
413 PTR_TO_BTF_ID,
414
415
416
417
418 PTR_TO_BTF_ID_OR_NULL,
419 PTR_TO_MEM,
420 PTR_TO_MEM_OR_NULL,
421 PTR_TO_RDONLY_BUF,
422 PTR_TO_RDONLY_BUF_OR_NULL,
423 PTR_TO_RDWR_BUF,
424 PTR_TO_RDWR_BUF_OR_NULL,
425 PTR_TO_PERCPU_BTF_ID,
426};
427
428
429
430
431struct bpf_insn_access_aux {
432 enum bpf_reg_type reg_type;
433 union {
434 int ctx_field_size;
435 struct {
436 struct btf *btf;
437 u32 btf_id;
438 };
439 };
440 struct bpf_verifier_log *log;
441};
442
443static inline void
444bpf_ctx_record_field_size(struct bpf_insn_access_aux *aux, u32 size)
445{
446 aux->ctx_field_size = size;
447}
448
449struct bpf_prog_ops {
450 int (*test_run)(struct bpf_prog *prog, const union bpf_attr *kattr,
451 union bpf_attr __user *uattr);
452};
453
454struct bpf_verifier_ops {
455
456 const struct bpf_func_proto *
457 (*get_func_proto)(enum bpf_func_id func_id,
458 const struct bpf_prog *prog);
459
460
461
462
463 bool (*is_valid_access)(int off, int size, enum bpf_access_type type,
464 const struct bpf_prog *prog,
465 struct bpf_insn_access_aux *info);
466 int (*gen_prologue)(struct bpf_insn *insn, bool direct_write,
467 const struct bpf_prog *prog);
468 int (*gen_ld_abs)(const struct bpf_insn *orig,
469 struct bpf_insn *insn_buf);
470 u32 (*convert_ctx_access)(enum bpf_access_type type,
471 const struct bpf_insn *src,
472 struct bpf_insn *dst,
473 struct bpf_prog *prog, u32 *target_size);
474 int (*btf_struct_access)(struct bpf_verifier_log *log,
475 const struct btf *btf,
476 const struct btf_type *t, int off, int size,
477 enum bpf_access_type atype,
478 u32 *next_btf_id);
479};
480
481struct bpf_prog_offload_ops {
482
483 int (*insn_hook)(struct bpf_verifier_env *env,
484 int insn_idx, int prev_insn_idx);
485 RH_KABI_BROKEN_INSERT_BLOCK(
486 int (*finalize)(struct bpf_verifier_env *env);
487
488 int (*replace_insn)(struct bpf_verifier_env *env, u32 off,
489 struct bpf_insn *insn);
490 int (*remove_insns)(struct bpf_verifier_env *env, u32 off, u32 cnt);
491
492 int (*prepare)(struct bpf_prog *prog);
493 int (*translate)(struct bpf_prog *prog);
494 void (*destroy)(struct bpf_prog *prog);
495 )
496};
497
498struct bpf_prog_offload {
499 struct bpf_prog *prog;
500 struct net_device *netdev;
501 RH_KABI_BROKEN_INSERT(struct bpf_offload_dev *offdev)
502 void *dev_priv;
503 struct list_head offloads;
504 bool dev_state;
505 RH_KABI_BROKEN_INSERT(bool opt_failed)
506 RH_KABI_BROKEN_REMOVE(const struct bpf_prog_offload_ops *dev_ops)
507 void *jited_image;
508 u32 jited_len;
509};
510
511enum bpf_cgroup_storage_type {
512 BPF_CGROUP_STORAGE_SHARED,
513 BPF_CGROUP_STORAGE_PERCPU,
514 __BPF_CGROUP_STORAGE_MAX
515};
516
517#define MAX_BPF_CGROUP_STORAGE_TYPE __BPF_CGROUP_STORAGE_MAX
518
519
520
521
522#define MAX_BPF_FUNC_ARGS 12
523
524struct bpf_prog_stats {
525 u64 cnt;
526 u64 nsecs;
527 struct u64_stats_sync syncp;
528} __aligned(2 * sizeof(u64));
529
530struct btf_func_model {
531 u8 ret_size;
532 u8 nr_args;
533 u8 arg_size[MAX_BPF_FUNC_ARGS];
534};
535
536
537
538
539
540#define BPF_TRAMP_F_RESTORE_REGS BIT(0)
541
542
543
544#define BPF_TRAMP_F_CALL_ORIG BIT(1)
545
546
547
548#define BPF_TRAMP_F_SKIP_FRAME BIT(2)
549
550
551
552
553#define BPF_MAX_TRAMP_PROGS 40
554
555struct bpf_tramp_progs {
556 struct bpf_prog *progs[BPF_MAX_TRAMP_PROGS];
557 int nr_progs;
558};
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580struct bpf_tramp_image;
581int arch_prepare_bpf_trampoline(struct bpf_tramp_image *tr, void *image, void *image_end,
582 const struct btf_func_model *m, u32 flags,
583 struct bpf_tramp_progs *tprogs,
584 void *orig_call);
585
586u64 notrace __bpf_prog_enter(void);
587void notrace __bpf_prog_exit(struct bpf_prog *prog, u64 start);
588void notrace __bpf_prog_enter_sleepable(void);
589void notrace __bpf_prog_exit_sleepable(void);
590void notrace __bpf_tramp_enter(struct bpf_tramp_image *tr);
591void notrace __bpf_tramp_exit(struct bpf_tramp_image *tr);
592
593struct bpf_ksym {
594 unsigned long start;
595 unsigned long end;
596 char name[KSYM_NAME_LEN];
597 struct list_head lnode;
598 struct latch_tree_node tnode;
599 bool prog;
600};
601
602enum bpf_tramp_prog_type {
603 BPF_TRAMP_FENTRY,
604 BPF_TRAMP_FEXIT,
605 BPF_TRAMP_MODIFY_RETURN,
606 BPF_TRAMP_MAX,
607 BPF_TRAMP_REPLACE,
608};
609
610struct bpf_tramp_image {
611 void *image;
612 struct bpf_ksym ksym;
613 struct percpu_ref pcref;
614 void *ip_after_call;
615 void *ip_epilogue;
616 union {
617 struct rcu_head rcu;
618 struct work_struct work;
619 };
620};
621
622struct bpf_trampoline {
623
624 struct hlist_node hlist;
625
626 struct mutex mutex;
627 refcount_t refcnt;
628 u64 key;
629 struct {
630 struct btf_func_model model;
631 void *addr;
632 bool ftrace_managed;
633 } func;
634
635
636
637
638 struct bpf_prog *extension_prog;
639
640 struct hlist_head progs_hlist[BPF_TRAMP_MAX];
641
642 int progs_cnt[BPF_TRAMP_MAX];
643
644 struct bpf_tramp_image *cur_image;
645 u64 selector;
646};
647
648struct bpf_attach_target_info {
649 struct btf_func_model fmodel;
650 long tgt_addr;
651 const char *tgt_name;
652 const struct btf_type *tgt_type;
653};
654
655#define BPF_DISPATCHER_MAX 48
656
657struct bpf_dispatcher_prog {
658 struct bpf_prog *prog;
659 refcount_t users;
660};
661
662struct bpf_dispatcher {
663
664 struct mutex mutex;
665 void *func;
666 struct bpf_dispatcher_prog progs[BPF_DISPATCHER_MAX];
667 int num_progs;
668 void *image;
669 u32 image_off;
670 struct bpf_ksym ksym;
671};
672
673static __always_inline unsigned int bpf_dispatcher_nop_func(
674 const void *ctx,
675 const struct bpf_insn *insnsi,
676 unsigned int (*bpf_func)(const void *,
677 const struct bpf_insn *))
678{
679 return bpf_func(ctx, insnsi);
680}
681#ifdef CONFIG_BPF_JIT
682int bpf_trampoline_link_prog(struct bpf_prog *prog, struct bpf_trampoline *tr);
683int bpf_trampoline_unlink_prog(struct bpf_prog *prog, struct bpf_trampoline *tr);
684struct bpf_trampoline *bpf_trampoline_get(u64 key,
685 struct bpf_attach_target_info *tgt_info);
686void bpf_trampoline_put(struct bpf_trampoline *tr);
687#define BPF_DISPATCHER_INIT(_name) { \
688 .mutex = __MUTEX_INITIALIZER(_name.mutex), \
689 .func = &_name##_func, \
690 .progs = {}, \
691 .num_progs = 0, \
692 .image = NULL, \
693 .image_off = 0, \
694 .ksym = { \
695 .name = #_name, \
696 .lnode = LIST_HEAD_INIT(_name.ksym.lnode), \
697 }, \
698}
699
700#define DEFINE_BPF_DISPATCHER(name) \
701 noinline unsigned int bpf_dispatcher_##name##_func( \
702 const void *ctx, \
703 const struct bpf_insn *insnsi, \
704 unsigned int (*bpf_func)(const void *, \
705 const struct bpf_insn *)) \
706 { \
707 return bpf_func(ctx, insnsi); \
708 } \
709 EXPORT_SYMBOL(bpf_dispatcher_##name##_func); \
710 struct bpf_dispatcher bpf_dispatcher_##name = \
711 BPF_DISPATCHER_INIT(bpf_dispatcher_##name);
712#define DECLARE_BPF_DISPATCHER(name) \
713 unsigned int bpf_dispatcher_##name##_func( \
714 const void *ctx, \
715 const struct bpf_insn *insnsi, \
716 unsigned int (*bpf_func)(const void *, \
717 const struct bpf_insn *)); \
718 extern struct bpf_dispatcher bpf_dispatcher_##name;
719#define BPF_DISPATCHER_FUNC(name) bpf_dispatcher_##name##_func
720#define BPF_DISPATCHER_PTR(name) (&bpf_dispatcher_##name)
721void bpf_dispatcher_change_prog(struct bpf_dispatcher *d, struct bpf_prog *from,
722 struct bpf_prog *to);
723
724void *bpf_jit_alloc_exec_page(void);
725void bpf_image_ksym_add(void *data, struct bpf_ksym *ksym);
726void bpf_image_ksym_del(struct bpf_ksym *ksym);
727void bpf_ksym_add(struct bpf_ksym *ksym);
728void bpf_ksym_del(struct bpf_ksym *ksym);
729int bpf_jit_charge_modmem(u32 pages);
730void bpf_jit_uncharge_modmem(u32 pages);
731#else
732static inline int bpf_trampoline_link_prog(struct bpf_prog *prog,
733 struct bpf_trampoline *tr)
734{
735 return -ENOTSUPP;
736}
737static inline int bpf_trampoline_unlink_prog(struct bpf_prog *prog,
738 struct bpf_trampoline *tr)
739{
740 return -ENOTSUPP;
741}
742static inline struct bpf_trampoline *bpf_trampoline_get(u64 key,
743 struct bpf_attach_target_info *tgt_info)
744{
745 return ERR_PTR(-EOPNOTSUPP);
746}
747static inline void bpf_trampoline_put(struct bpf_trampoline *tr) {}
748#define DEFINE_BPF_DISPATCHER(name)
749#define DECLARE_BPF_DISPATCHER(name)
750#define BPF_DISPATCHER_FUNC(name) bpf_dispatcher_nop_func
751#define BPF_DISPATCHER_PTR(name) NULL
752static inline void bpf_dispatcher_change_prog(struct bpf_dispatcher *d,
753 struct bpf_prog *from,
754 struct bpf_prog *to) {}
755static inline bool is_bpf_image_address(unsigned long address)
756{
757 return false;
758}
759#endif
760
761struct bpf_func_info_aux {
762 u16 linkage;
763 bool unreliable;
764};
765
766enum bpf_jit_poke_reason {
767 BPF_POKE_REASON_TAIL_CALL,
768};
769
770
771struct bpf_jit_poke_descriptor {
772 void *tailcall_target;
773 void *tailcall_bypass;
774 void *bypass_addr;
775 void *aux;
776 union {
777 struct {
778 struct bpf_map *map;
779 u32 key;
780 } tail_call;
781 };
782 bool tailcall_target_stable;
783 u8 adj_off;
784 u16 reason;
785 u32 insn_idx;
786};
787
788
789struct bpf_ctx_arg_aux {
790 u32 offset;
791 enum bpf_reg_type reg_type;
792 u32 btf_id;
793};
794
795struct btf_mod_pair {
796 struct btf *btf;
797 struct module *module;
798};
799
800struct bpf_prog_aux {
801 RH_KABI_BROKEN_REPLACE(atomic_t refcnt, atomic64_t refcnt)
802 u32 used_map_cnt;
803 RH_KABI_BROKEN_INSERT(u32 used_btf_cnt)
804 u32 max_ctx_offset;
805
806 RH_KABI_BROKEN_INSERT(u32 max_pkt_offset)
807 RH_KABI_BROKEN_INSERT(u32 max_tp_access)
808 u32 stack_depth;
809 u32 id;
810 u32 func_cnt;
811 RH_KABI_BROKEN_INSERT(u32 func_idx)
812 RH_KABI_BROKEN_INSERT(u32 attach_btf_id)
813 RH_KABI_BROKEN_INSERT(u32 ctx_arg_info_size)
814 RH_KABI_BROKEN_INSERT(u32 max_rdonly_access)
815 RH_KABI_BROKEN_INSERT(u32 max_rdwr_access)
816 RH_KABI_BROKEN_INSERT(const struct bpf_ctx_arg_aux *ctx_arg_info)
817 RH_KABI_BROKEN_INSERT_BLOCK(
818 struct mutex dst_mutex;
819 struct bpf_prog *dst_prog;
820 struct bpf_trampoline *dst_trampoline;
821 enum bpf_prog_type saved_dst_prog_type;
822 enum bpf_attach_type saved_dst_attach_type;
823 struct btf *attach_btf;
824 )
825 RH_KABI_BROKEN_INSERT(bool verifier_zext)
826 bool offload_requested;
827 RH_KABI_BROKEN_INSERT(bool attach_btf_trace)
828 RH_KABI_BROKEN_INSERT(bool func_proto_unreliable)
829 RH_KABI_BROKEN_INSERT(bool sleepable)
830 RH_KABI_BROKEN_INSERT(bool tail_call_reachable)
831 RH_KABI_BROKEN_INSERT(struct hlist_node tramp_hlist)
832
833 RH_KABI_BROKEN_INSERT(const struct btf_type *attach_func_proto)
834
835 RH_KABI_BROKEN_INSERT(const char *attach_func_name)
836 struct bpf_prog **func;
837 void *jit_data;
838 RH_KABI_BROKEN_INSERT(struct bpf_jit_poke_descriptor *poke_tab)
839 RH_KABI_BROKEN_INSERT(u32 size_poke_tab)
840 RH_KABI_BROKEN_REMOVE(struct latch_tree_node ksym_tnode)
841 RH_KABI_BROKEN_REMOVE(struct list_head ksym_lnode)
842 RH_KABI_BROKEN_INSERT(struct bpf_ksym ksym)
843 const struct bpf_prog_ops *ops;
844 struct bpf_map **used_maps;
845 RH_KABI_BROKEN_INSERT(struct mutex used_maps_mutex)
846 RH_KABI_BROKEN_INSERT(struct btf_mod_pair *used_btfs)
847 struct bpf_prog *prog;
848 struct user_struct *user;
849 u64 load_time;
850 RH_KABI_BROKEN_INSERT(struct bpf_map *cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE])
851 char name[BPF_OBJ_NAME_LEN];
852#ifdef CONFIG_SECURITY
853 void *security;
854#endif
855 struct bpf_prog_offload *offload;
856 RH_KABI_BROKEN_INSERT_BLOCK(
857 struct btf *btf;
858 struct bpf_func_info *func_info;
859 struct bpf_func_info_aux *func_info_aux;
860
861
862
863
864
865
866 struct bpf_line_info *linfo;
867
868
869
870
871
872
873
874 void **jited_linfo;
875 u32 func_info_cnt;
876 u32 nr_linfo;
877
878
879
880
881 u32 linfo_idx;
882 u32 num_exentries;
883 struct exception_table_entry *extable;
884 struct bpf_prog_stats __percpu *stats;
885 )
886 union {
887 struct work_struct work;
888 struct rcu_head rcu;
889 };
890};
891
892struct bpf_array_aux {
893
894
895
896
897
898 enum bpf_prog_type type;
899 bool jited;
900
901 struct list_head poke_progs;
902 struct bpf_map *map;
903 struct mutex poke_mutex;
904 struct work_struct work;
905};
906
907struct bpf_link {
908 atomic64_t refcnt;
909 u32 id;
910 enum bpf_link_type type;
911 const struct bpf_link_ops *ops;
912 struct bpf_prog *prog;
913 struct work_struct work;
914};
915
916struct bpf_link_ops {
917 void (*release)(struct bpf_link *link);
918 void (*dealloc)(struct bpf_link *link);
919 int (*detach)(struct bpf_link *link);
920 int (*update_prog)(struct bpf_link *link, struct bpf_prog *new_prog,
921 struct bpf_prog *old_prog);
922 void (*show_fdinfo)(const struct bpf_link *link, struct seq_file *seq);
923 int (*fill_link_info)(const struct bpf_link *link,
924 struct bpf_link_info *info);
925};
926
927struct bpf_link_primer {
928 struct bpf_link *link;
929 struct file *file;
930 int fd;
931 u32 id;
932};
933
934struct bpf_struct_ops_value;
935struct btf_type;
936struct btf_member;
937
938#define BPF_STRUCT_OPS_MAX_NR_MEMBERS 64
939struct bpf_struct_ops {
940 const struct bpf_verifier_ops *verifier_ops;
941 int (*init)(struct btf *btf);
942 int (*check_member)(const struct btf_type *t,
943 const struct btf_member *member);
944 int (*init_member)(const struct btf_type *t,
945 const struct btf_member *member,
946 void *kdata, const void *udata);
947 int (*reg)(void *kdata);
948 void (*unreg)(void *kdata);
949 const struct btf_type *type;
950 const struct btf_type *value_type;
951 const char *name;
952 struct btf_func_model func_models[BPF_STRUCT_OPS_MAX_NR_MEMBERS];
953 u32 type_id;
954 u32 value_id;
955};
956
957#if defined(CONFIG_BPF_JIT) && defined(CONFIG_BPF_SYSCALL)
958#define BPF_MODULE_OWNER ((void *)((0xeB9FUL << 2) + POISON_POINTER_DELTA))
959const struct bpf_struct_ops *bpf_struct_ops_find(u32 type_id);
960void bpf_struct_ops_init(struct btf *btf, struct bpf_verifier_log *log);
961bool bpf_struct_ops_get(const void *kdata);
962void bpf_struct_ops_put(const void *kdata);
963int bpf_struct_ops_map_sys_lookup_elem(struct bpf_map *map, void *key,
964 void *value);
965static inline bool bpf_try_module_get(const void *data, struct module *owner)
966{
967 if (owner == BPF_MODULE_OWNER)
968 return bpf_struct_ops_get(data);
969 else
970 return try_module_get(owner);
971}
972static inline void bpf_module_put(const void *data, struct module *owner)
973{
974 if (owner == BPF_MODULE_OWNER)
975 bpf_struct_ops_put(data);
976 else
977 module_put(owner);
978}
979#else
980static inline const struct bpf_struct_ops *bpf_struct_ops_find(u32 type_id)
981{
982 return NULL;
983}
984static inline void bpf_struct_ops_init(struct btf *btf,
985 struct bpf_verifier_log *log)
986{
987}
988static inline bool bpf_try_module_get(const void *data, struct module *owner)
989{
990 return try_module_get(owner);
991}
992static inline void bpf_module_put(const void *data, struct module *owner)
993{
994 module_put(owner);
995}
996static inline int bpf_struct_ops_map_sys_lookup_elem(struct bpf_map *map,
997 void *key,
998 void *value)
999{
1000 return -EINVAL;
1001}
1002#endif
1003
1004struct bpf_array {
1005 struct bpf_map map;
1006 u32 elem_size;
1007 u32 index_mask;
1008 struct bpf_array_aux *aux;
1009 union {
1010 char value[0] __aligned(8);
1011 void *ptrs[0] __aligned(8);
1012 void __percpu *pptrs[0] __aligned(8);
1013 };
1014};
1015
1016#define BPF_COMPLEXITY_LIMIT_INSNS 1000000
1017#define MAX_TAIL_CALL_CNT 32
1018
1019#define BPF_F_ACCESS_MASK (BPF_F_RDONLY | \
1020 BPF_F_RDONLY_PROG | \
1021 BPF_F_WRONLY | \
1022 BPF_F_WRONLY_PROG)
1023
1024#define BPF_MAP_CAN_READ BIT(0)
1025#define BPF_MAP_CAN_WRITE BIT(1)
1026
1027static inline u32 bpf_map_flags_to_cap(struct bpf_map *map)
1028{
1029 u32 access_flags = map->map_flags & (BPF_F_RDONLY_PROG | BPF_F_WRONLY_PROG);
1030
1031
1032
1033
1034 if (access_flags & BPF_F_RDONLY_PROG)
1035 return BPF_MAP_CAN_READ;
1036 else if (access_flags & BPF_F_WRONLY_PROG)
1037 return BPF_MAP_CAN_WRITE;
1038 else
1039 return BPF_MAP_CAN_READ | BPF_MAP_CAN_WRITE;
1040}
1041
1042static inline bool bpf_map_flags_access_ok(u32 access_flags)
1043{
1044 return (access_flags & (BPF_F_RDONLY_PROG | BPF_F_WRONLY_PROG)) !=
1045 (BPF_F_RDONLY_PROG | BPF_F_WRONLY_PROG);
1046}
1047
1048struct bpf_event_entry {
1049 struct perf_event *event;
1050 struct file *perf_file;
1051 struct file *map_file;
1052 struct rcu_head rcu;
1053};
1054
1055bool bpf_prog_array_compatible(struct bpf_array *array, const struct bpf_prog *fp);
1056int bpf_prog_calc_tag(struct bpf_prog *fp);
1057
1058const struct bpf_func_proto *bpf_get_trace_printk_proto(void);
1059
1060typedef unsigned long (*bpf_ctx_copy_t)(void *dst, const void *src,
1061 unsigned long off, unsigned long len);
1062typedef u32 (*bpf_convert_ctx_access_t)(enum bpf_access_type type,
1063 const struct bpf_insn *src,
1064 struct bpf_insn *dst,
1065 struct bpf_prog *prog,
1066 u32 *target_size);
1067
1068u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
1069 void *ctx, u64 ctx_size, bpf_ctx_copy_t ctx_copy);
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083struct bpf_prog_array_item {
1084 struct bpf_prog *prog;
1085 struct bpf_cgroup_storage *cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE];
1086};
1087
1088struct bpf_prog_array {
1089 struct rcu_head rcu;
1090 RH_KABI_BROKEN_REMOVE(struct bpf_prog *progs[0])
1091 RH_KABI_BROKEN_INSERT(struct bpf_prog_array_item items[])
1092};
1093
1094struct bpf_prog_array *bpf_prog_array_alloc(u32 prog_cnt, gfp_t flags);
1095void bpf_prog_array_free(struct bpf_prog_array *progs);
1096int bpf_prog_array_length(struct bpf_prog_array *progs);
1097bool bpf_prog_array_is_empty(struct bpf_prog_array *array);
1098int bpf_prog_array_copy_to_user(struct bpf_prog_array *progs,
1099 __u32 __user *prog_ids, u32 cnt);
1100
1101void bpf_prog_array_delete_safe(struct bpf_prog_array *progs,
1102 struct bpf_prog *old_prog);
1103int bpf_prog_array_delete_safe_at(struct bpf_prog_array *array, int index);
1104int bpf_prog_array_update_at(struct bpf_prog_array *array, int index,
1105 struct bpf_prog *prog);
1106int bpf_prog_array_copy_info(struct bpf_prog_array *array,
1107 u32 *prog_ids, u32 request_cnt,
1108 u32 *prog_cnt);
1109int bpf_prog_array_copy(struct bpf_prog_array *old_array,
1110 struct bpf_prog *exclude_prog,
1111 struct bpf_prog *include_prog,
1112 struct bpf_prog_array **new_array);
1113
1114#define __BPF_PROG_RUN_ARRAY(array, ctx, func, check_non_null) \
1115 ({ \
1116 struct bpf_prog_array_item *_item; \
1117 struct bpf_prog *_prog; \
1118 struct bpf_prog_array *_array; \
1119 u32 _ret = 1; \
1120 migrate_disable(); \
1121 rcu_read_lock(); \
1122 _array = rcu_dereference(array); \
1123 if (unlikely(check_non_null && !_array))\
1124 goto _out; \
1125 _item = &_array->items[0]; \
1126 while ((_prog = READ_ONCE(_item->prog))) { \
1127 bpf_cgroup_storage_set(_item->cgroup_storage); \
1128 _ret &= func(_prog, ctx); \
1129 _item++; \
1130 } \
1131_out: \
1132 rcu_read_unlock(); \
1133 migrate_enable(); \
1134 _ret; \
1135 })
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159#define BPF_PROG_CGROUP_INET_EGRESS_RUN_ARRAY(array, ctx, func) \
1160 ({ \
1161 struct bpf_prog_array_item *_item; \
1162 struct bpf_prog *_prog; \
1163 struct bpf_prog_array *_array; \
1164 u32 ret; \
1165 u32 _ret = 1; \
1166 u32 _cn = 0; \
1167 migrate_disable(); \
1168 rcu_read_lock(); \
1169 _array = rcu_dereference(array); \
1170 _item = &_array->items[0]; \
1171 while ((_prog = READ_ONCE(_item->prog))) { \
1172 bpf_cgroup_storage_set(_item->cgroup_storage); \
1173 ret = func(_prog, ctx); \
1174 _ret &= (ret & 1); \
1175 _cn |= (ret & 2); \
1176 _item++; \
1177 } \
1178 rcu_read_unlock(); \
1179 migrate_enable(); \
1180 if (_ret) \
1181 _ret = (_cn ? NET_XMIT_CN : NET_XMIT_SUCCESS); \
1182 else \
1183 _ret = (_cn ? NET_XMIT_DROP : -EPERM); \
1184 _ret; \
1185 })
1186
1187#define BPF_PROG_RUN_ARRAY(array, ctx, func) \
1188 __BPF_PROG_RUN_ARRAY(array, ctx, func, false)
1189
1190#define BPF_PROG_RUN_ARRAY_CHECK(array, ctx, func) \
1191 __BPF_PROG_RUN_ARRAY(array, ctx, func, true)
1192
1193#ifdef CONFIG_BPF_SYSCALL
1194DECLARE_PER_CPU(int, bpf_prog_active);
1195extern struct mutex bpf_stats_enabled_mutex;
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209static inline void bpf_disable_instrumentation(void)
1210{
1211 migrate_disable();
1212 if (IS_ENABLED(CONFIG_PREEMPT_RT))
1213 this_cpu_inc(bpf_prog_active);
1214 else
1215 __this_cpu_inc(bpf_prog_active);
1216}
1217
1218static inline void bpf_enable_instrumentation(void)
1219{
1220 if (IS_ENABLED(CONFIG_PREEMPT_RT))
1221 this_cpu_dec(bpf_prog_active);
1222 else
1223 __this_cpu_dec(bpf_prog_active);
1224 migrate_enable();
1225}
1226
1227extern const struct file_operations bpf_map_fops;
1228extern const struct file_operations bpf_prog_fops;
1229extern const struct file_operations bpf_iter_fops;
1230
1231#define BPF_PROG_TYPE(_id, _name, prog_ctx_type, kern_ctx_type) \
1232 extern const struct bpf_prog_ops _name ## _prog_ops; \
1233 extern const struct bpf_verifier_ops _name ## _verifier_ops;
1234#define BPF_MAP_TYPE(_id, _ops) \
1235 extern const struct bpf_map_ops _ops;
1236#define BPF_LINK_TYPE(_id, _name)
1237#include <linux/bpf_types.h>
1238#undef BPF_PROG_TYPE
1239#undef BPF_MAP_TYPE
1240#undef BPF_LINK_TYPE
1241
1242extern const struct bpf_prog_ops bpf_offload_prog_ops;
1243extern const struct bpf_verifier_ops tc_cls_act_analyzer_ops;
1244extern const struct bpf_verifier_ops xdp_analyzer_ops;
1245
1246struct bpf_prog *bpf_prog_get(u32 ufd);
1247struct bpf_prog *bpf_prog_get_type_dev(u32 ufd, enum bpf_prog_type type,
1248 bool attach_drv);
1249void bpf_prog_add(struct bpf_prog *prog, int i);
1250void bpf_prog_sub(struct bpf_prog *prog, int i);
1251void bpf_prog_inc(struct bpf_prog *prog);
1252struct bpf_prog * __must_check bpf_prog_inc_not_zero(struct bpf_prog *prog);
1253void bpf_prog_put(struct bpf_prog *prog);
1254void __bpf_free_used_maps(struct bpf_prog_aux *aux,
1255 struct bpf_map **used_maps, u32 len);
1256
1257void bpf_prog_free_id(struct bpf_prog *prog, bool do_idr_lock);
1258void bpf_map_free_id(struct bpf_map *map, bool do_idr_lock);
1259
1260struct bpf_map *bpf_map_get(u32 ufd);
1261struct bpf_map *bpf_map_get_with_uref(u32 ufd);
1262struct bpf_map *__bpf_map_get(struct fd f);
1263void bpf_map_inc(struct bpf_map *map);
1264void bpf_map_inc_with_uref(struct bpf_map *map);
1265struct bpf_map * __must_check bpf_map_inc_not_zero(struct bpf_map *map);
1266void bpf_map_put_with_uref(struct bpf_map *map);
1267void bpf_map_put(struct bpf_map *map);
1268void *bpf_map_area_alloc(u64 size, int numa_node);
1269void *bpf_map_area_mmapable_alloc(u64 size, int numa_node);
1270void bpf_map_area_free(void *base);
1271void bpf_map_init_from_attr(struct bpf_map *map, union bpf_attr *attr);
1272int generic_map_lookup_batch(struct bpf_map *map,
1273 const union bpf_attr *attr,
1274 union bpf_attr __user *uattr);
1275int generic_map_update_batch(struct bpf_map *map,
1276 const union bpf_attr *attr,
1277 union bpf_attr __user *uattr);
1278int generic_map_delete_batch(struct bpf_map *map,
1279 const union bpf_attr *attr,
1280 union bpf_attr __user *uattr);
1281struct bpf_map *bpf_map_get_curr_or_next(u32 *id);
1282struct bpf_prog *bpf_prog_get_curr_or_next(u32 *id);
1283
1284#ifdef CONFIG_MEMCG_KMEM
1285void *bpf_map_kmalloc_node(const struct bpf_map *map, size_t size, gfp_t flags,
1286 int node);
1287void *bpf_map_kzalloc(const struct bpf_map *map, size_t size, gfp_t flags);
1288void __percpu *bpf_map_alloc_percpu(const struct bpf_map *map, size_t size,
1289 size_t align, gfp_t flags);
1290#else
1291static inline void *
1292bpf_map_kmalloc_node(const struct bpf_map *map, size_t size, gfp_t flags,
1293 int node)
1294{
1295 return kmalloc_node(size, flags, node);
1296}
1297
1298static inline void *
1299bpf_map_kzalloc(const struct bpf_map *map, size_t size, gfp_t flags)
1300{
1301 return kzalloc(size, flags);
1302}
1303
1304static inline void __percpu *
1305bpf_map_alloc_percpu(const struct bpf_map *map, size_t size, size_t align,
1306 gfp_t flags)
1307{
1308 return __alloc_percpu_gfp(size, align, flags);
1309}
1310#endif
1311
1312extern int sysctl_unprivileged_bpf_disabled;
1313
1314static inline bool bpf_allow_ptr_leaks(void)
1315{
1316 return perfmon_capable();
1317}
1318
1319static inline bool bpf_allow_uninit_stack(void)
1320{
1321 return perfmon_capable();
1322}
1323
1324static inline bool bpf_allow_ptr_to_map_access(void)
1325{
1326 return perfmon_capable();
1327}
1328
1329static inline bool bpf_bypass_spec_v1(void)
1330{
1331 return perfmon_capable();
1332}
1333
1334static inline bool bpf_bypass_spec_v4(void)
1335{
1336 return perfmon_capable();
1337}
1338
1339int bpf_map_new_fd(struct bpf_map *map, int flags);
1340int bpf_prog_new_fd(struct bpf_prog *prog);
1341
1342void bpf_link_init(struct bpf_link *link, enum bpf_link_type type,
1343 const struct bpf_link_ops *ops, struct bpf_prog *prog);
1344int bpf_link_prime(struct bpf_link *link, struct bpf_link_primer *primer);
1345int bpf_link_settle(struct bpf_link_primer *primer);
1346void bpf_link_cleanup(struct bpf_link_primer *primer);
1347void bpf_link_inc(struct bpf_link *link);
1348void bpf_link_put(struct bpf_link *link);
1349int bpf_link_new_fd(struct bpf_link *link);
1350struct file *bpf_link_new_file(struct bpf_link *link, int *reserved_fd);
1351struct bpf_link *bpf_link_get_from_fd(u32 ufd);
1352
1353int bpf_obj_pin_user(u32 ufd, const char __user *pathname);
1354int bpf_obj_get_user(const char __user *pathname, int flags);
1355
1356#define BPF_ITER_FUNC_PREFIX "bpf_iter_"
1357#define DEFINE_BPF_ITER_FUNC(target, args...) \
1358 extern int bpf_iter_ ## target(args); \
1359 int __init bpf_iter_ ## target(args) { return 0; }
1360
1361struct bpf_iter_aux_info {
1362 struct bpf_map *map;
1363};
1364
1365typedef int (*bpf_iter_attach_target_t)(struct bpf_prog *prog,
1366 union bpf_iter_link_info *linfo,
1367 struct bpf_iter_aux_info *aux);
1368typedef void (*bpf_iter_detach_target_t)(struct bpf_iter_aux_info *aux);
1369typedef void (*bpf_iter_show_fdinfo_t) (const struct bpf_iter_aux_info *aux,
1370 struct seq_file *seq);
1371typedef int (*bpf_iter_fill_link_info_t)(const struct bpf_iter_aux_info *aux,
1372 struct bpf_link_info *info);
1373
1374enum bpf_iter_feature {
1375 BPF_ITER_RESCHED = BIT(0),
1376};
1377
1378#define BPF_ITER_CTX_ARG_MAX 2
1379struct bpf_iter_reg {
1380 const char *target;
1381 bpf_iter_attach_target_t attach_target;
1382 bpf_iter_detach_target_t detach_target;
1383 bpf_iter_show_fdinfo_t show_fdinfo;
1384 bpf_iter_fill_link_info_t fill_link_info;
1385 u32 ctx_arg_info_size;
1386 u32 feature;
1387 struct bpf_ctx_arg_aux ctx_arg_info[BPF_ITER_CTX_ARG_MAX];
1388 const struct bpf_iter_seq_info *seq_info;
1389};
1390
1391struct bpf_iter_meta {
1392 __bpf_md_ptr(struct seq_file *, seq);
1393 u64 session_id;
1394 u64 seq_num;
1395};
1396
1397struct bpf_iter__bpf_map_elem {
1398 __bpf_md_ptr(struct bpf_iter_meta *, meta);
1399 __bpf_md_ptr(struct bpf_map *, map);
1400 __bpf_md_ptr(void *, key);
1401 __bpf_md_ptr(void *, value);
1402};
1403
1404int bpf_iter_reg_target(const struct bpf_iter_reg *reg_info);
1405void bpf_iter_unreg_target(const struct bpf_iter_reg *reg_info);
1406bool bpf_iter_prog_supported(struct bpf_prog *prog);
1407int bpf_iter_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
1408int bpf_iter_new_fd(struct bpf_link *link);
1409bool bpf_link_is_iter(struct bpf_link *link);
1410struct bpf_prog *bpf_iter_get_info(struct bpf_iter_meta *meta, bool in_stop);
1411int bpf_iter_run_prog(struct bpf_prog *prog, void *ctx);
1412void bpf_iter_map_show_fdinfo(const struct bpf_iter_aux_info *aux,
1413 struct seq_file *seq);
1414int bpf_iter_map_fill_link_info(const struct bpf_iter_aux_info *aux,
1415 struct bpf_link_info *info);
1416
1417int bpf_percpu_hash_copy(struct bpf_map *map, void *key, void *value);
1418int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value);
1419int bpf_percpu_hash_update(struct bpf_map *map, void *key, void *value,
1420 u64 flags);
1421int bpf_percpu_array_update(struct bpf_map *map, void *key, void *value,
1422 u64 flags);
1423
1424int bpf_stackmap_copy(struct bpf_map *map, void *key, void *value);
1425
1426int bpf_fd_array_map_update_elem(struct bpf_map *map, struct file *map_file,
1427 void *key, void *value, u64 map_flags);
1428int bpf_fd_array_map_lookup_elem(struct bpf_map *map, void *key, u32 *value);
1429int bpf_fd_htab_map_update_elem(struct bpf_map *map, struct file *map_file,
1430 void *key, void *value, u64 map_flags);
1431int bpf_fd_htab_map_lookup_elem(struct bpf_map *map, void *key, u32 *value);
1432
1433int bpf_get_file_flag(int flags);
1434int bpf_check_uarg_tail_zero(void __user *uaddr, size_t expected_size,
1435 size_t actual_size);
1436
1437
1438
1439
1440
1441
1442
1443static inline void bpf_long_memcpy(void *dst, const void *src, u32 size)
1444{
1445 const long *lsrc = src;
1446 long *ldst = dst;
1447
1448 size /= sizeof(long);
1449 while (size--)
1450 *ldst++ = *lsrc++;
1451}
1452
1453
1454int bpf_check(struct bpf_prog **fp, union bpf_attr *attr,
1455 union bpf_attr __user *uattr);
1456void bpf_patch_call_args(struct bpf_insn *insn, u32 stack_depth);
1457
1458struct btf *bpf_get_btf_vmlinux(void);
1459
1460
1461struct xdp_buff;
1462struct sk_buff;
1463
1464struct bpf_dtab_netdev *__dev_map_lookup_elem(struct bpf_map *map, u32 key);
1465struct bpf_dtab_netdev *__dev_map_hash_lookup_elem(struct bpf_map *map, u32 key);
1466void __dev_flush(void);
1467int dev_xdp_enqueue(struct net_device *dev, struct xdp_buff *xdp,
1468 struct net_device *dev_rx);
1469int dev_map_enqueue(struct bpf_dtab_netdev *dst, struct xdp_buff *xdp,
1470 struct net_device *dev_rx);
1471int dev_map_generic_redirect(struct bpf_dtab_netdev *dst, struct sk_buff *skb,
1472 struct bpf_prog *xdp_prog);
1473bool dev_map_can_have_prog(struct bpf_map *map);
1474
1475struct bpf_cpu_map_entry *__cpu_map_lookup_elem(struct bpf_map *map, u32 key);
1476void __cpu_map_flush(void);
1477int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_buff *xdp,
1478 struct net_device *dev_rx);
1479bool cpu_map_prog_allowed(struct bpf_map *map);
1480
1481
1482static inline int bpf_map_attr_numa_node(const union bpf_attr *attr)
1483{
1484 return (attr->map_flags & BPF_F_NUMA_NODE) ?
1485 attr->numa_node : NUMA_NO_NODE;
1486}
1487
1488struct bpf_prog *bpf_prog_get_type_path(const char *name, enum bpf_prog_type type);
1489int array_map_alloc_check(union bpf_attr *attr);
1490
1491int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
1492 union bpf_attr __user *uattr);
1493int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
1494 union bpf_attr __user *uattr);
1495int bpf_prog_test_run_tracing(struct bpf_prog *prog,
1496 const union bpf_attr *kattr,
1497 union bpf_attr __user *uattr);
1498int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
1499 const union bpf_attr *kattr,
1500 union bpf_attr __user *uattr);
1501int bpf_prog_test_run_raw_tp(struct bpf_prog *prog,
1502 const union bpf_attr *kattr,
1503 union bpf_attr __user *uattr);
1504bool btf_ctx_access(int off, int size, enum bpf_access_type type,
1505 const struct bpf_prog *prog,
1506 struct bpf_insn_access_aux *info);
1507int btf_struct_access(struct bpf_verifier_log *log, const struct btf *btf,
1508 const struct btf_type *t, int off, int size,
1509 enum bpf_access_type atype,
1510 u32 *next_btf_id);
1511bool btf_struct_ids_match(struct bpf_verifier_log *log,
1512 const struct btf *btf, u32 id, int off,
1513 const struct btf *need_btf, u32 need_type_id);
1514
1515int btf_distill_func_proto(struct bpf_verifier_log *log,
1516 struct btf *btf,
1517 const struct btf_type *func_proto,
1518 const char *func_name,
1519 struct btf_func_model *m);
1520
1521struct bpf_reg_state;
1522int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog,
1523 struct bpf_reg_state *regs);
1524int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog,
1525 struct bpf_reg_state *reg);
1526int btf_check_type_match(struct bpf_verifier_log *log, const struct bpf_prog *prog,
1527 struct btf *btf, const struct btf_type *t);
1528
1529struct bpf_prog *bpf_prog_by_id(u32 id);
1530struct bpf_link *bpf_link_by_id(u32 id);
1531
1532const struct bpf_func_proto *bpf_base_func_proto(enum bpf_func_id func_id);
1533#else
1534static inline struct bpf_prog *bpf_prog_get(u32 ufd)
1535{
1536 return ERR_PTR(-EOPNOTSUPP);
1537}
1538
1539static inline struct bpf_prog *bpf_prog_get_type_dev(u32 ufd,
1540 enum bpf_prog_type type,
1541 bool attach_drv)
1542{
1543 return ERR_PTR(-EOPNOTSUPP);
1544}
1545
1546static inline void bpf_prog_add(struct bpf_prog *prog, int i)
1547{
1548}
1549
1550static inline void bpf_prog_sub(struct bpf_prog *prog, int i)
1551{
1552}
1553
1554static inline void bpf_prog_put(struct bpf_prog *prog)
1555{
1556}
1557
1558static inline void bpf_prog_inc(struct bpf_prog *prog)
1559{
1560}
1561
1562static inline struct bpf_prog *__must_check
1563bpf_prog_inc_not_zero(struct bpf_prog *prog)
1564{
1565 return ERR_PTR(-EOPNOTSUPP);
1566}
1567
1568static inline void bpf_link_init(struct bpf_link *link, enum bpf_link_type type,
1569 const struct bpf_link_ops *ops,
1570 struct bpf_prog *prog)
1571{
1572}
1573
1574static inline int bpf_link_prime(struct bpf_link *link,
1575 struct bpf_link_primer *primer)
1576{
1577 return -EOPNOTSUPP;
1578}
1579
1580static inline int bpf_link_settle(struct bpf_link_primer *primer)
1581{
1582 return -EOPNOTSUPP;
1583}
1584
1585static inline void bpf_link_cleanup(struct bpf_link_primer *primer)
1586{
1587}
1588
1589static inline void bpf_link_inc(struct bpf_link *link)
1590{
1591}
1592
1593static inline void bpf_link_put(struct bpf_link *link)
1594{
1595}
1596
1597static inline int bpf_obj_get_user(const char __user *pathname, int flags)
1598{
1599 return -EOPNOTSUPP;
1600}
1601
1602static inline struct net_device *__dev_map_lookup_elem(struct bpf_map *map,
1603 u32 key)
1604{
1605 return NULL;
1606}
1607
1608static inline struct net_device *__dev_map_hash_lookup_elem(struct bpf_map *map,
1609 u32 key)
1610{
1611 return NULL;
1612}
1613static inline bool dev_map_can_have_prog(struct bpf_map *map)
1614{
1615 return false;
1616}
1617
1618static inline void __dev_flush(void)
1619{
1620}
1621
1622struct xdp_buff;
1623struct bpf_dtab_netdev;
1624
1625static inline
1626int dev_xdp_enqueue(struct net_device *dev, struct xdp_buff *xdp,
1627 struct net_device *dev_rx)
1628{
1629 return 0;
1630}
1631
1632static inline
1633int dev_map_enqueue(struct bpf_dtab_netdev *dst, struct xdp_buff *xdp,
1634 struct net_device *dev_rx)
1635{
1636 return 0;
1637}
1638
1639struct sk_buff;
1640
1641static inline int dev_map_generic_redirect(struct bpf_dtab_netdev *dst,
1642 struct sk_buff *skb,
1643 struct bpf_prog *xdp_prog)
1644{
1645 return 0;
1646}
1647
1648static inline
1649struct bpf_cpu_map_entry *__cpu_map_lookup_elem(struct bpf_map *map, u32 key)
1650{
1651 return NULL;
1652}
1653
1654static inline void __cpu_map_flush(void)
1655{
1656}
1657
1658static inline int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu,
1659 struct xdp_buff *xdp,
1660 struct net_device *dev_rx)
1661{
1662 return 0;
1663}
1664
1665static inline bool cpu_map_prog_allowed(struct bpf_map *map)
1666{
1667 return false;
1668}
1669
1670static inline struct bpf_prog *bpf_prog_get_type_path(const char *name,
1671 enum bpf_prog_type type)
1672{
1673 return ERR_PTR(-EOPNOTSUPP);
1674}
1675
1676static inline int bpf_prog_test_run_xdp(struct bpf_prog *prog,
1677 const union bpf_attr *kattr,
1678 union bpf_attr __user *uattr)
1679{
1680 return -ENOTSUPP;
1681}
1682
1683static inline int bpf_prog_test_run_skb(struct bpf_prog *prog,
1684 const union bpf_attr *kattr,
1685 union bpf_attr __user *uattr)
1686{
1687 return -ENOTSUPP;
1688}
1689
1690static inline int bpf_prog_test_run_tracing(struct bpf_prog *prog,
1691 const union bpf_attr *kattr,
1692 union bpf_attr __user *uattr)
1693{
1694 return -ENOTSUPP;
1695}
1696
1697static inline int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
1698 const union bpf_attr *kattr,
1699 union bpf_attr __user *uattr)
1700{
1701 return -ENOTSUPP;
1702}
1703
1704static inline void bpf_map_put(struct bpf_map *map)
1705{
1706}
1707
1708static inline struct bpf_prog *bpf_prog_by_id(u32 id)
1709{
1710 return ERR_PTR(-ENOTSUPP);
1711}
1712
1713static inline const struct bpf_func_proto *
1714bpf_base_func_proto(enum bpf_func_id func_id)
1715{
1716 return NULL;
1717}
1718#endif
1719
1720void __bpf_free_used_btfs(struct bpf_prog_aux *aux,
1721 struct btf_mod_pair *used_btfs, u32 len);
1722
1723static inline struct bpf_prog *bpf_prog_get_type(u32 ufd,
1724 enum bpf_prog_type type)
1725{
1726 return bpf_prog_get_type_dev(ufd, type, false);
1727}
1728
1729bool bpf_prog_get_ok(struct bpf_prog *, enum bpf_prog_type *, bool);
1730
1731int bpf_prog_offload_compile(struct bpf_prog *prog);
1732void bpf_prog_offload_destroy(struct bpf_prog *prog);
1733int bpf_prog_offload_info_fill(struct bpf_prog_info *info,
1734 struct bpf_prog *prog);
1735
1736int bpf_map_offload_info_fill(struct bpf_map_info *info, struct bpf_map *map);
1737
1738int bpf_map_offload_lookup_elem(struct bpf_map *map, void *key, void *value);
1739int bpf_map_offload_update_elem(struct bpf_map *map,
1740 void *key, void *value, u64 flags);
1741int bpf_map_offload_delete_elem(struct bpf_map *map, void *key);
1742int bpf_map_offload_get_next_key(struct bpf_map *map,
1743 void *key, void *next_key);
1744
1745bool bpf_offload_prog_map_match(struct bpf_prog *prog, struct bpf_map *map);
1746
1747struct bpf_offload_dev *
1748bpf_offload_dev_create(const struct bpf_prog_offload_ops *ops, void *priv);
1749void bpf_offload_dev_destroy(struct bpf_offload_dev *offdev);
1750void *bpf_offload_dev_priv(struct bpf_offload_dev *offdev);
1751int bpf_offload_dev_netdev_register(struct bpf_offload_dev *offdev,
1752 struct net_device *netdev);
1753void bpf_offload_dev_netdev_unregister(struct bpf_offload_dev *offdev,
1754 struct net_device *netdev);
1755bool bpf_offload_dev_match(struct bpf_prog *prog, struct net_device *netdev);
1756
1757#if defined(CONFIG_NET) && defined(CONFIG_BPF_SYSCALL)
1758int bpf_prog_offload_init(struct bpf_prog *prog, union bpf_attr *attr);
1759
1760static inline bool bpf_prog_is_dev_bound(const struct bpf_prog_aux *aux)
1761{
1762 return aux->offload_requested;
1763}
1764
1765static inline bool bpf_map_is_dev_bound(struct bpf_map *map)
1766{
1767 return unlikely(map->ops == &bpf_map_offload_ops);
1768}
1769
1770struct bpf_map *bpf_map_offload_map_alloc(union bpf_attr *attr);
1771void bpf_map_offload_map_free(struct bpf_map *map);
1772#else
1773static inline int bpf_prog_offload_init(struct bpf_prog *prog,
1774 union bpf_attr *attr)
1775{
1776 return -EOPNOTSUPP;
1777}
1778
1779static inline bool bpf_prog_is_dev_bound(struct bpf_prog_aux *aux)
1780{
1781 return false;
1782}
1783
1784static inline bool bpf_map_is_dev_bound(struct bpf_map *map)
1785{
1786 return false;
1787}
1788
1789static inline struct bpf_map *bpf_map_offload_map_alloc(union bpf_attr *attr)
1790{
1791 return ERR_PTR(-EOPNOTSUPP);
1792}
1793
1794static inline void bpf_map_offload_map_free(struct bpf_map *map)
1795{
1796}
1797#endif
1798
1799#if defined(CONFIG_BPF_STREAM_PARSER)
1800int sock_map_prog_update(struct bpf_map *map, struct bpf_prog *prog,
1801 struct bpf_prog *old, u32 which);
1802int sock_map_get_from_fd(const union bpf_attr *attr, struct bpf_prog *prog);
1803int sock_map_prog_detach(const union bpf_attr *attr, enum bpf_prog_type ptype);
1804int sock_map_update_elem_sys(struct bpf_map *map, void *key, void *value, u64 flags);
1805void sock_map_unhash(struct sock *sk);
1806void sock_map_close(struct sock *sk, long timeout);
1807#else
1808static inline int sock_map_prog_update(struct bpf_map *map,
1809 struct bpf_prog *prog,
1810 struct bpf_prog *old, u32 which)
1811{
1812 return -EOPNOTSUPP;
1813}
1814
1815static inline int sock_map_get_from_fd(const union bpf_attr *attr,
1816 struct bpf_prog *prog)
1817{
1818 return -EINVAL;
1819}
1820
1821static inline int sock_map_prog_detach(const union bpf_attr *attr,
1822 enum bpf_prog_type ptype)
1823{
1824 return -EOPNOTSUPP;
1825}
1826
1827static inline int sock_map_update_elem_sys(struct bpf_map *map, void *key, void *value,
1828 u64 flags)
1829{
1830 return -EOPNOTSUPP;
1831}
1832#endif
1833
1834#if defined(CONFIG_INET) && defined(CONFIG_BPF_SYSCALL)
1835void bpf_sk_reuseport_detach(struct sock *sk);
1836int bpf_fd_reuseport_array_lookup_elem(struct bpf_map *map, void *key,
1837 void *value);
1838int bpf_fd_reuseport_array_update_elem(struct bpf_map *map, void *key,
1839 void *value, u64 map_flags);
1840#else
1841static inline void bpf_sk_reuseport_detach(struct sock *sk)
1842{
1843}
1844
1845#ifdef CONFIG_BPF_SYSCALL
1846static inline int bpf_fd_reuseport_array_lookup_elem(struct bpf_map *map,
1847 void *key, void *value)
1848{
1849 return -EOPNOTSUPP;
1850}
1851
1852static inline int bpf_fd_reuseport_array_update_elem(struct bpf_map *map,
1853 void *key, void *value,
1854 u64 map_flags)
1855{
1856 return -EOPNOTSUPP;
1857}
1858#endif
1859#endif
1860
1861
1862extern const struct bpf_func_proto bpf_map_lookup_elem_proto;
1863extern const struct bpf_func_proto bpf_map_update_elem_proto;
1864extern const struct bpf_func_proto bpf_map_delete_elem_proto;
1865extern const struct bpf_func_proto bpf_map_push_elem_proto;
1866extern const struct bpf_func_proto bpf_map_pop_elem_proto;
1867extern const struct bpf_func_proto bpf_map_peek_elem_proto;
1868
1869extern const struct bpf_func_proto bpf_get_prandom_u32_proto;
1870extern const struct bpf_func_proto bpf_get_smp_processor_id_proto;
1871extern const struct bpf_func_proto bpf_get_numa_node_id_proto;
1872extern const struct bpf_func_proto bpf_tail_call_proto;
1873extern const struct bpf_func_proto bpf_ktime_get_ns_proto;
1874extern const struct bpf_func_proto bpf_ktime_get_boot_ns_proto;
1875extern const struct bpf_func_proto bpf_get_current_pid_tgid_proto;
1876extern const struct bpf_func_proto bpf_get_current_uid_gid_proto;
1877extern const struct bpf_func_proto bpf_get_current_comm_proto;
1878extern const struct bpf_func_proto bpf_get_stackid_proto;
1879extern const struct bpf_func_proto bpf_get_stack_proto;
1880extern const struct bpf_func_proto bpf_get_task_stack_proto;
1881extern const struct bpf_func_proto bpf_get_stackid_proto_pe;
1882extern const struct bpf_func_proto bpf_get_stack_proto_pe;
1883extern const struct bpf_func_proto bpf_sock_map_update_proto;
1884extern const struct bpf_func_proto bpf_sock_hash_update_proto;
1885extern const struct bpf_func_proto bpf_get_current_cgroup_id_proto;
1886extern const struct bpf_func_proto bpf_get_current_ancestor_cgroup_id_proto;
1887extern const struct bpf_func_proto bpf_msg_redirect_hash_proto;
1888extern const struct bpf_func_proto bpf_msg_redirect_map_proto;
1889extern const struct bpf_func_proto bpf_sk_redirect_hash_proto;
1890extern const struct bpf_func_proto bpf_sk_redirect_map_proto;
1891extern const struct bpf_func_proto bpf_spin_lock_proto;
1892extern const struct bpf_func_proto bpf_spin_unlock_proto;
1893extern const struct bpf_func_proto bpf_get_local_storage_proto;
1894extern const struct bpf_func_proto bpf_strtol_proto;
1895extern const struct bpf_func_proto bpf_strtoul_proto;
1896extern const struct bpf_func_proto bpf_tcp_sock_proto;
1897extern const struct bpf_func_proto bpf_jiffies64_proto;
1898extern const struct bpf_func_proto bpf_get_ns_current_pid_tgid_proto;
1899extern const struct bpf_func_proto bpf_event_output_data_proto;
1900extern const struct bpf_func_proto bpf_ringbuf_output_proto;
1901extern const struct bpf_func_proto bpf_ringbuf_reserve_proto;
1902extern const struct bpf_func_proto bpf_ringbuf_submit_proto;
1903extern const struct bpf_func_proto bpf_ringbuf_discard_proto;
1904extern const struct bpf_func_proto bpf_ringbuf_query_proto;
1905extern const struct bpf_func_proto bpf_skc_to_tcp6_sock_proto;
1906extern const struct bpf_func_proto bpf_skc_to_tcp_sock_proto;
1907extern const struct bpf_func_proto bpf_skc_to_tcp_timewait_sock_proto;
1908extern const struct bpf_func_proto bpf_skc_to_tcp_request_sock_proto;
1909extern const struct bpf_func_proto bpf_skc_to_udp6_sock_proto;
1910extern const struct bpf_func_proto bpf_copy_from_user_proto;
1911extern const struct bpf_func_proto bpf_snprintf_btf_proto;
1912extern const struct bpf_func_proto bpf_per_cpu_ptr_proto;
1913extern const struct bpf_func_proto bpf_this_cpu_ptr_proto;
1914extern const struct bpf_func_proto bpf_ktime_get_coarse_ns_proto;
1915extern const struct bpf_func_proto bpf_sock_from_file_proto;
1916
1917const struct bpf_func_proto *bpf_tracing_func_proto(
1918 enum bpf_func_id func_id, const struct bpf_prog *prog);
1919
1920const struct bpf_func_proto *tracing_prog_func_proto(
1921 enum bpf_func_id func_id, const struct bpf_prog *prog);
1922
1923
1924void bpf_user_rnd_init_once(void);
1925u64 bpf_user_rnd_u32(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
1926u64 bpf_get_raw_cpu_id(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
1927
1928#if defined(CONFIG_NET)
1929bool bpf_sock_common_is_valid_access(int off, int size,
1930 enum bpf_access_type type,
1931 struct bpf_insn_access_aux *info);
1932bool bpf_sock_is_valid_access(int off, int size, enum bpf_access_type type,
1933 struct bpf_insn_access_aux *info);
1934u32 bpf_sock_convert_ctx_access(enum bpf_access_type type,
1935 const struct bpf_insn *si,
1936 struct bpf_insn *insn_buf,
1937 struct bpf_prog *prog,
1938 u32 *target_size);
1939#else
1940static inline bool bpf_sock_common_is_valid_access(int off, int size,
1941 enum bpf_access_type type,
1942 struct bpf_insn_access_aux *info)
1943{
1944 return false;
1945}
1946static inline bool bpf_sock_is_valid_access(int off, int size,
1947 enum bpf_access_type type,
1948 struct bpf_insn_access_aux *info)
1949{
1950 return false;
1951}
1952static inline u32 bpf_sock_convert_ctx_access(enum bpf_access_type type,
1953 const struct bpf_insn *si,
1954 struct bpf_insn *insn_buf,
1955 struct bpf_prog *prog,
1956 u32 *target_size)
1957{
1958 return 0;
1959}
1960#endif
1961
1962#ifdef CONFIG_INET
1963struct sk_reuseport_kern {
1964 struct sk_buff *skb;
1965 struct sock *sk;
1966 struct sock *selected_sk;
1967 void *data_end;
1968 u32 hash;
1969 u32 reuseport_id;
1970 bool bind_inany;
1971};
1972bool bpf_tcp_sock_is_valid_access(int off, int size, enum bpf_access_type type,
1973 struct bpf_insn_access_aux *info);
1974
1975u32 bpf_tcp_sock_convert_ctx_access(enum bpf_access_type type,
1976 const struct bpf_insn *si,
1977 struct bpf_insn *insn_buf,
1978 struct bpf_prog *prog,
1979 u32 *target_size);
1980
1981bool bpf_xdp_sock_is_valid_access(int off, int size, enum bpf_access_type type,
1982 struct bpf_insn_access_aux *info);
1983
1984u32 bpf_xdp_sock_convert_ctx_access(enum bpf_access_type type,
1985 const struct bpf_insn *si,
1986 struct bpf_insn *insn_buf,
1987 struct bpf_prog *prog,
1988 u32 *target_size);
1989#else
1990static inline bool bpf_tcp_sock_is_valid_access(int off, int size,
1991 enum bpf_access_type type,
1992 struct bpf_insn_access_aux *info)
1993{
1994 return false;
1995}
1996
1997static inline u32 bpf_tcp_sock_convert_ctx_access(enum bpf_access_type type,
1998 const struct bpf_insn *si,
1999 struct bpf_insn *insn_buf,
2000 struct bpf_prog *prog,
2001 u32 *target_size)
2002{
2003 return 0;
2004}
2005static inline bool bpf_xdp_sock_is_valid_access(int off, int size,
2006 enum bpf_access_type type,
2007 struct bpf_insn_access_aux *info)
2008{
2009 return false;
2010}
2011
2012static inline u32 bpf_xdp_sock_convert_ctx_access(enum bpf_access_type type,
2013 const struct bpf_insn *si,
2014 struct bpf_insn *insn_buf,
2015 struct bpf_prog *prog,
2016 u32 *target_size)
2017{
2018 return 0;
2019}
2020#endif
2021
2022enum bpf_text_poke_type {
2023 BPF_MOD_CALL,
2024 BPF_MOD_JUMP,
2025};
2026
2027int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
2028 void *addr1, void *addr2);
2029
2030struct btf_id_set;
2031bool btf_id_set_contains(const struct btf_id_set *set, u32 id);
2032
2033#endif
2034