Skip to content

Commit 954b3c4

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Alexei Starovoitov says: ==================== pull-request: bpf-next 2020-01-22 The following pull-request contains BPF updates for your *net-next* tree. We've added 92 non-merge commits during the last 16 day(s) which contain a total of 320 files changed, 7532 insertions(+), 1448 deletions(-). The main changes are: 1) function by function verification and program extensions from Alexei. 2) massive cleanup of selftests/bpf from Toke and Andrii. 3) batched bpf map operations from Brian and Yonghong. 4) tcp congestion control in bpf from Martin. 5) bulking for non-map xdp_redirect form Toke. 6) bpf_send_signal_thread helper from Yonghong. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents c5d19a6 + 85cc12f commit 954b3c4

320 files changed

Lines changed: 7532 additions & 1448 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎arch/x86/net/bpf_jit_comp.c‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ xadd: if (is_imm8(insn->off))
13281328
return proglen;
13291329
}
13301330

1331-
static void save_regs(struct btf_func_model *m, u8 **prog, int nr_args,
1331+
static void save_regs(const struct btf_func_model *m, u8 **prog, int nr_args,
13321332
int stack_size)
13331333
{
13341334
int i;
@@ -1344,7 +1344,7 @@ static void save_regs(struct btf_func_model *m, u8 **prog, int nr_args,
13441344
-(stack_size - i * 8));
13451345
}
13461346

1347-
static void restore_regs(struct btf_func_model *m, u8 **prog, int nr_args,
1347+
static void restore_regs(const struct btf_func_model *m, u8 **prog, int nr_args,
13481348
int stack_size)
13491349
{
13501350
int i;
@@ -1361,7 +1361,7 @@ static void restore_regs(struct btf_func_model *m, u8 **prog, int nr_args,
13611361
-(stack_size - i * 8));
13621362
}
13631363

1364-
static int invoke_bpf(struct btf_func_model *m, u8 **pprog,
1364+
static int invoke_bpf(const struct btf_func_model *m, u8 **pprog,
13651365
struct bpf_prog **progs, int prog_cnt, int stack_size)
13661366
{
13671367
u8 *prog = *pprog;
@@ -1456,7 +1456,8 @@ static int invoke_bpf(struct btf_func_model *m, u8 **pprog,
14561456
* add rsp, 8 // skip eth_type_trans's frame
14571457
* ret // return to its caller
14581458
*/
1459-
int arch_prepare_bpf_trampoline(void *image, struct btf_func_model *m, u32 flags,
1459+
int arch_prepare_bpf_trampoline(void *image, void *image_end,
1460+
const struct btf_func_model *m, u32 flags,
14601461
struct bpf_prog **fentry_progs, int fentry_cnt,
14611462
struct bpf_prog **fexit_progs, int fexit_cnt,
14621463
void *orig_call)
@@ -1523,13 +1524,10 @@ int arch_prepare_bpf_trampoline(void *image, struct btf_func_model *m, u32 flags
15231524
/* skip our return address and return to parent */
15241525
EMIT4(0x48, 0x83, 0xC4, 8); /* add rsp, 8 */
15251526
EMIT1(0xC3); /* ret */
1526-
/* One half of the page has active running trampoline.
1527-
* Another half is an area for next trampoline.
1528-
* Make sure the trampoline generation logic doesn't overflow.
1529-
*/
1530-
if (WARN_ON_ONCE(prog - (u8 *)image > PAGE_SIZE / 2 - BPF_INSN_SAFETY))
1527+
/* Make sure the trampoline generation logic doesn't overflow */
1528+
if (WARN_ON_ONCE(prog > (u8 *)image_end - BPF_INSN_SAFETY))
15311529
return -EFAULT;
1532-
return 0;
1530+
return prog - (u8 *)image;
15331531
}
15341532

15351533
static int emit_cond_near_jump(u8 **pprog, void *func, void *ip, u8 jmp_cond)

‎drivers/net/tun.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
17181718
if (err < 0)
17191719
goto err_xdp;
17201720
if (err == XDP_REDIRECT)
1721-
xdp_do_flush_map();
1721+
xdp_do_flush();
17221722
if (err != XDP_PASS)
17231723
goto out;
17241724

@@ -2549,7 +2549,7 @@ static int tun_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)
25492549
}
25502550

25512551
if (flush)
2552-
xdp_do_flush_map();
2552+
xdp_do_flush();
25532553

25542554
rcu_read_unlock();
25552555
local_bh_enable();

‎drivers/net/veth.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ static int veth_poll(struct napi_struct *napi, int budget)
769769
if (xdp_xmit & VETH_XDP_TX)
770770
veth_xdp_flush(rq->dev, &bq);
771771
if (xdp_xmit & VETH_XDP_REDIR)
772-
xdp_do_flush_map();
772+
xdp_do_flush();
773773
xdp_clear_return_frame_no_direct();
774774

775775
return done;

‎drivers/net/virtio_net.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ static int virtnet_poll(struct napi_struct *napi, int budget)
14321432
virtqueue_napi_complete(napi, rq->vq, received);
14331433

14341434
if (xdp_xmit & VIRTIO_XDP_REDIR)
1435-
xdp_do_flush_map();
1435+
xdp_do_flush();
14361436

14371437
if (xdp_xmit & VIRTIO_XDP_TX) {
14381438
sq = virtnet_xdp_sq(vi);

‎include/linux/bpf.h‎

Lines changed: 122 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/u64_stats_sync.h>
1818
#include <linux/refcount.h>
1919
#include <linux/mutex.h>
20+
#include <linux/module.h>
2021

2122
struct bpf_verifier_env;
2223
struct bpf_verifier_log;
@@ -43,6 +44,15 @@ struct bpf_map_ops {
4344
int (*map_get_next_key)(struct bpf_map *map, void *key, void *next_key);
4445
void (*map_release_uref)(struct bpf_map *map);
4546
void *(*map_lookup_elem_sys_only)(struct bpf_map *map, void *key);
47+
int (*map_lookup_batch)(struct bpf_map *map, const union bpf_attr *attr,
48+
union bpf_attr __user *uattr);
49+
int (*map_lookup_and_delete_batch)(struct bpf_map *map,
50+
const union bpf_attr *attr,
51+
union bpf_attr __user *uattr);
52+
int (*map_update_batch)(struct bpf_map *map, const union bpf_attr *attr,
53+
union bpf_attr __user *uattr);
54+
int (*map_delete_batch)(struct bpf_map *map, const union bpf_attr *attr,
55+
union bpf_attr __user *uattr);
4656

4757
/* funcs callable from userspace and from eBPF programs */
4858
void *(*map_lookup_elem)(struct bpf_map *map, void *key);
@@ -106,6 +116,7 @@ struct bpf_map {
106116
struct btf *btf;
107117
struct bpf_map_memory memory;
108118
char name[BPF_OBJ_NAME_LEN];
119+
u32 btf_vmlinux_value_type_id;
109120
bool unpriv_array;
110121
bool frozen; /* write-once; write-protected by freeze_mutex */
111122
/* 22 bytes hole */
@@ -183,7 +194,8 @@ static inline bool bpf_map_offload_neutral(const struct bpf_map *map)
183194

184195
static inline bool bpf_map_support_seq_show(const struct bpf_map *map)
185196
{
186-
return map->btf && map->ops->map_seq_show_elem;
197+
return (map->btf_value_type_id || map->btf_vmlinux_value_type_id) &&
198+
map->ops->map_seq_show_elem;
187199
}
188200

189201
int map_check_no_btf(const struct bpf_map *map,
@@ -349,6 +361,10 @@ struct bpf_verifier_ops {
349361
const struct bpf_insn *src,
350362
struct bpf_insn *dst,
351363
struct bpf_prog *prog, u32 *target_size);
364+
int (*btf_struct_access)(struct bpf_verifier_log *log,
365+
const struct btf_type *t, int off, int size,
366+
enum bpf_access_type atype,
367+
u32 *next_btf_id);
352368
};
353369

354370
struct bpf_prog_offload_ops {
@@ -437,7 +453,8 @@ struct btf_func_model {
437453
* fentry = a set of program to run before calling original function
438454
* fexit = a set of program to run after original function
439455
*/
440-
int arch_prepare_bpf_trampoline(void *image, struct btf_func_model *m, u32 flags,
456+
int arch_prepare_bpf_trampoline(void *image, void *image_end,
457+
const struct btf_func_model *m, u32 flags,
441458
struct bpf_prog **fentry_progs, int fentry_cnt,
442459
struct bpf_prog **fexit_progs, int fexit_cnt,
443460
void *orig_call);
@@ -448,7 +465,8 @@ void notrace __bpf_prog_exit(struct bpf_prog *prog, u64 start);
448465
enum bpf_tramp_prog_type {
449466
BPF_TRAMP_FENTRY,
450467
BPF_TRAMP_FEXIT,
451-
BPF_TRAMP_MAX
468+
BPF_TRAMP_MAX,
469+
BPF_TRAMP_REPLACE, /* more than MAX */
452470
};
453471

454472
struct bpf_trampoline {
@@ -463,6 +481,11 @@ struct bpf_trampoline {
463481
void *addr;
464482
bool ftrace_managed;
465483
} func;
484+
/* if !NULL this is BPF_PROG_TYPE_EXT program that extends another BPF
485+
* program by replacing one of its functions. func.addr is the address
486+
* of the function it replaced.
487+
*/
488+
struct bpf_prog *extension_prog;
466489
/* list of BPF programs using this trampoline */
467490
struct hlist_head progs_hlist[BPF_TRAMP_MAX];
468491
/* Number of attached programs. A counter per kind. */
@@ -558,6 +581,7 @@ static inline void bpf_dispatcher_change_prog(struct bpf_dispatcher *d,
558581
#endif
559582

560583
struct bpf_func_info_aux {
584+
u16 linkage;
561585
bool unreliable;
562586
};
563587

@@ -668,6 +692,73 @@ struct bpf_array_aux {
668692
struct work_struct work;
669693
};
670694

695+
struct bpf_struct_ops_value;
696+
struct btf_type;
697+
struct btf_member;
698+
699+
#define BPF_STRUCT_OPS_MAX_NR_MEMBERS 64
700+
struct bpf_struct_ops {
701+
const struct bpf_verifier_ops *verifier_ops;
702+
int (*init)(struct btf *btf);
703+
int (*check_member)(const struct btf_type *t,
704+
const struct btf_member *member);
705+
int (*init_member)(const struct btf_type *t,
706+
const struct btf_member *member,
707+
void *kdata, const void *udata);
708+
int (*reg)(void *kdata);
709+
void (*unreg)(void *kdata);
710+
const struct btf_type *type;
711+
const struct btf_type *value_type;
712+
const char *name;
713+
struct btf_func_model func_models[BPF_STRUCT_OPS_MAX_NR_MEMBERS];
714+
u32 type_id;
715+
u32 value_id;
716+
};
717+
718+
#if defined(CONFIG_BPF_JIT) && defined(CONFIG_BPF_SYSCALL)
719+
#define BPF_MODULE_OWNER ((void *)((0xeB9FUL << 2) + POISON_POINTER_DELTA))
720+
const struct bpf_struct_ops *bpf_struct_ops_find(u32 type_id);
721+
void bpf_struct_ops_init(struct btf *btf);
722+
bool bpf_struct_ops_get(const void *kdata);
723+
void bpf_struct_ops_put(const void *kdata);
724+
int bpf_struct_ops_map_sys_lookup_elem(struct bpf_map *map, void *key,
725+
void *value);
726+
static inline bool bpf_try_module_get(const void *data, struct module *owner)
727+
{
728+
if (owner == BPF_MODULE_OWNER)
729+
return bpf_struct_ops_get(data);
730+
else
731+
return try_module_get(owner);
732+
}
733+
static inline void bpf_module_put(const void *data, struct module *owner)
734+
{
735+
if (owner == BPF_MODULE_OWNER)
736+
bpf_struct_ops_put(data);
737+
else
738+
module_put(owner);
739+
}
740+
#else
741+
static inline const struct bpf_struct_ops *bpf_struct_ops_find(u32 type_id)
742+
{
743+
return NULL;
744+
}
745+
static inline void bpf_struct_ops_init(struct btf *btf) { }
746+
static inline bool bpf_try_module_get(const void *data, struct module *owner)
747+
{
748+
return try_module_get(owner);
749+
}
750+
static inline void bpf_module_put(const void *data, struct module *owner)
751+
{
752+
module_put(owner);
753+
}
754+
static inline int bpf_struct_ops_map_sys_lookup_elem(struct bpf_map *map,
755+
void *key,
756+
void *value)
757+
{
758+
return -EINVAL;
759+
}
760+
#endif
761+
671762
struct bpf_array {
672763
struct bpf_map map;
673764
u32 elem_size;
@@ -906,6 +997,15 @@ void *bpf_map_area_alloc(u64 size, int numa_node);
906997
void *bpf_map_area_mmapable_alloc(u64 size, int numa_node);
907998
void bpf_map_area_free(void *base);
908999
void bpf_map_init_from_attr(struct bpf_map *map, union bpf_attr *attr);
1000+
int generic_map_lookup_batch(struct bpf_map *map,
1001+
const union bpf_attr *attr,
1002+
union bpf_attr __user *uattr);
1003+
int generic_map_update_batch(struct bpf_map *map,
1004+
const union bpf_attr *attr,
1005+
union bpf_attr __user *uattr);
1006+
int generic_map_delete_batch(struct bpf_map *map,
1007+
const union bpf_attr *attr,
1008+
union bpf_attr __user *uattr);
9091009

9101010
extern int sysctl_unprivileged_bpf_disabled;
9111011

@@ -962,7 +1062,9 @@ struct sk_buff;
9621062

9631063
struct bpf_dtab_netdev *__dev_map_lookup_elem(struct bpf_map *map, u32 key);
9641064
struct bpf_dtab_netdev *__dev_map_hash_lookup_elem(struct bpf_map *map, u32 key);
965-
void __dev_map_flush(void);
1065+
void __dev_flush(void);
1066+
int dev_xdp_enqueue(struct net_device *dev, struct xdp_buff *xdp,
1067+
struct net_device *dev_rx);
9661068
int dev_map_enqueue(struct bpf_dtab_netdev *dst, struct xdp_buff *xdp,
9671069
struct net_device *dev_rx);
9681070
int dev_map_generic_redirect(struct bpf_dtab_netdev *dst, struct sk_buff *skb,
@@ -1006,7 +1108,13 @@ int btf_distill_func_proto(struct bpf_verifier_log *log,
10061108
const char *func_name,
10071109
struct btf_func_model *m);
10081110

1009-
int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog);
1111+
struct bpf_reg_state;
1112+
int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog,
1113+
struct bpf_reg_state *regs);
1114+
int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog,
1115+
struct bpf_reg_state *reg);
1116+
int btf_check_type_match(struct bpf_verifier_env *env, struct bpf_prog *prog,
1117+
struct btf *btf, const struct btf_type *t);
10101118

10111119
struct bpf_prog *bpf_prog_by_id(u32 id);
10121120

@@ -1071,13 +1179,20 @@ static inline struct net_device *__dev_map_hash_lookup_elem(struct bpf_map *map
10711179
return NULL;
10721180
}
10731181

1074-
static inline void __dev_map_flush(void)
1182+
static inline void __dev_flush(void)
10751183
{
10761184
}
10771185

10781186
struct xdp_buff;
10791187
struct bpf_dtab_netdev;
10801188

1189+
static inline
1190+
int dev_xdp_enqueue(struct net_device *dev, struct xdp_buff *xdp,
1191+
struct net_device *dev_rx)
1192+
{
1193+
return 0;
1194+
}
1195+
10811196
static inline
10821197
int dev_map_enqueue(struct bpf_dtab_netdev *dst, struct xdp_buff *xdp,
10831198
struct net_device *dev_rx)
@@ -1299,6 +1414,7 @@ extern const struct bpf_func_proto bpf_get_local_storage_proto;
12991414
extern const struct bpf_func_proto bpf_strtol_proto;
13001415
extern const struct bpf_func_proto bpf_strtoul_proto;
13011416
extern const struct bpf_func_proto bpf_tcp_sock_proto;
1417+
extern const struct bpf_func_proto bpf_jiffies64_proto;
13021418

13031419
/* Shared helpers among cBPF and eBPF. */
13041420
void bpf_user_rnd_init_once(void);

‎include/linux/bpf_types.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ BPF_PROG_TYPE(BPF_PROG_TYPE_LIRC_MODE2, lirc_mode2,
6565
BPF_PROG_TYPE(BPF_PROG_TYPE_SK_REUSEPORT, sk_reuseport,
6666
struct sk_reuseport_md, struct sk_reuseport_kern)
6767
#endif
68+
#if defined(CONFIG_BPF_JIT)
69+
BPF_PROG_TYPE(BPF_PROG_TYPE_STRUCT_OPS, bpf_struct_ops,
70+
void *, void *)
71+
BPF_PROG_TYPE(BPF_PROG_TYPE_EXT, bpf_extension,
72+
void *, void *)
73+
#endif
6874

6975
BPF_MAP_TYPE(BPF_MAP_TYPE_ARRAY, array_map_ops)
7076
BPF_MAP_TYPE(BPF_MAP_TYPE_PERCPU_ARRAY, percpu_array_map_ops)
@@ -105,3 +111,6 @@ BPF_MAP_TYPE(BPF_MAP_TYPE_REUSEPORT_SOCKARRAY, reuseport_array_ops)
105111
#endif
106112
BPF_MAP_TYPE(BPF_MAP_TYPE_QUEUE, queue_map_ops)
107113
BPF_MAP_TYPE(BPF_MAP_TYPE_STACK, stack_map_ops)
114+
#if defined(CONFIG_BPF_JIT)
115+
BPF_MAP_TYPE(BPF_MAP_TYPE_STRUCT_OPS, bpf_struct_ops_map_ops)
116+
#endif

‎include/linux/bpf_verifier.h‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,13 @@ struct bpf_insn_aux_data {
304304
u64 map_key_state; /* constant (32 bit) key tracking for maps */
305305
int ctx_field_size; /* the ctx field size for load insn, maybe 0 */
306306
int sanitize_stack_off; /* stack slot to be cleared */
307-
bool seen; /* this insn was processed by the verifier */
307+
u32 seen; /* this insn was processed by the verifier at env->pass_cnt */
308308
bool zext_dst; /* this insn zero extends dst reg */
309309
u8 alu_state; /* used in combination with alu_limit */
310-
bool prune_point;
310+
311+
/* below fields are initialized once */
311312
unsigned int orig_idx; /* original instruction index */
313+
bool prune_point;
312314
};
313315

314316
#define MAX_USED_MAPS 64 /* max number of maps accessed by one eBPF program */
@@ -379,6 +381,7 @@ struct bpf_verifier_env {
379381
int *insn_stack;
380382
int cur_stack;
381383
} cfg;
384+
u32 pass_cnt; /* number of times do_check() was called */
382385
u32 subprog_cnt;
383386
/* number of instructions analyzed by the verifier */
384387
u32 prev_insn_processed, insn_processed;
@@ -428,4 +431,7 @@ bpf_prog_offload_replace_insn(struct bpf_verifier_env *env, u32 off,
428431
void
429432
bpf_prog_offload_remove_insns(struct bpf_verifier_env *env, u32 off, u32 cnt);
430433

434+
int check_ctx_reg(struct bpf_verifier_env *env,
435+
const struct bpf_reg_state *reg, int regno);
436+
431437
#endif /* _LINUX_BPF_VERIFIER_H */

0 commit comments

Comments
 (0)