blob: 5a4a256473c34f2c4d3c155588821da1db958873 [file] [log] [blame]
Alexei Starovoitov99c55f72014-09-26 00:16:57 -07001/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
6 */
7#ifndef _LINUX_BPF_H
8#define _LINUX_BPF_H 1
9
10#include <uapi/linux/bpf.h>
Daniel Borkmann74451e662017-02-16 22:24:50 +010011
Alexei Starovoitov99c55f72014-09-26 00:16:57 -070012#include <linux/workqueue.h>
Alexei Starovoitovdb20fd22014-09-26 00:16:59 -070013#include <linux/file.h>
Alexei Starovoitovb121d1e2016-03-07 21:57:13 -080014#include <linux/percpu.h>
Zi Shen Lim002245c2016-06-08 21:18:47 -070015#include <linux/err.h>
Daniel Borkmann74451e662017-02-16 22:24:50 +010016#include <linux/rbtree_latch.h>
David S. Millerd6e1e462017-08-19 23:34:03 -070017#include <linux/numa.h>
Jakub Kicinskiab3f0062017-11-03 13:56:17 -070018#include <linux/wait.h>
Alexei Starovoitov99c55f72014-09-26 00:16:57 -070019
Jakub Kicinskicae19272017-12-27 18:39:05 -080020struct bpf_verifier_env;
Daniel Borkmann3b1efb12016-06-15 22:47:14 +020021struct perf_event;
John Fastabend174a79f2017-08-15 22:32:47 -070022struct bpf_prog;
Alexei Starovoitov99c55f72014-09-26 00:16:57 -070023struct bpf_map;
John Fastabend4f738ad2018-03-18 12:57:10 -070024struct sock;
Martin KaFai Laua26ca7c2018-04-18 15:56:03 -070025struct seq_file;
26struct btf;
Alexei Starovoitov99c55f72014-09-26 00:16:57 -070027
28/* map is generic key/value storage optionally accesible by eBPF programs */
29struct bpf_map_ops {
30 /* funcs callable from userspace (via syscall) */
Jakub Kicinski1110f3a2018-01-11 20:29:03 -080031 int (*map_alloc_check)(union bpf_attr *attr);
Alexei Starovoitov99c55f72014-09-26 00:16:57 -070032 struct bpf_map *(*map_alloc)(union bpf_attr *attr);
Daniel Borkmann61d1b6a2016-06-15 22:47:12 +020033 void (*map_release)(struct bpf_map *map, struct file *map_file);
34 void (*map_free)(struct bpf_map *map);
Alexei Starovoitovdb20fd22014-09-26 00:16:59 -070035 int (*map_get_next_key)(struct bpf_map *map, void *key, void *next_key);
John Fastabendba6b8de2018-04-23 15:39:23 -070036 void (*map_release_uref)(struct bpf_map *map);
Alexei Starovoitovdb20fd22014-09-26 00:16:59 -070037
38 /* funcs callable from userspace and from eBPF programs */
39 void *(*map_lookup_elem)(struct bpf_map *map, void *key);
Alexei Starovoitov3274f522014-11-13 17:36:44 -080040 int (*map_update_elem)(struct bpf_map *map, void *key, void *value, u64 flags);
Alexei Starovoitovdb20fd22014-09-26 00:16:59 -070041 int (*map_delete_elem)(struct bpf_map *map, void *key);
Wang Nan2a36f0b2015-08-06 07:02:33 +000042
43 /* funcs called by prog_array and perf_event_array map */
Daniel Borkmannd056a782016-06-15 22:47:13 +020044 void *(*map_fd_get_ptr)(struct bpf_map *map, struct file *map_file,
45 int fd);
46 void (*map_fd_put_ptr)(void *ptr);
Alexei Starovoitov81ed18a2017-03-15 18:26:42 -070047 u32 (*map_gen_lookup)(struct bpf_map *map, struct bpf_insn *insn_buf);
Martin KaFai Lau14dc6f02017-06-27 23:08:34 -070048 u32 (*map_fd_sys_lookup_elem)(void *ptr);
Martin KaFai Laua26ca7c2018-04-18 15:56:03 -070049 void (*map_seq_show_elem)(struct bpf_map *map, void *key,
50 struct seq_file *m);
51 int (*map_check_btf)(const struct bpf_map *map, const struct btf *btf,
52 u32 key_type_id, u32 value_type_id);
Alexei Starovoitov99c55f72014-09-26 00:16:57 -070053};
54
55struct bpf_map {
Martin KaFai Laua26ca7c2018-04-18 15:56:03 -070056 /* The first two cachelines with read-mostly members of which some
Daniel Borkmannbe95a842018-01-09 13:17:44 +010057 * are also accessed in fast-path (e.g. ops, max_entries).
58 */
59 const struct bpf_map_ops *ops ____cacheline_aligned;
60 struct bpf_map *inner_map_meta;
61#ifdef CONFIG_SECURITY
62 void *security;
63#endif
Alexei Starovoitov99c55f72014-09-26 00:16:57 -070064 enum bpf_map_type map_type;
65 u32 key_size;
66 u32 value_size;
67 u32 max_entries;
Alexei Starovoitov6c905982016-03-07 21:57:15 -080068 u32 map_flags;
Alexei Starovoitovaaac3ba2015-10-07 22:23:22 -070069 u32 pages;
Martin KaFai Lauf3f1c052017-06-05 12:15:47 -070070 u32 id;
Martin KaFai Lau96eabe72017-08-18 11:28:00 -070071 int numa_node;
Martin KaFai Lau9b2cf322018-05-22 14:57:21 -070072 u32 btf_key_type_id;
73 u32 btf_value_type_id;
Martin KaFai Laua26ca7c2018-04-18 15:56:03 -070074 struct btf *btf;
Alexei Starovoitovb2157392018-01-07 17:33:02 -080075 bool unpriv_array;
Martin KaFai Laua26ca7c2018-04-18 15:56:03 -070076 /* 55 bytes hole */
Daniel Borkmannbe95a842018-01-09 13:17:44 +010077
Martin KaFai Laua26ca7c2018-04-18 15:56:03 -070078 /* The 3rd and 4th cacheline with misc members to avoid false sharing
Daniel Borkmannbe95a842018-01-09 13:17:44 +010079 * particularly with refcounting.
80 */
81 struct user_struct *user ____cacheline_aligned;
82 atomic_t refcnt;
Daniel Borkmannc9da1612015-11-24 21:28:15 +010083 atomic_t usercnt;
Daniel Borkmannbe95a842018-01-09 13:17:44 +010084 struct work_struct work;
Martin KaFai Lau067cae42017-10-05 21:52:12 -070085 char name[BPF_OBJ_NAME_LEN];
Alexei Starovoitov99c55f72014-09-26 00:16:57 -070086};
87
Jakub Kicinski602144c2018-07-17 10:53:25 -070088struct bpf_offload_dev;
Jakub Kicinskia3884572018-01-11 20:29:09 -080089struct bpf_offloaded_map;
90
91struct bpf_map_dev_ops {
92 int (*map_get_next_key)(struct bpf_offloaded_map *map,
93 void *key, void *next_key);
94 int (*map_lookup_elem)(struct bpf_offloaded_map *map,
95 void *key, void *value);
96 int (*map_update_elem)(struct bpf_offloaded_map *map,
97 void *key, void *value, u64 flags);
98 int (*map_delete_elem)(struct bpf_offloaded_map *map, void *key);
99};
100
101struct bpf_offloaded_map {
102 struct bpf_map map;
103 struct net_device *netdev;
104 const struct bpf_map_dev_ops *dev_ops;
105 void *dev_priv;
106 struct list_head offloads;
107};
108
109static inline struct bpf_offloaded_map *map_to_offmap(struct bpf_map *map)
110{
111 return container_of(map, struct bpf_offloaded_map, map);
112}
113
Jakub Kicinski0cd3cbe2018-05-03 18:37:08 -0700114static inline bool bpf_map_offload_neutral(const struct bpf_map *map)
115{
116 return map->map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY;
117}
118
Martin KaFai Laua26ca7c2018-04-18 15:56:03 -0700119static inline bool bpf_map_support_seq_show(const struct bpf_map *map)
120{
121 return map->ops->map_seq_show_elem && map->ops->map_check_btf;
122}
123
Jakub Kicinskia3884572018-01-11 20:29:09 -0800124extern const struct bpf_map_ops bpf_map_offload_ops;
125
Alexei Starovoitov17a52672014-09-26 00:17:06 -0700126/* function argument constraints */
127enum bpf_arg_type {
Daniel Borkmann80f1d682015-03-12 17:21:42 +0100128 ARG_DONTCARE = 0, /* unused argument in helper function */
Alexei Starovoitov17a52672014-09-26 00:17:06 -0700129
130 /* the following constraints used to prototype
131 * bpf_map_lookup/update/delete_elem() functions
132 */
133 ARG_CONST_MAP_PTR, /* const argument used as pointer to bpf_map */
134 ARG_PTR_TO_MAP_KEY, /* pointer to stack used as map key */
135 ARG_PTR_TO_MAP_VALUE, /* pointer to stack used as map value */
136
137 /* the following constraints used to prototype bpf_memcmp() and other
138 * functions that access data on eBPF program stack
139 */
Alexei Starovoitov39f19ebb2017-01-09 10:19:50 -0800140 ARG_PTR_TO_MEM, /* pointer to valid memory (stack, packet, map value) */
Gianluca Borellodb1ac492017-11-22 18:32:53 +0000141 ARG_PTR_TO_MEM_OR_NULL, /* pointer to valid memory or NULL */
Alexei Starovoitov39f19ebb2017-01-09 10:19:50 -0800142 ARG_PTR_TO_UNINIT_MEM, /* pointer to memory does not need to be initialized,
143 * helper function must fill all bytes or clear
144 * them in error case.
Daniel Borkmann435faee12016-04-13 00:10:51 +0200145 */
146
Alexei Starovoitov39f19ebb2017-01-09 10:19:50 -0800147 ARG_CONST_SIZE, /* number of bytes accessed from memory */
148 ARG_CONST_SIZE_OR_ZERO, /* number of bytes accessed from memory or 0 */
Daniel Borkmann80f1d682015-03-12 17:21:42 +0100149
Alexei Starovoitov608cd712015-03-26 19:53:57 -0700150 ARG_PTR_TO_CTX, /* pointer to context */
Daniel Borkmann80f1d682015-03-12 17:21:42 +0100151 ARG_ANYTHING, /* any (initialized) argument is ok */
Alexei Starovoitov17a52672014-09-26 00:17:06 -0700152};
153
154/* type of values returned from helper functions */
155enum bpf_return_type {
156 RET_INTEGER, /* function returns integer */
157 RET_VOID, /* function doesn't return anything */
158 RET_PTR_TO_MAP_VALUE_OR_NULL, /* returns a pointer to map elem value or NULL */
159};
160
Alexei Starovoitov09756af2014-09-26 00:17:00 -0700161/* eBPF function prototype used by verifier to allow BPF_CALLs from eBPF programs
162 * to in-kernel helper functions and for adjusting imm32 field in BPF_CALL
163 * instructions after verifying
164 */
165struct bpf_func_proto {
166 u64 (*func)(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
167 bool gpl_only;
Daniel Borkmann36bbef52016-09-20 00:26:13 +0200168 bool pkt_access;
Alexei Starovoitov17a52672014-09-26 00:17:06 -0700169 enum bpf_return_type ret_type;
170 enum bpf_arg_type arg1_type;
171 enum bpf_arg_type arg2_type;
172 enum bpf_arg_type arg3_type;
173 enum bpf_arg_type arg4_type;
174 enum bpf_arg_type arg5_type;
175};
176
177/* bpf_context is intentionally undefined structure. Pointer to bpf_context is
178 * the first argument to eBPF programs.
179 * For socket filters: 'struct bpf_context *' == 'struct sk_buff *'
180 */
181struct bpf_context;
182
183enum bpf_access_type {
184 BPF_READ = 1,
185 BPF_WRITE = 2
Alexei Starovoitov09756af2014-09-26 00:17:00 -0700186};
187
Alexei Starovoitov19de99f2016-06-15 18:25:38 -0700188/* types of values stored in eBPF registers */
Edward Creef1174f72017-08-07 15:26:19 +0100189/* Pointer types represent:
190 * pointer
191 * pointer + imm
192 * pointer + (u16) var
193 * pointer + (u16) var + imm
194 * if (range > 0) then [ptr, ptr + range - off) is safe to access
195 * if (id > 0) means that some 'var' was added
196 * if (off > 0) means that 'imm' was added
197 */
Alexei Starovoitov19de99f2016-06-15 18:25:38 -0700198enum bpf_reg_type {
199 NOT_INIT = 0, /* nothing was written into register */
Edward Creef1174f72017-08-07 15:26:19 +0100200 SCALAR_VALUE, /* reg doesn't contain a valid pointer */
Alexei Starovoitov19de99f2016-06-15 18:25:38 -0700201 PTR_TO_CTX, /* reg points to bpf_context */
202 CONST_PTR_TO_MAP, /* reg points to struct bpf_map */
203 PTR_TO_MAP_VALUE, /* reg points to map element value */
204 PTR_TO_MAP_VALUE_OR_NULL,/* points to map elem value or NULL */
Edward Creef1174f72017-08-07 15:26:19 +0100205 PTR_TO_STACK, /* reg == frame_pointer + offset */
Daniel Borkmannde8f3a82017-09-25 02:25:51 +0200206 PTR_TO_PACKET_META, /* skb->data - meta_len */
Edward Creef1174f72017-08-07 15:26:19 +0100207 PTR_TO_PACKET, /* reg points to skb->data */
Alexei Starovoitov19de99f2016-06-15 18:25:38 -0700208 PTR_TO_PACKET_END, /* skb->data + headlen */
209};
210
Yonghong Song23994632017-06-22 15:07:39 -0700211/* The information passed from prog-specific *_is_valid_access
212 * back to the verifier.
213 */
214struct bpf_insn_access_aux {
215 enum bpf_reg_type reg_type;
216 int ctx_field_size;
Yonghong Song23994632017-06-22 15:07:39 -0700217};
218
Daniel Borkmannf96da092017-07-02 02:13:27 +0200219static inline void
220bpf_ctx_record_field_size(struct bpf_insn_access_aux *aux, u32 size)
221{
222 aux->ctx_field_size = size;
223}
224
Jakub Kicinski7de16e32017-10-16 16:40:53 -0700225struct bpf_prog_ops {
226 int (*test_run)(struct bpf_prog *prog, const union bpf_attr *kattr,
227 union bpf_attr __user *uattr);
228};
229
Alexei Starovoitov09756af2014-09-26 00:17:00 -0700230struct bpf_verifier_ops {
231 /* return eBPF function prototype for verification */
Andrey Ignatov5e43f892018-03-30 15:08:00 -0700232 const struct bpf_func_proto *
233 (*get_func_proto)(enum bpf_func_id func_id,
234 const struct bpf_prog *prog);
Alexei Starovoitov17a52672014-09-26 00:17:06 -0700235
236 /* return true if 'size' wide access at offset 'off' within bpf_context
237 * with 'type' (read or write) is allowed
238 */
Alexei Starovoitov19de99f2016-06-15 18:25:38 -0700239 bool (*is_valid_access)(int off, int size, enum bpf_access_type type,
Andrey Ignatov5e43f892018-03-30 15:08:00 -0700240 const struct bpf_prog *prog,
Yonghong Song23994632017-06-22 15:07:39 -0700241 struct bpf_insn_access_aux *info);
Daniel Borkmann36bbef52016-09-20 00:26:13 +0200242 int (*gen_prologue)(struct bpf_insn *insn, bool direct_write,
243 const struct bpf_prog *prog);
Daniel Borkmanne0cea7c2018-05-04 01:08:14 +0200244 int (*gen_ld_abs)(const struct bpf_insn *orig,
245 struct bpf_insn *insn_buf);
Daniel Borkmann6b8cc1d2017-01-12 11:51:32 +0100246 u32 (*convert_ctx_access)(enum bpf_access_type type,
247 const struct bpf_insn *src,
248 struct bpf_insn *dst,
Daniel Borkmannf96da092017-07-02 02:13:27 +0200249 struct bpf_prog *prog, u32 *target_size);
Alexei Starovoitov09756af2014-09-26 00:17:00 -0700250};
251
Jakub Kicinskicae19272017-12-27 18:39:05 -0800252struct bpf_prog_offload_ops {
253 int (*insn_hook)(struct bpf_verifier_env *env,
254 int insn_idx, int prev_insn_idx);
255};
256
Jakub Kicinski0a9c1992018-01-11 20:29:07 -0800257struct bpf_prog_offload {
Jakub Kicinskiab3f0062017-11-03 13:56:17 -0700258 struct bpf_prog *prog;
259 struct net_device *netdev;
260 void *dev_priv;
261 struct list_head offloads;
262 bool dev_state;
Jakub Kicinskicae19272017-12-27 18:39:05 -0800263 const struct bpf_prog_offload_ops *dev_ops;
Jiong Wangfcfb1262018-01-16 16:05:19 -0800264 void *jited_image;
265 u32 jited_len;
Jakub Kicinskiab3f0062017-11-03 13:56:17 -0700266};
267
Alexei Starovoitov09756af2014-09-26 00:17:00 -0700268struct bpf_prog_aux {
269 atomic_t refcnt;
Daniel Borkmann24701ec2015-03-01 12:31:47 +0100270 u32 used_map_cnt;
Alexei Starovoitov32bbe002016-04-06 18:43:28 -0700271 u32 max_ctx_offset;
Alexei Starovoitov87266792017-05-30 13:31:29 -0700272 u32 stack_depth;
Martin KaFai Laudc4bb0e2017-06-05 12:15:46 -0700273 u32 id;
Alexei Starovoitov1c2a0882017-12-14 17:55:15 -0800274 u32 func_cnt;
Jakub Kicinski9a18eed2017-12-27 18:39:04 -0800275 bool offload_requested;
Alexei Starovoitov1c2a0882017-12-14 17:55:15 -0800276 struct bpf_prog **func;
277 void *jit_data; /* JIT specific data. arch dependent */
Daniel Borkmann74451e662017-02-16 22:24:50 +0100278 struct latch_tree_node ksym_tnode;
279 struct list_head ksym_lnode;
Jakub Kicinski7de16e32017-10-16 16:40:53 -0700280 const struct bpf_prog_ops *ops;
Alexei Starovoitov09756af2014-09-26 00:17:00 -0700281 struct bpf_map **used_maps;
Alexei Starovoitov09756af2014-09-26 00:17:00 -0700282 struct bpf_prog *prog;
Alexei Starovoitovaaac3ba2015-10-07 22:23:22 -0700283 struct user_struct *user;
Martin KaFai Laucb4d2b32017-09-27 14:37:52 -0700284 u64 load_time; /* ns since boottime */
Martin KaFai Lau067cae42017-10-05 21:52:12 -0700285 char name[BPF_OBJ_NAME_LEN];
Chenbo Fengafdb09c2017-10-18 13:00:24 -0700286#ifdef CONFIG_SECURITY
287 void *security;
288#endif
Jakub Kicinski0a9c1992018-01-11 20:29:07 -0800289 struct bpf_prog_offload *offload;
Alexei Starovoitovabf2e7d2015-05-28 19:26:02 -0700290 union {
291 struct work_struct work;
292 struct rcu_head rcu;
293 };
Alexei Starovoitov09756af2014-09-26 00:17:00 -0700294};
295
Alexei Starovoitov04fd61a2015-05-19 16:59:03 -0700296struct bpf_array {
297 struct bpf_map map;
298 u32 elem_size;
Alexei Starovoitovb2157392018-01-07 17:33:02 -0800299 u32 index_mask;
Alexei Starovoitov04fd61a2015-05-19 16:59:03 -0700300 /* 'ownership' of prog_array is claimed by the first program that
301 * is going to use this map or by the first program which FD is stored
302 * in the map to make sure that all callers and callees have the same
303 * prog_type and JITed flag
304 */
305 enum bpf_prog_type owner_prog_type;
306 bool owner_jited;
307 union {
308 char value[0] __aligned(8);
Wang Nan2a36f0b2015-08-06 07:02:33 +0000309 void *ptrs[0] __aligned(8);
Alexei Starovoitova10423b2016-02-01 22:39:54 -0800310 void __percpu *pptrs[0] __aligned(8);
Alexei Starovoitov04fd61a2015-05-19 16:59:03 -0700311 };
312};
Daniel Borkmann3b1efb12016-06-15 22:47:14 +0200313
Alexei Starovoitov04fd61a2015-05-19 16:59:03 -0700314#define MAX_TAIL_CALL_CNT 32
315
Daniel Borkmann3b1efb12016-06-15 22:47:14 +0200316struct bpf_event_entry {
317 struct perf_event *event;
318 struct file *perf_file;
319 struct file *map_file;
320 struct rcu_head rcu;
321};
322
Alexei Starovoitov04fd61a2015-05-19 16:59:03 -0700323bool bpf_prog_array_compatible(struct bpf_array *array, const struct bpf_prog *fp);
Daniel Borkmannf1f77142017-01-13 23:38:15 +0100324int bpf_prog_calc_tag(struct bpf_prog *fp);
Daniel Borkmannbd570ff2016-04-18 21:01:24 +0200325
Alexei Starovoitov0756ea32015-06-12 19:39:13 -0700326const struct bpf_func_proto *bpf_get_trace_printk_proto(void);
Daniel Borkmann555c8a82016-07-14 18:08:05 +0200327
328typedef unsigned long (*bpf_ctx_copy_t)(void *dst, const void *src,
Daniel Borkmannaa7145c2016-07-22 01:19:42 +0200329 unsigned long off, unsigned long len);
Daniel Borkmann555c8a82016-07-14 18:08:05 +0200330
331u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
332 void *ctx, u64 ctx_size, bpf_ctx_copy_t ctx_copy);
Alexei Starovoitov04fd61a2015-05-19 16:59:03 -0700333
Alexei Starovoitov1cf1cae2017-03-30 21:45:38 -0700334int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
335 union bpf_attr __user *uattr);
336int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
337 union bpf_attr __user *uattr);
338
Alexei Starovoitov324bda9e62017-10-02 22:50:21 -0700339/* an array of programs to be executed under rcu_lock.
340 *
341 * Typical usage:
342 * ret = BPF_PROG_RUN_ARRAY(&bpf_prog_array, ctx, BPF_PROG_RUN);
343 *
344 * the structure returned by bpf_prog_array_alloc() should be populated
345 * with program pointers and the last pointer must be NULL.
346 * The user has to keep refcnt on the program and make sure the program
347 * is removed from the array before bpf_prog_put().
348 * The 'struct bpf_prog_array *' should only be replaced with xchg()
349 * since other cpus are walking the array of pointers in parallel.
350 */
351struct bpf_prog_array {
352 struct rcu_head rcu;
353 struct bpf_prog *progs[0];
354};
355
Roman Gushchind29ab6e2018-07-13 12:41:10 -0700356struct bpf_prog_array *bpf_prog_array_alloc(u32 prog_cnt, gfp_t flags);
Alexei Starovoitov324bda9e62017-10-02 22:50:21 -0700357void bpf_prog_array_free(struct bpf_prog_array __rcu *progs);
Alexei Starovoitov468e2f62017-10-02 22:50:22 -0700358int bpf_prog_array_length(struct bpf_prog_array __rcu *progs);
359int bpf_prog_array_copy_to_user(struct bpf_prog_array __rcu *progs,
360 __u32 __user *prog_ids, u32 cnt);
Alexei Starovoitov324bda9e62017-10-02 22:50:21 -0700361
Yonghong Songe87c6bc2017-10-23 23:53:08 -0700362void bpf_prog_array_delete_safe(struct bpf_prog_array __rcu *progs,
363 struct bpf_prog *old_prog);
Yonghong Songf371b302017-12-11 11:39:02 -0800364int bpf_prog_array_copy_info(struct bpf_prog_array __rcu *array,
Yonghong Song3a38bb92018-04-10 09:37:32 -0700365 u32 *prog_ids, u32 request_cnt,
366 u32 *prog_cnt);
Yonghong Songe87c6bc2017-10-23 23:53:08 -0700367int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array,
368 struct bpf_prog *exclude_prog,
369 struct bpf_prog *include_prog,
370 struct bpf_prog_array **new_array);
371
372#define __BPF_PROG_RUN_ARRAY(array, ctx, func, check_non_null) \
Alexei Starovoitov324bda9e62017-10-02 22:50:21 -0700373 ({ \
Yonghong Songe87c6bc2017-10-23 23:53:08 -0700374 struct bpf_prog **_prog, *__prog; \
375 struct bpf_prog_array *_array; \
Alexei Starovoitov324bda9e62017-10-02 22:50:21 -0700376 u32 _ret = 1; \
Roman Gushchin6899b322018-04-23 18:09:21 +0100377 preempt_disable(); \
Alexei Starovoitov324bda9e62017-10-02 22:50:21 -0700378 rcu_read_lock(); \
Yonghong Songe87c6bc2017-10-23 23:53:08 -0700379 _array = rcu_dereference(array); \
380 if (unlikely(check_non_null && !_array))\
381 goto _out; \
382 _prog = _array->progs; \
383 while ((__prog = READ_ONCE(*_prog))) { \
384 _ret &= func(__prog, ctx); \
385 _prog++; \
386 } \
387_out: \
Alexei Starovoitov324bda9e62017-10-02 22:50:21 -0700388 rcu_read_unlock(); \
Roman Gushchin6899b322018-04-23 18:09:21 +0100389 preempt_enable_no_resched(); \
Alexei Starovoitov324bda9e62017-10-02 22:50:21 -0700390 _ret; \
391 })
392
Yonghong Songe87c6bc2017-10-23 23:53:08 -0700393#define BPF_PROG_RUN_ARRAY(array, ctx, func) \
394 __BPF_PROG_RUN_ARRAY(array, ctx, func, false)
395
396#define BPF_PROG_RUN_ARRAY_CHECK(array, ctx, func) \
397 __BPF_PROG_RUN_ARRAY(array, ctx, func, true)
398
Alexei Starovoitov89aa0752014-12-01 15:06:35 -0800399#ifdef CONFIG_BPF_SYSCALL
Alexei Starovoitovb121d1e2016-03-07 21:57:13 -0800400DECLARE_PER_CPU(int, bpf_prog_active);
401
Chenbo Fengf66e4482017-10-18 13:00:26 -0700402extern const struct file_operations bpf_map_fops;
403extern const struct file_operations bpf_prog_fops;
404
Jakub Kicinski7de16e32017-10-16 16:40:53 -0700405#define BPF_PROG_TYPE(_id, _name) \
406 extern const struct bpf_prog_ops _name ## _prog_ops; \
407 extern const struct bpf_verifier_ops _name ## _verifier_ops;
Johannes Berg40077e02017-04-11 15:34:58 +0200408#define BPF_MAP_TYPE(_id, _ops) \
409 extern const struct bpf_map_ops _ops;
Johannes Bergbe9370a2017-04-11 15:34:57 +0200410#include <linux/bpf_types.h>
411#undef BPF_PROG_TYPE
Johannes Berg40077e02017-04-11 15:34:58 +0200412#undef BPF_MAP_TYPE
Daniel Borkmann0fc174d2015-03-01 12:31:44 +0100413
Jakub Kicinskiab3f0062017-11-03 13:56:17 -0700414extern const struct bpf_prog_ops bpf_offload_prog_ops;
Jakub Kicinski4f9218a2017-10-16 16:40:55 -0700415extern const struct bpf_verifier_ops tc_cls_act_analyzer_ops;
416extern const struct bpf_verifier_ops xdp_analyzer_ops;
417
Alexei Starovoitov09756af2014-09-26 00:17:00 -0700418struct bpf_prog *bpf_prog_get(u32 ufd);
Jakub Kicinski248f3462017-11-03 13:56:20 -0700419struct bpf_prog *bpf_prog_get_type_dev(u32 ufd, enum bpf_prog_type type,
Jakub Kicinski288b3de2017-11-20 15:21:54 -0800420 bool attach_drv);
Daniel Borkmann6d67942dd2016-11-19 01:45:03 +0100421struct bpf_prog * __must_check bpf_prog_add(struct bpf_prog *prog, int i);
Daniel Borkmannc5405942016-11-09 22:02:34 +0100422void bpf_prog_sub(struct bpf_prog *prog, int i);
Daniel Borkmann6d67942dd2016-11-19 01:45:03 +0100423struct bpf_prog * __must_check bpf_prog_inc(struct bpf_prog *prog);
John Fastabenda6f6df62017-08-15 22:32:22 -0700424struct bpf_prog * __must_check bpf_prog_inc_not_zero(struct bpf_prog *prog);
Daniel Borkmann61e021f2015-03-02 15:21:55 +0100425void bpf_prog_put(struct bpf_prog *prog);
Daniel Borkmann5ccb0712016-12-18 01:52:58 +0100426int __bpf_prog_charge(struct user_struct *user, u32 pages);
427void __bpf_prog_uncharge(struct user_struct *user, u32 pages);
Daniel Borkmann61e021f2015-03-02 15:21:55 +0100428
Jakub Kicinskiad8ad792017-12-27 18:39:07 -0800429void bpf_prog_free_id(struct bpf_prog *prog, bool do_idr_lock);
Jakub Kicinskia3884572018-01-11 20:29:09 -0800430void bpf_map_free_id(struct bpf_map *map, bool do_idr_lock);
Jakub Kicinskiad8ad792017-12-27 18:39:07 -0800431
Daniel Borkmannc9da1612015-11-24 21:28:15 +0100432struct bpf_map *bpf_map_get_with_uref(u32 ufd);
Daniel Borkmannc2101292015-10-29 14:58:07 +0100433struct bpf_map *__bpf_map_get(struct fd f);
Daniel Borkmann6d67942dd2016-11-19 01:45:03 +0100434struct bpf_map * __must_check bpf_map_inc(struct bpf_map *map, bool uref);
Daniel Borkmannc9da1612015-11-24 21:28:15 +0100435void bpf_map_put_with_uref(struct bpf_map *map);
Daniel Borkmann61e021f2015-03-02 15:21:55 +0100436void bpf_map_put(struct bpf_map *map);
Alexei Starovoitov6c905982016-03-07 21:57:15 -0800437int bpf_map_precharge_memlock(u32 pages);
Roman Gushchin0a4c58f2018-08-02 14:27:17 -0700438int bpf_map_charge_memlock(struct bpf_map *map, u32 pages);
439void bpf_map_uncharge_memlock(struct bpf_map *map, u32 pages);
Martin KaFai Lau96eabe72017-08-18 11:28:00 -0700440void *bpf_map_area_alloc(size_t size, int numa_node);
Daniel Borkmannd407bd22017-01-18 15:14:17 +0100441void bpf_map_area_free(void *base);
Jakub Kicinskibd475642018-01-11 20:29:06 -0800442void bpf_map_init_from_attr(struct bpf_map *map, union bpf_attr *attr);
Daniel Borkmann61e021f2015-03-02 15:21:55 +0100443
Alexei Starovoitov1be7f752015-10-07 22:23:21 -0700444extern int sysctl_unprivileged_bpf_disabled;
445
Chenbo Feng6e71b042017-10-18 13:00:22 -0700446int bpf_map_new_fd(struct bpf_map *map, int flags);
Daniel Borkmannb2197752015-10-29 14:58:09 +0100447int bpf_prog_new_fd(struct bpf_prog *prog);
448
449int bpf_obj_pin_user(u32 ufd, const char __user *pathname);
Chenbo Feng6e71b042017-10-18 13:00:22 -0700450int bpf_obj_get_user(const char __user *pathname, int flags);
Daniel Borkmannb2197752015-10-29 14:58:09 +0100451
Alexei Starovoitov15a07b32016-02-01 22:39:55 -0800452int bpf_percpu_hash_copy(struct bpf_map *map, void *key, void *value);
453int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value);
454int bpf_percpu_hash_update(struct bpf_map *map, void *key, void *value,
455 u64 flags);
456int bpf_percpu_array_update(struct bpf_map *map, void *key, void *value,
457 u64 flags);
Daniel Borkmannd056a782016-06-15 22:47:13 +0200458
Alexei Starovoitov557c0c62016-03-07 21:57:17 -0800459int bpf_stackmap_copy(struct bpf_map *map, void *key, void *value);
Alexei Starovoitov15a07b32016-02-01 22:39:55 -0800460
Daniel Borkmannd056a782016-06-15 22:47:13 +0200461int bpf_fd_array_map_update_elem(struct bpf_map *map, struct file *map_file,
462 void *key, void *value, u64 map_flags);
Martin KaFai Lau14dc6f02017-06-27 23:08:34 -0700463int bpf_fd_array_map_lookup_elem(struct bpf_map *map, void *key, u32 *value);
Martin KaFai Laubcc6b1b2017-03-22 10:00:34 -0700464int bpf_fd_htab_map_update_elem(struct bpf_map *map, struct file *map_file,
465 void *key, void *value, u64 map_flags);
Martin KaFai Lau14dc6f02017-06-27 23:08:34 -0700466int bpf_fd_htab_map_lookup_elem(struct bpf_map *map, void *key, u32 *value);
Daniel Borkmannd056a782016-06-15 22:47:13 +0200467
Chenbo Feng6e71b042017-10-18 13:00:22 -0700468int bpf_get_file_flag(int flags);
Martin KaFai Laudcab51f2018-05-22 15:03:31 -0700469int bpf_check_uarg_tail_zero(void __user *uaddr, size_t expected_size,
470 size_t actual_size);
Chenbo Feng6e71b042017-10-18 13:00:22 -0700471
Alexei Starovoitov15a07b32016-02-01 22:39:55 -0800472/* memcpy that is used with 8-byte aligned pointers, power-of-8 size and
473 * forced to use 'long' read/writes to try to atomically copy long counters.
474 * Best-effort only. No barriers here, since it _will_ race with concurrent
475 * updates from BPF programs. Called from bpf syscall and mostly used with
476 * size 8 or 16 bytes, so ask compiler to inline it.
477 */
478static inline void bpf_long_memcpy(void *dst, const void *src, u32 size)
479{
480 const long *lsrc = src;
481 long *ldst = dst;
482
483 size /= sizeof(long);
484 while (size--)
485 *ldst++ = *lsrc++;
486}
487
Daniel Borkmann61e021f2015-03-02 15:21:55 +0100488/* verify correctness of eBPF program */
Alexei Starovoitov9bac3d62015-03-13 11:57:42 -0700489int bpf_check(struct bpf_prog **fp, union bpf_attr *attr);
Alexei Starovoitov1ea47e02017-12-14 17:55:13 -0800490void bpf_patch_call_args(struct bpf_insn *insn, u32 stack_depth);
John Fastabend46f55cf2017-07-17 21:56:48 -0700491
492/* Map specifics */
Jesper Dangaard Brouer67f29e02018-05-24 16:45:46 +0200493struct xdp_buff;
Toshiaki Makita6d5fc192018-06-14 11:07:42 +0900494struct sk_buff;
Jesper Dangaard Brouer67f29e02018-05-24 16:45:46 +0200495
496struct bpf_dtab_netdev *__dev_map_lookup_elem(struct bpf_map *map, u32 key);
John Fastabend46f55cf2017-07-17 21:56:48 -0700497void __dev_map_insert_ctx(struct bpf_map *map, u32 index);
498void __dev_map_flush(struct bpf_map *map);
Jesper Dangaard Brouer38edddb2018-05-24 16:45:57 +0200499int dev_map_enqueue(struct bpf_dtab_netdev *dst, struct xdp_buff *xdp,
500 struct net_device *dev_rx);
Toshiaki Makita6d5fc192018-06-14 11:07:42 +0900501int dev_map_generic_redirect(struct bpf_dtab_netdev *dst, struct sk_buff *skb,
502 struct bpf_prog *xdp_prog);
John Fastabend46f55cf2017-07-17 21:56:48 -0700503
Jesper Dangaard Brouer9c270af2017-10-16 12:19:34 +0200504struct bpf_cpu_map_entry *__cpu_map_lookup_elem(struct bpf_map *map, u32 key);
505void __cpu_map_insert_ctx(struct bpf_map *map, u32 index);
506void __cpu_map_flush(struct bpf_map *map);
Jesper Dangaard Brouer9c270af2017-10-16 12:19:34 +0200507int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_buff *xdp,
508 struct net_device *dev_rx);
509
Martin KaFai Lau96eabe72017-08-18 11:28:00 -0700510/* Return map's numa specified by userspace */
511static inline int bpf_map_attr_numa_node(const union bpf_attr *attr)
512{
513 return (attr->map_flags & BPF_F_NUMA_NODE) ?
514 attr->numa_node : NUMA_NO_NODE;
515}
516
Al Viro040ee692017-12-02 20:20:38 -0500517struct bpf_prog *bpf_prog_get_type_path(const char *name, enum bpf_prog_type type);
518
Jesper Dangaard Brouer9c270af2017-10-16 12:19:34 +0200519#else /* !CONFIG_BPF_SYSCALL */
Daniel Borkmann0fc174d2015-03-01 12:31:44 +0100520static inline struct bpf_prog *bpf_prog_get(u32 ufd)
521{
522 return ERR_PTR(-EOPNOTSUPP);
523}
524
Jakub Kicinski248f3462017-11-03 13:56:20 -0700525static inline struct bpf_prog *bpf_prog_get_type_dev(u32 ufd,
526 enum bpf_prog_type type,
Jakub Kicinski288b3de2017-11-20 15:21:54 -0800527 bool attach_drv)
Jakub Kicinski248f3462017-11-03 13:56:20 -0700528{
529 return ERR_PTR(-EOPNOTSUPP);
530}
531
Daniel Borkmann6d67942dd2016-11-19 01:45:03 +0100532static inline struct bpf_prog * __must_check bpf_prog_add(struct bpf_prog *prog,
533 int i)
Brenden Blancocc2e0b32016-07-20 07:55:52 -0700534{
535 return ERR_PTR(-EOPNOTSUPP);
536}
Daniel Borkmann113214b2016-06-30 17:24:44 +0200537
Daniel Borkmannc5405942016-11-09 22:02:34 +0100538static inline void bpf_prog_sub(struct bpf_prog *prog, int i)
539{
540}
541
Daniel Borkmann0fc174d2015-03-01 12:31:44 +0100542static inline void bpf_prog_put(struct bpf_prog *prog)
543{
544}
Daniel Borkmann6d67942dd2016-11-19 01:45:03 +0100545
546static inline struct bpf_prog * __must_check bpf_prog_inc(struct bpf_prog *prog)
Alexei Starovoitovaa6a5f32016-09-01 18:37:24 -0700547{
548 return ERR_PTR(-EOPNOTSUPP);
549}
Daniel Borkmann5ccb0712016-12-18 01:52:58 +0100550
John Fastabenda6f6df62017-08-15 22:32:22 -0700551static inline struct bpf_prog *__must_check
552bpf_prog_inc_not_zero(struct bpf_prog *prog)
553{
554 return ERR_PTR(-EOPNOTSUPP);
555}
556
Daniel Borkmann5ccb0712016-12-18 01:52:58 +0100557static inline int __bpf_prog_charge(struct user_struct *user, u32 pages)
558{
559 return 0;
560}
561
562static inline void __bpf_prog_uncharge(struct user_struct *user, u32 pages)
563{
564}
John Fastabend46f55cf2017-07-17 21:56:48 -0700565
Chenbo Feng6e71b042017-10-18 13:00:22 -0700566static inline int bpf_obj_get_user(const char __user *pathname, int flags)
Shmulik Ladkani98589a02017-10-09 15:27:15 +0300567{
568 return -EOPNOTSUPP;
569}
570
John Fastabend46f55cf2017-07-17 21:56:48 -0700571static inline struct net_device *__dev_map_lookup_elem(struct bpf_map *map,
572 u32 key)
573{
574 return NULL;
575}
576
577static inline void __dev_map_insert_ctx(struct bpf_map *map, u32 index)
578{
579}
580
581static inline void __dev_map_flush(struct bpf_map *map)
582{
583}
Jesper Dangaard Brouer9c270af2017-10-16 12:19:34 +0200584
Jesper Dangaard Brouer67f29e02018-05-24 16:45:46 +0200585struct xdp_buff;
586struct bpf_dtab_netdev;
587
588static inline
Jesper Dangaard Brouer38edddb2018-05-24 16:45:57 +0200589int dev_map_enqueue(struct bpf_dtab_netdev *dst, struct xdp_buff *xdp,
590 struct net_device *dev_rx)
Jesper Dangaard Brouer67f29e02018-05-24 16:45:46 +0200591{
592 return 0;
593}
594
Toshiaki Makita6d5fc192018-06-14 11:07:42 +0900595struct sk_buff;
596
597static inline int dev_map_generic_redirect(struct bpf_dtab_netdev *dst,
598 struct sk_buff *skb,
599 struct bpf_prog *xdp_prog)
600{
601 return 0;
602}
603
Jesper Dangaard Brouer9c270af2017-10-16 12:19:34 +0200604static inline
605struct bpf_cpu_map_entry *__cpu_map_lookup_elem(struct bpf_map *map, u32 key)
606{
607 return NULL;
608}
609
610static inline void __cpu_map_insert_ctx(struct bpf_map *map, u32 index)
611{
612}
613
614static inline void __cpu_map_flush(struct bpf_map *map)
615{
616}
617
Jesper Dangaard Brouer9c270af2017-10-16 12:19:34 +0200618static inline int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu,
619 struct xdp_buff *xdp,
620 struct net_device *dev_rx)
621{
622 return 0;
623}
Al Viro040ee692017-12-02 20:20:38 -0500624
625static inline struct bpf_prog *bpf_prog_get_type_path(const char *name,
626 enum bpf_prog_type type)
627{
628 return ERR_PTR(-EOPNOTSUPP);
629}
Daniel Borkmann61e021f2015-03-02 15:21:55 +0100630#endif /* CONFIG_BPF_SYSCALL */
Alexei Starovoitov09756af2014-09-26 00:17:00 -0700631
Jakub Kicinski479321e2017-11-20 15:21:56 -0800632static inline struct bpf_prog *bpf_prog_get_type(u32 ufd,
633 enum bpf_prog_type type)
634{
635 return bpf_prog_get_type_dev(ufd, type, false);
636}
637
Al Viro040ee692017-12-02 20:20:38 -0500638bool bpf_prog_get_ok(struct bpf_prog *, enum bpf_prog_type *, bool);
639
Jakub Kicinskiab3f0062017-11-03 13:56:17 -0700640int bpf_prog_offload_compile(struct bpf_prog *prog);
641void bpf_prog_offload_destroy(struct bpf_prog *prog);
Jakub Kicinski675fc272017-12-27 18:39:09 -0800642int bpf_prog_offload_info_fill(struct bpf_prog_info *info,
643 struct bpf_prog *prog);
Jakub Kicinskiab3f0062017-11-03 13:56:17 -0700644
Jakub Kicinski52775b32018-01-17 19:13:28 -0800645int bpf_map_offload_info_fill(struct bpf_map_info *info, struct bpf_map *map);
646
Jakub Kicinskia3884572018-01-11 20:29:09 -0800647int bpf_map_offload_lookup_elem(struct bpf_map *map, void *key, void *value);
648int bpf_map_offload_update_elem(struct bpf_map *map,
649 void *key, void *value, u64 flags);
650int bpf_map_offload_delete_elem(struct bpf_map *map, void *key);
651int bpf_map_offload_get_next_key(struct bpf_map *map,
652 void *key, void *next_key);
653
Jakub Kicinski09728262018-07-17 10:53:23 -0700654bool bpf_offload_prog_map_match(struct bpf_prog *prog, struct bpf_map *map);
Jakub Kicinskia3884572018-01-11 20:29:09 -0800655
Jakub Kicinski602144c2018-07-17 10:53:25 -0700656struct bpf_offload_dev *bpf_offload_dev_create(void);
657void bpf_offload_dev_destroy(struct bpf_offload_dev *offdev);
658int bpf_offload_dev_netdev_register(struct bpf_offload_dev *offdev,
659 struct net_device *netdev);
660void bpf_offload_dev_netdev_unregister(struct bpf_offload_dev *offdev,
661 struct net_device *netdev);
Jakub Kicinskifd4f2272018-07-17 10:53:26 -0700662bool bpf_offload_dev_match(struct bpf_prog *prog, struct net_device *netdev);
Jakub Kicinski9fd7c552018-07-17 10:53:24 -0700663
Jakub Kicinskiab3f0062017-11-03 13:56:17 -0700664#if defined(CONFIG_NET) && defined(CONFIG_BPF_SYSCALL)
665int bpf_prog_offload_init(struct bpf_prog *prog, union bpf_attr *attr);
666
Jakub Kicinski0d830032018-05-08 19:37:06 -0700667static inline bool bpf_prog_is_dev_bound(const struct bpf_prog_aux *aux)
Jakub Kicinskiab3f0062017-11-03 13:56:17 -0700668{
Jakub Kicinski9a18eed2017-12-27 18:39:04 -0800669 return aux->offload_requested;
Jakub Kicinskiab3f0062017-11-03 13:56:17 -0700670}
Jakub Kicinskia3884572018-01-11 20:29:09 -0800671
672static inline bool bpf_map_is_dev_bound(struct bpf_map *map)
673{
674 return unlikely(map->ops == &bpf_map_offload_ops);
675}
676
677struct bpf_map *bpf_map_offload_map_alloc(union bpf_attr *attr);
678void bpf_map_offload_map_free(struct bpf_map *map);
Jakub Kicinskiab3f0062017-11-03 13:56:17 -0700679#else
680static inline int bpf_prog_offload_init(struct bpf_prog *prog,
681 union bpf_attr *attr)
682{
683 return -EOPNOTSUPP;
684}
685
686static inline bool bpf_prog_is_dev_bound(struct bpf_prog_aux *aux)
687{
688 return false;
689}
Jakub Kicinskia3884572018-01-11 20:29:09 -0800690
691static inline bool bpf_map_is_dev_bound(struct bpf_map *map)
692{
693 return false;
694}
695
696static inline struct bpf_map *bpf_map_offload_map_alloc(union bpf_attr *attr)
697{
698 return ERR_PTR(-EOPNOTSUPP);
699}
700
701static inline void bpf_map_offload_map_free(struct bpf_map *map)
702{
703}
Jakub Kicinskiab3f0062017-11-03 13:56:17 -0700704#endif /* CONFIG_NET && CONFIG_BPF_SYSCALL */
705
John Fastabend5f103c52018-01-03 17:57:56 -0800706#if defined(CONFIG_STREAM_PARSER) && defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_INET)
John Fastabend6bdc9c42017-08-16 15:02:32 -0700707struct sock *__sock_map_lookup_elem(struct bpf_map *map, u32 key);
John Fastabend81110382018-05-14 10:00:17 -0700708struct sock *__sock_hash_lookup_elem(struct bpf_map *map, void *key);
John Fastabend5a67da22017-09-08 14:00:49 -0700709int sock_map_prog(struct bpf_map *map, struct bpf_prog *prog, u32 type);
Sean Youngfdb5c452018-06-19 00:04:24 +0100710int sockmap_get_from_fd(const union bpf_attr *attr, int type,
711 struct bpf_prog *prog);
John Fastabend6bdc9c42017-08-16 15:02:32 -0700712#else
713static inline struct sock *__sock_map_lookup_elem(struct bpf_map *map, u32 key)
714{
715 return NULL;
716}
John Fastabend464bc0f2017-08-28 07:10:04 -0700717
John Fastabend81110382018-05-14 10:00:17 -0700718static inline struct sock *__sock_hash_lookup_elem(struct bpf_map *map,
719 void *key)
720{
721 return NULL;
722}
723
John Fastabend5a67da22017-09-08 14:00:49 -0700724static inline int sock_map_prog(struct bpf_map *map,
725 struct bpf_prog *prog,
726 u32 type)
John Fastabend464bc0f2017-08-28 07:10:04 -0700727{
728 return -EOPNOTSUPP;
729}
Sean Youngfdb5c452018-06-19 00:04:24 +0100730
731static inline int sockmap_get_from_fd(const union bpf_attr *attr, int type,
732 struct bpf_prog *prog)
733{
734 return -EINVAL;
735}
John Fastabend6bdc9c42017-08-16 15:02:32 -0700736#endif
737
Björn Töpelfbfc5042018-05-02 13:01:28 +0200738#if defined(CONFIG_XDP_SOCKETS)
739struct xdp_sock;
740struct xdp_sock *__xsk_map_lookup_elem(struct bpf_map *map, u32 key);
741int __xsk_map_redirect(struct bpf_map *map, struct xdp_buff *xdp,
742 struct xdp_sock *xs);
743void __xsk_map_flush(struct bpf_map *map);
744#else
745struct xdp_sock;
746static inline struct xdp_sock *__xsk_map_lookup_elem(struct bpf_map *map,
747 u32 key)
748{
749 return NULL;
750}
751
752static inline int __xsk_map_redirect(struct bpf_map *map, struct xdp_buff *xdp,
753 struct xdp_sock *xs)
754{
755 return -EOPNOTSUPP;
756}
757
758static inline void __xsk_map_flush(struct bpf_map *map)
759{
760}
761#endif
762
Alexei Starovoitovd0003ec2014-11-13 17:36:49 -0800763/* verifier prototypes for helper functions called from eBPF programs */
Daniel Borkmanna2c83ff2015-03-01 12:31:42 +0100764extern const struct bpf_func_proto bpf_map_lookup_elem_proto;
765extern const struct bpf_func_proto bpf_map_update_elem_proto;
766extern const struct bpf_func_proto bpf_map_delete_elem_proto;
Alexei Starovoitovd0003ec2014-11-13 17:36:49 -0800767
Daniel Borkmann03e69b52015-03-14 02:27:16 +0100768extern const struct bpf_func_proto bpf_get_prandom_u32_proto;
Daniel Borkmannc04167c2015-03-14 02:27:17 +0100769extern const struct bpf_func_proto bpf_get_smp_processor_id_proto;
Daniel Borkmann2d0e30c2016-10-21 12:46:33 +0200770extern const struct bpf_func_proto bpf_get_numa_node_id_proto;
Alexei Starovoitov04fd61a2015-05-19 16:59:03 -0700771extern const struct bpf_func_proto bpf_tail_call_proto;
Daniel Borkmann17ca8cb2015-05-29 23:23:06 +0200772extern const struct bpf_func_proto bpf_ktime_get_ns_proto;
Alexei Starovoitovffeedaf2015-06-12 19:39:12 -0700773extern const struct bpf_func_proto bpf_get_current_pid_tgid_proto;
774extern const struct bpf_func_proto bpf_get_current_uid_gid_proto;
775extern const struct bpf_func_proto bpf_get_current_comm_proto;
Alexei Starovoitovd5a3b1f2016-02-17 19:58:58 -0800776extern const struct bpf_func_proto bpf_get_stackid_proto;
Yonghong Songc195651e2018-04-28 22:28:08 -0700777extern const struct bpf_func_proto bpf_get_stack_proto;
John Fastabend174a79f2017-08-15 22:32:47 -0700778extern const struct bpf_func_proto bpf_sock_map_update_proto;
John Fastabend81110382018-05-14 10:00:17 -0700779extern const struct bpf_func_proto bpf_sock_hash_update_proto;
Yonghong Songbf6fa2c2018-06-03 15:59:41 -0700780extern const struct bpf_func_proto bpf_get_current_cgroup_id_proto;
Daniel Borkmann03e69b52015-03-14 02:27:16 +0100781
Daniel Borkmann3ad00402015-10-08 01:20:39 +0200782/* Shared helpers among cBPF and eBPF. */
783void bpf_user_rnd_init_once(void);
784u64 bpf_user_rnd_u32(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
785
Alexei Starovoitov99c55f72014-09-26 00:16:57 -0700786#endif /* _LINUX_BPF_H */