Skip to content

Commit 43df215

Browse files
committed
Merge branch 'bpf-and-netdevsim-test-updates'
Jakub Kicinski says: ==================== bpf and netdevsim test updates A number of test improvements (delayed by merges). Quentin provides patches for checking printing to the verifier log from the drivers and validating extack messages are propagated. There is also a test for replacing TC filters to avoid adding back the bug Daniel recently fixed in net and stable. ==================== Acked-by: Daniel Borkmann <[email protected]> Signed-off-by: David S. Miller <[email protected]>
2 parents 5215046 + 6d2d58f commit 43df215

File tree

4 files changed

+216
-38
lines changed

4 files changed

+216
-38
lines changed

drivers/net/netdevsim/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ obj-$(CONFIG_NETDEVSIM) += netdevsim.o
44

55
netdevsim-objs := \
66
netdev.o \
7-
bpf.o \
7+
8+
ifeq ($(CONFIG_BPF_SYSCALL),y)
9+
netdevsim-objs += \
10+
bpf.o
11+
endif

drivers/net/netdevsim/bpf.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
#include "netdevsim.h"
2525

26+
#define pr_vlog(env, fmt, ...) \
27+
bpf_verifier_log_write(env, "[netdevsim] " fmt, ##__VA_ARGS__)
28+
2629
struct nsim_bpf_bound_prog {
2730
struct netdevsim *ns;
2831
struct bpf_prog *prog;
@@ -77,6 +80,9 @@ nsim_bpf_verify_insn(struct bpf_verifier_env *env, int insn_idx, int prev_insn)
7780
if (state->ns->bpf_bind_verifier_delay && !insn_idx)
7881
msleep(state->ns->bpf_bind_verifier_delay);
7982

83+
if (insn_idx == env->prog->len - 1)
84+
pr_vlog(env, "Hello from netdevsim!\n");
85+
8086
return 0;
8187
}
8288

@@ -123,17 +129,35 @@ int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type,
123129
struct netdevsim *ns = cb_priv;
124130
struct bpf_prog *oldprog;
125131

126-
if (type != TC_SETUP_CLSBPF ||
127-
!tc_can_offload(ns->netdev) ||
128-
cls_bpf->common.protocol != htons(ETH_P_ALL) ||
129-
cls_bpf->common.chain_index)
132+
if (type != TC_SETUP_CLSBPF) {
133+
NSIM_EA(cls_bpf->common.extack,
134+
"only offload of BPF classifiers supported");
130135
return -EOPNOTSUPP;
136+
}
131137

132-
if (!ns->bpf_tc_accept)
138+
if (!tc_can_offload_extack(ns->netdev, cls_bpf->common.extack))
133139
return -EOPNOTSUPP;
140+
141+
if (cls_bpf->common.protocol != htons(ETH_P_ALL)) {
142+
NSIM_EA(cls_bpf->common.extack,
143+
"only ETH_P_ALL supported as filter protocol");
144+
return -EOPNOTSUPP;
145+
}
146+
147+
if (cls_bpf->common.chain_index)
148+
return -EOPNOTSUPP;
149+
150+
if (!ns->bpf_tc_accept) {
151+
NSIM_EA(cls_bpf->common.extack,
152+
"netdevsim configured to reject BPF TC offload");
153+
return -EOPNOTSUPP;
154+
}
134155
/* Note: progs without skip_sw will probably not be dev bound */
135-
if (prog && !prog->aux->offload && !ns->bpf_tc_non_bound_accept)
156+
if (prog && !prog->aux->offload && !ns->bpf_tc_non_bound_accept) {
157+
NSIM_EA(cls_bpf->common.extack,
158+
"netdevsim configured to reject unbound programs");
136159
return -EOPNOTSUPP;
160+
}
137161

138162
if (cls_bpf->command != TC_CLSBPF_OFFLOAD)
139163
return -EOPNOTSUPP;
@@ -145,8 +169,11 @@ int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type,
145169
oldprog = NULL;
146170
if (!cls_bpf->prog)
147171
return 0;
148-
if (ns->bpf_offloaded)
172+
if (ns->bpf_offloaded) {
173+
NSIM_EA(cls_bpf->common.extack,
174+
"driver and netdev offload states mismatch");
149175
return -EBUSY;
176+
}
150177
}
151178

152179
return nsim_bpf_offload(ns, cls_bpf->prog, oldprog);

drivers/net/netdevsim/netdevsim.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,40 @@ struct netdevsim {
6868

6969
extern struct dentry *nsim_ddir;
7070

71+
#ifdef CONFIG_BPF_SYSCALL
7172
int nsim_bpf_init(struct netdevsim *ns);
7273
void nsim_bpf_uninit(struct netdevsim *ns);
7374
int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf);
7475
int nsim_bpf_disable_tc(struct netdevsim *ns);
7576
int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type,
7677
void *type_data, void *cb_priv);
78+
#else
79+
static inline int nsim_bpf_init(struct netdevsim *ns)
80+
{
81+
return 0;
82+
}
83+
84+
static inline void nsim_bpf_uninit(struct netdevsim *ns)
85+
{
86+
}
87+
88+
static inline int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf)
89+
{
90+
return bpf->command == XDP_QUERY_PROG ? 0 : -EOPNOTSUPP;
91+
}
92+
93+
static inline int nsim_bpf_disable_tc(struct netdevsim *ns)
94+
{
95+
return 0;
96+
}
97+
98+
static inline int
99+
nsim_bpf_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
100+
void *cb_priv)
101+
{
102+
return -EOPNOTSUPP;
103+
}
104+
#endif
77105

78106
static inline struct netdevsim *to_nsim(struct device *ptr)
79107
{

0 commit comments

Comments
 (0)