Skip to contentSkip to conversation

selftests: drv-net: devmem: set reuseaddr on the sender's source port

PATCH Superseded Jakub Kicinski 4 participants 4 messages Sep 8 – Sep 9

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 selftests: drv-net: devmem: set reuseaddr on the sender's source port

devmem.py fails on the HW runners with:

  CMD[remote]: dd if=/dev/zero bs=512 count=1 2>/dev/null | socat -b 512 \
    -u - TCP6:[fd00:2::1]:50051,bind=[fd00:2::2]:50051,nodelay
    STDERR: socat[41018] W bind(5, {AF=10 [fd00:2::2]:50051}, 28): \
            Address already in use

ncdevmem installs a 5-tuple flow rule which matches the source port, so socat has to bind it explicitly. The port comes from rand_port(), which checks availability on the DUT - but we bind on the remote... That said the failure rate seems to high to be random collisions (~2% per sub-test). It's probably TIME_WAIT sockets on the remote, run_rx_hds() alone creates 12 of them.

Set reuseaddr so a TIME_WAIT socket does not fail the bind. Collisions with a live socket are still possible, we'll see if they are frequent enough to care.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 tools/testing/selftests/drivers/net/hw/devmem_lib.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/drivers/net/hw/devmem_lib.py +1 -1
index 3554954a6691..b6e52fa9dda5 100644
@@ -201,7 +201,7 @@ def ncdevmem_rx(cfg, port, verify=True, fail_on_linear=False, flow_steer=False,
     else:
         addr = cfg.baddr
 
-    suffix = f",bind={cfg.remote_baddr}:{port}"
+    suffix = f",bind={cfg.remote_baddr}:{port},reuseaddr"
 
     buf = ""
     if buf_size:
Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Jakub Kicinski

devmem.py fails on the HW runners with:

  CMD[remote]: dd if=/dev/zero bs=512 count=1 2>/dev/null | socat -b 512 \
    -u - TCP6:[fd00:2::1]:50051,bind=[fd00:2::2]:50051,nodelay
    STDERR: socat[41018] W bind(5, {AF=10 [fd00:2::2]:50051}, 28): \
            Address already in use

ncdevmem installs a 5-tuple flow rule which matches the source port, so socat has to bind it explicitly. The port comes from rand_port(), which checks availability on the DUT - but we bind on the remote... That said the failure rate seems to high to be random collisions (~2% per sub-test). It's probably TIME_WAIT sockets on the remote, run_rx_hds() alone creates 12 of them.

Quoted 5 lines

Set reuseaddr so a TIME_WAIT socket does not fail the bind. Collisions with a live socket are still possible, we'll see if they are frequent enough to care.

tools/testing/selftests/drivers/net/hw/devmem_lib.py def ncdevmem_rx(cfg, port, verify=True, fail_on_linear=False, flow_steer=False, · line 204

Quoted 8 lines
tools/testing/selftests/drivers/net/hw/devmem_lib.py +1 -1
@@ -201,7 +201,7 @@ def ncdevmem_rx(cfg, port, verify=True, fail_on_linear=False, flow_steer=False,
     else:
         addr = cfg.baddr
 
-    suffix = f",bind={cfg.remote_baddr}:{port}"
+    suffix = f",bind={cfg.remote_baddr}:{port},reuseaddr"

socat_listen(), used by run_tx() and run_tx_chunks(), still builds without reuseaddr. From my reading, I understand we don't need it given ncdevmem does the active close on those tests. Leaving it alone seems right.

#2 lore raw
In reply to Jakub Kicinski
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Critical: 0 · High: 0 · Medium: 1 · Low: 0

- [Medium] Incomplete fix: the sibling helper socat_listen() in the same file still has no reuse option, so the EADDRINUSE/TIME_WAIT flake the…

--

selftests: drv-net: devmem: set reuseaddr on the sender's source port

The devmem selftest's sender has to bind an explicit source port on the remote host because ncdevmem installs a 5-tuple flow rule. The port is picked by rand_port() on the DUT, so lingering TIME_WAIT sockets on the remote can make the bind fail with EADDRINUSE; this adds reuseaddr to the socat bind option.

tools/testing/selftests/drivers/net/hw/devmem_lib.py def socat_send(cfg, port, buf_size=0): · line 207

Quoted 13 lines
tools/testing/selftests/drivers/net/hw/devmem_lib.py +1 -1
index 3554954a6691..b6e52fa9dda5 100644
@@ -201,7 +201,7 @@ def socat_send(cfg, port, buf_size=0):
     else:
         addr = cfg.baddr
 
-    suffix = f",bind={cfg.remote_baddr}:{port}"
+    suffix = f",bind={cfg.remote_baddr}:{port},reuseaddr"
 
     buf = ""
     if buf_size:

[Severity: Medium]
Should socat_listen() in the same file get the same treatment? It builds the remote listener for the TX tests without any reuse option:

tools/testing/selftests/drivers/net/hw/devmem_lib.py:
def socat_listen(cfg, port):
"""Socat listen command for TX tests.""" return f"socat -U - TCP{cfg.addr_ipver}-LISTEN:{port}"

That command also runs on cfg.remote, and the port again comes from rand_port(), which only binds a probe socket on the DUT. The RX sub-tests are what leave the TIME_WAIT sockets described in the changelog, and they sit on remote_baddr:<port> in the same ephemeral range that rand_port() draws from.

If run_tx() or run_tx_chunks() then draws a colliding port, the wildcard bind of the listener conflicts with the lingering TIME_WAIT socket without SO_REUSEADDR, socat exits, and:

with bkg(listen_cmd, host=cfg.remote, exit_wait=True) as socat:
wait_port_listen(port, host=cfg.remote)

times out, failing the sub-test. Is that the same failure mode the patch removes for the sender, just on the listener side?

For reference, the other socat listeners under drivers/net (ping.py, tso.py, uso.py, xdp.py, xdp_metadata.py, ntuple.py) all pass ",reuseport" explicitly, so devmem_lib.py's socat_listen() looks like the only bare one.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260908183420.1369630-1-kuba%40kernel.org
Reviewed-by on v1 1/1
#3 lore raw
In reply to Jakub Kicinski
Quoted 46 lines · Jakub Kicinski

devmem.py fails on the HW runners with:

  CMD[remote]: dd if=/dev/zero bs=512 count=1 2>/dev/null | socat -b 512 \
    -u - TCP6:[fd00:2::1]:50051,bind=[fd00:2::2]:50051,nodelay
    STDERR: socat[41018] W bind(5, {AF=10 [fd00:2::2]:50051}, 28): \
            Address already in use

ncdevmem installs a 5-tuple flow rule which matches the source port, so socat has to bind it explicitly. The port comes from rand_port(), which checks availability on the DUT - but we bind on the remote... That said the failure rate seems to high to be random collisions (~2% per sub-test). It's probably TIME_WAIT sockets on the remote, run_rx_hds() alone creates 12 of them.

Set reuseaddr so a TIME_WAIT socket does not fail the bind. Collisions with a live socket are still possible, we'll see if they are frequent enough to care.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 tools/testing/selftests/drivers/net/hw/devmem_lib.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/drivers/net/hw/devmem_lib.py +1 -1
index 3554954a6691..b6e52fa9dda5 100644
@@ -201,7 +201,7 @@ def ncdevmem_rx(cfg, port, verify=True, fail_on_linear=False, flow_steer=False,
     else:
         addr = cfg.baddr
 
-    suffix = f",bind={cfg.remote_baddr}:{port}"
+    suffix = f",bind={cfg.remote_baddr}:{port},reuseaddr"
 
     buf = ""
     if buf_size:
Signature · 1 line
2.55.0