linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/3] selftests: Test XDP_TX for single-buffer
@ 2025-08-21  1:40 Dimitri Daskalakis
  2025-08-21  1:40 ` [PATCH net-next 1/3] selftests: drv-net: xdp: Extract common XDP_TX setup/validation Dimitri Daskalakis
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Dimitri Daskalakis @ 2025-08-21  1:40 UTC (permalink / raw)
  To: David S . Miller
  Cc: Andrew Lunn, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Shuah Khan, Daniel Borkmann, Jesper Dangaard Brouer,
	Stanislav Fomichev, netdev, linux-kselftest

Ensure single buffer XDP functions correctly by covering the following cases:
1) Zero size payload
2) Full MTU
3) Single buffer packets through a multi-buffer XDP program

These changes were tested with netdevsim and fbnic.

 # ./ksft-net-drv/drivers/net/xdp.py
 TAP version 13
 1..10
 ok 1 xdp.test_xdp_native_pass_sb
 ok 2 xdp.test_xdp_native_pass_mb
 ok 3 xdp.test_xdp_native_drop_sb
 ok 4 xdp.test_xdp_native_drop_mb
 ok 5 xdp.test_xdp_native_tx_sb
 ok 6 xdp.test_xdp_native_tx_mb
 # Failed run: pkt_sz 2048, offset 1. Last successful run: pkt_sz 1024, offset 256. Reason: Adjustment failed
 ok 7 xdp.test_xdp_native_adjst_tail_grow_data
 ok 8 xdp.test_xdp_native_adjst_tail_shrnk_data
 # Failed run: pkt_sz 512, offset -256. Last successful run: pkt_sz 512, offset -128. Reason: Adjustment failed
 ok 9 xdp.test_xdp_native_adjst_head_grow_data
 # Failed run: pkt_sz (2048) > HDS threshold (1536) and offset 64 > 48
 ok 10 xdp.test_xdp_native_adjst_head_shrnk_data
 # Totals: pass:10 fail:0 xfail:0 xpass:0 skip:0 error:0

Dimitri Daskalakis (3):
  selftests: drv-net: xdp: Extract common XDP_TX setup/validation.
  selftests: drv-net: xdp: Add a single-buffer XDP_TX test.
  selftests: drv-net: xdp: Validate single-buff XDP_TX in multi-buff
    mode

 tools/testing/selftests/drivers/net/xdp.py | 71 ++++++++++++++++++----
 1 file changed, 58 insertions(+), 13 deletions(-)

-- 
2.47.3


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

* [PATCH net-next 1/3] selftests: drv-net: xdp: Extract common XDP_TX setup/validation.
  2025-08-21  1:40 [PATCH net-next 0/3] selftests: Test XDP_TX for single-buffer Dimitri Daskalakis
@ 2025-08-21  1:40 ` Dimitri Daskalakis
  2025-08-21  1:40 ` [PATCH net-next 2/3] selftests: drv-net: xdp: Add a single-buffer XDP_TX test Dimitri Daskalakis
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Dimitri Daskalakis @ 2025-08-21  1:40 UTC (permalink / raw)
  To: David S . Miller
  Cc: Andrew Lunn, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Shuah Khan, Daniel Borkmann, Jesper Dangaard Brouer,
	Stanislav Fomichev, netdev, linux-kselftest

In preparation of single-buffer XDP_TX tests, refactor common test code
into the _test_xdp_native_tx method. Add support for multiple payload
sizes, and additional validation for RX packet count. Pass the -n flag
to echo to avoid adding an extra byte into the TX packet.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Dimitri Daskalakis <dimitri.daskalakis1@gmail.com>
---
 tools/testing/selftests/drivers/net/xdp.py | 47 ++++++++++++++++------
 1 file changed, 34 insertions(+), 13 deletions(-)

diff --git a/tools/testing/selftests/drivers/net/xdp.py b/tools/testing/selftests/drivers/net/xdp.py
index 1dd8bf3bf6c9..ea4da9024f9f 100755
--- a/tools/testing/selftests/drivers/net/xdp.py
+++ b/tools/testing/selftests/drivers/net/xdp.py
@@ -290,34 +290,55 @@ def test_xdp_native_drop_mb(cfg):
     _test_drop(cfg, bpf_info, 8000)
 
 
-def test_xdp_native_tx_mb(cfg):
+def _test_xdp_native_tx(cfg, bpf_info, payload_lens):
     """
-    Tests the XDP_TX action for a multi-buff case.
+    Tests the XDP_TX action.
 
     Args:
         cfg: Configuration object containing network settings.
+        bpf_info: BPFProgInfo object containing the BPF program metadata.
+        payload_lens: Array of packet lengths to send.
     """
     cfg.require_cmd("socat", remote=True)
-
-    bpf_info = BPFProgInfo("xdp_prog_frags", "xdp_native.bpf.o", "xdp.frags", 9000)
     prog_info = _load_xdp_prog(cfg, bpf_info)
     port = rand_port()
 
     _set_xdp_map("map_xdp_setup", TestConfig.MODE.value, XDPAction.TX.value)
     _set_xdp_map("map_xdp_setup", TestConfig.PORT.value, port)
 
-    test_string = ''.join(random.choice(string.ascii_lowercase) for _ in range(8000))
-    rx_udp = f"socat -{cfg.addr_ipver} -T 2 -u UDP-RECV:{port},reuseport STDOUT"
-    tx_udp = f"echo {test_string} | socat -t 2 -u STDIN UDP:{cfg.baddr}:{port}"
+    expected_pkts = 0
+    for payload_len in payload_lens:
+        test_string = "".join(
+            random.choice(string.ascii_lowercase) for _ in range(payload_len)
+        )
+
+        rx_udp = f"socat -{cfg.addr_ipver} -T 2 " + \
+                 f"-u UDP-RECV:{port},reuseport STDOUT"
+        tx_udp = f"echo -n {test_string} | socat -t 2 " + \
+                 f"-u STDIN UDP:{cfg.baddr}:{port}"
+
+        with bkg(rx_udp, host=cfg.remote, exit_wait=True) as rnc:
+            wait_port_listen(port, proto="udp", host=cfg.remote)
+            cmd(tx_udp, host=cfg.remote, shell=True)
+
+        ksft_eq(rnc.stdout.strip(), test_string, "UDP packet exchange failed")
 
-    with bkg(rx_udp, host=cfg.remote, exit_wait=True) as rnc:
-        wait_port_listen(port, proto="udp", host=cfg.remote)
-        cmd(tx_udp, host=cfg.remote, shell=True)
+        expected_pkts += 1
+        stats = _get_stats(prog_info["maps"]["map_xdp_stats"])
+        ksft_eq(stats[XDPStats.RX.value], expected_pkts, "RX stats mismatch")
+        ksft_eq(stats[XDPStats.TX.value], expected_pkts, "TX stats mismatch")
 
-    stats = _get_stats(prog_info['maps']['map_xdp_stats'])
 
-    ksft_eq(rnc.stdout.strip(), test_string, "UDP packet exchange failed")
-    ksft_eq(stats[XDPStats.TX.value], 1, "TX stats mismatch")
+def test_xdp_native_tx_mb(cfg):
+    """
+    Tests the XDP_TX action for a multi-buff case.
+
+    Args:
+        cfg: Configuration object containing network settings.
+    """
+    bpf_info = BPFProgInfo("xdp_prog_frags", "xdp_native.bpf.o",
+                           "xdp.frags", 9000)
+    _test_xdp_native_tx(cfg, bpf_info, [8000])
 
 
 def _validate_res(res, offset_lst, pkt_sz_lst):
-- 
2.47.3


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

* [PATCH net-next 2/3] selftests: drv-net: xdp: Add a single-buffer XDP_TX test.
  2025-08-21  1:40 [PATCH net-next 0/3] selftests: Test XDP_TX for single-buffer Dimitri Daskalakis
  2025-08-21  1:40 ` [PATCH net-next 1/3] selftests: drv-net: xdp: Extract common XDP_TX setup/validation Dimitri Daskalakis
@ 2025-08-21  1:40 ` Dimitri Daskalakis
  2025-08-21  1:40 ` [PATCH net-next 3/3] selftests: drv-net: xdp: Validate single-buff XDP_TX in multi-buff mode Dimitri Daskalakis
  2025-08-22 14:50 ` [PATCH net-next 0/3] selftests: Test XDP_TX for single-buffer patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Dimitri Daskalakis @ 2025-08-21  1:40 UTC (permalink / raw)
  To: David S . Miller
  Cc: Andrew Lunn, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Shuah Khan, Daniel Borkmann, Jesper Dangaard Brouer,
	Stanislav Fomichev, netdev, linux-kselftest

Test single-buffer XDP_TX for packets with various payload sizes.
Update the socat TX command to generate packets with 0 length payloads.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Dimitri Daskalakis <dimitri.daskalakis1@gmail.com>
---
 tools/testing/selftests/drivers/net/xdp.py | 23 +++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/drivers/net/xdp.py b/tools/testing/selftests/drivers/net/xdp.py
index ea4da9024f9f..cea24c9b573e 100755
--- a/tools/testing/selftests/drivers/net/xdp.py
+++ b/tools/testing/selftests/drivers/net/xdp.py
@@ -314,8 +314,13 @@ def _test_xdp_native_tx(cfg, bpf_info, payload_lens):
 
         rx_udp = f"socat -{cfg.addr_ipver} -T 2 " + \
                  f"-u UDP-RECV:{port},reuseport STDOUT"
+
+        # Writing zero bytes to stdin gets ignored by socat,
+        # but with the shut-null flag socat generates a zero sized packet
+        # when the socket is closed.
+        tx_cmd_suffix = ",shut-null" if payload_len == 0 else ""
         tx_udp = f"echo -n {test_string} | socat -t 2 " + \
-                 f"-u STDIN UDP:{cfg.baddr}:{port}"
+                 f"-u STDIN UDP:{cfg.baddr}:{port}{tx_cmd_suffix}"
 
         with bkg(rx_udp, host=cfg.remote, exit_wait=True) as rnc:
             wait_port_listen(port, proto="udp", host=cfg.remote)
@@ -329,6 +334,21 @@ def _test_xdp_native_tx(cfg, bpf_info, payload_lens):
         ksft_eq(stats[XDPStats.TX.value], expected_pkts, "TX stats mismatch")
 
 
+def test_xdp_native_tx_sb(cfg):
+    """
+    Tests the XDP_TX action for a single-buff case.
+
+    Args:
+        cfg: Configuration object containing network settings.
+    """
+    bpf_info = BPFProgInfo("xdp_prog", "xdp_native.bpf.o", "xdp", 1500)
+
+    # Ensure there's enough room for an ETH / IP / UDP header
+    pkt_hdr_len = 42 if cfg.addr_ipver == "4" else 62
+
+    _test_xdp_native_tx(cfg, bpf_info, [0, 1500 // 2, 1500 - pkt_hdr_len])
+
+
 def test_xdp_native_tx_mb(cfg):
     """
     Tests the XDP_TX action for a multi-buff case.
@@ -665,6 +685,7 @@ def main():
                 test_xdp_native_pass_mb,
                 test_xdp_native_drop_sb,
                 test_xdp_native_drop_mb,
+                test_xdp_native_tx_sb,
                 test_xdp_native_tx_mb,
                 test_xdp_native_adjst_tail_grow_data,
                 test_xdp_native_adjst_tail_shrnk_data,
-- 
2.47.3


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

* [PATCH net-next 3/3] selftests: drv-net: xdp: Validate single-buff XDP_TX in multi-buff mode
  2025-08-21  1:40 [PATCH net-next 0/3] selftests: Test XDP_TX for single-buffer Dimitri Daskalakis
  2025-08-21  1:40 ` [PATCH net-next 1/3] selftests: drv-net: xdp: Extract common XDP_TX setup/validation Dimitri Daskalakis
  2025-08-21  1:40 ` [PATCH net-next 2/3] selftests: drv-net: xdp: Add a single-buffer XDP_TX test Dimitri Daskalakis
@ 2025-08-21  1:40 ` Dimitri Daskalakis
  2025-08-22 14:50 ` [PATCH net-next 0/3] selftests: Test XDP_TX for single-buffer patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Dimitri Daskalakis @ 2025-08-21  1:40 UTC (permalink / raw)
  To: David S . Miller
  Cc: Andrew Lunn, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Shuah Khan, Daniel Borkmann, Jesper Dangaard Brouer,
	Stanislav Fomichev, netdev, linux-kselftest

Validate that drivers with multi-buff XDP programs properly reinitialize
xdp_buff between packets.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Dimitri Daskalakis <dimitri.daskalakis1@gmail.com>
---
 tools/testing/selftests/drivers/net/xdp.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/drivers/net/xdp.py b/tools/testing/selftests/drivers/net/xdp.py
index cea24c9b573e..35e9495cd506 100755
--- a/tools/testing/selftests/drivers/net/xdp.py
+++ b/tools/testing/selftests/drivers/net/xdp.py
@@ -358,7 +358,10 @@ def test_xdp_native_tx_mb(cfg):
     """
     bpf_info = BPFProgInfo("xdp_prog_frags", "xdp_native.bpf.o",
                            "xdp.frags", 9000)
-    _test_xdp_native_tx(cfg, bpf_info, [8000])
+    # The first packet ensures we exercise the fragmented code path.
+    # And the subsequent 0-sized packet ensures the driver
+    # reinitializes xdp_buff correctly.
+    _test_xdp_native_tx(cfg, bpf_info, [8000, 0])
 
 
 def _validate_res(res, offset_lst, pkt_sz_lst):
-- 
2.47.3


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

* Re: [PATCH net-next 0/3] selftests: Test XDP_TX for single-buffer
  2025-08-21  1:40 [PATCH net-next 0/3] selftests: Test XDP_TX for single-buffer Dimitri Daskalakis
                   ` (2 preceding siblings ...)
  2025-08-21  1:40 ` [PATCH net-next 3/3] selftests: drv-net: xdp: Validate single-buff XDP_TX in multi-buff mode Dimitri Daskalakis
@ 2025-08-22 14:50 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-08-22 14:50 UTC (permalink / raw)
  To: Dimitri Daskalakis
  Cc: davem, andrew+netdev, edumazet, kuba, pabeni, shuah, daniel, hawk,
	sdf, netdev, linux-kselftest

Hello:

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

On Wed, 20 Aug 2025 18:40:20 -0700 you wrote:
> Ensure single buffer XDP functions correctly by covering the following cases:
> 1) Zero size payload
> 2) Full MTU
> 3) Single buffer packets through a multi-buffer XDP program
> 
> These changes were tested with netdevsim and fbnic.
> 
> [...]

Here is the summary with links:
  - [net-next,1/3] selftests: drv-net: xdp: Extract common XDP_TX setup/validation.
    https://git.kernel.org/netdev/net-next/c/91aacd8ceffe
  - [net-next,2/3] selftests: drv-net: xdp: Add a single-buffer XDP_TX test.
    https://git.kernel.org/netdev/net-next/c/d06d70eb6af4
  - [net-next,3/3] selftests: drv-net: xdp: Validate single-buff XDP_TX in multi-buff mode
    https://git.kernel.org/netdev/net-next/c/bbd885b193cc

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] 5+ messages in thread

end of thread, other threads:[~2025-08-22 14:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-21  1:40 [PATCH net-next 0/3] selftests: Test XDP_TX for single-buffer Dimitri Daskalakis
2025-08-21  1:40 ` [PATCH net-next 1/3] selftests: drv-net: xdp: Extract common XDP_TX setup/validation Dimitri Daskalakis
2025-08-21  1:40 ` [PATCH net-next 2/3] selftests: drv-net: xdp: Add a single-buffer XDP_TX test Dimitri Daskalakis
2025-08-21  1:40 ` [PATCH net-next 3/3] selftests: drv-net: xdp: Validate single-buff XDP_TX in multi-buff mode Dimitri Daskalakis
2025-08-22 14:50 ` [PATCH net-next 0/3] selftests: Test XDP_TX for single-buffer patchwork-bot+netdevbpf

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).