Skip to contentSkip to conversation

selftests: drv-net: add a simple TSO test

PATCH Applied Jakub Kicinski 3 participants 8 messages Feb 18, 2025 – Feb 20, 2025

Subsystems (3)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

v4 cover selftests: drv-net: add a simple TSO test

Add a simple test for exercising TSO over tunnels.

Similarly to csum test we want to iterate over ip versions. Rework how addresses are stored in env to make this easier.

v4:
- [patch 3] fix f-strings on Python < 3.12
- [patch 4] fix v4/v6 test naming
- [patch 4] correctly select the inner vs outer protocol version
- [patch 4] enable mangleid if tunnel is supported via GSO partial
v3: https://lore.kernel.org/[email protected]
- [patch 3] new patch
- [patch 4] rework after new patch added
v2: https://lore.kernel.org/[email protected]
- [patch 1] check for IP being on multiple ifcs
- [patch 4] lower max noise
- [patch 4] mention header overhead in the comment
- [patch 4] fix the basic v4 TSO feature name
- [patch 4] also run a stream with just GSO partial for tunnels
v1: https://lore.kernel.org/[email protected]

Jakub Kicinski (4):
selftests: drv-net: resolve remote interface name
selftests: drv-net: get detailed interface info
selftests: drv-net: store addresses in dict indexed by ipver
selftests: drv-net: add a simple TSO test

 .../testing/selftests/drivers/net/hw/Makefile |   1 +
 .../testing/selftests/drivers/net/hw/csum.py  |  48 ++--
 .../selftests/drivers/net/hw/devmem.py        |   6 +-
 tools/testing/selftests/drivers/net/hw/tso.py | 241 ++++++++++++++++++
 .../selftests/drivers/net/lib/py/env.py       |  58 +++--
 tools/testing/selftests/drivers/net/ping.py   |  12 +-
 6 files changed, 305 insertions(+), 61 deletions(-)
 create mode 100755 tools/testing/selftests/drivers/net/hw/tso.py
Signature · 1 line
2.48.1
author maintainer
#1 lore raw

PATCH v4 1/4 selftests: drv-net: resolve remote interface name

Find out and record in env the name of the interface which remote host will use for the IP address provided via config.

Interface name is useful for mausezahn and for setting up tunnels.

---
v2:
- check for IP being on multiple ifcs
v1: https://lore.kernel.org/[email protected]

---
 tools/testing/selftests/drivers/net/lib/py/env.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
tools/testing/selftests/drivers/net/lib/py/env.py +15 -0
index 886b4904613c..55d6b3d992b6 100644
@@ -154,6 +154,9 @@ from .remote import Remote
         self.ifname = self.dev['ifname']
         self.ifindex = self.dev['ifindex']
 
+        # resolve remote interface name
+        self.remote_ifname = self.resolve_remote_ifc()
+
         self._required_cmd = {}
 
     def create_local(self):
@@ -200,6 +203,18 @@ from .remote import Remote
             raise Exception("Invalid environment, missing configuration:", missing,
                             "Please see tools/testing/selftests/drivers/net/README.rst")
 
+    def resolve_remote_ifc(self):
+        v4 = v6 = None
+        if self.remote_v4:
+            v4 = ip("addr show to " + self.remote_v4, json=True, host=self.remote)
+        if self.remote_v6:
+            v6 = ip("addr show to " + self.remote_v6, json=True, host=self.remote)
+        if v4 and v6 and v4[0]["ifname"] != v6[0]["ifname"]:
+            raise Exception("Can't resolve remote interface name, v4 and v6 don't match")
+        if (v4 and len(v4) > 1) or (v6 and len(v6) > 1):
+            raise Exception("Can't resolve remote interface name, multiple interfaces match")
+        return v6[0]["ifname"] if v6 else v4[0]["ifname"]
+
     def __enter__(self):
         return self
 
Signature · 1 line
2.48.1
author maintainer
#2 lore raw

PATCH v4 2/4 selftests: drv-net: get detailed interface info

In reply to Jakub Kicinski

We already record output of ip link for NETIF in env for easy access. Record the detailed version. TSO test will want to know the max tso size.

---
 tools/testing/selftests/drivers/net/lib/py/env.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/drivers/net/lib/py/env.py +2 -2
index 55d6b3d992b6..128acff4f753 100644
@@ -64,7 +64,7 @@ from .remote import Remote
         self._ns = None
 
         if 'NETIF' in self.env:
-            self.dev = ip("link show dev " + self.env['NETIF'], json=True)[0]
+            self.dev = ip("-d link show dev " + self.env['NETIF'], json=True)[0]
         else:
             self._ns = NetdevSimDev(**kwargs)
             self.dev = self._ns.nsims[0].dev
@@ -118,7 +118,7 @@ from .remote import Remote
                 raise KsftXfailEx("Test only works on netdevsim")
             self._check_env()
 
-            self.dev = ip("link show dev " + self.env['NETIF'], json=True)[0]
+            self.dev = ip("-d link show dev " + self.env['NETIF'], json=True)[0]
 
             self.v4 = self.env.get("LOCAL_V4")
             self.v6 = self.env.get("LOCAL_V6")
Signature · 1 line
2.48.1
author maintainer
#3 lore raw

PATCH v4 3/4 selftests: drv-net: store addresses in dict indexed by ipver

In reply to Jakub Kicinski

Looks like more and more tests want to iterate over IP version, run the same test over ipv4 and ipv6. The current naming of members in the env class makes it a bit awkward, we have separate members for ipv4 and ipv6 parameters.

Store the parameters inside dicts, so that tests can easily index them with ip version.

---
v4:
- fix f-strings on Python < 3.12
v3: https://lore.kernel.org/[email protected]
- new patch

---
 .../testing/selftests/drivers/net/hw/csum.py  | 48 +++++++------------
 .../selftests/drivers/net/hw/devmem.py        |  6 +--
 .../selftests/drivers/net/lib/py/env.py       | 47 +++++++++---------
 tools/testing/selftests/drivers/net/ping.py   | 12 ++---
 4 files changed, 50 insertions(+), 63 deletions(-)
tools/testing/selftests/drivers/net/hw/csum.py +18 -30
index cd477f3440ca..701aca1361e0 100755
@@ -9,15 +9,12 @@ from lib.py import ksft_run, ksft_exit, KsftSkipEx
 from lib.py import EthtoolFamily, NetDrvEpEnv
 from lib.py import bkg, cmd, wait_port_listen
 
-def test_receive(cfg, ipv4=False, extra_args=None):
+def test_receive(cfg, ipver="6", extra_args=None):
     """Test local nic checksum receive. Remote host sends crafted packets."""
     if not cfg.have_rx_csum:
         raise KsftSkipEx(f"Test requires rx checksum offload on {cfg.ifname}")
 
-    if ipv4:
-        ip_args = f"-4 -S {cfg.remote_v4} -D {cfg.v4}"
-    else:
-        ip_args = f"-6 -S {cfg.remote_v6} -D {cfg.v6}"
+    ip_args = f"-{ipver} -S {cfg.remote_addr_v[ipver]} -D {cfg.addr_v[ipver]}"
 
     rx_cmd = f"{cfg.bin_local} -i {cfg.ifname} -n 100 {ip_args} -r 1 -R {extra_args}"
     tx_cmd = f"{cfg.bin_remote} -i {cfg.ifname} -n 100 {ip_args} -r 1 -T {extra_args}"
@@ -27,17 +24,14 @@ from lib.py import bkg, cmd, wait_port_listen
         cmd(tx_cmd, host=cfg.remote)
 
 
-def test_transmit(cfg, ipv4=False, extra_args=None):
+def test_transmit(cfg, ipver="6", extra_args=None):
     """Test local nic checksum transmit. Remote host verifies packets."""
     if (not cfg.have_tx_csum_generic and
-        not (cfg.have_tx_csum_ipv4 and ipv4) and
-        not (cfg.have_tx_csum_ipv6 and not ipv4)):
+        not (cfg.have_tx_csum_ipv4 and ipver == "4") and
+        not (cfg.have_tx_csum_ipv6 and ipver == "6")):
         raise KsftSkipEx(f"Test requires tx checksum offload on {cfg.ifname}")
 
-    if ipv4:
-        ip_args = f"-4 -S {cfg.v4} -D {cfg.remote_v4}"
-    else:
-        ip_args = f"-6 -S {cfg.v6} -D {cfg.remote_v6}"
+    ip_args = f"-{ipver} -S {cfg.addr_v[ipver]} -D {cfg.remote_addr_v[ipver]}"
 
     # Cannot randomize input when calculating zero checksum
     if extra_args != "-U -Z":
@@ -51,26 +45,20 @@ from lib.py import bkg, cmd, wait_port_listen
         cmd(tx_cmd)
 
 
-def test_builder(name, cfg, ipv4=False, tx=False, extra_args=""):
+def test_builder(name, cfg, ipver="6", tx=False, extra_args=""):
     """Construct specific tests from the common template.
 
        Most tests follow the same basic pattern, differing only in
        Direction of the test and optional flags passed to csum."""
     def f(cfg):
-        if ipv4:
-            cfg.require_v4()
-        else:
-            cfg.require_v6()
+        cfg.require_ipver(ipver)
 
         if tx:
-            test_transmit(cfg, ipv4, extra_args)
+            test_transmit(cfg, ipver, extra_args)
         else:
-            test_receive(cfg, ipv4, extra_args)
+            test_receive(cfg, ipver, extra_args)
 
-    if ipv4:
-        f.__name__ = "ipv4_" + name
-    else:
-        f.__name__ = "ipv6_" + name
+    f.__name__ = f"ipv{ipver}_" + name
     return f
 
 
@@ -104,15 +92,15 @@ from lib.py import bkg, cmd, wait_port_listen
         cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
 
         cases = []
-        for ipv4 in [True, False]:
-            cases.append(test_builder("rx_tcp", cfg, ipv4, False, "-t"))
-            cases.append(test_builder("rx_tcp_invalid", cfg, ipv4, False, "-t -E"))
+        for ipver in ["4", "6"]:
+            cases.append(test_builder("rx_tcp", cfg, ipver, False, "-t"))
+            cases.append(test_builder("rx_tcp_invalid", cfg, ipver, False, "-t -E"))
 
-            cases.append(test_builder("rx_udp", cfg, ipv4, False, ""))
-            cases.append(test_builder("rx_udp_invalid", cfg, ipv4, False, "-E"))
+            cases.append(test_builder("rx_udp", cfg, ipver, False, ""))
+            cases.append(test_builder("rx_udp_invalid", cfg, ipver, False, "-E"))
 
-            cases.append(test_builder("tx_udp_csum_offload", cfg, ipv4, True, "-U"))
-            cases.append(test_builder("tx_udp_zero_checksum", cfg, ipv4, True, "-U -Z"))
+            cases.append(test_builder("tx_udp_csum_offload", cfg, ipver, True, "-U"))
+            cases.append(test_builder("tx_udp_zero_checksum", cfg, ipver, True, "-U -Z"))
 
         ksft_run(cases=cases, args=(cfg, ))
     ksft_exit()
tools/testing/selftests/drivers/net/hw/devmem.py +3 -3
index 1223f0f5c10c..3947e9157115 100755
@@ -21,15 +21,15 @@ from lib.py import ksft_disruptive
 
 @ksft_disruptive
 def check_rx(cfg) -> None:
-    cfg.require_v6()
+    cfg.require_ipver("6")
     require_devmem(cfg)
 
     port = rand_port()
-    listen_cmd = f"./ncdevmem -l -f {cfg.ifname} -s {cfg.v6} -p {port}"
+    listen_cmd = f"./ncdevmem -l -f {cfg.ifname} -s {cfg.addr_v['6']} -p {port}"
 
     with bkg(listen_cmd) as socat:
         wait_port_listen(port)
-        cmd(f"echo -e \"hello\\nworld\"| socat -u - TCP6:[{cfg.v6}]:{port}", host=cfg.remote, shell=True)
+        cmd(f"echo -e \"hello\\nworld\"| socat -u - TCP6:[{cfg.addr_v['6']}]:{port}", host=cfg.remote, shell=True)
 
     ksft_eq(socat.stdout.strip(), "hello\nworld")
 
tools/testing/selftests/drivers/net/lib/py/env.py +23 -24

84 lines not on this page · raw message

tools/testing/selftests/drivers/net/ping.py +6 -6
index eb83e7b48797..17dc11e9b6dd 100755
@@ -8,17 +8,17 @@ from lib.py import bkg, cmd, wait_port_listen, rand_port
 
 
 def test_v4(cfg) -> None:
-    cfg.require_v4()
+    cfg.require_ipver("4")
 
-    cmd(f"ping -c 1 -W0.5 {cfg.remote_v4}")
-    cmd(f"ping -c 1 -W0.5 {cfg.v4}", host=cfg.remote)
+    cmd("ping -c 1 -W0.5 " + cfg.remote_addr_v["4"])
+    cmd("ping -c 1 -W0.5 " + cfg.addr_v["4"], host=cfg.remote)
 
 
 def test_v6(cfg) -> None:
-    cfg.require_v6()
+    cfg.require_ipver("6")
 
-    cmd(f"ping -c 1 -W0.5 {cfg.remote_v6}")
-    cmd(f"ping -c 1 -W0.5 {cfg.v6}", host=cfg.remote)
+    cmd("ping -c 1 -W0.5 " + cfg.remote_addr_v["6"])
+    cmd("ping -c 1 -W0.5 " + cfg.addr_v["6"], host=cfg.remote)
 
 
 def test_tcp(cfg) -> None:
Signature · 1 line
2.48.1
author maintainer
#5 lore raw

PATCH v4 4/4 selftests: drv-net: add a simple TSO test

In reply to Jakub Kicinski

Add a simple test for TSO. Send a few MB of data and check device stats to verify that the device was performing segmentation. Do the same thing over a few tunnel types.

Injecting GSO packets directly would give us more ability to test corner cases, but perhaps starting simple is good enough?

  # ./ksft-net-drv/drivers/net/hw/tso.py
  # Detected qstat for LSO wire-packets
  KTAP version 1
  1..14
  ok 1 tso.ipv4 # SKIP Test requires IPv4 connectivity
  ok 2 tso.vxlan4_ipv4 # SKIP Test requires IPv4 connectivity
  ok 3 tso.vxlan6_ipv4 # SKIP Test requires IPv4 connectivity
  ok 4 tso.vxlan_csum4_ipv4 # SKIP Test requires IPv4 connectivity
  ok 5 tso.vxlan_csum6_ipv4 # SKIP Test requires IPv4 connectivity
  ok 6 tso.gre4_ipv4 # SKIP Test requires IPv4 connectivity
  ok 7 tso.gre6_ipv4 # SKIP Test requires IPv4 connectivity
  ok 8 tso.ipv6
  ok 9 tso.vxlan4_ipv6
  ok 10 tso.vxlan6_ipv6
  ok 11 tso.vxlan_csum4_ipv6
  ok 12 tso.vxlan_csum6_ipv6
  # Testing with mangleid enabled
  ok 13 tso.gre4_ipv6
  ok 14 tso.gre6_ipv6
  # Totals: pass:7 fail:0 xfail:0 xpass:0 skip:7 error:0

Note that the test currently depends on the driver reporting the LSO count via qstat, which appears to be relatively rare (virtio, cisco/enic, sfc/efc; but virtio needs host support).

---
v4:
- fix v4/v6 test naming
- correctly select the inner vs outer protocol version
- enable mangleid if tunnel is supported via GSO partial
v3: https://lore.kernel.org/[email protected]
- rework after the v4/v6 address split
v2: https://lore.kernel.org/[email protected]
- lower max noise
- mention header overhead in the comment
- fix the basic v4 TSO feature name
- also run a stream with just GSO partial for tunnels
v1: https://lore.kernel.org/[email protected]

---
 .../testing/selftests/drivers/net/hw/Makefile |   1 +
 tools/testing/selftests/drivers/net/hw/tso.py | 241 ++++++++++++++++++
 2 files changed, 242 insertions(+)
 create mode 100755 tools/testing/selftests/drivers/net/hw/tso.py
tools/testing/selftests/drivers/net/hw/Makefile +1 -0
index 21ba64ce1e34..ae783e18be83 100644
@@ -15,6 +15,7 @@ TEST_PROGS = \
 	nic_performance.py \
 	pp_alloc_fail.py \
 	rss_ctx.py \
+	tso.py \
 	#
 
 TEST_FILES := \
tools/testing/selftests/drivers/net/hw/tso.py new file +241 -0

241 lines not on this page · raw message

Signature · 1 line
2.48.1
Reviewed-by on v4 3/4
#4 lore raw

Re: [PATCH net-next v4 3/4] selftests: drv-net: store addresses in dict indexed by ipver

In reply to Jakub Kicinski
Quoted 9 lines · Jakub Kicinski

Looks like more and more tests want to iterate over IP version, run the same test over ipv4 and ipv6. The current naming of members in the env class makes it a bit awkward, we have separate members for ipv4 and ipv6 parameters.

Store the parameters inside dicts, so that tests can easily index them with ip version.

Reviewed-by on v4 4/4
#6 lore raw
In reply to Jakub Kicinski
Quoted 28 lines · Jakub Kicinski

Add a simple test for TSO. Send a few MB of data and check device stats to verify that the device was performing segmentation. Do the same thing over a few tunnel types.

Injecting GSO packets directly would give us more ability to test corner cases, but perhaps starting simple is good enough?

  # ./ksft-net-drv/drivers/net/hw/tso.py
  # Detected qstat for LSO wire-packets
  KTAP version 1
  1..14
  ok 1 tso.ipv4 # SKIP Test requires IPv4 connectivity
  ok 2 tso.vxlan4_ipv4 # SKIP Test requires IPv4 connectivity
  ok 3 tso.vxlan6_ipv4 # SKIP Test requires IPv4 connectivity
  ok 4 tso.vxlan_csum4_ipv4 # SKIP Test requires IPv4 connectivity
  ok 5 tso.vxlan_csum6_ipv4 # SKIP Test requires IPv4 connectivity
  ok 6 tso.gre4_ipv4 # SKIP Test requires IPv4 connectivity
  ok 7 tso.gre6_ipv4 # SKIP Test requires IPv4 connectivity
  ok 8 tso.ipv6
  ok 9 tso.vxlan4_ipv6
  ok 10 tso.vxlan6_ipv6
  ok 11 tso.vxlan_csum4_ipv6
  ok 12 tso.vxlan_csum6_ipv6
  # Testing with mangleid enabled
  ok 13 tso.gre4_ipv6
  ok 14 tso.gre6_ipv6
  # Totals: pass:7 fail:0 xfail:0 xpass:0 skip:7 error:0
Quoted 5 lines

Note that the test currently depends on the driver reporting the LSO count via qstat, which appears to be relatively rare (virtio, cisco/enic, sfc/efc; but virtio needs host support).

#7 lore raw
In reply to Jakub Kicinski
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 21 lines · On Tue, 18 Feb 2025 14:54:22 -0800 you wrote:

Add a simple test for exercising TSO over tunnels.

Similarly to csum test we want to iterate over ip versions. Rework how addresses are stored in env to make this easier.

v4:
- [patch 3] fix f-strings on Python < 3.12
- [patch 4] fix v4/v6 test naming
- [patch 4] correctly select the inner vs outer protocol version
- [patch 4] enable mangleid if tunnel is supported via GSO partial
v3: https://lore.kernel.org/[email protected]
- [patch 3] new patch
- [patch 4] rework after new patch added
v2: https://lore.kernel.org/[email protected]
- [patch 1] check for IP being on multiple ifcs
- [patch 4] lower max noise
- [patch 4] mention header overhead in the comment
- [patch 4] fix the basic v4 TSO feature name
- [patch 4] also run a stream with just GSO partial for tunnels
v1: https://lore.kernel.org/[email protected]

Quoted 1 line

[...]

Here is the summary with links:
- [net-next,v4,1/4] selftests: drv-net: resolve remote interface name

    https://git.kernel.org/netdev/net-next/c/2217bcb49149
  - [net-next,v4,2/4] selftests: drv-net: get detailed interface info
    https://git.kernel.org/netdev/net-next/c/2aefca8e1fa8
  - [net-next,v4,3/4] selftests: drv-net: store addresses in dict indexed by ipver
    https://git.kernel.org/netdev/net-next/c/de94e8697405
  - [net-next,v4,4/4] selftests: drv-net: add a simple TSO test
    https://git.kernel.org/netdev/net-next/c/0d0f4174f6c8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html