All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net
@ 2024-04-09  3:15 Jakub Kicinski
  2024-04-09  3:15 ` [PATCH net-next 1/4] " Jakub Kicinski
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: Jakub Kicinski @ 2024-04-09  3:15 UTC (permalink / raw)
  To: davem
  Cc: netdev, edumazet, pabeni, bpf, andrii, mykolal, eddyz87, shuah,
	linux-kselftest, Jakub Kicinski

The test_offload.py test fits in networking and bpf equally
well. We started adding more Python tests in networking
and some of the code in test_offload.py can be reused,
so move it to networking. Looks like it bit rotted over
time and some fixes are needed.

Admittedly more code could be extracted but I only had
the time for a minor cleanup :(

Jakub Kicinski (4):
  selftests: move bpf-offload test from bpf to net
  selftests: net: bpf_offload: wait for maps
  selftests: net: declare section names for bpf_offload
  selftests: net: reuse common code in bpf_offload

 tools/testing/selftests/bpf/Makefile          |   1 -
 tools/testing/selftests/net/Makefile          |  11 +-
 .../test_offload.py => net/bpf_offload.py}    | 138 +++++-------------
 tools/testing/selftests/net/lib/py/nsim.py    |   9 +-
 .../sample_map_ret0.bpf.c}                    |   2 +-
 .../sample_ret0.c => net/sample_ret0.bpf.c}   |   3 +
 6 files changed, 57 insertions(+), 107 deletions(-)
 rename tools/testing/selftests/{bpf/test_offload.py => net/bpf_offload.py} (93%)
 rename tools/testing/selftests/{bpf/progs/sample_map_ret0.c => net/sample_map_ret0.bpf.c} (96%)
 rename tools/testing/selftests/{bpf/progs/sample_ret0.c => net/sample_ret0.bpf.c} (70%)

-- 
2.44.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH net-next 1/4] selftests: move bpf-offload test from bpf to net
  2024-04-09  3:15 [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net Jakub Kicinski
@ 2024-04-09  3:15 ` Jakub Kicinski
  2024-04-09  3:15 ` [PATCH net-next 2/4] selftests: net: bpf_offload: wait for maps Jakub Kicinski
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Jakub Kicinski @ 2024-04-09  3:15 UTC (permalink / raw)
  To: davem
  Cc: netdev, edumazet, pabeni, bpf, andrii, mykolal, eddyz87, shuah,
	linux-kselftest, Jakub Kicinski

We're building more python tests on the netdev side, and some
of the classes from the venerable BPF offload tests can be reused.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/testing/selftests/bpf/Makefile                      | 1 -
 tools/testing/selftests/net/Makefile                      | 8 +++++++-
 .../selftests/{bpf/test_offload.py => net/bpf_offload.py} | 0
 .../progs/sample_map_ret0.c => net/sample_map_ret0.bpf.c} | 0
 .../{bpf/progs/sample_ret0.c => net/sample_ret0.bpf.c}    | 0
 5 files changed, 7 insertions(+), 2 deletions(-)
 rename tools/testing/selftests/{bpf/test_offload.py => net/bpf_offload.py} (100%)
 rename tools/testing/selftests/{bpf/progs/sample_map_ret0.c => net/sample_map_ret0.bpf.c} (100%)
 rename tools/testing/selftests/{bpf/progs/sample_ret0.c => net/sample_ret0.bpf.c} (100%)

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 3b9eb40d6343..b0be07f29dde 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -102,7 +102,6 @@ TEST_PROGS := test_kmod.sh \
 	test_xdp_redirect_multi.sh \
 	test_xdp_meta.sh \
 	test_xdp_veth.sh \
-	test_offload.py \
 	test_sock_addr.sh \
 	test_tunnel.sh \
 	test_lwt_seg6local.sh \
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 5e34c93aa51b..e8bfa715aa49 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -84,6 +84,8 @@ TEST_GEN_FILES += sctp_hello
 TEST_GEN_FILES += csum
 TEST_GEN_FILES += nat6to4.o
 TEST_GEN_FILES += xdp_dummy.o
+TEST_GEN_FILES += sample_ret0.bpf.o
+TEST_GEN_FILES += sample_map_ret0.bpf.o
 TEST_GEN_FILES += ip_local_port_range
 TEST_GEN_FILES += bind_wildcard
 TEST_PROGS += test_vxlan_mdb.sh
@@ -93,6 +95,7 @@ TEST_PROGS += test_bridge_backup_port.sh
 TEST_PROGS += fdb_flush.sh
 TEST_PROGS += fq_band_pktlimit.sh
 TEST_PROGS += vlan_hw_filter.sh
+TEST_PROGS += bpf_offload.py
 
 TEST_FILES := settings
 TEST_FILES += in_netns.sh lib.sh net_helper.sh setup_loopback.sh setup_veth.sh
@@ -142,7 +145,10 @@ endif
 
 CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
 
-$(OUTPUT)/nat6to4.o $(OUTPUT)/xdp_dummy.o: $(OUTPUT)/%.o : %.c $(BPFOBJ) | $(MAKE_DIRS)
+BPF_PROG_OBJS := $(OUTPUT)/nat6to4.o $(OUTPUT)/xdp_dummy.o \
+	$(OUTPUT)/sample_map_ret0.bpf.o $(OUTPUT)/sample_ret0.bpf.o
+
+$(BPF_PROG_OBJS): $(OUTPUT)/%.o : %.c $(BPFOBJ) | $(MAKE_DIRS)
 	$(CLANG) -O2 --target=bpf -c $< $(CCINCLUDE) $(CLANG_SYS_INCLUDES) -o $@
 
 $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile)		       \
diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/net/bpf_offload.py
similarity index 100%
rename from tools/testing/selftests/bpf/test_offload.py
rename to tools/testing/selftests/net/bpf_offload.py
diff --git a/tools/testing/selftests/bpf/progs/sample_map_ret0.c b/tools/testing/selftests/net/sample_map_ret0.bpf.c
similarity index 100%
rename from tools/testing/selftests/bpf/progs/sample_map_ret0.c
rename to tools/testing/selftests/net/sample_map_ret0.bpf.c
diff --git a/tools/testing/selftests/bpf/progs/sample_ret0.c b/tools/testing/selftests/net/sample_ret0.bpf.c
similarity index 100%
rename from tools/testing/selftests/bpf/progs/sample_ret0.c
rename to tools/testing/selftests/net/sample_ret0.bpf.c
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next 2/4] selftests: net: bpf_offload: wait for maps
  2024-04-09  3:15 [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net Jakub Kicinski
  2024-04-09  3:15 ` [PATCH net-next 1/4] " Jakub Kicinski
@ 2024-04-09  3:15 ` Jakub Kicinski
  2024-04-09  3:15 ` [PATCH net-next 3/4] selftests: net: declare section names for bpf_offload Jakub Kicinski
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Jakub Kicinski @ 2024-04-09  3:15 UTC (permalink / raw)
  To: davem
  Cc: netdev, edumazet, pabeni, bpf, andrii, mykolal, eddyz87, shuah,
	linux-kselftest, Jakub Kicinski

Maps are removed asynchronously. Either there's a bigger delay
now or the test has always been flaky. Retry waiting in the loop.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/testing/selftests/net/bpf_offload.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/net/bpf_offload.py b/tools/testing/selftests/net/bpf_offload.py
index 6157f884d091..174dba1a48d3 100755
--- a/tools/testing/selftests/net/bpf_offload.py
+++ b/tools/testing/selftests/net/bpf_offload.py
@@ -201,11 +201,11 @@ netns = [] # net namespaces to be removed
         time.sleep(0.05)
     raise Exception("Time out waiting for program counts to stabilize want %d, have %d" % (expected, nprogs))
 
-def bpftool_map_list_wait(expected=0, n_retry=20):
+def bpftool_map_list_wait(expected=0, n_retry=20, ns=""):
     for i in range(n_retry):
-        nmaps = len(bpftool_map_list())
-        if nmaps == expected:
-            return
+        maps = bpftool_map_list(ns=ns)
+        if len(maps) == expected:
+            return maps
         time.sleep(0.05)
     raise Exception("Time out waiting for map counts to stabilize want %d, have %d" % (expected, nmaps))
 
@@ -605,7 +605,7 @@ def bpftool_prog_load(sample, file_name, maps=[], prog_type="xdp", dev=None,
     return file_name, bpf_pinned(file_name)
 
 def pin_map(file_name, idx=0, expected=1):
-    maps = bpftool_map_list(expected=expected)
+    maps = bpftool_map_list_wait(expected=expected)
     m = maps[idx]
     bpftool("map pin id %d %s" % (m["id"], file_name))
     files.append(file_name)
@@ -618,7 +618,7 @@ def bpftool_prog_load(sample, file_name, maps=[], prog_type="xdp", dev=None,
     ret, err = bpftool("prog show pin %s" % (prog_file), fail=False)
     fail(ret != 0, "failed to show prog with removed device")
 
-    bpftool_map_list(expected=0)
+    bpftool_map_list_wait(expected=0)
     ret, err = bpftool("map show pin %s" % (map_file), fail=False)
     fail(ret == 0, "Showing map with removed device did not fail")
     fail(err["error"].find("No such device") == -1,
@@ -642,7 +642,7 @@ def bpftool_prog_load(sample, file_name, maps=[], prog_type="xdp", dev=None,
     else:
         fail("ifname" in dev.keys(), "Ifname is reported for other ns")
 
-    maps = bpftool_map_list(expected=2, ns=ns)
+    maps = bpftool_map_list_wait(expected=2, ns=ns)
     for m in maps:
         fail("dev" not in m.keys(), "Device parameters not reported")
         fail(dev != m["dev"], "Map's device different than program's")
@@ -1206,7 +1206,7 @@ netns = []
 
     start_test("Test map update (no flags)...")
     sim.set_xdp(map_obj, "offload", JSON=False) # map fixup msg breaks JSON
-    maps = bpftool_map_list(expected=2)
+    maps = bpftool_map_list_wait(expected=2)
     array = maps[0] if maps[0]["type"] == "array" else maps[1]
     htab = maps[0] if maps[0]["type"] == "hash" else maps[1]
     for m in maps:
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next 3/4] selftests: net: declare section names for bpf_offload
  2024-04-09  3:15 [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net Jakub Kicinski
  2024-04-09  3:15 ` [PATCH net-next 1/4] " Jakub Kicinski
  2024-04-09  3:15 ` [PATCH net-next 2/4] selftests: net: bpf_offload: wait for maps Jakub Kicinski
@ 2024-04-09  3:15 ` Jakub Kicinski
  2024-04-09 17:32   ` Alexei Starovoitov
  2024-04-09  3:15 ` [PATCH net-next 4/4] selftests: net: reuse common code in bpf_offload Jakub Kicinski
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Jakub Kicinski @ 2024-04-09  3:15 UTC (permalink / raw)
  To: davem
  Cc: netdev, edumazet, pabeni, bpf, andrii, mykolal, eddyz87, shuah,
	linux-kselftest, Jakub Kicinski

Non-ancient ip (iproute2-5.15.0, libbpf 0.7.0) refuses to load
the sample with maps because we don't generate BTF:

   libbpf: BTF is required, but is missing or corrupted.
   ERROR: opening BPF object file failed

Enable BTF by adding -g to clang flags. With that done
neither of the programs load:

  libbpf: prog 'func': error relocating .BTF.ext function info: -22
  libbpf: prog 'func': failed to relocate calls: -22
  libbpf: failed to load object 'ksft-net-drv/net/sample_ret0.bpf.o'

Andrii explains that this is because we don't specify
section names for the code. Add the section names, too.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/testing/selftests/net/Makefile              | 3 ++-
 tools/testing/selftests/net/bpf_offload.py        | 2 +-
 tools/testing/selftests/net/sample_map_ret0.bpf.c | 2 +-
 tools/testing/selftests/net/sample_ret0.bpf.c     | 3 +++
 4 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index e8bfa715aa49..a3c781cb8367 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -149,7 +149,8 @@ BPF_PROG_OBJS := $(OUTPUT)/nat6to4.o $(OUTPUT)/xdp_dummy.o \
 	$(OUTPUT)/sample_map_ret0.bpf.o $(OUTPUT)/sample_ret0.bpf.o
 
 $(BPF_PROG_OBJS): $(OUTPUT)/%.o : %.c $(BPFOBJ) | $(MAKE_DIRS)
-	$(CLANG) -O2 --target=bpf -c $< $(CCINCLUDE) $(CLANG_SYS_INCLUDES) -o $@
+	$(CLANG) -O2 -g --target=bpf $(CCINCLUDE) $(CLANG_SYS_INCLUDES) \
+	-c $< -o $@
 
 $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile)		       \
 	   $(APIDIR)/linux/bpf.h					       \
diff --git a/tools/testing/selftests/net/bpf_offload.py b/tools/testing/selftests/net/bpf_offload.py
index 174dba1a48d3..76b53ac2c8c6 100755
--- a/tools/testing/selftests/net/bpf_offload.py
+++ b/tools/testing/selftests/net/bpf_offload.py
@@ -237,7 +237,7 @@ def bpftool_prog_load(sample, file_name, maps=[], prog_type="xdp", dev=None,
 def ethtool(dev, opt, args, fail=True):
     return cmd("ethtool %s %s %s" % (opt, dev["ifname"], args), fail=fail)
 
-def bpf_obj(name, sec=".text", path=bpf_test_dir,):
+def bpf_obj(name, sec="xdp", path=bpf_test_dir,):
     return "obj %s sec %s" % (os.path.join(path, name), sec)
 
 def bpf_pinned(name):
diff --git a/tools/testing/selftests/net/sample_map_ret0.bpf.c b/tools/testing/selftests/net/sample_map_ret0.bpf.c
index 495990d355ef..43ca92594926 100644
--- a/tools/testing/selftests/net/sample_map_ret0.bpf.c
+++ b/tools/testing/selftests/net/sample_map_ret0.bpf.c
@@ -17,7 +17,7 @@ struct {
 } array SEC(".maps");
 
 /* Sample program which should always load for testing control paths. */
-SEC(".text") int func()
+SEC("xdp") int func()
 {
 	__u64 key64 = 0;
 	__u32 key = 0;
diff --git a/tools/testing/selftests/net/sample_ret0.bpf.c b/tools/testing/selftests/net/sample_ret0.bpf.c
index fec99750d6ea..1df5ca98bb65 100644
--- a/tools/testing/selftests/net/sample_ret0.bpf.c
+++ b/tools/testing/selftests/net/sample_ret0.bpf.c
@@ -1,6 +1,9 @@
 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */
 
+#define SEC(name) __attribute__((section(name), used))
+
 /* Sample program which should always load for testing control paths. */
+SEC("xdp")
 int func()
 {
 	return 0;
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next 4/4] selftests: net: reuse common code in bpf_offload
  2024-04-09  3:15 [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net Jakub Kicinski
                   ` (2 preceding siblings ...)
  2024-04-09  3:15 ` [PATCH net-next 3/4] selftests: net: declare section names for bpf_offload Jakub Kicinski
@ 2024-04-09  3:15 ` Jakub Kicinski
  2024-04-09 16:10 ` [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net Stanislav Fomichev
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Jakub Kicinski @ 2024-04-09  3:15 UTC (permalink / raw)
  To: davem
  Cc: netdev, edumazet, pabeni, bpf, andrii, mykolal, eddyz87, shuah,
	linux-kselftest, Jakub Kicinski

net/lib/py/nsim.py already contains the most useful parts
of the netdevsim wrapper classes. Reuse them.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/testing/selftests/net/bpf_offload.py | 120 +++++----------------
 tools/testing/selftests/net/lib/py/nsim.py |   9 +-
 2 files changed, 35 insertions(+), 94 deletions(-)

diff --git a/tools/testing/selftests/net/bpf_offload.py b/tools/testing/selftests/net/bpf_offload.py
index 76b53ac2c8c6..3efe44f6e92a 100755
--- a/tools/testing/selftests/net/bpf_offload.py
+++ b/tools/testing/selftests/net/bpf_offload.py
@@ -29,6 +29,9 @@ import subprocess
 import time
 import traceback
 
+from lib.py import NetdevSim, NetdevSimDev
+
+
 logfile = None
 log_level = 1
 skip_extack = False
@@ -145,8 +148,10 @@ netns = [] # net namespaces to be removed
     if JSON:
         params += "%s " % (flags["json"])
 
-    if ns != "":
+    if ns:
         ns = "ip netns exec %s " % (ns)
+    elif ns is None:
+        ns = ""
 
     if include_stderr:
         ret, stdout, stderr = cmd(ns + name + " " + params + args,
@@ -334,72 +339,16 @@ def bpftool_prog_load(sample, file_name, maps=[], prog_type="xdp", dev=None,
 
         return dfs
 
-class NetdevSimDev:
+class BpfNetdevSimDev(NetdevSimDev):
     """
     Class for netdevsim bus device and its attributes.
     """
-    @staticmethod
-    def ctrl_write(path, val):
-        fullpath = os.path.join("/sys/bus/netdevsim/", path)
-        try:
-            with open(fullpath, "w") as f:
-                f.write(val)
-        except OSError as e:
-            log("WRITE %s: %r" % (fullpath, val), -e.errno)
-            raise e
-        log("WRITE %s: %r" % (fullpath, val), 0)
-
-    def __init__(self, port_count=1):
-        addr = 0
-        while True:
-            try:
-                self.ctrl_write("new_device", "%u %u" % (addr, port_count))
-            except OSError as e:
-                if e.errno == errno.ENOSPC:
-                    addr += 1
-                    continue
-                raise e
-            break
-        self.addr = addr
-
-        # As probe of netdevsim device might happen from a workqueue,
-        # so wait here until all netdevs appear.
-        self.wait_for_netdevs(port_count)
-
-        ret, out = cmd("udevadm settle", fail=False)
-        if ret:
-            raise Exception("udevadm settle failed")
-        ifnames = self.get_ifnames()
-
+    def __init__(self, port_count=1, ns=None):
+        super().__init__(port_count, ns=ns)
         devs.append(self)
-        self.dfs_dir = "/sys/kernel/debug/netdevsim/netdevsim%u/" % addr
 
-        self.nsims = []
-        for port_index in range(port_count):
-            self.nsims.append(NetdevSim(self, port_index, ifnames[port_index]))
-
-    def get_ifnames(self):
-        ifnames = []
-        listdir = os.listdir("/sys/bus/netdevsim/devices/netdevsim%u/net/" % self.addr)
-        for ifname in listdir:
-            ifnames.append(ifname)
-        ifnames.sort()
-        return ifnames
-
-    def wait_for_netdevs(self, port_count):
-        timeout = 5
-        timeout_start = time.time()
-
-        while True:
-            try:
-                ifnames = self.get_ifnames()
-            except FileNotFoundError as e:
-                ifnames = []
-            if len(ifnames) == port_count:
-                break
-            if time.time() < timeout_start + timeout:
-                continue
-            raise Exception("netdevices did not appear within timeout")
+    def _make_port(self, port_index, ifname):
+        return BpfNetdevSim(self, port_index, ifname, self.ns)
 
     def dfs_num_bound_progs(self):
         path = os.path.join(self.dfs_dir, "bpf_bound_progs")
@@ -415,33 +364,20 @@ def bpftool_prog_load(sample, file_name, maps=[], prog_type="xdp", dev=None,
         return progs
 
     def remove(self):
-        self.ctrl_write("del_device", "%u" % (self.addr, ))
+        super().remove()
         devs.remove(self)
 
-    def remove_nsim(self, nsim):
-        self.nsims.remove(nsim)
-        self.ctrl_write("devices/netdevsim%u/del_port" % (self.addr, ),
-                        "%u" % (nsim.port_index, ))
 
-class NetdevSim:
+class BpfNetdevSim(NetdevSim):
     """
     Class for netdevsim netdevice and its attributes.
     """
 
-    def __init__(self, nsimdev, port_index, ifname):
-        # In case udev renamed the netdev to according to new schema,
-        # check if the name matches the port_index.
-        nsimnamere = re.compile("eni\d+np(\d+)")
-        match = nsimnamere.match(ifname)
-        if match and int(match.groups()[0]) != port_index + 1:
-            raise Exception("netdevice name mismatches the expected one")
+    def __init__(self, nsimdev, port_index, ifname, ns=None):
+        super().__init__(nsimdev, port_index, ifname, ns=ns)
 
-        self.nsimdev = nsimdev
-        self.port_index = port_index
-        self.ns = ""
         self.dfs_dir = "%s/ports/%u/" % (nsimdev.dfs_dir, port_index)
         self.dfs_refresh()
-        _, [self.dev] = ip("link show dev %s" % ifname)
 
     def __getitem__(self, key):
         return self.dev[key]
@@ -468,7 +404,7 @@ def bpftool_prog_load(sample, file_name, maps=[], prog_type="xdp", dev=None,
         raise Exception("Time out waiting for program counts to stabilize want %d/%d, have %d bound, %d loaded" % (bound, total, nbound, nprogs))
 
     def set_ns(self, ns):
-        name = "1" if ns == "" else ns
+        name = ns if ns else "1"
         ip("link set dev %s netns %s" % (self.dev["ifname"], name), ns=self.ns)
         self.ns = ns
 
@@ -744,7 +680,7 @@ def bpftool_prog_load(sample, file_name, maps=[], prog_type="xdp", dev=None,
     start_test("Test multi-attachment XDP - device remove...")
     simdev.remove()
 
-    simdev = NetdevSimDev()
+    simdev = BpfNetdevSimDev()
     sim, = simdev.nsims
     sim.set_ethtool_tc_offloads(True)
     return [simdev, sim]
@@ -809,13 +745,13 @@ netns = []
     bytecode = bpf_bytecode("1,6 0 0 4294967295,")
 
     start_test("Test destruction of generic XDP...")
-    simdev = NetdevSimDev()
+    simdev = BpfNetdevSimDev()
     sim, = simdev.nsims
     sim.set_xdp(obj, "generic")
     simdev.remove()
     bpftool_prog_list_wait(expected=0)
 
-    simdev = NetdevSimDev()
+    simdev = BpfNetdevSimDev()
     sim, = simdev.nsims
     sim.tc_add_ingress()
 
@@ -967,7 +903,7 @@ netns = []
     simdev.remove()
     bpftool_prog_list_wait(expected=0)
 
-    simdev = NetdevSimDev()
+    simdev = BpfNetdevSimDev()
     sim, = simdev.nsims
     sim.set_ethtool_tc_offloads(True)
 
@@ -976,7 +912,7 @@ netns = []
     simdev.remove()
     bpftool_prog_list_wait(expected=0)
 
-    simdev = NetdevSimDev()
+    simdev = BpfNetdevSimDev()
     sim, = simdev.nsims
     sim.set_ethtool_tc_offloads(True)
 
@@ -1080,7 +1016,7 @@ netns = []
     bpftool_prog_list_wait(expected=0)
 
     start_test("Test attempt to use a program for a wrong device...")
-    simdev2 = NetdevSimDev()
+    simdev2 = BpfNetdevSimDev()
     sim2, = simdev2.nsims
     sim2.set_xdp(obj, "offload")
     pin_file, pinned = pin_prog("/sys/fs/bpf/tmp")
@@ -1169,7 +1105,7 @@ netns = []
     clean_up()
     bpftool_prog_list_wait(expected=0)
 
-    simdev = NetdevSimDev()
+    simdev = BpfNetdevSimDev()
     sim, = simdev.nsims
     map_obj = bpf_obj("sample_map_ret0.bpf.o")
     start_test("Test loading program with maps...")
@@ -1201,7 +1137,7 @@ netns = []
     clean_up()
     bpftool_prog_list_wait(expected=0)
 
-    simdev = NetdevSimDev()
+    simdev = BpfNetdevSimDev()
     sim, = simdev.nsims
 
     start_test("Test map update (no flags)...")
@@ -1285,14 +1221,14 @@ netns = []
     bpftool_map_list_wait(expected=0)
     simdev.remove()
 
-    simdev = NetdevSimDev()
+    simdev = BpfNetdevSimDev()
     sim, = simdev.nsims
     sim.set_xdp(map_obj, "offload", JSON=False) # map fixup msg breaks JSON
     simdev.remove()
     bpftool_map_list_wait(expected=0)
 
     start_test("Test map creation fail path...")
-    simdev = NetdevSimDev()
+    simdev = BpfNetdevSimDev()
     sim, = simdev.nsims
     sim.dfs["bpf_map_accept"] = "N"
     ret, _ = sim.set_xdp(map_obj, "offload", JSON=False, fail=False)
@@ -1302,9 +1238,9 @@ netns = []
     simdev.remove()
 
     start_test("Test multi-dev ASIC program reuse...")
-    simdevA = NetdevSimDev()
+    simdevA = BpfNetdevSimDev()
     simA, = simdevA.nsims
-    simdevB = NetdevSimDev(3)
+    simdevB = BpfNetdevSimDev(3)
     simB1, simB2, simB3 = simdevB.nsims
     sims = (simA, simB1, simB2, simB3)
     simB = (simB1, simB2, simB3)
diff --git a/tools/testing/selftests/net/lib/py/nsim.py b/tools/testing/selftests/net/lib/py/nsim.py
index b2d696e12805..97457aca7e08 100644
--- a/tools/testing/selftests/net/lib/py/nsim.py
+++ b/tools/testing/selftests/net/lib/py/nsim.py
@@ -21,8 +21,11 @@ from .utils import cmd, ip
         if match and int(match.groups()[0]) != port_index + 1:
             raise Exception("netdevice name mismatches the expected one")
 
+        self.ifname = ifname
         self.nsimdev = nsimdev
         self.port_index = port_index
+        self.ns = ns
+        self.dfs_dir = "%s/ports/%u/" % (nsimdev.dfs_dir, port_index)
         ret = ip("-j link show dev %s" % ifname, ns=ns)
         self.dev = json.loads(ret.stdout)[0]
 
@@ -79,8 +82,10 @@ from .utils import cmd, ip
 
         self.nsims = []
         for port_index in range(port_count):
-            self.nsims.append(NetdevSim(self, port_index, ifnames[port_index],
-                                        ns=ns))
+            self.nsims.append(self._make_port(port_index, ifnames[port_index]))
+
+    def _make_port(self, port_index, ifname):
+        return NetdevSim(self, port_index, ifname, self.ns)
 
     def get_ifnames(self):
         ifnames = []
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net
  2024-04-09  3:15 [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net Jakub Kicinski
                   ` (3 preceding siblings ...)
  2024-04-09  3:15 ` [PATCH net-next 4/4] selftests: net: reuse common code in bpf_offload Jakub Kicinski
@ 2024-04-09 16:10 ` Stanislav Fomichev
  2024-04-09 16:19   ` Jakub Kicinski
  2024-04-09 18:12 ` Martin KaFai Lau
  2024-04-10 21:20 ` patchwork-bot+netdevbpf
  6 siblings, 1 reply; 11+ messages in thread
From: Stanislav Fomichev @ 2024-04-09 16:10 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni, bpf, andrii, mykolal, eddyz87,
	shuah, linux-kselftest

On 04/08, Jakub Kicinski wrote:
> The test_offload.py test fits in networking and bpf equally
> well. We started adding more Python tests in networking
> and some of the code in test_offload.py can be reused,
> so move it to networking. Looks like it bit rotted over
> time and some fixes are needed.
> 
> Admittedly more code could be extracted but I only had
> the time for a minor cleanup :(

Acked-by: Stanislav Fomichev <sdf@google.com>

Far too often I've seen this test broken because it's not in the CI :-(
Hope you can put it in the netdev one so we get a better signal.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net
  2024-04-09 16:10 ` [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net Stanislav Fomichev
@ 2024-04-09 16:19   ` Jakub Kicinski
  2024-04-09 21:31     ` Jakub Kicinski
  0 siblings, 1 reply; 11+ messages in thread
From: Jakub Kicinski @ 2024-04-09 16:19 UTC (permalink / raw)
  To: Stanislav Fomichev
  Cc: davem, netdev, edumazet, pabeni, bpf, andrii, mykolal, eddyz87,
	shuah, linux-kselftest

On Tue, 9 Apr 2024 09:10:04 -0700 Stanislav Fomichev wrote:
> Acked-by: Stanislav Fomichev <sdf@google.com>

Thanks!

> Far too often I've seen this test broken because it's not in the CI :-(
> Hope you can put it in the netdev one so we get a better signal.

We use kselftest infra directly, so they got auto-included.
But I gotta investigate what's going on on the runner because 
it seems to be failing right now:
https://netdev.bots.linux.dev/contest.html?test=bpf-offload-py

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next 3/4] selftests: net: declare section names for bpf_offload
  2024-04-09  3:15 ` [PATCH net-next 3/4] selftests: net: declare section names for bpf_offload Jakub Kicinski
@ 2024-04-09 17:32   ` Alexei Starovoitov
  0 siblings, 0 replies; 11+ messages in thread
From: Alexei Starovoitov @ 2024-04-09 17:32 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Network Development, Eric Dumazet, Paolo Abeni,
	bpf, Andrii Nakryiko, Mykola Lysenko, Eddy Z, Shuah Khan,
	open list:KERNEL SELFTEST FRAMEWORK

On Mon, Apr 8, 2024 at 8:17 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> Non-ancient ip (iproute2-5.15.0, libbpf 0.7.0) refuses to load
> the sample with maps because we don't generate BTF:
>
>    libbpf: BTF is required, but is missing or corrupted.
>    ERROR: opening BPF object file failed
>
> Enable BTF by adding -g to clang flags. With that done
> neither of the programs load:
>
>   libbpf: prog 'func': error relocating .BTF.ext function info: -22
>   libbpf: prog 'func': failed to relocate calls: -22
>   libbpf: failed to load object 'ksft-net-drv/net/sample_ret0.bpf.o'
>
> Andrii explains that this is because we don't specify
> section names for the code. Add the section names, too.
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
>  tools/testing/selftests/net/Makefile              | 3 ++-
>  tools/testing/selftests/net/bpf_offload.py        | 2 +-
>  tools/testing/selftests/net/sample_map_ret0.bpf.c | 2 +-
>  tools/testing/selftests/net/sample_ret0.bpf.c     | 3 +++
>  4 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
> index e8bfa715aa49..a3c781cb8367 100644
> --- a/tools/testing/selftests/net/Makefile
> +++ b/tools/testing/selftests/net/Makefile
> @@ -149,7 +149,8 @@ BPF_PROG_OBJS := $(OUTPUT)/nat6to4.o $(OUTPUT)/xdp_dummy.o \
>         $(OUTPUT)/sample_map_ret0.bpf.o $(OUTPUT)/sample_ret0.bpf.o
>
>  $(BPF_PROG_OBJS): $(OUTPUT)/%.o : %.c $(BPFOBJ) | $(MAKE_DIRS)
> -       $(CLANG) -O2 --target=bpf -c $< $(CCINCLUDE) $(CLANG_SYS_INCLUDES) -o $@
> +       $(CLANG) -O2 -g --target=bpf $(CCINCLUDE) $(CLANG_SYS_INCLUDES) \
> +       -c $< -o $@
>
>  $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile)                    \
>            $(APIDIR)/linux/bpf.h                                               \
> diff --git a/tools/testing/selftests/net/bpf_offload.py b/tools/testing/selftests/net/bpf_offload.py
> index 174dba1a48d3..76b53ac2c8c6 100755
> --- a/tools/testing/selftests/net/bpf_offload.py
> +++ b/tools/testing/selftests/net/bpf_offload.py
> @@ -237,7 +237,7 @@ def bpftool_prog_load(sample, file_name, maps=[], prog_type="xdp", dev=None,
>  def ethtool(dev, opt, args, fail=True):
>      return cmd("ethtool %s %s %s" % (opt, dev["ifname"], args), fail=fail)
>
> -def bpf_obj(name, sec=".text", path=bpf_test_dir,):
> +def bpf_obj(name, sec="xdp", path=bpf_test_dir,):
>      return "obj %s sec %s" % (os.path.join(path, name), sec)
>
>  def bpf_pinned(name):
> diff --git a/tools/testing/selftests/net/sample_map_ret0.bpf.c b/tools/testing/selftests/net/sample_map_ret0.bpf.c
> index 495990d355ef..43ca92594926 100644
> --- a/tools/testing/selftests/net/sample_map_ret0.bpf.c
> +++ b/tools/testing/selftests/net/sample_map_ret0.bpf.c
> @@ -17,7 +17,7 @@ struct {
>  } array SEC(".maps");
>
>  /* Sample program which should always load for testing control paths. */
> -SEC(".text") int func()
> +SEC("xdp") int func()

It bitrotted so much.. ouch.

For the series:
Acked-by: Alexei Starovoitov <ast@kernel.org>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net
  2024-04-09  3:15 [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net Jakub Kicinski
                   ` (4 preceding siblings ...)
  2024-04-09 16:10 ` [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net Stanislav Fomichev
@ 2024-04-09 18:12 ` Martin KaFai Lau
  2024-04-10 21:20 ` patchwork-bot+netdevbpf
  6 siblings, 0 replies; 11+ messages in thread
From: Martin KaFai Lau @ 2024-04-09 18:12 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: netdev, davem, edumazet, pabeni, bpf, andrii, mykolal, eddyz87,
	shuah, linux-kselftest

On 4/8/24 8:15 PM, Jakub Kicinski wrote:
> The test_offload.py test fits in networking and bpf equally
> well. We started adding more Python tests in networking
> and some of the code in test_offload.py can be reused,
> so move it to networking. Looks like it bit rotted over
> time and some fixes are needed.

Acked-by: Martin KaFai Lau <martin.lau@kernel.org>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net
  2024-04-09 16:19   ` Jakub Kicinski
@ 2024-04-09 21:31     ` Jakub Kicinski
  0 siblings, 0 replies; 11+ messages in thread
From: Jakub Kicinski @ 2024-04-09 21:31 UTC (permalink / raw)
  To: Stanislav Fomichev
  Cc: davem, netdev, edumazet, pabeni, bpf, andrii, mykolal, eddyz87,
	shuah, linux-kselftest

On Tue, 9 Apr 2024 09:19:08 -0700 Jakub Kicinski wrote:
> > Far too often I've seen this test broken because it's not in the CI :-(
> > Hope you can put it in the netdev one so we get a better signal.  
> 
> We use kselftest infra directly, so they got auto-included.
> But I gotta investigate what's going on on the runner because 
> it seems to be failing right now:
> https://netdev.bots.linux.dev/contest.html?test=bpf-offload-py

FWIW looks like iproute2 on the worker was built without libbpf support.
Fixed now, let's see if it turns green :)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net
  2024-04-09  3:15 [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net Jakub Kicinski
                   ` (5 preceding siblings ...)
  2024-04-09 18:12 ` Martin KaFai Lau
@ 2024-04-10 21:20 ` patchwork-bot+netdevbpf
  6 siblings, 0 replies; 11+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-04-10 21:20 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni, bpf, andrii, mykolal, eddyz87,
	shuah, linux-kselftest

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon,  8 Apr 2024 20:15:45 -0700 you wrote:
> The test_offload.py test fits in networking and bpf equally
> well. We started adding more Python tests in networking
> and some of the code in test_offload.py can be reused,
> so move it to networking. Looks like it bit rotted over
> time and some fixes are needed.
> 
> Admittedly more code could be extracted but I only had
> the time for a minor cleanup :(
> 
> [...]

Here is the summary with links:
  - [net-next,1/4] selftests: move bpf-offload test from bpf to net
    https://git.kernel.org/netdev/net-next/c/e59f0e93e92e
  - [net-next,2/4] selftests: net: bpf_offload: wait for maps
    https://git.kernel.org/netdev/net-next/c/fc50c698c28b
  - [net-next,3/4] selftests: net: declare section names for bpf_offload
    https://git.kernel.org/netdev/net-next/c/b1c2ce11d428
  - [net-next,4/4] selftests: net: reuse common code in bpf_offload
    https://git.kernel.org/netdev/net-next/c/6ce2b689932b

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-04-10 21:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-09  3:15 [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net Jakub Kicinski
2024-04-09  3:15 ` [PATCH net-next 1/4] " Jakub Kicinski
2024-04-09  3:15 ` [PATCH net-next 2/4] selftests: net: bpf_offload: wait for maps Jakub Kicinski
2024-04-09  3:15 ` [PATCH net-next 3/4] selftests: net: declare section names for bpf_offload Jakub Kicinski
2024-04-09 17:32   ` Alexei Starovoitov
2024-04-09  3:15 ` [PATCH net-next 4/4] selftests: net: reuse common code in bpf_offload Jakub Kicinski
2024-04-09 16:10 ` [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net Stanislav Fomichev
2024-04-09 16:19   ` Jakub Kicinski
2024-04-09 21:31     ` Jakub Kicinski
2024-04-09 18:12 ` Martin KaFai Lau
2024-04-10 21:20 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.