aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/bpf.h
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2018-01-16 22:42:14 -0500
committerDavid S. Miller <davem@davemloft.net>2018-01-16 22:42:14 -0500
commit7018d1b3f20fb4308ed9bc577160cb8ffb79b62a (patch)
treeb61a17c694d3cdc3490b190c35104b936bcc6638 /include/linux/bpf.h
parente7e70fa6784b48a811fdd4253c41fc7195300570 (diff)
parente8a9d9683c8a62f917c19e57f1618363fb9ed04e (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Daniel Borkmann says: ==================== pull-request: bpf-next 2018-01-17 The following pull-request contains BPF updates for your *net-next* tree. The main changes are: 1) Add initial BPF map offloading for nfp driver. Currently only programs were supported so far w/o being able to access maps. Offloaded programs are right now only allowed to perform map lookups, and control path is responsible for populating the maps. BPF core infrastructure along with nfp implementation is provided, from Jakub. 2) Various follow-ups to Josef's BPF error injections. More specifically that includes: properly check whether the error injectable event is on function entry or not, remove the percpu bpf_kprobe_override and rather compare instruction pointer with original one, separate error-injection from kprobes since it's not limited to it, add injectable error types in order to specify what is the expected type of failure, and last but not least also support the kernel's fault injection framework, all from Masami. 3) Various misc improvements and cleanups to the libbpf Makefile. That is, fix permissions when installing BPF header files, remove unused variables and functions, and also install the libbpf.h header, from Jesper. 4) When offloading to nfp JIT and the BPF insn is unsupported in the JIT, then reject right at verification time. Also fix libbpf with regards to ELF section name matching by properly treating the program type as prefix. Both from Quentin. 5) Add -DPACKAGE to bpftool when including bfd.h for the disassembler. This is needed, for example, when building libfd from source as bpftool doesn't supply a config.h for bfd.h. Fix from Jiong. 6) xdp_convert_ctx_access() is simplified since it doesn't need to set target size during verification, from Jesper. 7) Let bpftool properly recognize BPF_PROG_TYPE_CGROUP_DEVICE program types, from Roman. 8) Various functions in BPF cpumap were not declared static, from Wei. 9) Fix a double semicolon in BPF samples, from Luis. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
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 */