]> Git Repo - linux.git/blob - include/linux/bpf.h
bpf: Add bpf_map iterator
[linux.git] / include / linux / bpf.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
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
23 struct bpf_verifier_env;
24 struct bpf_verifier_log;
25 struct perf_event;
26 struct bpf_prog;
27 struct bpf_prog_aux;
28 struct bpf_map;
29 struct sock;
30 struct seq_file;
31 struct btf;
32 struct btf_type;
33 struct exception_table_entry;
34 struct seq_operations;
35
36 extern struct idr btf_idr;
37 extern spinlock_t btf_idr_lock;
38
39 /* map is generic key/value storage optionally accesible by eBPF programs */
40 struct bpf_map_ops {
41         /* funcs callable from userspace (via syscall) */
42         int (*map_alloc_check)(union bpf_attr *attr);
43         struct bpf_map *(*map_alloc)(union bpf_attr *attr);
44         void (*map_release)(struct bpf_map *map, struct file *map_file);
45         void (*map_free)(struct bpf_map *map);
46         int (*map_get_next_key)(struct bpf_map *map, void *key, void *next_key);
47         void (*map_release_uref)(struct bpf_map *map);
48         void *(*map_lookup_elem_sys_only)(struct bpf_map *map, void *key);
49         int (*map_lookup_batch)(struct bpf_map *map, const union bpf_attr *attr,
50                                 union bpf_attr __user *uattr);
51         int (*map_lookup_and_delete_batch)(struct bpf_map *map,
52                                            const union bpf_attr *attr,
53                                            union bpf_attr __user *uattr);
54         int (*map_update_batch)(struct bpf_map *map, const union bpf_attr *attr,
55                                 union bpf_attr __user *uattr);
56         int (*map_delete_batch)(struct bpf_map *map, const union bpf_attr *attr,
57                                 union bpf_attr __user *uattr);
58
59         /* funcs callable from userspace and from eBPF programs */
60         void *(*map_lookup_elem)(struct bpf_map *map, void *key);
61         int (*map_update_elem)(struct bpf_map *map, void *key, void *value, u64 flags);
62         int (*map_delete_elem)(struct bpf_map *map, void *key);
63         int (*map_push_elem)(struct bpf_map *map, void *value, u64 flags);
64         int (*map_pop_elem)(struct bpf_map *map, void *value);
65         int (*map_peek_elem)(struct bpf_map *map, void *value);
66
67         /* funcs called by prog_array and perf_event_array map */
68         void *(*map_fd_get_ptr)(struct bpf_map *map, struct file *map_file,
69                                 int fd);
70         void (*map_fd_put_ptr)(void *ptr);
71         u32 (*map_gen_lookup)(struct bpf_map *map, struct bpf_insn *insn_buf);
72         u32 (*map_fd_sys_lookup_elem)(void *ptr);
73         void (*map_seq_show_elem)(struct bpf_map *map, void *key,
74                                   struct seq_file *m);
75         int (*map_check_btf)(const struct bpf_map *map,
76                              const struct btf *btf,
77                              const struct btf_type *key_type,
78                              const struct btf_type *value_type);
79
80         /* Prog poke tracking helpers. */
81         int (*map_poke_track)(struct bpf_map *map, struct bpf_prog_aux *aux);
82         void (*map_poke_untrack)(struct bpf_map *map, struct bpf_prog_aux *aux);
83         void (*map_poke_run)(struct bpf_map *map, u32 key, struct bpf_prog *old,
84                              struct bpf_prog *new);
85
86         /* Direct value access helpers. */
87         int (*map_direct_value_addr)(const struct bpf_map *map,
88                                      u64 *imm, u32 off);
89         int (*map_direct_value_meta)(const struct bpf_map *map,
90                                      u64 imm, u32 *off);
91         int (*map_mmap)(struct bpf_map *map, struct vm_area_struct *vma);
92 };
93
94 struct bpf_map_memory {
95         u32 pages;
96         struct user_struct *user;
97 };
98
99 struct bpf_map {
100         /* The first two cachelines with read-mostly members of which some
101          * are also accessed in fast-path (e.g. ops, max_entries).
102          */
103         const struct bpf_map_ops *ops ____cacheline_aligned;
104         struct bpf_map *inner_map_meta;
105 #ifdef CONFIG_SECURITY
106         void *security;
107 #endif
108         enum bpf_map_type map_type;
109         u32 key_size;
110         u32 value_size;
111         u32 max_entries;
112         u32 map_flags;
113         int spin_lock_off; /* >=0 valid offset, <0 error */
114         u32 id;
115         int numa_node;
116         u32 btf_key_type_id;
117         u32 btf_value_type_id;
118         struct btf *btf;
119         struct bpf_map_memory memory;
120         char name[BPF_OBJ_NAME_LEN];
121         u32 btf_vmlinux_value_type_id;
122         bool unpriv_array;
123         bool frozen; /* write-once; write-protected by freeze_mutex */
124         /* 22 bytes hole */
125
126         /* The 3rd and 4th cacheline with misc members to avoid false sharing
127          * particularly with refcounting.
128          */
129         atomic64_t refcnt ____cacheline_aligned;
130         atomic64_t usercnt;
131         struct work_struct work;
132         struct mutex freeze_mutex;
133         u64 writecnt; /* writable mmap cnt; protected by freeze_mutex */
134 };
135
136 static inline bool map_value_has_spin_lock(const struct bpf_map *map)
137 {
138         return map->spin_lock_off >= 0;
139 }
140
141 static inline void check_and_init_map_lock(struct bpf_map *map, void *dst)
142 {
143         if (likely(!map_value_has_spin_lock(map)))
144                 return;
145         *(struct bpf_spin_lock *)(dst + map->spin_lock_off) =
146                 (struct bpf_spin_lock){};
147 }
148
149 /* copy everything but bpf_spin_lock */
150 static inline void copy_map_value(struct bpf_map *map, void *dst, void *src)
151 {
152         if (unlikely(map_value_has_spin_lock(map))) {
153                 u32 off = map->spin_lock_off;
154
155                 memcpy(dst, src, off);
156                 memcpy(dst + off + sizeof(struct bpf_spin_lock),
157                        src + off + sizeof(struct bpf_spin_lock),
158                        map->value_size - off - sizeof(struct bpf_spin_lock));
159         } else {
160                 memcpy(dst, src, map->value_size);
161         }
162 }
163 void copy_map_value_locked(struct bpf_map *map, void *dst, void *src,
164                            bool lock_src);
165 int bpf_obj_name_cpy(char *dst, const char *src, unsigned int size);
166
167 struct bpf_offload_dev;
168 struct bpf_offloaded_map;
169
170 struct bpf_map_dev_ops {
171         int (*map_get_next_key)(struct bpf_offloaded_map *map,
172                                 void *key, void *next_key);
173         int (*map_lookup_elem)(struct bpf_offloaded_map *map,
174                                void *key, void *value);
175         int (*map_update_elem)(struct bpf_offloaded_map *map,
176                                void *key, void *value, u64 flags);
177         int (*map_delete_elem)(struct bpf_offloaded_map *map, void *key);
178 };
179
180 struct bpf_offloaded_map {
181         struct bpf_map map;
182         struct net_device *netdev;
183         const struct bpf_map_dev_ops *dev_ops;
184         void *dev_priv;
185         struct list_head offloads;
186 };
187
188 static inline struct bpf_offloaded_map *map_to_offmap(struct bpf_map *map)
189 {
190         return container_of(map, struct bpf_offloaded_map, map);
191 }
192
193 static inline bool bpf_map_offload_neutral(const struct bpf_map *map)
194 {
195         return map->map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY;
196 }
197
198 static inline bool bpf_map_support_seq_show(const struct bpf_map *map)
199 {
200         return (map->btf_value_type_id || map->btf_vmlinux_value_type_id) &&
201                 map->ops->map_seq_show_elem;
202 }
203
204 int map_check_no_btf(const struct bpf_map *map,
205                      const struct btf *btf,
206                      const struct btf_type *key_type,
207                      const struct btf_type *value_type);
208
209 extern const struct bpf_map_ops bpf_map_offload_ops;
210
211 /* function argument constraints */
212 enum bpf_arg_type {
213         ARG_DONTCARE = 0,       /* unused argument in helper function */
214
215         /* the following constraints used to prototype
216          * bpf_map_lookup/update/delete_elem() functions
217          */
218         ARG_CONST_MAP_PTR,      /* const argument used as pointer to bpf_map */
219         ARG_PTR_TO_MAP_KEY,     /* pointer to stack used as map key */
220         ARG_PTR_TO_MAP_VALUE,   /* pointer to stack used as map value */
221         ARG_PTR_TO_UNINIT_MAP_VALUE,    /* pointer to valid memory used to store a map value */
222         ARG_PTR_TO_MAP_VALUE_OR_NULL,   /* pointer to stack used as map value or NULL */
223
224         /* the following constraints used to prototype bpf_memcmp() and other
225          * functions that access data on eBPF program stack
226          */
227         ARG_PTR_TO_MEM,         /* pointer to valid memory (stack, packet, map value) */
228         ARG_PTR_TO_MEM_OR_NULL, /* pointer to valid memory or NULL */
229         ARG_PTR_TO_UNINIT_MEM,  /* pointer to memory does not need to be initialized,
230                                  * helper function must fill all bytes or clear
231                                  * them in error case.
232                                  */
233
234         ARG_CONST_SIZE,         /* number of bytes accessed from memory */
235         ARG_CONST_SIZE_OR_ZERO, /* number of bytes accessed from memory or 0 */
236
237         ARG_PTR_TO_CTX,         /* pointer to context */
238         ARG_PTR_TO_CTX_OR_NULL, /* pointer to context or NULL */
239         ARG_ANYTHING,           /* any (initialized) argument is ok */
240         ARG_PTR_TO_SPIN_LOCK,   /* pointer to bpf_spin_lock */
241         ARG_PTR_TO_SOCK_COMMON, /* pointer to sock_common */
242         ARG_PTR_TO_INT,         /* pointer to int */
243         ARG_PTR_TO_LONG,        /* pointer to long */
244         ARG_PTR_TO_SOCKET,      /* pointer to bpf_sock (fullsock) */
245         ARG_PTR_TO_BTF_ID,      /* pointer to in-kernel struct */
246 };
247
248 /* type of values returned from helper functions */
249 enum bpf_return_type {
250         RET_INTEGER,                    /* function returns integer */
251         RET_VOID,                       /* function doesn't return anything */
252         RET_PTR_TO_MAP_VALUE,           /* returns a pointer to map elem value */
253         RET_PTR_TO_MAP_VALUE_OR_NULL,   /* returns a pointer to map elem value or NULL */
254         RET_PTR_TO_SOCKET_OR_NULL,      /* returns a pointer to a socket or NULL */
255         RET_PTR_TO_TCP_SOCK_OR_NULL,    /* returns a pointer to a tcp_sock or NULL */
256         RET_PTR_TO_SOCK_COMMON_OR_NULL, /* returns a pointer to a sock_common or NULL */
257 };
258
259 /* eBPF function prototype used by verifier to allow BPF_CALLs from eBPF programs
260  * to in-kernel helper functions and for adjusting imm32 field in BPF_CALL
261  * instructions after verifying
262  */
263 struct bpf_func_proto {
264         u64 (*func)(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
265         bool gpl_only;
266         bool pkt_access;
267         enum bpf_return_type ret_type;
268         union {
269                 struct {
270                         enum bpf_arg_type arg1_type;
271                         enum bpf_arg_type arg2_type;
272                         enum bpf_arg_type arg3_type;
273                         enum bpf_arg_type arg4_type;
274                         enum bpf_arg_type arg5_type;
275                 };
276                 enum bpf_arg_type arg_type[5];
277         };
278         int *btf_id; /* BTF ids of arguments */
279 };
280
281 /* bpf_context is intentionally undefined structure. Pointer to bpf_context is
282  * the first argument to eBPF programs.
283  * For socket filters: 'struct bpf_context *' == 'struct sk_buff *'
284  */
285 struct bpf_context;
286
287 enum bpf_access_type {
288         BPF_READ = 1,
289         BPF_WRITE = 2
290 };
291
292 /* types of values stored in eBPF registers */
293 /* Pointer types represent:
294  * pointer
295  * pointer + imm
296  * pointer + (u16) var
297  * pointer + (u16) var + imm
298  * if (range > 0) then [ptr, ptr + range - off) is safe to access
299  * if (id > 0) means that some 'var' was added
300  * if (off > 0) means that 'imm' was added
301  */
302 enum bpf_reg_type {
303         NOT_INIT = 0,            /* nothing was written into register */
304         SCALAR_VALUE,            /* reg doesn't contain a valid pointer */
305         PTR_TO_CTX,              /* reg points to bpf_context */
306         CONST_PTR_TO_MAP,        /* reg points to struct bpf_map */
307         PTR_TO_MAP_VALUE,        /* reg points to map element value */
308         PTR_TO_MAP_VALUE_OR_NULL,/* points to map elem value or NULL */
309         PTR_TO_STACK,            /* reg == frame_pointer + offset */
310         PTR_TO_PACKET_META,      /* skb->data - meta_len */
311         PTR_TO_PACKET,           /* reg points to skb->data */
312         PTR_TO_PACKET_END,       /* skb->data + headlen */
313         PTR_TO_FLOW_KEYS,        /* reg points to bpf_flow_keys */
314         PTR_TO_SOCKET,           /* reg points to struct bpf_sock */
315         PTR_TO_SOCKET_OR_NULL,   /* reg points to struct bpf_sock or NULL */
316         PTR_TO_SOCK_COMMON,      /* reg points to sock_common */
317         PTR_TO_SOCK_COMMON_OR_NULL, /* reg points to sock_common or NULL */
318         PTR_TO_TCP_SOCK,         /* reg points to struct tcp_sock */
319         PTR_TO_TCP_SOCK_OR_NULL, /* reg points to struct tcp_sock or NULL */
320         PTR_TO_TP_BUFFER,        /* reg points to a writable raw tp's buffer */
321         PTR_TO_XDP_SOCK,         /* reg points to struct xdp_sock */
322         PTR_TO_BTF_ID,           /* reg points to kernel struct */
323 };
324
325 /* The information passed from prog-specific *_is_valid_access
326  * back to the verifier.
327  */
328 struct bpf_insn_access_aux {
329         enum bpf_reg_type reg_type;
330         union {
331                 int ctx_field_size;
332                 u32 btf_id;
333         };
334         struct bpf_verifier_log *log; /* for verbose logs */
335 };
336
337 static inline void
338 bpf_ctx_record_field_size(struct bpf_insn_access_aux *aux, u32 size)
339 {
340         aux->ctx_field_size = size;
341 }
342
343 struct bpf_prog_ops {
344         int (*test_run)(struct bpf_prog *prog, const union bpf_attr *kattr,
345                         union bpf_attr __user *uattr);
346 };
347
348 struct bpf_verifier_ops {
349         /* return eBPF function prototype for verification */
350         const struct bpf_func_proto *
351         (*get_func_proto)(enum bpf_func_id func_id,
352                           const struct bpf_prog *prog);
353
354         /* return true if 'size' wide access at offset 'off' within bpf_context
355          * with 'type' (read or write) is allowed
356          */
357         bool (*is_valid_access)(int off, int size, enum bpf_access_type type,
358                                 const struct bpf_prog *prog,
359                                 struct bpf_insn_access_aux *info);
360         int (*gen_prologue)(struct bpf_insn *insn, bool direct_write,
361                             const struct bpf_prog *prog);
362         int (*gen_ld_abs)(const struct bpf_insn *orig,
363                           struct bpf_insn *insn_buf);
364         u32 (*convert_ctx_access)(enum bpf_access_type type,
365                                   const struct bpf_insn *src,
366                                   struct bpf_insn *dst,
367                                   struct bpf_prog *prog, u32 *target_size);
368         int (*btf_struct_access)(struct bpf_verifier_log *log,
369                                  const struct btf_type *t, int off, int size,
370                                  enum bpf_access_type atype,
371                                  u32 *next_btf_id);
372 };
373
374 struct bpf_prog_offload_ops {
375         /* verifier basic callbacks */
376         int (*insn_hook)(struct bpf_verifier_env *env,
377                          int insn_idx, int prev_insn_idx);
378         int (*finalize)(struct bpf_verifier_env *env);
379         /* verifier optimization callbacks (called after .finalize) */
380         int (*replace_insn)(struct bpf_verifier_env *env, u32 off,
381                             struct bpf_insn *insn);
382         int (*remove_insns)(struct bpf_verifier_env *env, u32 off, u32 cnt);
383         /* program management callbacks */
384         int (*prepare)(struct bpf_prog *prog);
385         int (*translate)(struct bpf_prog *prog);
386         void (*destroy)(struct bpf_prog *prog);
387 };
388
389 struct bpf_prog_offload {
390         struct bpf_prog         *prog;
391         struct net_device       *netdev;
392         struct bpf_offload_dev  *offdev;
393         void                    *dev_priv;
394         struct list_head        offloads;
395         bool                    dev_state;
396         bool                    opt_failed;
397         void                    *jited_image;
398         u32                     jited_len;
399 };
400
401 enum bpf_cgroup_storage_type {
402         BPF_CGROUP_STORAGE_SHARED,
403         BPF_CGROUP_STORAGE_PERCPU,
404         __BPF_CGROUP_STORAGE_MAX
405 };
406
407 #define MAX_BPF_CGROUP_STORAGE_TYPE __BPF_CGROUP_STORAGE_MAX
408
409 /* The longest tracepoint has 12 args.
410  * See include/trace/bpf_probe.h
411  */
412 #define MAX_BPF_FUNC_ARGS 12
413
414 struct bpf_prog_stats {
415         u64 cnt;
416         u64 nsecs;
417         struct u64_stats_sync syncp;
418 } __aligned(2 * sizeof(u64));
419
420 struct btf_func_model {
421         u8 ret_size;
422         u8 nr_args;
423         u8 arg_size[MAX_BPF_FUNC_ARGS];
424 };
425
426 /* Restore arguments before returning from trampoline to let original function
427  * continue executing. This flag is used for fentry progs when there are no
428  * fexit progs.
429  */
430 #define BPF_TRAMP_F_RESTORE_REGS        BIT(0)
431 /* Call original function after fentry progs, but before fexit progs.
432  * Makes sense for fentry/fexit, normal calls and indirect calls.
433  */
434 #define BPF_TRAMP_F_CALL_ORIG           BIT(1)
435 /* Skip current frame and return to parent.  Makes sense for fentry/fexit
436  * programs only. Should not be used with normal calls and indirect calls.
437  */
438 #define BPF_TRAMP_F_SKIP_FRAME          BIT(2)
439
440 /* Each call __bpf_prog_enter + call bpf_func + call __bpf_prog_exit is ~50
441  * bytes on x86.  Pick a number to fit into BPF_IMAGE_SIZE / 2
442  */
443 #define BPF_MAX_TRAMP_PROGS 40
444
445 struct bpf_tramp_progs {
446         struct bpf_prog *progs[BPF_MAX_TRAMP_PROGS];
447         int nr_progs;
448 };
449
450 /* Different use cases for BPF trampoline:
451  * 1. replace nop at the function entry (kprobe equivalent)
452  *    flags = BPF_TRAMP_F_RESTORE_REGS
453  *    fentry = a set of programs to run before returning from trampoline
454  *
455  * 2. replace nop at the function entry (kprobe + kretprobe equivalent)
456  *    flags = BPF_TRAMP_F_CALL_ORIG | BPF_TRAMP_F_SKIP_FRAME
457  *    orig_call = fentry_ip + MCOUNT_INSN_SIZE
458  *    fentry = a set of program to run before calling original function
459  *    fexit = a set of program to run after original function
460  *
461  * 3. replace direct call instruction anywhere in the function body
462  *    or assign a function pointer for indirect call (like tcp_congestion_ops->cong_avoid)
463  *    With flags = 0
464  *      fentry = a set of programs to run before returning from trampoline
465  *    With flags = BPF_TRAMP_F_CALL_ORIG
466  *      orig_call = original callback addr or direct function addr
467  *      fentry = a set of program to run before calling original function
468  *      fexit = a set of program to run after original function
469  */
470 int arch_prepare_bpf_trampoline(void *image, void *image_end,
471                                 const struct btf_func_model *m, u32 flags,
472                                 struct bpf_tramp_progs *tprogs,
473                                 void *orig_call);
474 /* these two functions are called from generated trampoline */
475 u64 notrace __bpf_prog_enter(void);
476 void notrace __bpf_prog_exit(struct bpf_prog *prog, u64 start);
477
478 struct bpf_ksym {
479         unsigned long            start;
480         unsigned long            end;
481         char                     name[KSYM_NAME_LEN];
482         struct list_head         lnode;
483         struct latch_tree_node   tnode;
484         bool                     prog;
485 };
486
487 enum bpf_tramp_prog_type {
488         BPF_TRAMP_FENTRY,
489         BPF_TRAMP_FEXIT,
490         BPF_TRAMP_MODIFY_RETURN,
491         BPF_TRAMP_MAX,
492         BPF_TRAMP_REPLACE, /* more than MAX */
493 };
494
495 struct bpf_trampoline {
496         /* hlist for trampoline_table */
497         struct hlist_node hlist;
498         /* serializes access to fields of this trampoline */
499         struct mutex mutex;
500         refcount_t refcnt;
501         u64 key;
502         struct {
503                 struct btf_func_model model;
504                 void *addr;
505                 bool ftrace_managed;
506         } func;
507         /* if !NULL this is BPF_PROG_TYPE_EXT program that extends another BPF
508          * program by replacing one of its functions. func.addr is the address
509          * of the function it replaced.
510          */
511         struct bpf_prog *extension_prog;
512         /* list of BPF programs using this trampoline */
513         struct hlist_head progs_hlist[BPF_TRAMP_MAX];
514         /* Number of attached programs. A counter per kind. */
515         int progs_cnt[BPF_TRAMP_MAX];
516         /* Executable image of trampoline */
517         void *image;
518         u64 selector;
519         struct bpf_ksym ksym;
520 };
521
522 #define BPF_DISPATCHER_MAX 48 /* Fits in 2048B */
523
524 struct bpf_dispatcher_prog {
525         struct bpf_prog *prog;
526         refcount_t users;
527 };
528
529 struct bpf_dispatcher {
530         /* dispatcher mutex */
531         struct mutex mutex;
532         void *func;
533         struct bpf_dispatcher_prog progs[BPF_DISPATCHER_MAX];
534         int num_progs;
535         void *image;
536         u32 image_off;
537         struct bpf_ksym ksym;
538 };
539
540 static __always_inline unsigned int bpf_dispatcher_nop_func(
541         const void *ctx,
542         const struct bpf_insn *insnsi,
543         unsigned int (*bpf_func)(const void *,
544                                  const struct bpf_insn *))
545 {
546         return bpf_func(ctx, insnsi);
547 }
548 #ifdef CONFIG_BPF_JIT
549 struct bpf_trampoline *bpf_trampoline_lookup(u64 key);
550 int bpf_trampoline_link_prog(struct bpf_prog *prog);
551 int bpf_trampoline_unlink_prog(struct bpf_prog *prog);
552 void bpf_trampoline_put(struct bpf_trampoline *tr);
553 #define BPF_DISPATCHER_INIT(_name) {                            \
554         .mutex = __MUTEX_INITIALIZER(_name.mutex),              \
555         .func = &_name##_func,                                  \
556         .progs = {},                                            \
557         .num_progs = 0,                                         \
558         .image = NULL,                                          \
559         .image_off = 0,                                         \
560         .ksym = {                                               \
561                 .name  = #_name,                                \
562                 .lnode = LIST_HEAD_INIT(_name.ksym.lnode),      \
563         },                                                      \
564 }
565
566 #define DEFINE_BPF_DISPATCHER(name)                                     \
567         noinline unsigned int bpf_dispatcher_##name##_func(             \
568                 const void *ctx,                                        \
569                 const struct bpf_insn *insnsi,                          \
570                 unsigned int (*bpf_func)(const void *,                  \
571                                          const struct bpf_insn *))      \
572         {                                                               \
573                 return bpf_func(ctx, insnsi);                           \
574         }                                                               \
575         EXPORT_SYMBOL(bpf_dispatcher_##name##_func);                    \
576         struct bpf_dispatcher bpf_dispatcher_##name =                   \
577                 BPF_DISPATCHER_INIT(bpf_dispatcher_##name);
578 #define DECLARE_BPF_DISPATCHER(name)                                    \
579         unsigned int bpf_dispatcher_##name##_func(                      \
580                 const void *ctx,                                        \
581                 const struct bpf_insn *insnsi,                          \
582                 unsigned int (*bpf_func)(const void *,                  \
583                                          const struct bpf_insn *));     \
584         extern struct bpf_dispatcher bpf_dispatcher_##name;
585 #define BPF_DISPATCHER_FUNC(name) bpf_dispatcher_##name##_func
586 #define BPF_DISPATCHER_PTR(name) (&bpf_dispatcher_##name)
587 void bpf_dispatcher_change_prog(struct bpf_dispatcher *d, struct bpf_prog *from,
588                                 struct bpf_prog *to);
589 /* Called only from JIT-enabled code, so there's no need for stubs. */
590 void *bpf_jit_alloc_exec_page(void);
591 void bpf_image_ksym_add(void *data, struct bpf_ksym *ksym);
592 void bpf_image_ksym_del(struct bpf_ksym *ksym);
593 void bpf_ksym_add(struct bpf_ksym *ksym);
594 void bpf_ksym_del(struct bpf_ksym *ksym);
595 #else
596 static inline struct bpf_trampoline *bpf_trampoline_lookup(u64 key)
597 {
598         return NULL;
599 }
600 static inline int bpf_trampoline_link_prog(struct bpf_prog *prog)
601 {
602         return -ENOTSUPP;
603 }
604 static inline int bpf_trampoline_unlink_prog(struct bpf_prog *prog)
605 {
606         return -ENOTSUPP;
607 }
608 static inline void bpf_trampoline_put(struct bpf_trampoline *tr) {}
609 #define DEFINE_BPF_DISPATCHER(name)
610 #define DECLARE_BPF_DISPATCHER(name)
611 #define BPF_DISPATCHER_FUNC(name) bpf_dispatcher_nop_func
612 #define BPF_DISPATCHER_PTR(name) NULL
613 static inline void bpf_dispatcher_change_prog(struct bpf_dispatcher *d,
614                                               struct bpf_prog *from,
615                                               struct bpf_prog *to) {}
616 static inline bool is_bpf_image_address(unsigned long address)
617 {
618         return false;
619 }
620 #endif
621
622 struct bpf_func_info_aux {
623         u16 linkage;
624         bool unreliable;
625 };
626
627 enum bpf_jit_poke_reason {
628         BPF_POKE_REASON_TAIL_CALL,
629 };
630
631 /* Descriptor of pokes pointing /into/ the JITed image. */
632 struct bpf_jit_poke_descriptor {
633         void *ip;
634         union {
635                 struct {
636                         struct bpf_map *map;
637                         u32 key;
638                 } tail_call;
639         };
640         bool ip_stable;
641         u8 adj_off;
642         u16 reason;
643 };
644
645 struct bpf_prog_aux {
646         atomic64_t refcnt;
647         u32 used_map_cnt;
648         u32 max_ctx_offset;
649         u32 max_pkt_offset;
650         u32 max_tp_access;
651         u32 stack_depth;
652         u32 id;
653         u32 func_cnt; /* used by non-func prog as the number of func progs */
654         u32 func_idx; /* 0 for non-func prog, the index in func array for func prog */
655         u32 attach_btf_id; /* in-kernel BTF type id to attach to */
656         struct bpf_prog *linked_prog;
657         bool verifier_zext; /* Zero extensions has been inserted by verifier. */
658         bool offload_requested;
659         bool attach_btf_trace; /* true if attaching to BTF-enabled raw tp */
660         bool func_proto_unreliable;
661         enum bpf_tramp_prog_type trampoline_prog_type;
662         struct bpf_trampoline *trampoline;
663         struct hlist_node tramp_hlist;
664         /* BTF_KIND_FUNC_PROTO for valid attach_btf_id */
665         const struct btf_type *attach_func_proto;
666         /* function name for valid attach_btf_id */
667         const char *attach_func_name;
668         struct bpf_prog **func;
669         void *jit_data; /* JIT specific data. arch dependent */
670         struct bpf_jit_poke_descriptor *poke_tab;
671         u32 size_poke_tab;
672         struct bpf_ksym ksym;
673         const struct bpf_prog_ops *ops;
674         struct bpf_map **used_maps;
675         struct bpf_prog *prog;
676         struct user_struct *user;
677         u64 load_time; /* ns since boottime */
678         struct bpf_map *cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE];
679         char name[BPF_OBJ_NAME_LEN];
680 #ifdef CONFIG_SECURITY
681         void *security;
682 #endif
683         struct bpf_prog_offload *offload;
684         struct btf *btf;
685         struct bpf_func_info *func_info;
686         struct bpf_func_info_aux *func_info_aux;
687         /* bpf_line_info loaded from userspace.  linfo->insn_off
688          * has the xlated insn offset.
689          * Both the main and sub prog share the same linfo.
690          * The subprog can access its first linfo by
691          * using the linfo_idx.
692          */
693         struct bpf_line_info *linfo;
694         /* jited_linfo is the jited addr of the linfo.  It has a
695          * one to one mapping to linfo:
696          * jited_linfo[i] is the jited addr for the linfo[i]->insn_off.
697          * Both the main and sub prog share the same jited_linfo.
698          * The subprog can access its first jited_linfo by
699          * using the linfo_idx.
700          */
701         void **jited_linfo;
702         u32 func_info_cnt;
703         u32 nr_linfo;
704         /* subprog can use linfo_idx to access its first linfo and
705          * jited_linfo.
706          * main prog always has linfo_idx == 0
707          */
708         u32 linfo_idx;
709         u32 num_exentries;
710         struct exception_table_entry *extable;
711         struct bpf_prog_stats __percpu *stats;
712         union {
713                 struct work_struct work;
714                 struct rcu_head rcu;
715         };
716 };
717
718 struct bpf_array_aux {
719         /* 'Ownership' of prog array is claimed by the first program that
720          * is going to use this map or by the first program which FD is
721          * stored in the map to make sure that all callers and callees have
722          * the same prog type and JITed flag.
723          */
724         enum bpf_prog_type type;
725         bool jited;
726         /* Programs with direct jumps into programs part of this array. */
727         struct list_head poke_progs;
728         struct bpf_map *map;
729         struct mutex poke_mutex;
730         struct work_struct work;
731 };
732
733 struct bpf_struct_ops_value;
734 struct btf_type;
735 struct btf_member;
736
737 #define BPF_STRUCT_OPS_MAX_NR_MEMBERS 64
738 struct bpf_struct_ops {
739         const struct bpf_verifier_ops *verifier_ops;
740         int (*init)(struct btf *btf);
741         int (*check_member)(const struct btf_type *t,
742                             const struct btf_member *member);
743         int (*init_member)(const struct btf_type *t,
744                            const struct btf_member *member,
745                            void *kdata, const void *udata);
746         int (*reg)(void *kdata);
747         void (*unreg)(void *kdata);
748         const struct btf_type *type;
749         const struct btf_type *value_type;
750         const char *name;
751         struct btf_func_model func_models[BPF_STRUCT_OPS_MAX_NR_MEMBERS];
752         u32 type_id;
753         u32 value_id;
754 };
755
756 #if defined(CONFIG_BPF_JIT) && defined(CONFIG_BPF_SYSCALL)
757 #define BPF_MODULE_OWNER ((void *)((0xeB9FUL << 2) + POISON_POINTER_DELTA))
758 const struct bpf_struct_ops *bpf_struct_ops_find(u32 type_id);
759 void bpf_struct_ops_init(struct btf *btf, struct bpf_verifier_log *log);
760 bool bpf_struct_ops_get(const void *kdata);
761 void bpf_struct_ops_put(const void *kdata);
762 int bpf_struct_ops_map_sys_lookup_elem(struct bpf_map *map, void *key,
763                                        void *value);
764 static inline bool bpf_try_module_get(const void *data, struct module *owner)
765 {
766         if (owner == BPF_MODULE_OWNER)
767                 return bpf_struct_ops_get(data);
768         else
769                 return try_module_get(owner);
770 }
771 static inline void bpf_module_put(const void *data, struct module *owner)
772 {
773         if (owner == BPF_MODULE_OWNER)
774                 bpf_struct_ops_put(data);
775         else
776                 module_put(owner);
777 }
778 #else
779 static inline const struct bpf_struct_ops *bpf_struct_ops_find(u32 type_id)
780 {
781         return NULL;
782 }
783 static inline void bpf_struct_ops_init(struct btf *btf,
784                                        struct bpf_verifier_log *log)
785 {
786 }
787 static inline bool bpf_try_module_get(const void *data, struct module *owner)
788 {
789         return try_module_get(owner);
790 }
791 static inline void bpf_module_put(const void *data, struct module *owner)
792 {
793         module_put(owner);
794 }
795 static inline int bpf_struct_ops_map_sys_lookup_elem(struct bpf_map *map,
796                                                      void *key,
797                                                      void *value)
798 {
799         return -EINVAL;
800 }
801 #endif
802
803 struct bpf_array {
804         struct bpf_map map;
805         u32 elem_size;
806         u32 index_mask;
807         struct bpf_array_aux *aux;
808         union {
809                 char value[0] __aligned(8);
810                 void *ptrs[0] __aligned(8);
811                 void __percpu *pptrs[0] __aligned(8);
812         };
813 };
814
815 #define BPF_COMPLEXITY_LIMIT_INSNS      1000000 /* yes. 1M insns */
816 #define MAX_TAIL_CALL_CNT 32
817
818 #define BPF_F_ACCESS_MASK       (BPF_F_RDONLY |         \
819                                  BPF_F_RDONLY_PROG |    \
820                                  BPF_F_WRONLY |         \
821                                  BPF_F_WRONLY_PROG)
822
823 #define BPF_MAP_CAN_READ        BIT(0)
824 #define BPF_MAP_CAN_WRITE       BIT(1)
825
826 static inline u32 bpf_map_flags_to_cap(struct bpf_map *map)
827 {
828         u32 access_flags = map->map_flags & (BPF_F_RDONLY_PROG | BPF_F_WRONLY_PROG);
829
830         /* Combination of BPF_F_RDONLY_PROG | BPF_F_WRONLY_PROG is
831          * not possible.
832          */
833         if (access_flags & BPF_F_RDONLY_PROG)
834                 return BPF_MAP_CAN_READ;
835         else if (access_flags & BPF_F_WRONLY_PROG)
836                 return BPF_MAP_CAN_WRITE;
837         else
838                 return BPF_MAP_CAN_READ | BPF_MAP_CAN_WRITE;
839 }
840
841 static inline bool bpf_map_flags_access_ok(u32 access_flags)
842 {
843         return (access_flags & (BPF_F_RDONLY_PROG | BPF_F_WRONLY_PROG)) !=
844                (BPF_F_RDONLY_PROG | BPF_F_WRONLY_PROG);
845 }
846
847 struct bpf_event_entry {
848         struct perf_event *event;
849         struct file *perf_file;
850         struct file *map_file;
851         struct rcu_head rcu;
852 };
853
854 bool bpf_prog_array_compatible(struct bpf_array *array, const struct bpf_prog *fp);
855 int bpf_prog_calc_tag(struct bpf_prog *fp);
856 const char *kernel_type_name(u32 btf_type_id);
857
858 const struct bpf_func_proto *bpf_get_trace_printk_proto(void);
859
860 typedef unsigned long (*bpf_ctx_copy_t)(void *dst, const void *src,
861                                         unsigned long off, unsigned long len);
862 typedef u32 (*bpf_convert_ctx_access_t)(enum bpf_access_type type,
863                                         const struct bpf_insn *src,
864                                         struct bpf_insn *dst,
865                                         struct bpf_prog *prog,
866                                         u32 *target_size);
867
868 u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
869                      void *ctx, u64 ctx_size, bpf_ctx_copy_t ctx_copy);
870
871 /* an array of programs to be executed under rcu_lock.
872  *
873  * Typical usage:
874  * ret = BPF_PROG_RUN_ARRAY(&bpf_prog_array, ctx, BPF_PROG_RUN);
875  *
876  * the structure returned by bpf_prog_array_alloc() should be populated
877  * with program pointers and the last pointer must be NULL.
878  * The user has to keep refcnt on the program and make sure the program
879  * is removed from the array before bpf_prog_put().
880  * The 'struct bpf_prog_array *' should only be replaced with xchg()
881  * since other cpus are walking the array of pointers in parallel.
882  */
883 struct bpf_prog_array_item {
884         struct bpf_prog *prog;
885         struct bpf_cgroup_storage *cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE];
886 };
887
888 struct bpf_prog_array {
889         struct rcu_head rcu;
890         struct bpf_prog_array_item items[];
891 };
892
893 struct bpf_prog_array *bpf_prog_array_alloc(u32 prog_cnt, gfp_t flags);
894 void bpf_prog_array_free(struct bpf_prog_array *progs);
895 int bpf_prog_array_length(struct bpf_prog_array *progs);
896 bool bpf_prog_array_is_empty(struct bpf_prog_array *array);
897 int bpf_prog_array_copy_to_user(struct bpf_prog_array *progs,
898                                 __u32 __user *prog_ids, u32 cnt);
899
900 void bpf_prog_array_delete_safe(struct bpf_prog_array *progs,
901                                 struct bpf_prog *old_prog);
902 int bpf_prog_array_copy_info(struct bpf_prog_array *array,
903                              u32 *prog_ids, u32 request_cnt,
904                              u32 *prog_cnt);
905 int bpf_prog_array_copy(struct bpf_prog_array *old_array,
906                         struct bpf_prog *exclude_prog,
907                         struct bpf_prog *include_prog,
908                         struct bpf_prog_array **new_array);
909
910 #define __BPF_PROG_RUN_ARRAY(array, ctx, func, check_non_null)  \
911         ({                                              \
912                 struct bpf_prog_array_item *_item;      \
913                 struct bpf_prog *_prog;                 \
914                 struct bpf_prog_array *_array;          \
915                 u32 _ret = 1;                           \
916                 migrate_disable();                      \
917                 rcu_read_lock();                        \
918                 _array = rcu_dereference(array);        \
919                 if (unlikely(check_non_null && !_array))\
920                         goto _out;                      \
921                 _item = &_array->items[0];              \
922                 while ((_prog = READ_ONCE(_item->prog))) {              \
923                         bpf_cgroup_storage_set(_item->cgroup_storage);  \
924                         _ret &= func(_prog, ctx);       \
925                         _item++;                        \
926                 }                                       \
927 _out:                                                   \
928                 rcu_read_unlock();                      \
929                 migrate_enable();                       \
930                 _ret;                                   \
931          })
932
933 /* To be used by __cgroup_bpf_run_filter_skb for EGRESS BPF progs
934  * so BPF programs can request cwr for TCP packets.
935  *
936  * Current cgroup skb programs can only return 0 or 1 (0 to drop the
937  * packet. This macro changes the behavior so the low order bit
938  * indicates whether the packet should be dropped (0) or not (1)
939  * and the next bit is a congestion notification bit. This could be
940  * used by TCP to call tcp_enter_cwr()
941  *
942  * Hence, new allowed return values of CGROUP EGRESS BPF programs are:
943  *   0: drop packet
944  *   1: keep packet
945  *   2: drop packet and cn
946  *   3: keep packet and cn
947  *
948  * This macro then converts it to one of the NET_XMIT or an error
949  * code that is then interpreted as drop packet (and no cn):
950  *   0: NET_XMIT_SUCCESS  skb should be transmitted
951  *   1: NET_XMIT_DROP     skb should be dropped and cn
952  *   2: NET_XMIT_CN       skb should be transmitted and cn
953  *   3: -EPERM            skb should be dropped
954  */
955 #define BPF_PROG_CGROUP_INET_EGRESS_RUN_ARRAY(array, ctx, func)         \
956         ({                                              \
957                 struct bpf_prog_array_item *_item;      \
958                 struct bpf_prog *_prog;                 \
959                 struct bpf_prog_array *_array;          \
960                 u32 ret;                                \
961                 u32 _ret = 1;                           \
962                 u32 _cn = 0;                            \
963                 migrate_disable();                      \
964                 rcu_read_lock();                        \
965                 _array = rcu_dereference(array);        \
966                 _item = &_array->items[0];              \
967                 while ((_prog = READ_ONCE(_item->prog))) {              \
968                         bpf_cgroup_storage_set(_item->cgroup_storage);  \
969                         ret = func(_prog, ctx);         \
970                         _ret &= (ret & 1);              \
971                         _cn |= (ret & 2);               \
972                         _item++;                        \
973                 }                                       \
974                 rcu_read_unlock();                      \
975                 migrate_enable();                       \
976                 if (_ret)                               \
977                         _ret = (_cn ? NET_XMIT_CN : NET_XMIT_SUCCESS);  \
978                 else                                    \
979                         _ret = (_cn ? NET_XMIT_DROP : -EPERM);          \
980                 _ret;                                   \
981         })
982
983 #define BPF_PROG_RUN_ARRAY(array, ctx, func)            \
984         __BPF_PROG_RUN_ARRAY(array, ctx, func, false)
985
986 #define BPF_PROG_RUN_ARRAY_CHECK(array, ctx, func)      \
987         __BPF_PROG_RUN_ARRAY(array, ctx, func, true)
988
989 #ifdef CONFIG_BPF_SYSCALL
990 DECLARE_PER_CPU(int, bpf_prog_active);
991 extern struct mutex bpf_stats_enabled_mutex;
992
993 /*
994  * Block execution of BPF programs attached to instrumentation (perf,
995  * kprobes, tracepoints) to prevent deadlocks on map operations as any of
996  * these events can happen inside a region which holds a map bucket lock
997  * and can deadlock on it.
998  *
999  * Use the preemption safe inc/dec variants on RT because migrate disable
1000  * is preemptible on RT and preemption in the middle of the RMW operation
1001  * might lead to inconsistent state. Use the raw variants for non RT
1002  * kernels as migrate_disable() maps to preempt_disable() so the slightly
1003  * more expensive save operation can be avoided.
1004  */
1005 static inline void bpf_disable_instrumentation(void)
1006 {
1007         migrate_disable();
1008         if (IS_ENABLED(CONFIG_PREEMPT_RT))
1009                 this_cpu_inc(bpf_prog_active);
1010         else
1011                 __this_cpu_inc(bpf_prog_active);
1012 }
1013
1014 static inline void bpf_enable_instrumentation(void)
1015 {
1016         if (IS_ENABLED(CONFIG_PREEMPT_RT))
1017                 this_cpu_dec(bpf_prog_active);
1018         else
1019                 __this_cpu_dec(bpf_prog_active);
1020         migrate_enable();
1021 }
1022
1023 extern const struct file_operations bpf_map_fops;
1024 extern const struct file_operations bpf_prog_fops;
1025 extern const struct file_operations bpf_iter_fops;
1026
1027 #define BPF_PROG_TYPE(_id, _name, prog_ctx_type, kern_ctx_type) \
1028         extern const struct bpf_prog_ops _name ## _prog_ops; \
1029         extern const struct bpf_verifier_ops _name ## _verifier_ops;
1030 #define BPF_MAP_TYPE(_id, _ops) \
1031         extern const struct bpf_map_ops _ops;
1032 #define BPF_LINK_TYPE(_id, _name)
1033 #include <linux/bpf_types.h>
1034 #undef BPF_PROG_TYPE
1035 #undef BPF_MAP_TYPE
1036 #undef BPF_LINK_TYPE
1037
1038 extern const struct bpf_prog_ops bpf_offload_prog_ops;
1039 extern const struct bpf_verifier_ops tc_cls_act_analyzer_ops;
1040 extern const struct bpf_verifier_ops xdp_analyzer_ops;
1041
1042 struct bpf_prog *bpf_prog_get(u32 ufd);
1043 struct bpf_prog *bpf_prog_get_type_dev(u32 ufd, enum bpf_prog_type type,
1044                                        bool attach_drv);
1045 void bpf_prog_add(struct bpf_prog *prog, int i);
1046 void bpf_prog_sub(struct bpf_prog *prog, int i);
1047 void bpf_prog_inc(struct bpf_prog *prog);
1048 struct bpf_prog * __must_check bpf_prog_inc_not_zero(struct bpf_prog *prog);
1049 void bpf_prog_put(struct bpf_prog *prog);
1050 int __bpf_prog_charge(struct user_struct *user, u32 pages);
1051 void __bpf_prog_uncharge(struct user_struct *user, u32 pages);
1052 void __bpf_free_used_maps(struct bpf_prog_aux *aux,
1053                           struct bpf_map **used_maps, u32 len);
1054
1055 void bpf_prog_free_id(struct bpf_prog *prog, bool do_idr_lock);
1056 void bpf_map_free_id(struct bpf_map *map, bool do_idr_lock);
1057
1058 struct bpf_map *bpf_map_get(u32 ufd);
1059 struct bpf_map *bpf_map_get_with_uref(u32 ufd);
1060 struct bpf_map *__bpf_map_get(struct fd f);
1061 void bpf_map_inc(struct bpf_map *map);
1062 void bpf_map_inc_with_uref(struct bpf_map *map);
1063 struct bpf_map * __must_check bpf_map_inc_not_zero(struct bpf_map *map);
1064 void bpf_map_put_with_uref(struct bpf_map *map);
1065 void bpf_map_put(struct bpf_map *map);
1066 int bpf_map_charge_memlock(struct bpf_map *map, u32 pages);
1067 void bpf_map_uncharge_memlock(struct bpf_map *map, u32 pages);
1068 int bpf_map_charge_init(struct bpf_map_memory *mem, u64 size);
1069 void bpf_map_charge_finish(struct bpf_map_memory *mem);
1070 void bpf_map_charge_move(struct bpf_map_memory *dst,
1071                          struct bpf_map_memory *src);
1072 void *bpf_map_area_alloc(u64 size, int numa_node);
1073 void *bpf_map_area_mmapable_alloc(u64 size, int numa_node);
1074 void bpf_map_area_free(void *base);
1075 void bpf_map_init_from_attr(struct bpf_map *map, union bpf_attr *attr);
1076 int  generic_map_lookup_batch(struct bpf_map *map,
1077                               const union bpf_attr *attr,
1078                               union bpf_attr __user *uattr);
1079 int  generic_map_update_batch(struct bpf_map *map,
1080                               const union bpf_attr *attr,
1081                               union bpf_attr __user *uattr);
1082 int  generic_map_delete_batch(struct bpf_map *map,
1083                               const union bpf_attr *attr,
1084                               union bpf_attr __user *uattr);
1085 struct bpf_map *bpf_map_get_curr_or_next(u32 *id);
1086
1087 extern int sysctl_unprivileged_bpf_disabled;
1088
1089 int bpf_map_new_fd(struct bpf_map *map, int flags);
1090 int bpf_prog_new_fd(struct bpf_prog *prog);
1091
1092 struct bpf_link {
1093         atomic64_t refcnt;
1094         u32 id;
1095         enum bpf_link_type type;
1096         const struct bpf_link_ops *ops;
1097         struct bpf_prog *prog;
1098         struct work_struct work;
1099 };
1100
1101 struct bpf_link_primer {
1102         struct bpf_link *link;
1103         struct file *file;
1104         int fd;
1105         u32 id;
1106 };
1107
1108 struct bpf_link_ops {
1109         void (*release)(struct bpf_link *link);
1110         void (*dealloc)(struct bpf_link *link);
1111         int (*update_prog)(struct bpf_link *link, struct bpf_prog *new_prog,
1112                            struct bpf_prog *old_prog);
1113         void (*show_fdinfo)(const struct bpf_link *link, struct seq_file *seq);
1114         int (*fill_link_info)(const struct bpf_link *link,
1115                               struct bpf_link_info *info);
1116 };
1117
1118 void bpf_link_init(struct bpf_link *link, enum bpf_link_type type,
1119                    const struct bpf_link_ops *ops, struct bpf_prog *prog);
1120 int bpf_link_prime(struct bpf_link *link, struct bpf_link_primer *primer);
1121 int bpf_link_settle(struct bpf_link_primer *primer);
1122 void bpf_link_cleanup(struct bpf_link_primer *primer);
1123 void bpf_link_inc(struct bpf_link *link);
1124 void bpf_link_put(struct bpf_link *link);
1125 int bpf_link_new_fd(struct bpf_link *link);
1126 struct file *bpf_link_new_file(struct bpf_link *link, int *reserved_fd);
1127 struct bpf_link *bpf_link_get_from_fd(u32 ufd);
1128
1129 int bpf_obj_pin_user(u32 ufd, const char __user *pathname);
1130 int bpf_obj_get_user(const char __user *pathname, int flags);
1131
1132 #define BPF_ITER_FUNC_PREFIX "__bpf_iter__"
1133 #define DEFINE_BPF_ITER_FUNC(target, args...)                   \
1134         extern int __bpf_iter__ ## target(args);                \
1135         int __init __bpf_iter__ ## target(args) { return 0; }
1136
1137 typedef int (*bpf_iter_init_seq_priv_t)(void *private_data);
1138 typedef void (*bpf_iter_fini_seq_priv_t)(void *private_data);
1139
1140 struct bpf_iter_reg {
1141         const char *target;
1142         const struct seq_operations *seq_ops;
1143         bpf_iter_init_seq_priv_t init_seq_private;
1144         bpf_iter_fini_seq_priv_t fini_seq_private;
1145         u32 seq_priv_size;
1146 };
1147
1148 struct bpf_iter_meta {
1149         __bpf_md_ptr(struct seq_file *, seq);
1150         u64 session_id;
1151         u64 seq_num;
1152 };
1153
1154 int bpf_iter_reg_target(struct bpf_iter_reg *reg_info);
1155 void bpf_iter_unreg_target(const char *target);
1156 bool bpf_iter_prog_supported(struct bpf_prog *prog);
1157 int bpf_iter_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
1158 int bpf_iter_new_fd(struct bpf_link *link);
1159 bool bpf_link_is_iter(struct bpf_link *link);
1160 struct bpf_prog *bpf_iter_get_info(struct bpf_iter_meta *meta, bool in_stop);
1161 int bpf_iter_run_prog(struct bpf_prog *prog, void *ctx);
1162
1163 int bpf_percpu_hash_copy(struct bpf_map *map, void *key, void *value);
1164 int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value);
1165 int bpf_percpu_hash_update(struct bpf_map *map, void *key, void *value,
1166                            u64 flags);
1167 int bpf_percpu_array_update(struct bpf_map *map, void *key, void *value,
1168                             u64 flags);
1169
1170 int bpf_stackmap_copy(struct bpf_map *map, void *key, void *value);
1171
1172 int bpf_fd_array_map_update_elem(struct bpf_map *map, struct file *map_file,
1173                                  void *key, void *value, u64 map_flags);
1174 int bpf_fd_array_map_lookup_elem(struct bpf_map *map, void *key, u32 *value);
1175 int bpf_fd_htab_map_update_elem(struct bpf_map *map, struct file *map_file,
1176                                 void *key, void *value, u64 map_flags);
1177 int bpf_fd_htab_map_lookup_elem(struct bpf_map *map, void *key, u32 *value);
1178
1179 int bpf_get_file_flag(int flags);
1180 int bpf_check_uarg_tail_zero(void __user *uaddr, size_t expected_size,
1181                              size_t actual_size);
1182
1183 /* memcpy that is used with 8-byte aligned pointers, power-of-8 size and
1184  * forced to use 'long' read/writes to try to atomically copy long counters.
1185  * Best-effort only.  No barriers here, since it _will_ race with concurrent
1186  * updates from BPF programs. Called from bpf syscall and mostly used with
1187  * size 8 or 16 bytes, so ask compiler to inline it.
1188  */
1189 static inline void bpf_long_memcpy(void *dst, const void *src, u32 size)
1190 {
1191         const long *lsrc = src;
1192         long *ldst = dst;
1193
1194         size /= sizeof(long);
1195         while (size--)
1196                 *ldst++ = *lsrc++;
1197 }
1198
1199 /* verify correctness of eBPF program */
1200 int bpf_check(struct bpf_prog **fp, union bpf_attr *attr,
1201               union bpf_attr __user *uattr);
1202 void bpf_patch_call_args(struct bpf_insn *insn, u32 stack_depth);
1203
1204 /* Map specifics */
1205 struct xdp_buff;
1206 struct sk_buff;
1207
1208 struct bpf_dtab_netdev *__dev_map_lookup_elem(struct bpf_map *map, u32 key);
1209 struct bpf_dtab_netdev *__dev_map_hash_lookup_elem(struct bpf_map *map, u32 key);
1210 void __dev_flush(void);
1211 int dev_xdp_enqueue(struct net_device *dev, struct xdp_buff *xdp,
1212                     struct net_device *dev_rx);
1213 int dev_map_enqueue(struct bpf_dtab_netdev *dst, struct xdp_buff *xdp,
1214                     struct net_device *dev_rx);
1215 int dev_map_generic_redirect(struct bpf_dtab_netdev *dst, struct sk_buff *skb,
1216                              struct bpf_prog *xdp_prog);
1217
1218 struct bpf_cpu_map_entry *__cpu_map_lookup_elem(struct bpf_map *map, u32 key);
1219 void __cpu_map_flush(void);
1220 int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_buff *xdp,
1221                     struct net_device *dev_rx);
1222
1223 /* Return map's numa specified by userspace */
1224 static inline int bpf_map_attr_numa_node(const union bpf_attr *attr)
1225 {
1226         return (attr->map_flags & BPF_F_NUMA_NODE) ?
1227                 attr->numa_node : NUMA_NO_NODE;
1228 }
1229
1230 struct bpf_prog *bpf_prog_get_type_path(const char *name, enum bpf_prog_type type);
1231 int array_map_alloc_check(union bpf_attr *attr);
1232
1233 int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
1234                           union bpf_attr __user *uattr);
1235 int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
1236                           union bpf_attr __user *uattr);
1237 int bpf_prog_test_run_tracing(struct bpf_prog *prog,
1238                               const union bpf_attr *kattr,
1239                               union bpf_attr __user *uattr);
1240 int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
1241                                      const union bpf_attr *kattr,
1242                                      union bpf_attr __user *uattr);
1243 bool btf_ctx_access(int off, int size, enum bpf_access_type type,
1244                     const struct bpf_prog *prog,
1245                     struct bpf_insn_access_aux *info);
1246 int btf_struct_access(struct bpf_verifier_log *log,
1247                       const struct btf_type *t, int off, int size,
1248                       enum bpf_access_type atype,
1249                       u32 *next_btf_id);
1250 int btf_resolve_helper_id(struct bpf_verifier_log *log,
1251                           const struct bpf_func_proto *fn, int);
1252
1253 int btf_distill_func_proto(struct bpf_verifier_log *log,
1254                            struct btf *btf,
1255                            const struct btf_type *func_proto,
1256                            const char *func_name,
1257                            struct btf_func_model *m);
1258
1259 struct bpf_reg_state;
1260 int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog,
1261                              struct bpf_reg_state *regs);
1262 int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog,
1263                           struct bpf_reg_state *reg);
1264 int btf_check_type_match(struct bpf_verifier_env *env, struct bpf_prog *prog,
1265                          struct btf *btf, const struct btf_type *t);
1266
1267 struct bpf_prog *bpf_prog_by_id(u32 id);
1268
1269 const struct bpf_func_proto *bpf_base_func_proto(enum bpf_func_id func_id);
1270 #else /* !CONFIG_BPF_SYSCALL */
1271 static inline struct bpf_prog *bpf_prog_get(u32 ufd)
1272 {
1273         return ERR_PTR(-EOPNOTSUPP);
1274 }
1275
1276 static inline struct bpf_prog *bpf_prog_get_type_dev(u32 ufd,
1277                                                      enum bpf_prog_type type,
1278                                                      bool attach_drv)
1279 {
1280         return ERR_PTR(-EOPNOTSUPP);
1281 }
1282
1283 static inline void bpf_prog_add(struct bpf_prog *prog, int i)
1284 {
1285 }
1286
1287 static inline void bpf_prog_sub(struct bpf_prog *prog, int i)
1288 {
1289 }
1290
1291 static inline void bpf_prog_put(struct bpf_prog *prog)
1292 {
1293 }
1294
1295 static inline void bpf_prog_inc(struct bpf_prog *prog)
1296 {
1297 }
1298
1299 static inline struct bpf_prog *__must_check
1300 bpf_prog_inc_not_zero(struct bpf_prog *prog)
1301 {
1302         return ERR_PTR(-EOPNOTSUPP);
1303 }
1304
1305 static inline int __bpf_prog_charge(struct user_struct *user, u32 pages)
1306 {
1307         return 0;
1308 }
1309
1310 static inline void __bpf_prog_uncharge(struct user_struct *user, u32 pages)
1311 {
1312 }
1313
1314 static inline int bpf_obj_get_user(const char __user *pathname, int flags)
1315 {
1316         return -EOPNOTSUPP;
1317 }
1318
1319 static inline struct net_device  *__dev_map_lookup_elem(struct bpf_map *map,
1320                                                        u32 key)
1321 {
1322         return NULL;
1323 }
1324
1325 static inline struct net_device  *__dev_map_hash_lookup_elem(struct bpf_map *map,
1326                                                              u32 key)
1327 {
1328         return NULL;
1329 }
1330
1331 static inline void __dev_flush(void)
1332 {
1333 }
1334
1335 struct xdp_buff;
1336 struct bpf_dtab_netdev;
1337
1338 static inline
1339 int dev_xdp_enqueue(struct net_device *dev, struct xdp_buff *xdp,
1340                     struct net_device *dev_rx)
1341 {
1342         return 0;
1343 }
1344
1345 static inline
1346 int dev_map_enqueue(struct bpf_dtab_netdev *dst, struct xdp_buff *xdp,
1347                     struct net_device *dev_rx)
1348 {
1349         return 0;
1350 }
1351
1352 struct sk_buff;
1353
1354 static inline int dev_map_generic_redirect(struct bpf_dtab_netdev *dst,
1355                                            struct sk_buff *skb,
1356                                            struct bpf_prog *xdp_prog)
1357 {
1358         return 0;
1359 }
1360
1361 static inline
1362 struct bpf_cpu_map_entry *__cpu_map_lookup_elem(struct bpf_map *map, u32 key)
1363 {
1364         return NULL;
1365 }
1366
1367 static inline void __cpu_map_flush(void)
1368 {
1369 }
1370
1371 static inline int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu,
1372                                   struct xdp_buff *xdp,
1373                                   struct net_device *dev_rx)
1374 {
1375         return 0;
1376 }
1377
1378 static inline struct bpf_prog *bpf_prog_get_type_path(const char *name,
1379                                 enum bpf_prog_type type)
1380 {
1381         return ERR_PTR(-EOPNOTSUPP);
1382 }
1383
1384 static inline int bpf_prog_test_run_xdp(struct bpf_prog *prog,
1385                                         const union bpf_attr *kattr,
1386                                         union bpf_attr __user *uattr)
1387 {
1388         return -ENOTSUPP;
1389 }
1390
1391 static inline int bpf_prog_test_run_skb(struct bpf_prog *prog,
1392                                         const union bpf_attr *kattr,
1393                                         union bpf_attr __user *uattr)
1394 {
1395         return -ENOTSUPP;
1396 }
1397
1398 static inline int bpf_prog_test_run_tracing(struct bpf_prog *prog,
1399                                             const union bpf_attr *kattr,
1400                                             union bpf_attr __user *uattr)
1401 {
1402         return -ENOTSUPP;
1403 }
1404
1405 static inline int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
1406                                                    const union bpf_attr *kattr,
1407                                                    union bpf_attr __user *uattr)
1408 {
1409         return -ENOTSUPP;
1410 }
1411
1412 static inline void bpf_map_put(struct bpf_map *map)
1413 {
1414 }
1415
1416 static inline struct bpf_prog *bpf_prog_by_id(u32 id)
1417 {
1418         return ERR_PTR(-ENOTSUPP);
1419 }
1420
1421 static inline const struct bpf_func_proto *
1422 bpf_base_func_proto(enum bpf_func_id func_id)
1423 {
1424         return NULL;
1425 }
1426 #endif /* CONFIG_BPF_SYSCALL */
1427
1428 static inline struct bpf_prog *bpf_prog_get_type(u32 ufd,
1429                                                  enum bpf_prog_type type)
1430 {
1431         return bpf_prog_get_type_dev(ufd, type, false);
1432 }
1433
1434 bool bpf_prog_get_ok(struct bpf_prog *, enum bpf_prog_type *, bool);
1435
1436 int bpf_prog_offload_compile(struct bpf_prog *prog);
1437 void bpf_prog_offload_destroy(struct bpf_prog *prog);
1438 int bpf_prog_offload_info_fill(struct bpf_prog_info *info,
1439                                struct bpf_prog *prog);
1440
1441 int bpf_map_offload_info_fill(struct bpf_map_info *info, struct bpf_map *map);
1442
1443 int bpf_map_offload_lookup_elem(struct bpf_map *map, void *key, void *value);
1444 int bpf_map_offload_update_elem(struct bpf_map *map,
1445                                 void *key, void *value, u64 flags);
1446 int bpf_map_offload_delete_elem(struct bpf_map *map, void *key);
1447 int bpf_map_offload_get_next_key(struct bpf_map *map,
1448                                  void *key, void *next_key);
1449
1450 bool bpf_offload_prog_map_match(struct bpf_prog *prog, struct bpf_map *map);
1451
1452 struct bpf_offload_dev *
1453 bpf_offload_dev_create(const struct bpf_prog_offload_ops *ops, void *priv);
1454 void bpf_offload_dev_destroy(struct bpf_offload_dev *offdev);
1455 void *bpf_offload_dev_priv(struct bpf_offload_dev *offdev);
1456 int bpf_offload_dev_netdev_register(struct bpf_offload_dev *offdev,
1457                                     struct net_device *netdev);
1458 void bpf_offload_dev_netdev_unregister(struct bpf_offload_dev *offdev,
1459                                        struct net_device *netdev);
1460 bool bpf_offload_dev_match(struct bpf_prog *prog, struct net_device *netdev);
1461
1462 #if defined(CONFIG_NET) && defined(CONFIG_BPF_SYSCALL)
1463 int bpf_prog_offload_init(struct bpf_prog *prog, union bpf_attr *attr);
1464
1465 static inline bool bpf_prog_is_dev_bound(const struct bpf_prog_aux *aux)
1466 {
1467         return aux->offload_requested;
1468 }
1469
1470 static inline bool bpf_map_is_dev_bound(struct bpf_map *map)
1471 {
1472         return unlikely(map->ops == &bpf_map_offload_ops);
1473 }
1474
1475 struct bpf_map *bpf_map_offload_map_alloc(union bpf_attr *attr);
1476 void bpf_map_offload_map_free(struct bpf_map *map);
1477 #else
1478 static inline int bpf_prog_offload_init(struct bpf_prog *prog,
1479                                         union bpf_attr *attr)
1480 {
1481         return -EOPNOTSUPP;
1482 }
1483
1484 static inline bool bpf_prog_is_dev_bound(struct bpf_prog_aux *aux)
1485 {
1486         return false;
1487 }
1488
1489 static inline bool bpf_map_is_dev_bound(struct bpf_map *map)
1490 {
1491         return false;
1492 }
1493
1494 static inline struct bpf_map *bpf_map_offload_map_alloc(union bpf_attr *attr)
1495 {
1496         return ERR_PTR(-EOPNOTSUPP);
1497 }
1498
1499 static inline void bpf_map_offload_map_free(struct bpf_map *map)
1500 {
1501 }
1502 #endif /* CONFIG_NET && CONFIG_BPF_SYSCALL */
1503
1504 #if defined(CONFIG_BPF_STREAM_PARSER)
1505 int sock_map_prog_update(struct bpf_map *map, struct bpf_prog *prog, u32 which);
1506 int sock_map_get_from_fd(const union bpf_attr *attr, struct bpf_prog *prog);
1507 void sock_map_unhash(struct sock *sk);
1508 void sock_map_close(struct sock *sk, long timeout);
1509 #else
1510 static inline int sock_map_prog_update(struct bpf_map *map,
1511                                        struct bpf_prog *prog, u32 which)
1512 {
1513         return -EOPNOTSUPP;
1514 }
1515
1516 static inline int sock_map_get_from_fd(const union bpf_attr *attr,
1517                                        struct bpf_prog *prog)
1518 {
1519         return -EINVAL;
1520 }
1521 #endif /* CONFIG_BPF_STREAM_PARSER */
1522
1523 #if defined(CONFIG_INET) && defined(CONFIG_BPF_SYSCALL)
1524 void bpf_sk_reuseport_detach(struct sock *sk);
1525 int bpf_fd_reuseport_array_lookup_elem(struct bpf_map *map, void *key,
1526                                        void *value);
1527 int bpf_fd_reuseport_array_update_elem(struct bpf_map *map, void *key,
1528                                        void *value, u64 map_flags);
1529 #else
1530 static inline void bpf_sk_reuseport_detach(struct sock *sk)
1531 {
1532 }
1533
1534 #ifdef CONFIG_BPF_SYSCALL
1535 static inline int bpf_fd_reuseport_array_lookup_elem(struct bpf_map *map,
1536                                                      void *key, void *value)
1537 {
1538         return -EOPNOTSUPP;
1539 }
1540
1541 static inline int bpf_fd_reuseport_array_update_elem(struct bpf_map *map,
1542                                                      void *key, void *value,
1543                                                      u64 map_flags)
1544 {
1545         return -EOPNOTSUPP;
1546 }
1547 #endif /* CONFIG_BPF_SYSCALL */
1548 #endif /* defined(CONFIG_INET) && defined(CONFIG_BPF_SYSCALL) */
1549
1550 /* verifier prototypes for helper functions called from eBPF programs */
1551 extern const struct bpf_func_proto bpf_map_lookup_elem_proto;
1552 extern const struct bpf_func_proto bpf_map_update_elem_proto;
1553 extern const struct bpf_func_proto bpf_map_delete_elem_proto;
1554 extern const struct bpf_func_proto bpf_map_push_elem_proto;
1555 extern const struct bpf_func_proto bpf_map_pop_elem_proto;
1556 extern const struct bpf_func_proto bpf_map_peek_elem_proto;
1557
1558 extern const struct bpf_func_proto bpf_get_prandom_u32_proto;
1559 extern const struct bpf_func_proto bpf_get_smp_processor_id_proto;
1560 extern const struct bpf_func_proto bpf_get_numa_node_id_proto;
1561 extern const struct bpf_func_proto bpf_tail_call_proto;
1562 extern const struct bpf_func_proto bpf_ktime_get_ns_proto;
1563 extern const struct bpf_func_proto bpf_ktime_get_boot_ns_proto;
1564 extern const struct bpf_func_proto bpf_get_current_pid_tgid_proto;
1565 extern const struct bpf_func_proto bpf_get_current_uid_gid_proto;
1566 extern const struct bpf_func_proto bpf_get_current_comm_proto;
1567 extern const struct bpf_func_proto bpf_get_stackid_proto;
1568 extern const struct bpf_func_proto bpf_get_stack_proto;
1569 extern const struct bpf_func_proto bpf_sock_map_update_proto;
1570 extern const struct bpf_func_proto bpf_sock_hash_update_proto;
1571 extern const struct bpf_func_proto bpf_get_current_cgroup_id_proto;
1572 extern const struct bpf_func_proto bpf_get_current_ancestor_cgroup_id_proto;
1573 extern const struct bpf_func_proto bpf_msg_redirect_hash_proto;
1574 extern const struct bpf_func_proto bpf_msg_redirect_map_proto;
1575 extern const struct bpf_func_proto bpf_sk_redirect_hash_proto;
1576 extern const struct bpf_func_proto bpf_sk_redirect_map_proto;
1577 extern const struct bpf_func_proto bpf_spin_lock_proto;
1578 extern const struct bpf_func_proto bpf_spin_unlock_proto;
1579 extern const struct bpf_func_proto bpf_get_local_storage_proto;
1580 extern const struct bpf_func_proto bpf_strtol_proto;
1581 extern const struct bpf_func_proto bpf_strtoul_proto;
1582 extern const struct bpf_func_proto bpf_tcp_sock_proto;
1583 extern const struct bpf_func_proto bpf_jiffies64_proto;
1584 extern const struct bpf_func_proto bpf_get_ns_current_pid_tgid_proto;
1585 extern const struct bpf_func_proto bpf_event_output_data_proto;
1586
1587 const struct bpf_func_proto *bpf_tracing_func_proto(
1588         enum bpf_func_id func_id, const struct bpf_prog *prog);
1589
1590 /* Shared helpers among cBPF and eBPF. */
1591 void bpf_user_rnd_init_once(void);
1592 u64 bpf_user_rnd_u32(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
1593 u64 bpf_get_raw_cpu_id(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
1594
1595 #if defined(CONFIG_NET)
1596 bool bpf_sock_common_is_valid_access(int off, int size,
1597                                      enum bpf_access_type type,
1598                                      struct bpf_insn_access_aux *info);
1599 bool bpf_sock_is_valid_access(int off, int size, enum bpf_access_type type,
1600                               struct bpf_insn_access_aux *info);
1601 u32 bpf_sock_convert_ctx_access(enum bpf_access_type type,
1602                                 const struct bpf_insn *si,
1603                                 struct bpf_insn *insn_buf,
1604                                 struct bpf_prog *prog,
1605                                 u32 *target_size);
1606 #else
1607 static inline bool bpf_sock_common_is_valid_access(int off, int size,
1608                                                    enum bpf_access_type type,
1609                                                    struct bpf_insn_access_aux *info)
1610 {
1611         return false;
1612 }
1613 static inline bool bpf_sock_is_valid_access(int off, int size,
1614                                             enum bpf_access_type type,
1615                                             struct bpf_insn_access_aux *info)
1616 {
1617         return false;
1618 }
1619 static inline u32 bpf_sock_convert_ctx_access(enum bpf_access_type type,
1620                                               const struct bpf_insn *si,
1621                                               struct bpf_insn *insn_buf,
1622                                               struct bpf_prog *prog,
1623                                               u32 *target_size)
1624 {
1625         return 0;
1626 }
1627 #endif
1628
1629 #ifdef CONFIG_INET
1630 struct sk_reuseport_kern {
1631         struct sk_buff *skb;
1632         struct sock *sk;
1633         struct sock *selected_sk;
1634         void *data_end;
1635         u32 hash;
1636         u32 reuseport_id;
1637         bool bind_inany;
1638 };
1639 bool bpf_tcp_sock_is_valid_access(int off, int size, enum bpf_access_type type,
1640                                   struct bpf_insn_access_aux *info);
1641
1642 u32 bpf_tcp_sock_convert_ctx_access(enum bpf_access_type type,
1643                                     const struct bpf_insn *si,
1644                                     struct bpf_insn *insn_buf,
1645                                     struct bpf_prog *prog,
1646                                     u32 *target_size);
1647
1648 bool bpf_xdp_sock_is_valid_access(int off, int size, enum bpf_access_type type,
1649                                   struct bpf_insn_access_aux *info);
1650
1651 u32 bpf_xdp_sock_convert_ctx_access(enum bpf_access_type type,
1652                                     const struct bpf_insn *si,
1653                                     struct bpf_insn *insn_buf,
1654                                     struct bpf_prog *prog,
1655                                     u32 *target_size);
1656 #else
1657 static inline bool bpf_tcp_sock_is_valid_access(int off, int size,
1658                                                 enum bpf_access_type type,
1659                                                 struct bpf_insn_access_aux *info)
1660 {
1661         return false;
1662 }
1663
1664 static inline u32 bpf_tcp_sock_convert_ctx_access(enum bpf_access_type type,
1665                                                   const struct bpf_insn *si,
1666                                                   struct bpf_insn *insn_buf,
1667                                                   struct bpf_prog *prog,
1668                                                   u32 *target_size)
1669 {
1670         return 0;
1671 }
1672 static inline bool bpf_xdp_sock_is_valid_access(int off, int size,
1673                                                 enum bpf_access_type type,
1674                                                 struct bpf_insn_access_aux *info)
1675 {
1676         return false;
1677 }
1678
1679 static inline u32 bpf_xdp_sock_convert_ctx_access(enum bpf_access_type type,
1680                                                   const struct bpf_insn *si,
1681                                                   struct bpf_insn *insn_buf,
1682                                                   struct bpf_prog *prog,
1683                                                   u32 *target_size)
1684 {
1685         return 0;
1686 }
1687 #endif /* CONFIG_INET */
1688
1689 enum bpf_text_poke_type {
1690         BPF_MOD_CALL,
1691         BPF_MOD_JUMP,
1692 };
1693
1694 int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
1695                        void *addr1, void *addr2);
1696
1697 #endif /* _LINUX_BPF_H */
This page took 0.129186 seconds and 4 git commands to generate.