* [PATCH net-next 0/5] bpf and netdevsim test updates
@ 2018-01-23 19:22 Jakub Kicinski
2018-01-23 19:22 ` [PATCH net-next 1/5] netdevsim: add extack support for TC eBPF offload Jakub Kicinski
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Jakub Kicinski @ 2018-01-23 19:22 UTC (permalink / raw)
To: davem, alexei.starovoitov, daniel; +Cc: netdev, oss-drivers, Jakub Kicinski
Hi!
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.
Daniel, Alexei, could this be taken directly to net-next? I have
two series worth of follow ups to extack, including netdevsim and
test_offload.py changes.
Jakub Kicinski (2):
netdevsim: don't compile BPF code if syscall not enabled
selftests/bpf: validate replace of TC filters is working
Quentin Monnet (3):
netdevsim: add extack support for TC eBPF offload
selftests/bpf: add checks on extack messages for eBPF hw offload tests
selftests/bpf: check bpf verifier log buffer usage works for HW
offload
drivers/net/netdevsim/Makefile | 6 +-
drivers/net/netdevsim/bpf.c | 41 +++++--
drivers/net/netdevsim/netdevsim.h | 28 +++++
tools/testing/selftests/bpf/test_offload.py | 179 +++++++++++++++++++++++-----
4 files changed, 216 insertions(+), 38 deletions(-)
--
2.15.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH net-next 1/5] netdevsim: add extack support for TC eBPF offload
2018-01-23 19:22 [PATCH net-next 0/5] bpf and netdevsim test updates Jakub Kicinski
@ 2018-01-23 19:22 ` Jakub Kicinski
2018-01-23 19:22 ` [PATCH net-next 2/5] selftests/bpf: add checks on extack messages for eBPF hw offload tests Jakub Kicinski
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2018-01-23 19:22 UTC (permalink / raw)
To: davem, alexei.starovoitov, daniel; +Cc: netdev, oss-drivers, Quentin Monnet
From: Quentin Monnet <quentin.monnet@netronome.com>
Use the recently added extack support for TC eBPF filters in netdevsim.
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
drivers/net/netdevsim/bpf.c | 35 ++++++++++++++++++++++++++++-------
1 file changed, 28 insertions(+), 7 deletions(-)
diff --git a/drivers/net/netdevsim/bpf.c b/drivers/net/netdevsim/bpf.c
index b3851bbefad3..940c63eeebf9 100644
--- a/drivers/net/netdevsim/bpf.c
+++ b/drivers/net/netdevsim/bpf.c
@@ -123,17 +123,35 @@ int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type,
struct netdevsim *ns = cb_priv;
struct bpf_prog *oldprog;
- if (type != TC_SETUP_CLSBPF ||
- !tc_can_offload(ns->netdev) ||
- cls_bpf->common.protocol != htons(ETH_P_ALL) ||
- cls_bpf->common.chain_index)
+ if (type != TC_SETUP_CLSBPF) {
+ NSIM_EA(cls_bpf->common.extack,
+ "only offload of BPF classifiers supported");
return -EOPNOTSUPP;
+ }
+
+ if (!tc_can_offload_extack(ns->netdev, cls_bpf->common.extack))
+ return -EOPNOTSUPP;
+
+ if (cls_bpf->common.protocol != htons(ETH_P_ALL)) {
+ NSIM_EA(cls_bpf->common.extack,
+ "only ETH_P_ALL supported as filter protocol");
+ return -EOPNOTSUPP;
+ }
- if (!ns->bpf_tc_accept)
+ if (cls_bpf->common.chain_index)
return -EOPNOTSUPP;
+
+ if (!ns->bpf_tc_accept) {
+ NSIM_EA(cls_bpf->common.extack,
+ "netdevsim configured to reject BPF TC offload");
+ return -EOPNOTSUPP;
+ }
/* Note: progs without skip_sw will probably not be dev bound */
- if (prog && !prog->aux->offload && !ns->bpf_tc_non_bound_accept)
+ if (prog && !prog->aux->offload && !ns->bpf_tc_non_bound_accept) {
+ NSIM_EA(cls_bpf->common.extack,
+ "netdevsim configured to reject unbound programs");
return -EOPNOTSUPP;
+ }
if (cls_bpf->command != TC_CLSBPF_OFFLOAD)
return -EOPNOTSUPP;
@@ -145,8 +163,11 @@ int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type,
oldprog = NULL;
if (!cls_bpf->prog)
return 0;
- if (ns->bpf_offloaded)
+ if (ns->bpf_offloaded) {
+ NSIM_EA(cls_bpf->common.extack,
+ "driver and netdev offload states mismatch");
return -EBUSY;
+ }
}
return nsim_bpf_offload(ns, cls_bpf->prog, oldprog);
--
2.15.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 2/5] selftests/bpf: add checks on extack messages for eBPF hw offload tests
2018-01-23 19:22 [PATCH net-next 0/5] bpf and netdevsim test updates Jakub Kicinski
2018-01-23 19:22 ` [PATCH net-next 1/5] netdevsim: add extack support for TC eBPF offload Jakub Kicinski
@ 2018-01-23 19:22 ` Jakub Kicinski
2018-01-23 19:22 ` [PATCH net-next 3/5] netdevsim: don't compile BPF code if syscall not enabled Jakub Kicinski
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2018-01-23 19:22 UTC (permalink / raw)
To: davem, alexei.starovoitov, daniel
Cc: netdev, oss-drivers, Quentin Monnet, Jakub Kicinski
From: Quentin Monnet <quentin.monnet@netronome.com>
Add checks to test that netlink extack messages are correctly displayed
in some expected error cases for eBPF offload to netdevsim with TC and
XDP.
iproute2 may be built without libmnl support, in which case the extack
messages will not be reported. Try to detect this condition, and when
enountered print a mild warning to the user and skip the extack validation.
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
tools/testing/selftests/bpf/test_offload.py | 112 +++++++++++++++++++++-------
1 file changed, 86 insertions(+), 26 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py
index 833b9c1ec450..8dca4dc6c193 100755
--- a/tools/testing/selftests/bpf/test_offload.py
+++ b/tools/testing/selftests/bpf/test_offload.py
@@ -26,6 +26,7 @@ import time
logfile = None
log_level = 1
+skip_extack = False
bpf_test_dir = os.path.dirname(os.path.realpath(__file__))
pp = pprint.PrettyPrinter()
devs = [] # devices we created for clean up
@@ -132,7 +133,7 @@ netns = [] # net namespaces to be removed
if f in files:
files.remove(f)
-def tool(name, args, flags, JSON=True, ns="", fail=True):
+def tool(name, args, flags, JSON=True, ns="", fail=True, include_stderr=False):
params = ""
if JSON:
params += "%s " % (flags["json"])
@@ -140,9 +141,20 @@ netns = [] # net namespaces to be removed
if ns != "":
ns = "ip netns exec %s " % (ns)
- ret, out = cmd(ns + name + " " + params + args, fail=fail)
- if JSON and len(out.strip()) != 0:
- return ret, json.loads(out)
+ if include_stderr:
+ ret, stdout, stderr = cmd(ns + name + " " + params + args,
+ fail=fail, include_stderr=True)
+ else:
+ ret, stdout = cmd(ns + name + " " + params + args,
+ fail=fail, include_stderr=False)
+
+ if JSON and len(stdout.strip()) != 0:
+ out = json.loads(stdout)
+ else:
+ out = stdout
+
+ if include_stderr:
+ return ret, out, stderr
else:
return ret, out
@@ -181,13 +193,15 @@ netns = [] # net namespaces to be removed
time.sleep(0.05)
raise Exception("Time out waiting for map counts to stabilize want %d, have %d" % (expected, nmaps))
-def ip(args, force=False, JSON=True, ns="", fail=True):
+def ip(args, force=False, JSON=True, ns="", fail=True, include_stderr=False):
if force:
args = "-force " + args
- return tool("ip", args, {"json":"-j"}, JSON=JSON, ns=ns, fail=fail)
+ return tool("ip", args, {"json":"-j"}, JSON=JSON, ns=ns,
+ fail=fail, include_stderr=include_stderr)
-def tc(args, JSON=True, ns="", fail=True):
- return tool("tc", args, {"json":"-p"}, JSON=JSON, ns=ns, fail=fail)
+def tc(args, JSON=True, ns="", fail=True, include_stderr=False):
+ return tool("tc", args, {"json":"-p"}, JSON=JSON, ns=ns,
+ fail=fail, include_stderr=include_stderr)
def ethtool(dev, opt, args, fail=True):
return cmd("ethtool %s %s %s" % (opt, dev["ifname"], args), fail=fail)
@@ -348,13 +362,17 @@ netns = [] # net namespaces to be removed
return ip("link set dev %s mtu %d" % (self.dev["ifname"], mtu),
fail=fail)
- def set_xdp(self, bpf, mode, force=False, JSON=True, fail=True):
+ def set_xdp(self, bpf, mode, force=False, JSON=True,
+ fail=True, include_stderr=False):
return ip("link set dev %s xdp%s %s" % (self.dev["ifname"], mode, bpf),
- force=force, JSON=JSON, fail=fail)
+ force=force, JSON=JSON,
+ fail=fail, include_stderr=include_stderr)
- def unset_xdp(self, mode, force=False, JSON=True, fail=True):
+ def unset_xdp(self, mode, force=False, JSON=True,
+ fail=True, include_stderr=False):
return ip("link set dev %s xdp%s off" % (self.dev["ifname"], mode),
- force=force, JSON=JSON, fail=fail)
+ force=force, JSON=JSON,
+ fail=fail, include_stderr=include_stderr)
def ip_link_show(self, xdp):
_, link = ip("link show dev %s" % (self['ifname']))
@@ -410,7 +428,7 @@ netns = [] # net namespaces to be removed
return filters
def cls_bpf_add_filter(self, bpf, da=False, skip_sw=False, skip_hw=False,
- fail=True):
+ fail=True, include_stderr=False):
params = ""
if da:
params += " da"
@@ -419,7 +437,8 @@ netns = [] # net namespaces to be removed
if skip_hw:
params += " skip_hw"
return tc("filter add dev %s ingress bpf %s %s" %
- (self['ifname'], bpf, params), fail=fail)
+ (self['ifname'], bpf, params),
+ fail=fail, include_stderr=include_stderr)
def set_ethtool_tc_offloads(self, enable, fail=True):
args = "hw-tc-offload %s" % ("on" if enable else "off")
@@ -491,6 +510,16 @@ netns = [] # net namespaces to be removed
fail("dev" not in m.keys(), "Device parameters not reported")
fail(dev != m["dev"], "Map's device different than program's")
+def check_extack(output, reference, args):
+ if skip_extack:
+ return
+ lines = output.split("\n")
+ comp = len(lines) >= 2 and lines[1] == reference
+ fail(not comp, "Missing or incorrect netlink extack message")
+
+def check_extack_nsim(output, reference, args):
+ check_extack(output, "Error: netdevsim: " + reference, args)
+
# Parse command line
parser = argparse.ArgumentParser()
parser.add_argument("--log", help="output verbose log to given file")
@@ -527,6 +556,14 @@ samples = ["sample_ret0.o", "sample_map_ret0.o"]
skip(ret != 0, "sample %s/%s not found, please compile it" %
(bpf_test_dir, s))
+# Check if iproute2 is built with libmnl (needed by extack support)
+_, _, err = cmd("tc qdisc delete dev lo handle 0",
+ fail=False, include_stderr=True)
+if err.find("Error: Failed to find qdisc with specified handle.") == -1:
+ print("Warning: no extack message in iproute2 output, libmnl missing?")
+ log("Warning: no extack message in iproute2 output, libmnl missing?", "")
+ skip_extack = True
+
# Check if net namespaces seem to work
ns = mknetns()
skip(ns is None, "Could not create a net namespace")
@@ -558,8 +595,10 @@ netns = []
sim.tc_flush_filters()
start_test("Test TC offloads are off by default...")
- ret, _ = sim.cls_bpf_add_filter(obj, skip_sw=True, fail=False)
+ ret, _, err = sim.cls_bpf_add_filter(obj, skip_sw=True,
+ fail=False, include_stderr=True)
fail(ret == 0, "TC filter loaded without enabling TC offloads")
+ check_extack(err, "Error: TC offload is disabled on net device.", args)
sim.wait_for_flush()
sim.set_ethtool_tc_offloads(True)
@@ -587,8 +626,11 @@ netns = []
sim.dfs["bpf_tc_non_bound_accept"] = "N"
start_test("Test TC cBPF unbound bytecode doesn't offload...")
- ret, _ = sim.cls_bpf_add_filter(bytecode, skip_sw=True, fail=False)
+ ret, _, err = sim.cls_bpf_add_filter(bytecode, skip_sw=True,
+ fail=False, include_stderr=True)
fail(ret == 0, "TC bytecode loaded for offload")
+ check_extack_nsim(err, "netdevsim configured to reject unbound programs.",
+ args)
sim.wait_for_flush()
start_test("Test TC offloads work...")
@@ -669,16 +711,24 @@ netns = []
"Device parameters reported for non-offloaded program")
start_test("Test XDP prog replace with bad flags...")
- ret, _ = sim.set_xdp(obj, "offload", force=True, fail=False)
+ ret, _, err = sim.set_xdp(obj, "offload", force=True,
+ fail=False, include_stderr=True)
fail(ret == 0, "Replaced XDP program with a program in different mode")
- ret, _ = sim.set_xdp(obj, "", force=True, fail=False)
+ check_extack_nsim(err, "program loaded with different flags.", args)
+ ret, _, err = sim.set_xdp(obj, "", force=True,
+ fail=False, include_stderr=True)
fail(ret == 0, "Replaced XDP program with a program in different mode")
+ check_extack_nsim(err, "program loaded with different flags.", args)
start_test("Test XDP prog remove with bad flags...")
- ret, _ = sim.unset_xdp("offload", force=True, fail=False)
+ ret, _, err = sim.unset_xdp("offload", force=True,
+ fail=False, include_stderr=True)
fail(ret == 0, "Removed program with a bad mode mode")
- ret, _ = sim.unset_xdp("", force=True, fail=False)
+ check_extack_nsim(err, "program loaded with different flags.", args)
+ ret, _, err = sim.unset_xdp("", force=True,
+ fail=False, include_stderr=True)
fail(ret == 0, "Removed program with a bad mode mode")
+ check_extack_nsim(err, "program loaded with different flags.", args)
start_test("Test MTU restrictions...")
ret, _ = sim.set_mtu(9000, fail=False)
@@ -687,8 +737,9 @@ netns = []
sim.unset_xdp("drv")
bpftool_prog_list_wait(expected=0)
sim.set_mtu(9000)
- ret, _ = sim.set_xdp(obj, "drv", fail=False)
+ ret, _, err = sim.set_xdp(obj, "drv", fail=False, include_stderr=True)
fail(ret == 0, "Driver should refuse to load program with MTU of 9000...")
+ check_extack_nsim(err, "MTU too large w/ XDP enabled.", args)
sim.set_mtu(1500)
sim.wait_for_flush()
@@ -724,25 +775,32 @@ netns = []
sim2.set_xdp(obj, "offload")
pin_file, pinned = pin_prog("/sys/fs/bpf/tmp")
- ret, _ = sim.set_xdp(pinned, "offload", fail=False)
+ ret, _, err = sim.set_xdp(pinned, "offload",
+ fail=False, include_stderr=True)
fail(ret == 0, "Pinned program loaded for a different device accepted")
+ check_extack_nsim(err, "program bound to different dev.", args)
sim2.remove()
- ret, _ = sim.set_xdp(pinned, "offload", fail=False)
+ ret, _, err = sim.set_xdp(pinned, "offload",
+ fail=False, include_stderr=True)
fail(ret == 0, "Pinned program loaded for a removed device accepted")
+ check_extack_nsim(err, "xdpoffload of non-bound program.", args)
rm(pin_file)
bpftool_prog_list_wait(expected=0)
start_test("Test mixing of TC and XDP...")
sim.tc_add_ingress()
sim.set_xdp(obj, "offload")
- ret, _ = sim.cls_bpf_add_filter(obj, skip_sw=True, fail=False)
+ ret, _, err = sim.cls_bpf_add_filter(obj, skip_sw=True,
+ fail=False, include_stderr=True)
fail(ret == 0, "Loading TC when XDP active should fail")
+ check_extack_nsim(err, "driver and netdev offload states mismatch.", args)
sim.unset_xdp("offload")
sim.wait_for_flush()
sim.cls_bpf_add_filter(obj, skip_sw=True)
- ret, _ = sim.set_xdp(obj, "offload", fail=False)
+ ret, _, err = sim.set_xdp(obj, "offload", fail=False, include_stderr=True)
fail(ret == 0, "Loading XDP when TC active should fail")
+ check_extack_nsim(err, "TC program is already loaded.", args)
start_test("Test binding TC from pinned...")
pin_file, pinned = pin_prog("/sys/fs/bpf/tmp")
@@ -765,8 +823,10 @@ netns = []
start_test("Test asking for TC offload of two filters...")
sim.cls_bpf_add_filter(obj, da=True, skip_sw=True)
- ret, _ = sim.cls_bpf_add_filter(obj, da=True, skip_sw=True, fail=False)
+ ret, _, err = sim.cls_bpf_add_filter(obj, da=True, skip_sw=True,
+ fail=False, include_stderr=True)
fail(ret == 0, "Managed to offload two TC filters at the same time")
+ check_extack_nsim(err, "driver and netdev offload states mismatch.", args)
sim.tc_flush_filters(bound=2, total=2)
--
2.15.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 3/5] netdevsim: don't compile BPF code if syscall not enabled
2018-01-23 19:22 [PATCH net-next 0/5] bpf and netdevsim test updates Jakub Kicinski
2018-01-23 19:22 ` [PATCH net-next 1/5] netdevsim: add extack support for TC eBPF offload Jakub Kicinski
2018-01-23 19:22 ` [PATCH net-next 2/5] selftests/bpf: add checks on extack messages for eBPF hw offload tests Jakub Kicinski
@ 2018-01-23 19:22 ` Jakub Kicinski
2018-01-23 19:22 ` [PATCH net-next 4/5] selftests/bpf: check bpf verifier log buffer usage works for HW offload Jakub Kicinski
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2018-01-23 19:22 UTC (permalink / raw)
To: davem, alexei.starovoitov, daniel; +Cc: netdev, oss-drivers, Jakub Kicinski
We should not compile netdevsim/bpf.c if BPF syscall is not
enabled. Otherwise bpf core would have to provide wrappers
for all functions offload drivers may call, even though
system will never see a BPF object.
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
---
drivers/net/netdevsim/Makefile | 6 +++++-
drivers/net/netdevsim/netdevsim.h | 28 ++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/drivers/net/netdevsim/Makefile b/drivers/net/netdevsim/Makefile
index 074ddebbc41d..09388c06171d 100644
--- a/drivers/net/netdevsim/Makefile
+++ b/drivers/net/netdevsim/Makefile
@@ -4,4 +4,8 @@ obj-$(CONFIG_NETDEVSIM) += netdevsim.o
netdevsim-objs := \
netdev.o \
- bpf.o \
+
+ifeq ($(CONFIG_BPF_SYSCALL),y)
+netdevsim-objs += \
+ bpf.o
+endif
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index b80361200302..ea081c10efb8 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -68,12 +68,40 @@ struct netdevsim {
extern struct dentry *nsim_ddir;
+#ifdef CONFIG_BPF_SYSCALL
int nsim_bpf_init(struct netdevsim *ns);
void nsim_bpf_uninit(struct netdevsim *ns);
int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf);
int nsim_bpf_disable_tc(struct netdevsim *ns);
int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type,
void *type_data, void *cb_priv);
+#else
+static inline int nsim_bpf_init(struct netdevsim *ns)
+{
+ return 0;
+}
+
+static inline void nsim_bpf_uninit(struct netdevsim *ns)
+{
+}
+
+static inline int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf)
+{
+ return bpf->command == XDP_QUERY_PROG ? 0 : -EOPNOTSUPP;
+}
+
+static inline int nsim_bpf_disable_tc(struct netdevsim *ns)
+{
+ return 0;
+}
+
+static inline int
+nsim_bpf_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
+ void *cb_priv)
+{
+ return -EOPNOTSUPP;
+}
+#endif
static inline struct netdevsim *to_nsim(struct device *ptr)
{
--
2.15.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 4/5] selftests/bpf: check bpf verifier log buffer usage works for HW offload
2018-01-23 19:22 [PATCH net-next 0/5] bpf and netdevsim test updates Jakub Kicinski
` (2 preceding siblings ...)
2018-01-23 19:22 ` [PATCH net-next 3/5] netdevsim: don't compile BPF code if syscall not enabled Jakub Kicinski
@ 2018-01-23 19:22 ` Jakub Kicinski
2018-01-23 19:22 ` [PATCH net-next 5/5] selftests/bpf: validate replace of TC filters is working Jakub Kicinski
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2018-01-23 19:22 UTC (permalink / raw)
To: davem, alexei.starovoitov, daniel; +Cc: netdev, oss-drivers, Quentin Monnet
From: Quentin Monnet <quentin.monnet@netronome.com>
Make netdevsim print a message to the BPF verifier log buffer when a
program is offloaded.
Then use this message in hardware offload selftests to make sure that
using this buffer actually prints the message to the console for
eBPF hardware offload.
The message is appended after the last instruction is processed with the
verifying function from netdevsim. Output looks like the following:
$ tc filter add dev foo ingress bpf obj sample_ret0.o \
sec .text verbose skip_sw
Prog section '.text' loaded (5)!
- Type: 3
- Instructions: 2 (0 over limit)
- License:
Verifier analysis:
0: (b7) r0 = 0
1: (95) exit
[netdevsim] Hello from netdevsim!
processed 2 insns, stack depth 0
"verbose" flag is required to see it in the console since netdevsim does
not throw an error after printing the message.
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
drivers/net/netdevsim/bpf.c | 6 ++++++
tools/testing/selftests/bpf/test_offload.py | 24 +++++++++++++++++++-----
2 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/drivers/net/netdevsim/bpf.c b/drivers/net/netdevsim/bpf.c
index 940c63eeebf9..8166f121bbcc 100644
--- a/drivers/net/netdevsim/bpf.c
+++ b/drivers/net/netdevsim/bpf.c
@@ -23,6 +23,9 @@
#include "netdevsim.h"
+#define pr_vlog(env, fmt, ...) \
+ bpf_verifier_log_write(env, "[netdevsim] " fmt, ##__VA_ARGS__)
+
struct nsim_bpf_bound_prog {
struct netdevsim *ns;
struct bpf_prog *prog;
@@ -77,6 +80,9 @@ nsim_bpf_verify_insn(struct bpf_verifier_env *env, int insn_idx, int prev_insn)
if (state->ns->bpf_bind_verifier_delay && !insn_idx)
msleep(state->ns->bpf_bind_verifier_delay);
+ if (insn_idx == env->prog->len - 1)
+ pr_vlog(env, "Hello from netdevsim!\n");
+
return 0;
}
diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py
index 8dca4dc6c193..d128a16ee9a8 100755
--- a/tools/testing/selftests/bpf/test_offload.py
+++ b/tools/testing/selftests/bpf/test_offload.py
@@ -362,8 +362,10 @@ netns = [] # net namespaces to be removed
return ip("link set dev %s mtu %d" % (self.dev["ifname"], mtu),
fail=fail)
- def set_xdp(self, bpf, mode, force=False, JSON=True,
+ def set_xdp(self, bpf, mode, force=False, JSON=True, verbose=False,
fail=True, include_stderr=False):
+ if verbose:
+ bpf += " verbose"
return ip("link set dev %s xdp%s %s" % (self.dev["ifname"], mode, bpf),
force=force, JSON=JSON,
fail=fail, include_stderr=include_stderr)
@@ -427,11 +429,13 @@ netns = [] # net namespaces to be removed
(len(filters), expected))
return filters
- def cls_bpf_add_filter(self, bpf, da=False, skip_sw=False, skip_hw=False,
- fail=True, include_stderr=False):
+ def cls_bpf_add_filter(self, bpf, da=False, verbose=False, skip_sw=False,
+ skip_hw=False, fail=True, include_stderr=False):
params = ""
if da:
params += " da"
+ if verbose:
+ params += " verbose"
if skip_sw:
params += " skip_sw"
if skip_hw:
@@ -520,6 +524,13 @@ netns = [] # net namespaces to be removed
def check_extack_nsim(output, reference, args):
check_extack(output, "Error: netdevsim: " + reference, args)
+def check_verifier_log(output, reference):
+ lines = output.split("\n")
+ for l in reversed(lines):
+ if l == reference:
+ return
+ fail(True, "Missing or incorrect message from netdevsim in verifier log")
+
# Parse command line
parser = argparse.ArgumentParser()
parser.add_argument("--log", help="output verbose log to given file")
@@ -634,8 +645,10 @@ netns = []
sim.wait_for_flush()
start_test("Test TC offloads work...")
- ret, _ = sim.cls_bpf_add_filter(obj, skip_sw=True, fail=False)
+ ret, _, err = sim.cls_bpf_add_filter(obj, verbose=True, skip_sw=True,
+ fail=False, include_stderr=True)
fail(ret != 0, "TC filter did not load with TC offloads enabled")
+ check_verifier_log(err, "[netdevsim] Hello from netdevsim!")
start_test("Test TC offload basics...")
dfs = sim.dfs_get_bound_progs(expected=1)
@@ -744,12 +757,13 @@ netns = []
sim.wait_for_flush()
start_test("Test XDP offload...")
- sim.set_xdp(obj, "offload")
+ _, _, err = sim.set_xdp(obj, "offload", verbose=True, include_stderr=True)
ipl = sim.ip_link_show(xdp=True)
link_xdp = ipl["xdp"]["prog"]
progs = bpftool_prog_list(expected=1)
prog = progs[0]
fail(link_xdp["id"] != prog["id"], "Loaded program has wrong ID")
+ check_verifier_log(err, "[netdevsim] Hello from netdevsim!")
start_test("Test XDP offload is device bound...")
dfs = sim.dfs_get_bound_progs(expected=1)
--
2.15.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 5/5] selftests/bpf: validate replace of TC filters is working
2018-01-23 19:22 [PATCH net-next 0/5] bpf and netdevsim test updates Jakub Kicinski
` (3 preceding siblings ...)
2018-01-23 19:22 ` [PATCH net-next 4/5] selftests/bpf: check bpf verifier log buffer usage works for HW offload Jakub Kicinski
@ 2018-01-23 19:22 ` Jakub Kicinski
2018-01-23 20:36 ` [PATCH net-next 0/5] bpf and netdevsim test updates Daniel Borkmann
2018-01-24 1:26 ` David Miller
6 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2018-01-23 19:22 UTC (permalink / raw)
To: davem, alexei.starovoitov, daniel; +Cc: netdev, oss-drivers, Jakub Kicinski
Daniel discovered recently I broke TC filter replace (and fixed
it in commit ad9294dbc227 ("bpf: fix cls_bpf on filter replace")).
Add a test to make sure it never happens again.
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
tools/testing/selftests/bpf/test_offload.py | 55 ++++++++++++++++++++++++++---
1 file changed, 50 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py
index d128a16ee9a8..ae3eea3ab820 100755
--- a/tools/testing/selftests/bpf/test_offload.py
+++ b/tools/testing/selftests/bpf/test_offload.py
@@ -429,8 +429,26 @@ netns = [] # net namespaces to be removed
(len(filters), expected))
return filters
- def cls_bpf_add_filter(self, bpf, da=False, verbose=False, skip_sw=False,
- skip_hw=False, fail=True, include_stderr=False):
+ def cls_filter_op(self, op, qdisc="ingress", prio=None, handle=None,
+ cls="", params="",
+ fail=True, include_stderr=False):
+ spec = ""
+ if prio is not None:
+ spec += " prio %d" % (prio)
+ if handle:
+ spec += " handle %s" % (handle)
+
+ return tc("filter {op} dev {dev} {qdisc} {spec} {cls} {params}"\
+ .format(op=op, dev=self['ifname'], qdisc=qdisc, spec=spec,
+ cls=cls, params=params),
+ fail=fail, include_stderr=include_stderr)
+
+ def cls_bpf_add_filter(self, bpf, op="add", prio=None, handle=None,
+ da=False, verbose=False,
+ skip_sw=False, skip_hw=False,
+ fail=True, include_stderr=False):
+ cls = "bpf " + bpf
+
params = ""
if da:
params += " da"
@@ -440,9 +458,10 @@ netns = [] # net namespaces to be removed
params += " skip_sw"
if skip_hw:
params += " skip_hw"
- return tc("filter add dev %s ingress bpf %s %s" %
- (self['ifname'], bpf, params),
- fail=fail, include_stderr=include_stderr)
+
+ return self.cls_filter_op(op=op, prio=prio, handle=handle, cls=cls,
+ params=params,
+ fail=fail, include_stderr=include_stderr)
def set_ethtool_tc_offloads(self, enable, fail=True):
args = "hw-tc-offload %s" % ("on" if enable else "off")
@@ -644,6 +663,32 @@ netns = []
args)
sim.wait_for_flush()
+ start_test("Test TC replace...")
+ sim.cls_bpf_add_filter(obj, prio=1, handle=1)
+ sim.cls_bpf_add_filter(obj, op="replace", prio=1, handle=1)
+ sim.cls_filter_op(op="delete", prio=1, handle=1, cls="bpf")
+
+ sim.cls_bpf_add_filter(obj, prio=1, handle=1, skip_sw=True)
+ sim.cls_bpf_add_filter(obj, op="replace", prio=1, handle=1, skip_sw=True)
+ sim.cls_filter_op(op="delete", prio=1, handle=1, cls="bpf")
+
+ sim.cls_bpf_add_filter(obj, prio=1, handle=1, skip_hw=True)
+ sim.cls_bpf_add_filter(obj, op="replace", prio=1, handle=1, skip_hw=True)
+ sim.cls_filter_op(op="delete", prio=1, handle=1, cls="bpf")
+
+ start_test("Test TC replace bad flags...")
+ for i in range(3):
+ for j in range(3):
+ ret, _ = sim.cls_bpf_add_filter(obj, op="replace", prio=1, handle=1,
+ skip_sw=(j == 1), skip_hw=(j == 2),
+ fail=False)
+ fail(bool(ret) != bool(j),
+ "Software TC incorrect load in replace test, iteration %d" %
+ (j))
+ sim.cls_filter_op(op="delete", prio=1, handle=1, cls="bpf")
+
+ sim.tc_flush_filters()
+
start_test("Test TC offloads work...")
ret, _, err = sim.cls_bpf_add_filter(obj, verbose=True, skip_sw=True,
fail=False, include_stderr=True)
--
2.15.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 0/5] bpf and netdevsim test updates
2018-01-23 19:22 [PATCH net-next 0/5] bpf and netdevsim test updates Jakub Kicinski
` (4 preceding siblings ...)
2018-01-23 19:22 ` [PATCH net-next 5/5] selftests/bpf: validate replace of TC filters is working Jakub Kicinski
@ 2018-01-23 20:36 ` Daniel Borkmann
2018-01-24 1:26 ` David Miller
6 siblings, 0 replies; 8+ messages in thread
From: Daniel Borkmann @ 2018-01-23 20:36 UTC (permalink / raw)
To: Jakub Kicinski, davem, alexei.starovoitov; +Cc: netdev, oss-drivers
On 01/23/2018 08:22 PM, Jakub Kicinski wrote:
> Hi!
>
> 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.
>
> Daniel, Alexei, could this be taken directly to net-next? I have
> two series worth of follow ups to extack, including netdevsim and
> test_offload.py changes.
Ok, thanks for letting us know! No objections from my side if DaveM
takes the series directly into net-next. I don't expect any merge
issues later on since BPF selftests only touches test_offload.py here.
For the series:
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Thanks,
Daniel
> Jakub Kicinski (2):
> netdevsim: don't compile BPF code if syscall not enabled
> selftests/bpf: validate replace of TC filters is working
>
> Quentin Monnet (3):
> netdevsim: add extack support for TC eBPF offload
> selftests/bpf: add checks on extack messages for eBPF hw offload tests
> selftests/bpf: check bpf verifier log buffer usage works for HW
> offload
>
> drivers/net/netdevsim/Makefile | 6 +-
> drivers/net/netdevsim/bpf.c | 41 +++++--
> drivers/net/netdevsim/netdevsim.h | 28 +++++
> tools/testing/selftests/bpf/test_offload.py | 179 +++++++++++++++++++++++-----
> 4 files changed, 216 insertions(+), 38 deletions(-)
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 0/5] bpf and netdevsim test updates
2018-01-23 19:22 [PATCH net-next 0/5] bpf and netdevsim test updates Jakub Kicinski
` (5 preceding siblings ...)
2018-01-23 20:36 ` [PATCH net-next 0/5] bpf and netdevsim test updates Daniel Borkmann
@ 2018-01-24 1:26 ` David Miller
6 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2018-01-24 1:26 UTC (permalink / raw)
To: jakub.kicinski; +Cc: alexei.starovoitov, daniel, netdev, oss-drivers
From: Jakub Kicinski <jakub.kicinski@netronome.com>
Date: Tue, 23 Jan 2018 11:22:51 -0800
> 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.
>
> Daniel, Alexei, could this be taken directly to net-next? I have
> two series worth of follow ups to extack, including netdevsim and
> test_offload.py changes.
As Daniel said, we can take this directly into net-next.
Series applied, thanks Jakub.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-01-24 1:26 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-23 19:22 [PATCH net-next 0/5] bpf and netdevsim test updates Jakub Kicinski
2018-01-23 19:22 ` [PATCH net-next 1/5] netdevsim: add extack support for TC eBPF offload Jakub Kicinski
2018-01-23 19:22 ` [PATCH net-next 2/5] selftests/bpf: add checks on extack messages for eBPF hw offload tests Jakub Kicinski
2018-01-23 19:22 ` [PATCH net-next 3/5] netdevsim: don't compile BPF code if syscall not enabled Jakub Kicinski
2018-01-23 19:22 ` [PATCH net-next 4/5] selftests/bpf: check bpf verifier log buffer usage works for HW offload Jakub Kicinski
2018-01-23 19:22 ` [PATCH net-next 5/5] selftests/bpf: validate replace of TC filters is working Jakub Kicinski
2018-01-23 20:36 ` [PATCH net-next 0/5] bpf and netdevsim test updates Daniel Borkmann
2018-01-24 1:26 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).