aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/bpf.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/bpf.h')
-rw-r--r--include/linux/bpf.h76
1 files changed, 63 insertions, 13 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 44f26f6df8fc..5c2c104dc2c5 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -25,6 +25,7 @@ struct bpf_map;
25/* map is generic key/value storage optionally accesible by eBPF programs */ 25/* map is generic key/value storage optionally accesible by eBPF programs */
26struct bpf_map_ops { 26struct bpf_map_ops {
27 /* funcs callable from userspace (via syscall) */ 27 /* funcs callable from userspace (via syscall) */
28 int (*map_alloc_check)(union bpf_attr *attr);
28 struct bpf_map *(*map_alloc)(union bpf_attr *attr); 29 struct bpf_map *(*map_alloc)(union bpf_attr *attr);
29 void (*map_release)(struct bpf_map *map, struct file *map_file); 30 void (*map_release)(struct bpf_map *map, struct file *map_file);
30 void (*map_free)(struct bpf_map *map); 31 void (*map_free)(struct bpf_map *map);
@@ -73,6 +74,33 @@ struct bpf_map {
73 char name[BPF_OBJ_NAME_LEN]; 74 char name[BPF_OBJ_NAME_LEN];
74}; 75};
75 76
77struct bpf_offloaded_map;
78
79struct bpf_map_dev_ops {
80 int (*map_get_next_key)(struct bpf_offloaded_map *map,
81 void *key, void *next_key);
82 int (*map_lookup_elem)(struct bpf_offloaded_map *map,
83 void *key, void *value);
84 int (*map_update_elem)(struct bpf_offloaded_map *map,
85 void *key, void *value, u64 flags);
86 int (*map_delete_elem)(struct bpf_offloaded_map *map, void *key);
87};
88
89struct bpf_offloaded_map {
90 struct bpf_map map;
91 struct net_device *netdev;
92 const struct bpf_map_dev_ops *dev_ops;
93 void *dev_priv;
94 struct list_head offloads;
95};
96
97static inline struct bpf_offloaded_map *map_to_offmap(struct bpf_map *map)
98{
99 return container_of(map, struct bpf_offloaded_map, map);
100}
101
102extern const struct bpf_map_ops bpf_map_offload_ops;
103
76/* function argument constraints */ 104/* function argument constraints */
77enum bpf_arg_type { 105enum bpf_arg_type {
78 ARG_DONTCARE = 0, /* unused argument in helper function */ 106 ARG_DONTCARE = 0, /* unused argument in helper function */
@@ -199,7 +227,7 @@ struct bpf_prog_offload_ops {
199 int insn_idx, int prev_insn_idx); 227 int insn_idx, int prev_insn_idx);
200}; 228};
201 229
202struct bpf_dev_offload { 230struct bpf_prog_offload {
203 struct bpf_prog *prog; 231 struct bpf_prog *prog;
204 struct net_device *netdev; 232 struct net_device *netdev;
205 void *dev_priv; 233 void *dev_priv;
@@ -229,7 +257,7 @@ struct bpf_prog_aux {
229#ifdef CONFIG_SECURITY 257#ifdef CONFIG_SECURITY
230 void *security; 258 void *security;
231#endif 259#endif
232 struct bpf_dev_offload *offload; 260 struct bpf_prog_offload *offload;
233 union { 261 union {
234 struct work_struct work; 262 struct work_struct work;
235 struct rcu_head rcu; 263 struct rcu_head rcu;
@@ -368,6 +396,7 @@ int __bpf_prog_charge(struct user_struct *user, u32 pages);
368void __bpf_prog_uncharge(struct user_struct *user, u32 pages); 396void __bpf_prog_uncharge(struct user_struct *user, u32 pages);
369 397
370void bpf_prog_free_id(struct bpf_prog *prog, bool do_idr_lock); 398void bpf_prog_free_id(struct bpf_prog *prog, bool do_idr_lock);
399void bpf_map_free_id(struct bpf_map *map, bool do_idr_lock);
371 400
372struct bpf_map *bpf_map_get_with_uref(u32 ufd); 401struct bpf_map *bpf_map_get_with_uref(u32 ufd);
373struct bpf_map *__bpf_map_get(struct fd f); 402struct bpf_map *__bpf_map_get(struct fd f);
@@ -377,6 +406,7 @@ void bpf_map_put(struct bpf_map *map);
377int bpf_map_precharge_memlock(u32 pages); 406int bpf_map_precharge_memlock(u32 pages);
378void *bpf_map_area_alloc(size_t size, int numa_node); 407void *bpf_map_area_alloc(size_t size, int numa_node);
379void bpf_map_area_free(void *base); 408void bpf_map_area_free(void *base);
409void bpf_map_init_from_attr(struct bpf_map *map, union bpf_attr *attr);
380 410
381extern int sysctl_unprivileged_bpf_disabled; 411extern int sysctl_unprivileged_bpf_disabled;
382 412
@@ -554,6 +584,15 @@ void bpf_prog_offload_destroy(struct bpf_prog *prog);
554int bpf_prog_offload_info_fill(struct bpf_prog_info *info, 584int bpf_prog_offload_info_fill(struct bpf_prog_info *info,
555 struct bpf_prog *prog); 585 struct bpf_prog *prog);
556 586
587int bpf_map_offload_lookup_elem(struct bpf_map *map, void *key, void *value);
588int bpf_map_offload_update_elem(struct bpf_map *map,
589 void *key, void *value, u64 flags);
590int bpf_map_offload_delete_elem(struct bpf_map *map, void *key);
591int bpf_map_offload_get_next_key(struct bpf_map *map,
592 void *key, void *next_key);
593
594bool bpf_offload_dev_match(struct bpf_prog *prog, struct bpf_map *map);
595
557#if defined(CONFIG_NET) && defined(CONFIG_BPF_SYSCALL) 596#if defined(CONFIG_NET) && defined(CONFIG_BPF_SYSCALL)
558int bpf_prog_offload_init(struct bpf_prog *prog, union bpf_attr *attr); 597int bpf_prog_offload_init(struct bpf_prog *prog, union bpf_attr *attr);
559 598
@@ -561,6 +600,14 @@ static inline bool bpf_prog_is_dev_bound(struct bpf_prog_aux *aux)
561{ 600{
562 return aux->offload_requested; 601 return aux->offload_requested;
563} 602}
603
604static inline bool bpf_map_is_dev_bound(struct bpf_map *map)
605{
606 return unlikely(map->ops == &bpf_map_offload_ops);
607}
608
609struct bpf_map *bpf_map_offload_map_alloc(union bpf_attr *attr);
610void bpf_map_offload_map_free(struct bpf_map *map);
564#else 611#else
565static inline int bpf_prog_offload_init(struct bpf_prog *prog, 612static inline int bpf_prog_offload_init(struct bpf_prog *prog,
566 union bpf_attr *attr) 613 union bpf_attr *attr)
@@ -572,6 +619,20 @@ static inline bool bpf_prog_is_dev_bound(struct bpf_prog_aux *aux)
572{ 619{
573 return false; 620 return false;
574} 621}
622
623static inline bool bpf_map_is_dev_bound(struct bpf_map *map)
624{
625 return false;
626}
627
628static inline struct bpf_map *bpf_map_offload_map_alloc(union bpf_attr *attr)
629{
630 return ERR_PTR(-EOPNOTSUPP);
631}
632
633static inline void bpf_map_offload_map_free(struct bpf_map *map)
634{
635}
575#endif /* CONFIG_NET && CONFIG_BPF_SYSCALL */ 636#endif /* CONFIG_NET && CONFIG_BPF_SYSCALL */
576 637
577#if defined(CONFIG_STREAM_PARSER) && defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_INET) 638#if defined(CONFIG_STREAM_PARSER) && defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_INET)
@@ -613,15 +674,4 @@ extern const struct bpf_func_proto bpf_sock_map_update_proto;
613void bpf_user_rnd_init_once(void); 674void bpf_user_rnd_init_once(void);
614u64 bpf_user_rnd_u32(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5); 675u64 bpf_user_rnd_u32(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
615 676
616#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
617#ifdef CONFIG_BPF_KPROBE_OVERRIDE
618#define BPF_ALLOW_ERROR_INJECTION(fname) \
619static unsigned long __used \
620 __attribute__((__section__("_kprobe_error_inject_list"))) \
621 _eil_addr_##fname = (unsigned long)fname;
622#else
623#define BPF_ALLOW_ERROR_INJECTION(fname)
624#endif
625#endif
626
627#endif /* _LINUX_BPF_H */ 677#endif /* _LINUX_BPF_H */