* [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net
@ 2026-11-27 15:05 Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 01/15] selftests: xsk: fix the stack overrun in is_adjust_tail_supported() Maciej Fijalkowski
` (14 more replies)
0 siblings, 15 replies; 16+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:05 UTC (permalink / raw)
To: netdev
Cc: magnus.karlsson, stfomichev, kuba, pabeni, tushar.vyavahare,
kerneljasonxing, bjorn, Maciej Fijalkowski
v5:
https://lore.kernel.org/netdev/20261119164636.1071385-1-maciej.fijalkowski@intel.com/
v5->v6:
- new patch 1: stack overrun fix split out of patch 9 (Sashiko)
- new patch 11: poll the RX stats, a single read was flaky in CI (Jakub),
and retry a busy queue bind for up to --timeout seconds
- new patch 13: rename nsim_test to sw_test (Jakub)
- drop the README patch (Jakub)
- use NetDrvEpEnv(sw_drv="veth") (Jakub)
- busy poll over veth too (Jakub)
- set up huge pages, RSS, ntuple and busy poll per case (Jakub)
- reset RSS over netlink, drop the queue-out-of-RSS check (Jakub)
- use ctl_file_write(), set_ethtool_feat(), ethtool(), ksft_pr() (Jakub)
- steer the control connection to DUT queue 0 (Sashiko)
- fall back to IPv4 if IPv6 ntuple rules are rejected (Sashiko)
- detach XDP and restore MTU after every case (Sashiko)
- mark the tests disruptive (Sashiko)
- xskxceiver fixes: multi-buffer in SKB mode (if max MTU allows), link
wait, MTU restore, XDP cleanup, POLL_TXQ_FULL, --udp-port and --queue
checks, huge page probe, TX bind before READY (Sashiko)
v4:
https://lore.kernel.org/netdev/20261016174338.787135-1-maciej.fijalkowski@intel.com/
v4->v5:
- merge drivers/net/hw/xsk.py and net/test_xsk.py into
drivers/net/xsk.py (Jakub)
- make variables used for netdevsim addrs generic and reuse for veth
- drop net/lib/py/xsk.py and keep its helpers in xsk.py (Jakub)
- use and rely on bkg() and cmd() instead of home-grown solutions
(Jakub)
- make xsk.py pylint and ruff clean (Jakub)
- single test cases listing for both scenarios (hw/sw)
- skip busy_poll for veth; NAPI id is not exposed there (yet)
- skip HW_SW_MAX_RING_SIZE when the HW TX ring has 8 descriptors or
fewer (Sashiko)
- reject --timeout outside 1-0xffff and --max-frags above 0xffff in
xskxceiver (Sashiko)
- turn on ntuple filters before taking the DUT queue out of RSS, and
fail a case after which the queue is back in RSS, as on ixgbe (Sashiko)
v3: https://lore.kernel.org/netdev/20261014184539.774708-1-maciej.fijalkowski@intel.com/
v3 -> v4:
- add tags from Mr Björn
- drop --hw in xskxceiver, align packet layout between hw/veth runners (Björn)
- drop parse_u32() in xskxceiver (Björn)
- move ethtool -G and ring sizing logic from C to python
- configurable --timeout (Björn)
- keep the HW_SW_MAX_RING_SIZE batch below the XSK TX ring size (Sashiko)
- restore hugepage count in veth runner on exception paths (Sashiko)
- use ExitStack in hw runner to cover setup unrolls (Björn, Sashiko)
- support IPv6 next to IPv4 (Björn)
- send to the next-hop MAC, the peer need not be on-link (Björn)
- make --listen work on its own rather than follow the TX role (Björn)
- run XDP_SHARED_UMEM on HW, the socket is picked by UDP source port
- fail a case when one endpoint fails and the other skips (Björn)
- keep the TX half of the unaligned check in the xsk_caps conversion
- detach in cleanup_iface() with the flags of mode_to_xdp_flags()
- reserve 2 MiB huge pages, tolerate hosts without hugetlb or root (Sashiko)
- lower the veth case timeout to 20s, within the net timeout (Sashiko)
- guard pkts_in_flight against forged PROGRESS reports (Sashiko)
- log short fragments, fix the IPv4 fragment comment (Sashiko)
- keep the MIN_PKT_SIZE and PKT_HDR_SIZE names to cut churn
- read what a gone peer left at READY, drain after a SKIP (Sashiko)
- cap --max-frags, which sizes a packet array (Sashiko)
- skip the hw run when RSS or ntuple setup is refused (Sashiko)
- bound the gateway ping, fail clearly without its MAC (Sashiko)
- note in the README that RFS has to stay off on the DUT (Sashiko)
v2: https://lore.kernel.org/netdev/20261008114909.734364-1-maciej.fijalkowski@intel.com/
v2 -> v3:
- new patch: size the TX UMEM of HW_SW_MAX_RING_SIZE like the RX one
- replace test_xsk.sh with test_xsk.py, a veth pair per case (Sashiko)
- add busy-poll variants to both runners
- wait for the listener's stderr line instead of polling with ss
- default MTU of 1500, wait for link after MTU/XDP changes (Sashiko)
- fill the fill ring before bind, as zero-copy drivers need
- xskxceiver -L lists HW cases, replacing test_xsk_case_defs.h (Jakub)
- run more cases on HW, e.g. TEARDOWN and HW_SW_{MIN,MAX}_RING_SIZE
- follow drv-net conventions in xsk.py, drop XSK_* variables (Jakub)
- set up queue, ntuple and huge pages once per run
- build, ring reset, control channel, XDP and xsk.py fixes (Sashiko)
- document both runners with a netns remote example
v1: https://lore.kernel.org/netdev/20261001202124.692591-1-maciej.fijalkowski@intel.com/
v1 -> v2:
- rebase on net-next, NIPA could not apply v1 (Stanislav)
- new patch: pass non-test traffic to the stack on HW (Stanislav)
- support a netns remote, like NIPA's E810/X710 setup (Stanislav)
- drop XSK_STATIC, link xskxceiver dynamically
- fail TX when RX exits with packets in flight
- fix IPv4/UDP lengths in verbatim multi-buffer streams
- build fixes for a failing or broken bpftool
- document both remote types and the traffic filter
Hi,
[0] moved the AF_XDP test suite from selftests/bpf to selftests/net.
This series hooks it up to drv-net, so that it runs over veth in SW CI
and on a NIC in HW CI; so far our HW runs have been manual. We keep the
existing xskxceiver cases rather than start from scratch.
xskxceiver ran the RX and TX sides of a case as two threads of one
process. drv-net needs a process per side, so each endpoint becomes a
process of its own, and the two talk over xsk_peer, a small TCP control
channel: READY separates the steps, PROGRESS paces TX by what RX has
consumed, ABORT stops the peer after a failure, and SKIP makes the peer
skip a case that its endpoint skips.
drivers/net/xsk.py runs each case between a local and a remote
endpoint. The remote one is always an SKB-mode xskxceiver, so the remote
needs no zero-copy support, and both ends share the packet generation
and validation of the cases.
- Without NETIF, they run over a veth pair, the remote end in a
namespace, with the local endpoint receiving in SKB and DRV mode
(skb_<case> and drv_<case> variants).
- With NETIF, the local endpoint runs in zero-copy mode once per role
that xskxceiver -l lists for the case (rx_<case> and tx_<case>), e.g.
rx_SEND_RECEIVE tests ice_clean_rx_irq_zc() and tx_SEND_RECEIVE
ice_xmit_zc(). ntuple rules steer the test flow to the AF_XDP queue.
Every case also runs with the local endpoint busy polling. The single
interface (loopback) mode is removed.
Over veth, the cases that cannot pass are expected failures without
being run: XDP_ADJUST_TAIL_SHRINK_MULTI_BUFF and the XDP_ADJUST_TAIL_GROW
cases, which hit veth and generic XDP limits, and
HW_SW_{MIN,MAX}_RING_SIZE, as veth has no rings. We can keep them, drop
them or run them on HW only. The UNALIGNED cases are expected failures
without huge pages.
Patch 1 fixes a stack overrun, 2-4 prepare the split, 5-8 make the
endpoints separate processes and remove test_xsk.sh, 9-12 adapt the
endpoints to two hosts and list the roles of each case, 13-14 prepare
NetDrvEpEnv for veth, and 15 adds xsk.py.
Known issues:
- On ice, the RSS reset over netlink fails without [1], which NIPA
already carries.
- BIDIRECTIONAL, STAT_RX_DROPPED and TX_QUEUE_CONSUMER do not run on
HW. I think BIDIRECTIONAL can go, as the rx_ and tx_ variants cover
both directions.
Thanks,
Maciej
[0]: https://lore.kernel.org/netdev/20261109193048.1006986-1-maciej.fijalkowski@intel.com/
[1]: https://lore.kernel.org/netdev/20261123205600.1794292-2-kuba@kernel.org/
Maciej Fijalkowski (15):
selftests: xsk: fix the stack overrun in is_adjust_tail_supported()
selftests: xsk: factor endpoint work out of pthread wrappers
selftests: xsk: size the TX UMEM in HW_SW_MAX_RING_SIZE
selftests: xsk: drop the single-interface loopback mode
selftests: xsk: collect interface capabilities in struct xsk_caps
selftests: xsk: split xskxceiver main() into setup, run and cleanup
selftests: xsk: run one test case per xskxceiver invocation
selftests: xsk: run the RX and TX endpoints in separate processes
selftests: xsk: send UDP over IPv4 or IPv6 between the interface MACs
selftests: xsk: prepare xskxceiver for endpoints on two hosts
selftests: xsk: wait up to --timeout for the RX stats and a busy bind
selftests: xsk: list the endpoint roles of the test cases
selftests: drv-net: rename nsim_test to sw_test
selftests: drv-net: decouple local link setup from netdevsim
selftests: drv-net: run the AF_XDP tests over veth or a NIC
MAINTAINERS | 2 +-
tools/testing/selftests/drivers/net/Makefile | 1 +
tools/testing/selftests/drivers/net/config | 3 +
.../testing/selftests/drivers/net/hw/csum.py | 2 +-
.../drivers/net/hw/devlink_rate_cross_esw.py | 2 +-
.../drivers/net/hw/devlink_rate_tc_bw.py | 2 +-
.../selftests/drivers/net/hw/gro_stats.py | 2 +-
.../selftests/drivers/net/hw/ipsec_vxlan.py | 2 +-
tools/testing/selftests/drivers/net/hw/irq.py | 2 +-
.../selftests/drivers/net/hw/nic_timestamp.py | 2 +-
.../selftests/drivers/net/hw/ntuple.py | 2 +-
.../testing/selftests/drivers/net/hw/pause.py | 2 +-
.../selftests/drivers/net/hw/pp_alloc_fail.py | 2 +-
.../selftests/drivers/net/hw/rss_api.py | 2 +-
.../selftests/drivers/net/hw/rss_ctx.py | 2 +-
.../drivers/net/hw/rss_flow_label.py | 2 +-
.../drivers/net/hw/rss_input_xfrm.py | 2 +-
tools/testing/selftests/drivers/net/hw/tso.py | 10 +-
.../selftests/drivers/net/hw/xsk_reconfig.py | 2 +-
.../selftests/drivers/net/lib/py/env.py | 83 +-
.../selftests/drivers/net/perf/devmem.py | 2 +-
.../selftests/drivers/net/perf/iperf.py | 2 +-
tools/testing/selftests/drivers/net/xsk.py | 453 ++++++++
tools/testing/selftests/net/Makefile | 2 -
tools/testing/selftests/net/lib/Makefile | 4 +-
.../testing/selftests/net/lib/xsk/test_xsk.c | 1009 +++++++++++------
.../testing/selftests/net/lib/xsk/test_xsk.h | 151 ++-
tools/testing/selftests/net/lib/xsk/xsk.c | 134 ++-
tools/testing/selftests/net/lib/xsk/xsk.h | 5 +-
.../testing/selftests/net/lib/xsk/xsk_peer.c | 339 ++++++
.../testing/selftests/net/lib/xsk/xsk_peer.h | 21 +
.../selftests/net/lib/xsk/xsk_xdp_common.h | 3 +-
.../selftests/net/lib/xsk/xsk_xdp_progs.bpf.c | 91 +-
.../selftests/net/lib/xsk/xskxceiver.c | 564 +++++----
.../selftests/net/lib/xsk/xskxceiver.h | 1 -
tools/testing/selftests/net/test_xsk.sh | 251 ----
tools/testing/selftests/net/xsk_prereqs.sh | 93 --
37 files changed, 2215 insertions(+), 1039 deletions(-)
create mode 100755 tools/testing/selftests/drivers/net/xsk.py
create mode 100644 tools/testing/selftests/net/lib/xsk/xsk_peer.c
create mode 100644 tools/testing/selftests/net/lib/xsk/xsk_peer.h
delete mode 100755 tools/testing/selftests/net/test_xsk.sh
delete mode 100755 tools/testing/selftests/net/xsk_prereqs.sh
base-commit: ccb81d5e317b0ae2cc66ca1c628c0ca907928f94
--
2.43.0
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v6 net-next 01/15] selftests: xsk: fix the stack overrun in is_adjust_tail_supported()
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
@ 2026-11-27 15:05 ` Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 02/15] selftests: xsk: factor endpoint work out of pthread wrappers Maciej Fijalkowski
` (13 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:05 UTC (permalink / raw)
To: netdev
Cc: magnus.karlsson, stfomichev, kuba, pabeni, tushar.vyavahare,
kerneljasonxing, bjorn, Maciej Fijalkowski
is_adjust_tail_supported() looks up adjust_value in the .bss map, whose
value is all of .bss, so bpf_map_lookup_elem() copies 12 bytes into a
4-byte int on the stack.
Read adjust_value through the skeleton instead, and return a bool.
Fixes: 4b302092553c ("selftests/xsk: Add tail adjustment tests and support check")
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
.../testing/selftests/net/lib/xsk/test_xsk.c | 39 ++++---------------
1 file changed, 7 insertions(+), 32 deletions(-)
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c
index ca161511f1e5..407c65f7293c 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c
@@ -791,31 +791,12 @@ static bool is_metadata_correct(struct pkt *pkt, void *buffer, u64 addr)
return true;
}
-static int is_adjust_tail_supported(struct xsk_xdp_progs *skel_rx, bool *supported)
+static bool is_adjust_tail_supported(struct xsk_xdp_progs *skel_rx)
{
- struct bpf_map *data_map;
- int adjust_value = 0;
- int key = 0;
- int ret;
-
- data_map = bpf_object__find_map_by_name(skel_rx->obj, "xsk_xdp_.bss");
- if (!data_map || !bpf_map__is_internal(data_map)) {
- ksft_print_msg("Error: could not find bss section of XDP program\n");
- return -EINVAL;
- }
-
- ret = bpf_map_lookup_elem(bpf_map__fd(data_map), &key, &adjust_value);
- if (ret) {
- ksft_print_msg("Error: bpf_map_lookup_elem failed with error %d\n", ret);
- return ret;
- }
-
/* Set the 'adjust_value' variable to -EOPNOTSUPP in the XDP program if the adjust_tail
* helper is not supported. Skip the adjust_tail test case in this scenario.
*/
- *supported = adjust_value != -EOPNOTSUPP;
-
- return 0;
+ return skel_rx->bss->adjust_value != -EOPNOTSUPP;
}
static bool is_frag_valid(struct xsk_umem_info *umem, u64 addr, u32 len, u32 expected_pkt_nb,
@@ -1684,18 +1665,12 @@ void *worker_testapp_validate_rx(void *arg)
err = ifobject->validation_func(ifobject);
if (err) {
- if (!test->adjust_tail) {
+ if (!test->adjust_tail)
+ test->fail = true;
+ else if (!is_adjust_tail_supported(ifobject->xdp_progs))
+ test->adjust_tail_support = false;
+ else
test->fail = true;
- } else {
- bool supported;
-
- if (is_adjust_tail_supported(ifobject->xdp_progs, &supported))
- test->fail = true;
- else if (!supported)
- test->adjust_tail_support = false;
- else
- test->fail = true;
- }
}
pthread_exit(NULL);
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v6 net-next 02/15] selftests: xsk: factor endpoint work out of pthread wrappers
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 01/15] selftests: xsk: fix the stack overrun in is_adjust_tail_supported() Maciej Fijalkowski
@ 2026-11-27 15:05 ` Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 03/15] selftests: xsk: size the TX UMEM in HW_SW_MAX_RING_SIZE Maciej Fijalkowski
` (12 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:05 UTC (permalink / raw)
To: netdev
Cc: magnus.karlsson, stfomichev, kuba, pabeni, tushar.vyavahare,
kerneljasonxing, bjorn, Maciej Fijalkowski
Move TX execution, RX setup and RX validation into synchronous helpers
and leave the pthread entry points as thin wrappers, so that the same
code can run in a process per endpoint later in this series. Barrier,
pacing and test behavior are unchanged.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
.../testing/selftests/net/lib/xsk/test_xsk.c | 91 ++++++++++++-------
1 file changed, 57 insertions(+), 34 deletions(-)
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c
index 407c65f7293c..73f6e0302ee3 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c
@@ -1604,40 +1604,31 @@ static int thread_common_ops(struct test_spec *test, struct ifobject *ifobject)
return 0;
}
-void *worker_testapp_validate_tx(void *arg)
+static int testapp_validate_tx_endpoint(struct test_spec *test,
+ struct ifobject *ifobject)
{
- struct test_spec *test = (struct test_spec *)arg;
- struct ifobject *ifobject = test->ifobj_tx;
int err;
if (test->current_step == 1) {
- if (!ifobject->shared_umem) {
- if (thread_common_ops(test, ifobject)) {
- test->fail = true;
- pthread_exit(NULL);
- }
- } else {
- if (thread_common_ops_tx(test, ifobject)) {
- test->fail = true;
- pthread_exit(NULL);
- }
- }
+ if (!ifobject->shared_umem)
+ err = thread_common_ops(test, ifobject);
+ else
+ err = thread_common_ops_tx(test, ifobject);
+ if (err)
+ return err;
}
err = send_pkts(test, ifobject);
if (!err && ifobject->validation_func)
err = ifobject->validation_func(ifobject);
- if (err)
- test->fail = true;
- pthread_exit(NULL);
+ return err;
}
-void *worker_testapp_validate_rx(void *arg)
+static int testapp_prepare_rx_endpoint(struct test_spec *test,
+ struct ifobject *ifobject)
{
- struct test_spec *test = (struct test_spec *)arg;
- struct ifobject *ifobject = test->ifobj_rx;
int err;
if (test->current_step == 1) {
@@ -1650,29 +1641,61 @@ void *worker_testapp_validate_rx(void *arg)
strerror(-err));
}
- if (test->use_barrier)
- pthread_barrier_wait(&barr);
+ return err;
+}
- /* We leave only now in case of error to avoid getting stuck in the barrier */
- if (err) {
- test->fail = true;
- pthread_exit(NULL);
- }
+static int testapp_validate_rx_endpoint(struct test_spec *test,
+ struct ifobject *ifobject)
+{
+ int err;
err = receive_pkts(test);
if (!err && ifobject->validation_func)
err = ifobject->validation_func(ifobject);
+ if (!err)
+ return TEST_PASS;
- if (err) {
- if (!test->adjust_tail)
- test->fail = true;
- else if (!is_adjust_tail_supported(ifobject->xdp_progs))
- test->adjust_tail_support = false;
- else
- test->fail = true;
+ if (!test->adjust_tail)
+ return err;
+
+ if (!is_adjust_tail_supported(ifobject->xdp_progs)) {
+ test->adjust_tail_support = false;
+ return TEST_PASS;
}
+ return err;
+}
+
+void *worker_testapp_validate_tx(void *arg)
+{
+ struct test_spec *test = (struct test_spec *)arg;
+ int err;
+
+ err = testapp_validate_tx_endpoint(test, test->ifobj_tx);
+ if (err)
+ test->fail = true;
+
+ pthread_exit(NULL);
+}
+
+void *worker_testapp_validate_rx(void *arg)
+{
+ struct test_spec *test = (struct test_spec *)arg;
+ struct ifobject *ifobject = test->ifobj_rx;
+ int err;
+
+ err = testapp_prepare_rx_endpoint(test, ifobject);
+
+ if (test->use_barrier)
+ pthread_barrier_wait(&barr);
+
+ /* We leave only now in case of error to avoid getting stuck in the barrier */
+ if (!err)
+ err = testapp_validate_rx_endpoint(test, ifobject);
+ if (err)
+ test->fail = true;
+
pthread_exit(NULL);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v6 net-next 03/15] selftests: xsk: size the TX UMEM in HW_SW_MAX_RING_SIZE
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 01/15] selftests: xsk: fix the stack overrun in is_adjust_tail_supported() Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 02/15] selftests: xsk: factor endpoint work out of pthread wrappers Maciej Fijalkowski
@ 2026-11-27 15:05 ` Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 04/15] selftests: xsk: drop the single-interface loopback mode Maciej Fijalkowski
` (11 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:05 UTC (permalink / raw)
To: netdev
Cc: magnus.karlsson, stfomichev, kuba, pabeni, tushar.vyavahare,
kerneljasonxing, bjorn, Maciej Fijalkowski
HW_SW_MAX_RING_SIZE sizes the RX UMEM and rings for 8k frames, but on
two NIC ports TX has its own default UMEM of 1k frames and 2k rings.
The in-flight limit in __send_pkts() then goes negative for a 2k batch,
so TX never sends and RX times out. Size the TX UMEM like the RX one.
The second batch, the HW TX ring size minus 8, does not fit the 8k UMEM
and XSK TX ring either once the HW TX ring has 8200 descriptors or
more, as on nfp, octeontx2 and fbnic. Cap it 8 below their size, and
skip the case on a HW TX ring of 8 descriptors or fewer.
Fixes: c53908b254fc ("selftests/xsk: Add new test case for AF_XDP under max ring sizes")
Fixes: e4a195e2b95e ("selftests/xsk: Enhance batch size support with dynamic configurations")
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
.../testing/selftests/net/lib/xsk/test_xsk.c | 25 ++++++++++++++++---
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c
index 73f6e0302ee3..850bbd20c405 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c
@@ -2482,8 +2482,18 @@ int testapp_hw_sw_min_ring_size(struct test_spec *test)
int testapp_hw_sw_max_ring_size(struct test_spec *test)
{
u32 max_descs = XSK_RING_PROD__DEFAULT_NUM_DESCS * 4;
+ u32 batch_size;
int ret;
+ /* The second step sends batches of min(tx_max_pending, max_descs) - 8
+ * descriptors.
+ */
+ if (test->ifobj_tx->hw_ring_size_supp &&
+ test->ifobj_tx->ring.tx_max_pending <= 8) {
+ ksft_print_msg("HW TX ring too small.\n");
+ return TEST_SKIP;
+ }
+
test->set_ring = true;
test->total_steps = 2;
test->ifobj_tx->ring.tx_pending = test->ifobj_tx->ring.tx_max_pending;
@@ -2491,6 +2501,9 @@ int testapp_hw_sw_max_ring_size(struct test_spec *test)
test->ifobj_rx->xsk->umem->num_frames = max_descs;
test->ifobj_rx->xsk->umem->fill_size = max_descs;
test->ifobj_rx->xsk->umem->comp_size = max_descs;
+ test->ifobj_tx->xsk->umem->num_frames = max_descs;
+ test->ifobj_tx->xsk->umem->fill_size = max_descs;
+ test->ifobj_tx->xsk->umem->comp_size = max_descs;
test->ifobj_tx->xsk->batch_size = XSK_RING_PROD__DEFAULT_NUM_DESCS;
test->ifobj_rx->xsk->batch_size = XSK_RING_PROD__DEFAULT_NUM_DESCS;
@@ -2498,11 +2511,15 @@ int testapp_hw_sw_max_ring_size(struct test_spec *test)
if (ret)
return ret;
- /* Set batch_size to 8152 for testing, as the ice HW ignores the 3 lowest bits when
- * updating the Rx HW tail register.
+ /* Keep the batch 8 below the HW TX ring size, as the ice HW ignores
+ * the 3 lowest bits when updating the Rx HW tail register. Keep it 8
+ * below max_descs, the UMEM and XSK TX ring size, too: __send_pkts()
+ * sends only while fewer packets than the UMEM size minus a batch are
+ * in flight, and reserves a whole batch in the TX ring.
*/
- test->ifobj_tx->xsk->batch_size = test->ifobj_tx->ring.tx_max_pending - 8;
- test->ifobj_rx->xsk->batch_size = test->ifobj_tx->ring.tx_max_pending - 8;
+ batch_size = min(test->ifobj_tx->ring.tx_max_pending, max_descs) - 8;
+ test->ifobj_tx->xsk->batch_size = batch_size;
+ test->ifobj_rx->xsk->batch_size = batch_size;
if (pkt_stream_replace(test, max_descs, MIN_PKT_SIZE)) {
clean_sockets(test, test->ifobj_tx);
clean_sockets(test, test->ifobj_rx);
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v6 net-next 04/15] selftests: xsk: drop the single-interface loopback mode
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
` (2 preceding siblings ...)
2026-11-27 15:05 ` [PATCH v6 net-next 03/15] selftests: xsk: size the TX UMEM in HW_SW_MAX_RING_SIZE Maciej Fijalkowski
@ 2026-11-27 15:05 ` Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 05/15] selftests: xsk: collect interface capabilities in struct xsk_caps Maciej Fijalkowski
` (10 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:05 UTC (permalink / raw)
To: netdev
Cc: magnus.karlsson, stfomichev, kuba, pabeni, tushar.vyavahare,
kerneljasonxing, bjorn, Maciej Fijalkowski
xskxceiver -i ethX -i ethX binds both sockets to queue 0 of one
interface, which the kernel allows only with a shared UMEM, and the
endpoints are about to become separate processes. The mode also needs
the interface set up by hand, with one queue and promiscuous mode.
Drop it, with its shared-UMEM TX setup, split UMEM addressing,
POLL_TXQ_FULL workaround and the -i option of test_xsk.sh.
XDP_SHARED_UMEM is unaffected.
Also drop the ring resizing of HW_SW_{MIN,MAX}_RING_SIZE, which ran
only in this mode and left the test sizes behind when killed. The
hardware test added later sizes the rings with ethtool -G.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
.../testing/selftests/net/lib/xsk/test_xsk.c | 164 ++++--------------
.../testing/selftests/net/lib/xsk/test_xsk.h | 12 --
tools/testing/selftests/net/lib/xsk/xsk.c | 24 ---
tools/testing/selftests/net/lib/xsk/xsk.h | 1 -
.../selftests/net/lib/xsk/xskxceiver.c | 13 +-
tools/testing/selftests/net/test_xsk.sh | 49 ++----
tools/testing/selftests/net/xsk_prereqs.sh | 7 -
7 files changed, 50 insertions(+), 220 deletions(-)
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c
index 850bbd20c405..8826697c58de 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c
@@ -101,10 +101,6 @@ int xsk_configure_umem(struct ifobject *ifobj, struct xsk_umem_info *umem, void
return ret;
umem->buffer = buffer;
- if (ifobj->shared_umem && ifobj->rx_on) {
- umem->base_addr = umem_size(umem);
- umem->next_buffer = umem_size(umem);
- }
return 0;
}
@@ -115,8 +111,8 @@ static u64 umem_alloc_buffer(struct xsk_umem_info *umem)
addr = umem->next_buffer;
umem->next_buffer += umem->frame_size;
- if (umem->next_buffer >= umem->base_addr + umem_size(umem))
- umem->next_buffer = umem->base_addr;
+ if (umem->next_buffer >= umem_size(umem))
+ umem->next_buffer = 0;
return addr;
}
@@ -173,33 +169,6 @@ int xsk_configure_socket(struct xsk_socket_info *xsk, struct xsk_umem_info *umem
return xsk_socket__create(&xsk->xsk, ifobject->ifindex, 0, umem->umem, rxr, txr, &cfg);
}
-static int set_ring_size(struct ifobject *ifobj)
-{
- int ret;
- u32 ctr = 0;
-
- while (ctr++ < SOCK_RECONF_CTR) {
- ret = set_hw_ring_size(ifobj->ifname, &ifobj->ring);
- if (!ret)
- break;
-
- /* Retry if it fails */
- if (ctr >= SOCK_RECONF_CTR || errno != EBUSY)
- return -errno;
-
- usleep(USLEEP_MAX);
- }
-
- return ret;
-}
-
-int hw_ring_size_reset(struct ifobject *ifobj)
-{
- ifobj->ring.tx_pending = ifobj->set_ring.default_tx;
- ifobj->ring.rx_pending = ifobj->set_ring.default_rx;
- return set_ring_size(ifobj);
-}
-
static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
struct ifobject *ifobj_rx)
{
@@ -207,7 +176,7 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
for (i = 0; i < MAX_INTERFACES; i++) {
struct ifobject *ifobj = i ? ifobj_rx : ifobj_tx;
- struct xsk_umem_info *umem_real;
+ struct xsk_umem_info *umem;
ifobj->xsk = &ifobj->xsk_arr[0];
ifobj->use_poll = false;
@@ -224,16 +193,14 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
ifobj->tx_on = false;
}
- umem_real = ifobj->xsk_arr[0].umem_real;
- memset(umem_real, 0, sizeof(*umem_real));
+ umem = ifobj->xsk_arr[0].umem;
+ memset(umem, 0, sizeof(*umem));
for (j = 0; j < MAX_SOCKETS; j++) {
struct xsk_socket_info *xsk = &ifobj->xsk_arr[j];
memset(xsk, 0, sizeof(*xsk));
xsk->rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS;
- if (j == 0)
- xsk->umem_real = umem_real;
- xsk->umem = umem_real;
+ xsk->umem = umem;
xsk->batch_size = DEFAULT_BATCH_SIZE;
if (i == 0)
xsk->pkt_stream = test->tx_pkt_stream_default;
@@ -250,16 +217,12 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
ifobj->xsk->umem->frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE;
}
- if (ifobj_tx->hw_ring_size_supp)
- hw_ring_size_reset(ifobj_tx);
-
test->ifobj_tx = ifobj_tx;
test->ifobj_rx = ifobj_rx;
test->current_step = 0;
test->total_steps = 1;
test->nb_sockets = 1;
test->fail = false;
- test->set_ring = false;
test->adjust_tail = false;
test->adjust_tail_support = false;
test->mtu = MAX_ETH_PKT_SIZE;
@@ -806,8 +769,6 @@ static bool is_frag_valid(struct xsk_umem_info *umem, u64 addr, u32 len, u32 exp
void *data = xsk_umem__get_data(umem->buffer, addr);
u64 umem_sz = umem_size(umem);
- addr -= umem->base_addr;
-
if (addr >= umem_sz || addr + len > umem_sz) {
ksft_print_msg("Frag invalid addr: %llx len: %u\n",
(unsigned long long)addr, len);
@@ -1145,7 +1106,7 @@ static int __send_pkts(struct ifobject *ifobject, struct xsk_socket_info *xsk,
bool test_timeout)
{
u32 i, idx = 0, valid_pkts = 0, valid_frags = 0, buffer_len;
- struct xsk_umem_info *umem = ifobject->xsk_arr[0].umem_real;
+ struct xsk_umem_info *umem = ifobject->xsk_arr[0].umem;
struct pkt_stream *pkt_stream = xsk->pkt_stream;
bool use_poll = ifobject->use_poll;
struct pollfd fds = { };
@@ -1449,12 +1410,12 @@ static int validate_tx_invalid_descs(struct ifobject *ifobject)
}
static int xsk_configure(struct test_spec *test, struct ifobject *ifobject,
- struct xsk_umem_info *umem, bool tx)
+ struct xsk_umem_info *umem)
{
int i, ret;
for (i = 0; i < test->nb_sockets; i++) {
- bool shared = (ifobject->shared_umem && tx) ? true : !!i;
+ bool shared = !!i;
u32 ctr = 0;
while (ctr++ < SOCK_RECONF_CTR) {
@@ -1478,31 +1439,6 @@ static int xsk_configure(struct test_spec *test, struct ifobject *ifobject,
return 0;
}
-static int thread_common_ops_tx(struct test_spec *test, struct ifobject *ifobject)
-{
- struct xsk_umem_info *umem_rx, *umem_tx;
- int ret;
-
- if (!test->ifobj_rx || !test->ifobj_rx->xsk_arr[0].umem->umem) {
- ksft_print_msg("Error: RX UMEM is not initialized before shared-UMEM TX setup\n");
- return -EINVAL;
- }
-
- umem_rx = test->ifobj_rx->xsk_arr[0].umem;
- umem_tx = ifobject->xsk_arr[0].umem_real;
- memcpy(umem_tx, umem_rx, sizeof(*umem_tx));
- umem_tx->base_addr = 0;
- umem_tx->next_buffer = 0;
-
- ret = xsk_configure(test, ifobject, umem_rx, true);
- if (ret)
- return ret;
- ifobject->xsk = &ifobject->xsk_arr[0];
- ifobject->xskmap = test->ifobj_rx->xskmap;
-
- return 0;
-}
-
static int xsk_populate_fill_ring(struct xsk_umem_info *umem, struct pkt_stream *pkt_stream,
bool fill_up)
{
@@ -1528,7 +1464,7 @@ static int xsk_populate_fill_ring(struct xsk_umem_info *umem, struct pkt_stream
if (!pkt) {
if (!fill_up)
break;
- addr = filled * umem->frame_size + umem->base_addr;
+ addr = filled * umem->frame_size;
} else if (pkt->offset >= 0) {
addr = pkt->offset % umem->frame_size + umem_alloc_buffer(umem);
} else {
@@ -1565,9 +1501,6 @@ static int thread_common_ops(struct test_spec *test, struct ifobject *ifobject)
if (umem->unaligned_mode)
mmap_flags |= MAP_HUGETLB | MAP_HUGE_2MB;
- if (ifobject->shared_umem)
- umem_sz *= 2;
-
mmap_sz = umem->unaligned_mode ?
ceil_u64(umem_sz, HUGEPAGE_SIZE) * HUGEPAGE_SIZE : umem_sz;
@@ -1581,7 +1514,7 @@ static int thread_common_ops(struct test_spec *test, struct ifobject *ifobject)
if (ret)
return ret;
- ret = xsk_configure(test, ifobject, umem, false);
+ ret = xsk_configure(test, ifobject, umem);
if (ret)
return ret;
@@ -1610,10 +1543,7 @@ static int testapp_validate_tx_endpoint(struct test_spec *test,
int err;
if (test->current_step == 1) {
- if (!ifobject->shared_umem)
- err = thread_common_ops(test, ifobject);
- else
- err = thread_common_ops_tx(test, ifobject);
+ err = thread_common_ops(test, ifobject);
if (err)
return err;
}
@@ -1757,7 +1687,7 @@ static int xsk_attach_xdp_progs(struct test_spec *test, struct ifobject *ifobj_r
return err;
}
- if (!ifobj_tx || ifobj_tx->shared_umem)
+ if (!ifobj_tx)
return 0;
if (xdp_prog_changed_tx(test))
@@ -1783,7 +1713,7 @@ static void clean_umem(struct test_spec *test, struct ifobject *ifobj1, struct i
return;
testapp_clean_xsk_umem(ifobj1);
- if (ifobj2 && !ifobj2->shared_umem)
+ if (ifobj2)
testapp_clean_xsk_umem(ifobj2);
}
@@ -1875,18 +1805,6 @@ static int testapp_validate_traffic(struct test_spec *test)
return TEST_SKIP;
}
- if (test->set_ring) {
- if (ifobj_tx->hw_ring_size_supp) {
- if (set_ring_size(ifobj_tx)) {
- ksft_print_msg("Failed to change HW ring size.\n");
- return TEST_FAILURE;
- }
- } else {
- ksft_print_msg("Changing HW ring size not supported.\n");
- return TEST_SKIP;
- }
- }
-
return __testapp_validate_traffic(test, ifobj_rx, ifobj_tx);
}
@@ -2162,12 +2080,6 @@ int testapp_invalid_desc(struct test_spec *test)
pkts[8].valid = false;
}
- if (test->ifobj_tx->shared_umem) {
- pkts[4].offset += umem_sz;
- pkts[5].offset += umem_sz;
- pkts[6].offset += umem_sz;
- }
-
if (pkt_stream_generate_custom(test, pkts, ARRAY_SIZE(pkts)))
return TEST_FAILURE;
return testapp_validate_traffic(test);
@@ -2226,28 +2138,14 @@ int testapp_xdp_shared_umem(struct test_spec *test)
int testapp_poll_txq_tmout(struct test_spec *test)
{
- bool shared_umem = test->ifobj_tx->shared_umem;
- int ret;
-
test->poll_tmout = true;
- /*
- * POLL_TXQ_FULL exercises TX timeout setup in isolation.
- * Keep TX out of shared-UMEM mode here so TX setup does not require
- * RX UMEM to be initialized first.
- */
- test->ifobj_tx->shared_umem = false;
test->ifobj_tx->use_poll = true;
/* create invalid frame by set umem frame_size and pkt length equal to 2048 */
test->ifobj_tx->xsk->umem->frame_size = 2048;
- if (pkt_stream_replace(test, 2 * DEFAULT_PKT_CNT, 2048)) {
- test->ifobj_tx->shared_umem = shared_umem;
+ if (pkt_stream_replace(test, 2 * DEFAULT_PKT_CNT, 2048))
return TEST_FAILURE;
- }
- ret = testapp_validate_traffic_single_thread(test, test->ifobj_tx);
- test->ifobj_tx->shared_umem = shared_umem;
-
- return ret;
+ return testapp_validate_traffic_single_thread(test, test->ifobj_tx);
}
int testapp_poll_rxq_tmout(struct test_spec *test)
@@ -2459,14 +2357,19 @@ int testapp_xdp_metadata_mb(struct test_spec *test)
return testapp_xdp_metadata_copy(test);
}
+/* Expects the HW TX ring of the sender to hold DEFAULT_BATCH_SIZE
+ * descriptors.
+ */
int testapp_hw_sw_min_ring_size(struct test_spec *test)
{
int ret;
- test->set_ring = true;
+ if (!test->ifobj_tx->hw_ring_size_supp) {
+ ksft_print_msg("HW ring sizes not supported.\n");
+ return TEST_SKIP;
+ }
+
test->total_steps = 2;
- test->ifobj_tx->ring.tx_pending = DEFAULT_BATCH_SIZE;
- test->ifobj_tx->ring.rx_pending = DEFAULT_BATCH_SIZE * 2;
test->ifobj_tx->xsk->batch_size = 1;
test->ifobj_rx->xsk->batch_size = 1;
ret = testapp_validate_traffic(test);
@@ -2479,25 +2382,28 @@ int testapp_hw_sw_min_ring_size(struct test_spec *test)
return testapp_validate_traffic(test);
}
+/* Expects the HW TX ring of the sender and the HW RX ring of the receiver
+ * at their maximum sizes.
+ */
int testapp_hw_sw_max_ring_size(struct test_spec *test)
{
u32 max_descs = XSK_RING_PROD__DEFAULT_NUM_DESCS * 4;
u32 batch_size;
int ret;
+ if (!test->ifobj_tx->hw_ring_size_supp) {
+ ksft_print_msg("HW ring sizes not supported.\n");
+ return TEST_SKIP;
+ }
/* The second step sends batches of min(tx_max_pending, max_descs) - 8
* descriptors.
*/
- if (test->ifobj_tx->hw_ring_size_supp &&
- test->ifobj_tx->ring.tx_max_pending <= 8) {
+ if (test->ifobj_tx->ring.tx_max_pending <= 8) {
ksft_print_msg("HW TX ring too small.\n");
return TEST_SKIP;
}
- test->set_ring = true;
test->total_steps = 2;
- test->ifobj_tx->ring.tx_pending = test->ifobj_tx->ring.tx_max_pending;
- test->ifobj_tx->ring.rx_pending = test->ifobj_tx->ring.rx_max_pending;
test->ifobj_rx->xsk->umem->num_frames = max_descs;
test->ifobj_rx->xsk->umem->fill_size = max_descs;
test->ifobj_rx->xsk->umem->comp_size = max_descs;
@@ -2648,8 +2554,8 @@ struct ifobject *ifobject_create(void)
if (!ifobj->xsk_arr)
goto out_xsk_arr;
- ifobj->xsk_arr[0].umem_real = calloc(1, sizeof(struct xsk_umem_info));
- if (!ifobj->xsk_arr[0].umem_real)
+ ifobj->xsk_arr[0].umem = calloc(1, sizeof(struct xsk_umem_info));
+ if (!ifobj->xsk_arr[0].umem)
goto out_umem;
return ifobj;
@@ -2664,7 +2570,7 @@ struct ifobject *ifobject_create(void)
void ifobject_delete(struct ifobject *ifobj)
{
if (ifobj->xsk_arr)
- free(ifobj->xsk_arr[0].umem_real);
+ free(ifobj->xsk_arr[0].umem);
free(ifobj->xsk_arr);
free(ifobj);
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.h b/tools/testing/selftests/net/lib/xsk/test_xsk.h
index 2506b0dcc6bf..410702f89dc9 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.h
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.h
@@ -83,7 +83,6 @@ typedef int (*test_func_t)(struct test_spec *test);
struct xsk_socket_info {
struct xsk_ring_cons rx;
struct xsk_ring_prod tx;
- struct xsk_umem_info *umem_real;
struct xsk_umem_info *umem;
struct xsk_socket *xsk;
struct pkt_stream *pkt_stream;
@@ -108,19 +107,11 @@ struct xsk_umem_info {
u32 frame_headroom;
void *buffer;
u32 frame_size;
- u32 base_addr;
u32 fill_size;
u32 comp_size;
bool unaligned_mode;
};
-struct set_hw_ring {
- u32 default_tx;
- u32 default_rx;
-};
-
-int hw_ring_size_reset(struct ifobject *ifobj);
-
struct ifobject {
char ifname[MAX_INTERFACE_NAME_CHARS];
struct xsk_socket_info *xsk;
@@ -131,7 +122,6 @@ struct ifobject {
struct bpf_map *xskmap;
struct bpf_program *xdp_prog;
struct ethtool_ringparam ring;
- struct set_hw_ring set_ring;
enum test_mode mode;
int ifindex;
int mtu;
@@ -145,7 +135,6 @@ struct ifobject {
bool busy_poll;
bool use_fill_ring;
bool release_rx;
- bool shared_umem;
bool use_metadata;
bool unaligned_supp;
bool multi_buff_supp;
@@ -204,7 +193,6 @@ struct test_spec {
u16 current_step;
u16 nb_sockets;
bool fail;
- bool set_ring;
bool adjust_tail;
bool adjust_tail_support;
bool poll_tmout;
diff --git a/tools/testing/selftests/net/lib/xsk/xsk.c b/tools/testing/selftests/net/lib/xsk/xsk.c
index 4e9d14f883ac..74c7dd12a365 100644
--- a/tools/testing/selftests/net/lib/xsk/xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/xsk.c
@@ -801,27 +801,3 @@ int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)
close(sockfd);
return 0;
}
-
-int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)
-{
- struct ifreq ifr = {0};
- int sockfd, err;
-
- sockfd = socket(AF_INET, SOCK_DGRAM, 0);
- if (sockfd < 0)
- return -errno;
-
- memcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-
- ring_param->cmd = ETHTOOL_SRINGPARAM;
- ifr.ifr_data = (char *)ring_param;
-
- if (ioctl(sockfd, SIOCETHTOOL, &ifr) < 0) {
- err = errno;
- close(sockfd);
- return -err;
- }
-
- close(sockfd);
- return 0;
-}
diff --git a/tools/testing/selftests/net/lib/xsk/xsk.h b/tools/testing/selftests/net/lib/xsk/xsk.h
index 3f1fea999763..94a56dd43f2e 100644
--- a/tools/testing/selftests/net/lib/xsk/xsk.h
+++ b/tools/testing/selftests/net/lib/xsk/xsk.h
@@ -244,7 +244,6 @@ void xsk_socket__delete(struct xsk_socket *xsk);
int xsk_set_mtu(int ifindex, int mtu);
int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
-int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.c b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
index 0a63651434a5..7876ad47ed0f 100644
--- a/tools/testing/selftests/net/lib/xsk/xskxceiver.c
+++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
@@ -336,7 +336,6 @@ int main(int argc, char **argv)
u32 i, j, failed_tests = 0, nb_tests;
int modes = TEST_MODE_SKB + 1;
struct test_spec test;
- bool shared_netdev;
int ret;
/* Use libbpf 1.0 API mode */
@@ -383,10 +382,6 @@ int main(int argc, char **argv)
ksft_exit_xfail();
}
- shared_netdev = (ifobj_tx->ifindex == ifobj_rx->ifindex);
- ifobj_tx->shared_umem = shared_netdev;
- ifobj_rx->shared_umem = shared_netdev;
-
if (!validate_interface(ifobj_tx) || !validate_interface(ifobj_rx))
print_usage(argv);
@@ -397,11 +392,8 @@ int main(int argc, char **argv)
}
ret = get_hw_ring_size(ifobj_tx->ifname, &ifobj_tx->ring);
- if (!ret) {
+ if (!ret)
ifobj_tx->hw_ring_size_supp = true;
- ifobj_tx->set_ring.default_tx = ifobj_tx->ring.tx_pending;
- ifobj_tx->set_ring.default_rx = ifobj_tx->ring.rx_pending;
- }
if (init_iface(ifobj_rx, worker_testapp_validate_rx) ||
init_iface(ifobj_tx, worker_testapp_validate_tx)) {
@@ -453,9 +445,6 @@ int main(int argc, char **argv)
}
}
- if (ifobj_tx->hw_ring_size_supp)
- hw_ring_size_reset(ifobj_tx);
-
pkt_stream_delete(tx_pkt_stream_default);
pkt_stream_delete(rx_pkt_stream_default);
xsk_unload_xdp_programs(ifobj_tx);
diff --git a/tools/testing/selftests/net/test_xsk.sh b/tools/testing/selftests/net/test_xsk.sh
index 448cd2462278..fbf4551d596a 100755
--- a/tools/testing/selftests/net/test_xsk.sh
+++ b/tools/testing/selftests/net/test_xsk.sh
@@ -71,9 +71,6 @@
# Set up veth interfaces and leave them up so xskxceiver can be launched in a debugger:
# sudo ./test_xsk.sh -d
#
-# Run test suite for physical device in loopback mode
-# sudo ./test_xsk.sh -i IFACE
-#
# Run test suite in a specific mode only [skb,drv,zc]
# sudo ./test_xsk.sh -m MODE
#
@@ -88,14 +85,11 @@
. xsk_prereqs.sh
-ETH=""
-
-while getopts "vi:dm:lt:h" flag
+while getopts "vdm:lt:h" flag
do
case "${flag}" in
v) verbose=1;;
d) debug=1;;
- i) ETH=${OPTARG};;
m) MODE=${OPTARG};;
l) list=1;;
t) TEST=${OPTARG};;
@@ -162,21 +156,16 @@ if [[ $help -eq 1 ]]; then
exit
fi
-if [ ! -z $ETH ]; then
- VETH0=${ETH}
- VETH1=${ETH}
-else
- validate_root_exec
- validate_veth_support ${VETH0}
- validate_ip_utility
- setup_vethPairs
-
- retval=$?
- if [ $retval -ne 0 ]; then
- test_status $retval "${TEST_NAME}"
- cleanup_exit ${VETH0} ${VETH1}
- exit $retval
- fi
+validate_root_exec
+validate_veth_support ${VETH0}
+validate_ip_utility
+setup_vethPairs
+
+retval=$?
+if [ $retval -ne 0 ]; then
+ test_status $retval "${TEST_NAME}"
+ cleanup_exit ${VETH0} ${VETH1}
+ exit $retval
fi
@@ -208,11 +197,7 @@ fi
exec_xskxceiver
-if [ -z $ETH ]; then
- cleanup_exit ${VETH0} ${VETH1}
-else
- cleanup_iface ${ETH} ${MTU}
-fi
+cleanup_exit ${VETH0} ${VETH1}
if [[ $list -eq 1 ]]; then
exit
@@ -221,18 +206,12 @@ fi
TEST_NAME="XSK_SELFTESTS_${VETH0}_BUSY_POLL"
busy_poll=1
-if [ -z $ETH ]; then
- setup_vethPairs
-fi
+setup_vethPairs
exec_xskxceiver
## END TESTS
-if [ -z $ETH ]; then
- cleanup_exit ${VETH0} ${VETH1}
-else
- cleanup_iface ${ETH} ${MTU}
-fi
+cleanup_exit ${VETH0} ${VETH1}
failures=0
echo -e "\nSummary:"
diff --git a/tools/testing/selftests/net/xsk_prereqs.sh b/tools/testing/selftests/net/xsk_prereqs.sh
index d8fe786e967c..5e5c8ef3fff2 100755
--- a/tools/testing/selftests/net/xsk_prereqs.sh
+++ b/tools/testing/selftests/net/xsk_prereqs.sh
@@ -53,13 +53,6 @@ test_exit()
exit 1
}
-cleanup_iface()
-{
- ip link set $1 mtu $2
- ip link set $1 xdp off
- ip link set $1 xdpgeneric off
-}
-
clear_configs()
{
[ $(ip link show $1 &>/dev/null; echo $?;) == 0 ] &&
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v6 net-next 05/15] selftests: xsk: collect interface capabilities in struct xsk_caps
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
` (3 preceding siblings ...)
2026-11-27 15:05 ` [PATCH v6 net-next 04/15] selftests: xsk: drop the single-interface loopback mode Maciej Fijalkowski
@ 2026-11-27 15:05 ` Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 06/15] selftests: xsk: split xskxceiver main() into setup, run and cleanup Maciej Fijalkowski
` (9 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:05 UTC (permalink / raw)
To: netdev
Cc: magnus.karlsson, stfomichev, kuba, pabeni, tushar.vyavahare,
kerneljasonxing, bjorn, Maciej Fijalkowski
A later patch runs the RX and TX endpoints as separate processes, each
binding only its own interface, while the shared test code still checks
the capabilities of both ifobjects. A process will mirror its local
capabilities into a shadow ifobject for the other side.
Move the support flags and limits of struct ifobject into struct
xsk_caps, so that mirroring them is a single assignment, with
ifobj_has_cap() and ifobj_set_cap() for the flags and xsk_get_cap() for
the limits.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
.../testing/selftests/net/lib/xsk/test_xsk.c | 84 +++++++++++--------
.../testing/selftests/net/lib/xsk/test_xsk.h | 34 ++++++--
.../selftests/net/lib/xsk/xskxceiver.c | 14 ++--
3 files changed, 83 insertions(+), 49 deletions(-)
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c
index 8826697c58de..4e6adc2e4532 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c
@@ -1721,20 +1721,24 @@ static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *i
struct ifobject *ifobj2)
{
pthread_t t0, t1;
+ u32 mbuf_cap;
int err;
- if (test->mtu > MAX_ETH_PKT_SIZE) {
- if (test->mode == TEST_MODE_ZC && (!ifobj1->multi_buff_zc_supp ||
- (ifobj2 && !ifobj2->multi_buff_zc_supp))) {
- ksft_print_msg("Multi buffer for zero-copy not supported.\n");
- return TEST_SKIP;
- }
- if (test->mode != TEST_MODE_ZC && (!ifobj1->multi_buff_supp ||
- (ifobj2 && !ifobj2->multi_buff_supp))) {
- ksft_print_msg("Multi buffer not supported.\n");
- return TEST_SKIP;
- }
+ if (test->mtu <= MAX_ETH_PKT_SIZE)
+ goto skip_mbuf_check;
+
+ mbuf_cap = test->mode == TEST_MODE_ZC ? XSK_CAP_MBUF_ZC :
+ XSK_CAP_MBUF;
+
+ if (!ifobj_has_cap(ifobj1, mbuf_cap) ||
+ (ifobj2 && !ifobj_has_cap(ifobj2, mbuf_cap))) {
+ ksft_print_msg("Multi buffer%s not supported.\n",
+ mbuf_cap == XSK_CAP_MBUF_ZC ?
+ " for zero-copy" : "");
+ return TEST_SKIP;
}
+
+skip_mbuf_check:
err = test_spec_set_mtu(test, test->mtu);
if (err) {
ksft_print_msg("Error, could not set mtu.\n");
@@ -1799,8 +1803,10 @@ static int testapp_validate_traffic(struct test_spec *test)
struct ifobject *ifobj_rx = test->ifobj_rx;
struct ifobject *ifobj_tx = test->ifobj_tx;
- if ((ifobj_rx->xsk->umem->unaligned_mode && !ifobj_rx->unaligned_supp) ||
- (ifobj_tx->xsk->umem->unaligned_mode && !ifobj_tx->unaligned_supp)) {
+ if ((ifobj_rx->xsk->umem->unaligned_mode &&
+ !ifobj_has_cap(ifobj_rx, XSK_CAP_UNALIGNED)) ||
+ (ifobj_tx->xsk->umem->unaligned_mode &&
+ !ifobj_has_cap(ifobj_tx, XSK_CAP_UNALIGNED))) {
ksft_print_msg("No huge pages present.\n");
return TEST_SKIP;
}
@@ -1900,7 +1906,7 @@ int testapp_headroom(struct test_spec *test)
int testapp_stats_rx_dropped(struct test_spec *test)
{
struct xsk_umem_info *umem = test->ifobj_rx->xsk->umem;
- u32 umem_tr = test->ifobj_tx->umem_tailroom;
+ u32 umem_tr = xsk_get_cap(test, umem_tailroom);
if (test->mode == TEST_MODE_ZC) {
ksft_print_msg("Can not run RX_DROPPED test for ZC mode\n");
@@ -2162,9 +2168,9 @@ int testapp_too_many_frags(struct test_spec *test)
int ret = TEST_FAILURE;
if (test->mode == TEST_MODE_ZC) {
- max_frags = test->ifobj_tx->xdp_zc_max_segs;
+ max_frags = xsk_get_cap(test, xdp_zc_max_segs);
} else {
- max_frags = test->ifobj_tx->max_skb_frags;
+ max_frags = xsk_get_cap(test, max_skb_frags);
max_frags += 1;
}
@@ -2224,7 +2230,6 @@ static int xsk_load_xdp_programs(struct ifobject *ifobj)
return 0;
}
-/* Simple test */
static bool hugepages_present(void)
{
size_t mmap_sz = 2 * DEFAULT_UMEM_BUFFERS * XSK_UMEM__DEFAULT_FRAME_SIZE;
@@ -2240,21 +2245,13 @@ static bool hugepages_present(void)
return true;
}
-int init_iface(struct ifobject *ifobj, thread_func_t func_ptr)
+static int detect_ifobj_caps(struct ifobject *ifobj)
{
LIBBPF_OPTS(bpf_xdp_query_opts, query_opts);
int err;
- ifobj->func_ptr = func_ptr;
-
- err = xsk_load_xdp_programs(ifobj);
- if (err) {
- ksft_print_msg("Error loading XDP program\n");
- return err;
- }
-
if (hugepages_present())
- ifobj->unaligned_supp = true;
+ ifobj_set_cap(ifobj, XSK_CAP_UNALIGNED);
err = bpf_xdp_query(ifobj->ifindex, XDP_FLAGS_DRV_MODE, &query_opts);
if (err) {
@@ -2262,19 +2259,34 @@ int init_iface(struct ifobject *ifobj, thread_func_t func_ptr)
return err;
}
if (query_opts.feature_flags & NETDEV_XDP_ACT_RX_SG)
- ifobj->multi_buff_supp = true;
+ ifobj_set_cap(ifobj, XSK_CAP_MBUF);
if (query_opts.feature_flags & NETDEV_XDP_ACT_XSK_ZEROCOPY) {
if (query_opts.xdp_zc_max_segs > 1) {
- ifobj->multi_buff_zc_supp = true;
- ifobj->xdp_zc_max_segs = query_opts.xdp_zc_max_segs;
+ ifobj_set_cap(ifobj, XSK_CAP_MBUF_ZC);
+ ifobj->caps.xdp_zc_max_segs = query_opts.xdp_zc_max_segs;
} else {
- ifobj->xdp_zc_max_segs = 0;
+ ifobj->caps.xdp_zc_max_segs = 0;
}
}
return 0;
}
+int init_iface(struct ifobject *ifobj, thread_func_t func_ptr)
+{
+ int err;
+
+ ifobj->func_ptr = func_ptr;
+
+ err = xsk_load_xdp_programs(ifobj);
+ if (err) {
+ ksft_print_msg("Error loading XDP program\n");
+ return err;
+ }
+
+ return detect_ifobj_caps(ifobj);
+}
+
int testapp_send_receive(struct test_spec *test)
{
return testapp_validate_traffic(test);
@@ -2364,7 +2376,7 @@ int testapp_hw_sw_min_ring_size(struct test_spec *test)
{
int ret;
- if (!test->ifobj_tx->hw_ring_size_supp) {
+ if (!ifobj_has_cap(test->ifobj_tx, XSK_CAP_HW_RING)) {
ksft_print_msg("HW ring sizes not supported.\n");
return TEST_SKIP;
}
@@ -2391,14 +2403,14 @@ int testapp_hw_sw_max_ring_size(struct test_spec *test)
u32 batch_size;
int ret;
- if (!test->ifobj_tx->hw_ring_size_supp) {
+ if (!ifobj_has_cap(test->ifobj_tx, XSK_CAP_HW_RING)) {
ksft_print_msg("HW ring sizes not supported.\n");
return TEST_SKIP;
}
/* The second step sends batches of min(tx_max_pending, max_descs) - 8
* descriptors.
*/
- if (test->ifobj_tx->ring.tx_max_pending <= 8) {
+ if (xsk_get_cap(test, tx_max_pending) <= 8) {
ksft_print_msg("HW TX ring too small.\n");
return TEST_SKIP;
}
@@ -2423,7 +2435,7 @@ int testapp_hw_sw_max_ring_size(struct test_spec *test)
* sends only while fewer packets than the UMEM size minus a batch are
* in flight, and reserves a whole batch in the TX ring.
*/
- batch_size = min(test->ifobj_tx->ring.tx_max_pending, max_descs) - 8;
+ batch_size = min(xsk_get_cap(test, tx_max_pending), max_descs) - 8;
test->ifobj_tx->xsk->batch_size = batch_size;
test->ifobj_rx->xsk->batch_size = batch_size;
if (pkt_stream_replace(test, max_descs, MIN_PKT_SIZE)) {
@@ -2518,7 +2530,7 @@ int testapp_adjust_tail_grow_mb(struct test_spec *test)
grow_size = XSK_UMEM__MAX_FRAME_SIZE -
XSK_UMEM__LARGE_FRAME_SIZE -
XDP_PACKET_HEADROOM -
- test->ifobj_tx->umem_tailroom;
+ xsk_get_cap(test, umem_tailroom);
test->mtu = MAX_ETH_JUMBO_SIZE;
return testapp_adjust_tail(test, grow_size, XSK_UMEM__LARGE_FRAME_SIZE * 2);
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.h b/tools/testing/selftests/net/lib/xsk/test_xsk.h
index 410702f89dc9..716ea044797c 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.h
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.h
@@ -112,8 +112,22 @@ struct xsk_umem_info {
bool unaligned_mode;
};
+#define XSK_CAP_UNALIGNED (1U << 0)
+#define XSK_CAP_MBUF (1U << 1)
+#define XSK_CAP_MBUF_ZC (1U << 2)
+#define XSK_CAP_HW_RING (1U << 3)
+
+struct xsk_caps {
+ u32 flags;
+ u32 xdp_zc_max_segs;
+ u32 max_skb_frags;
+ u32 umem_tailroom;
+ u32 tx_max_pending;
+};
+
struct ifobject {
char ifname[MAX_INTERFACE_NAME_CHARS];
+ struct xsk_caps caps;
struct xsk_socket_info *xsk;
struct xsk_socket_info *xsk_arr;
thread_func_t func_ptr;
@@ -126,9 +140,6 @@ struct ifobject {
int ifindex;
int mtu;
u32 bind_flags;
- u32 xdp_zc_max_segs;
- u32 umem_tailroom;
- u32 max_skb_frags;
bool tx_on;
bool rx_on;
bool use_poll;
@@ -136,11 +147,20 @@ struct ifobject {
bool use_fill_ring;
bool release_rx;
bool use_metadata;
- bool unaligned_supp;
- bool multi_buff_supp;
- bool multi_buff_zc_supp;
- bool hw_ring_size_supp;
};
+
+static inline bool ifobj_has_cap(const struct ifobject *ifobj, u32 cap)
+{
+ return ifobj && (ifobj->caps.flags & cap);
+}
+
+static inline void ifobj_set_cap(struct ifobject *ifobj, u32 cap)
+{
+ ifobj->caps.flags |= cap;
+}
+
+#define xsk_get_cap(test, cap) ((test)->ifobj_tx->caps.cap)
+
struct ifobject *ifobject_create(void);
void ifobject_delete(struct ifobject *ifobj);
int init_iface(struct ifobject *ifobj, thread_func_t func_ptr);
diff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.c b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
index 7876ad47ed0f..d82224a4fa4b 100644
--- a/tools/testing/selftests/net/lib/xsk/xskxceiver.c
+++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
@@ -361,15 +361,15 @@ int main(int argc, char **argv)
ksft_print_msg("Can't get MAX_SKB_FRAGS from system, using default (17)\n");
max_frags = 17;
}
- ifobj_tx->max_skb_frags = max_frags;
- ifobj_rx->max_skb_frags = max_frags;
+ ifobj_tx->caps.max_skb_frags = max_frags;
+ ifobj_rx->caps.max_skb_frags = max_frags;
/* 48 bytes is a part of skb_shared_info w/o frags array;
* 16 bytes is sizeof(skb_frag_t)
*/
umem_tailroom = ALIGN(48 + (max_frags * 16), cache_line_size);
- ifobj_tx->umem_tailroom = umem_tailroom;
- ifobj_rx->umem_tailroom = umem_tailroom;
+ ifobj_tx->caps.umem_tailroom = umem_tailroom;
+ ifobj_rx->caps.umem_tailroom = umem_tailroom;
parse_command_line(ifobj_tx, ifobj_rx, argc, argv);
@@ -392,8 +392,10 @@ int main(int argc, char **argv)
}
ret = get_hw_ring_size(ifobj_tx->ifname, &ifobj_tx->ring);
- if (!ret)
- ifobj_tx->hw_ring_size_supp = true;
+ if (!ret) {
+ ifobj_set_cap(ifobj_tx, XSK_CAP_HW_RING);
+ ifobj_tx->caps.tx_max_pending = ifobj_tx->ring.tx_max_pending;
+ }
if (init_iface(ifobj_rx, worker_testapp_validate_rx) ||
init_iface(ifobj_tx, worker_testapp_validate_tx)) {
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v6 net-next 06/15] selftests: xsk: split xskxceiver main() into setup, run and cleanup
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
` (4 preceding siblings ...)
2026-11-27 15:05 ` [PATCH v6 net-next 05/15] selftests: xsk: collect interface capabilities in struct xsk_caps Maciej Fijalkowski
@ 2026-11-27 15:05 ` Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 07/15] selftests: xsk: run one test case per xskxceiver invocation Maciej Fijalkowski
` (8 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:05 UTC (permalink / raw)
To: netdev
Cc: magnus.karlsson, stfomichev, kuba, pabeni, tushar.vyavahare,
kerneljasonxing, bjorn, Maciej Fijalkowski
Prepare xskxceiver for one endpoint per process by splitting main():
- bind_iface() sets up the interface of one -i argument
- detect_mode_caps() and detect_ifobj_caps() record DRV, zero-copy and
HW ring support as XSK_CAP flags, which mode_supported() checks
- run_pkt_test() returns the result, as not every failing path sets
test->fail
- cleanup_iface() detaches and unloads one interface, also a partially
set up one, so that main() has a single exit path; it detaches with
the XDP flags of the attach
Call ksft_print_header() right after parsing; it also makes stdout line
buffered, so that a launcher reading a pipe gets the output as it
comes. -l prints no TAP header and exits with 0.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
.../testing/selftests/net/lib/xsk/test_xsk.c | 24 ++-
.../testing/selftests/net/lib/xsk/test_xsk.h | 3 +
.../selftests/net/lib/xsk/xskxceiver.c | 180 +++++++++---------
3 files changed, 115 insertions(+), 92 deletions(-)
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c
index 4e6adc2e4532..aaffa1b04ee4 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c
@@ -64,7 +64,7 @@ static void gen_eth_hdr(struct xsk_socket_info *xsk, struct ethhdr *eth_hdr)
eth_hdr->h_proto = htons(ETH_P_LOOPBACK);
}
-static u32 mode_to_xdp_flags(enum test_mode mode)
+u32 mode_to_xdp_flags(enum test_mode mode)
{
return (mode == TEST_MODE_SKB) ? XDP_FLAGS_SKB_MODE : XDP_FLAGS_DRV_MODE;
}
@@ -338,6 +338,9 @@ static struct pkt *pkt_stream_get_next_rx_pkt(struct pkt_stream *pkt_stream, u32
void pkt_stream_delete(struct pkt_stream *pkt_stream)
{
+ if (!pkt_stream)
+ return;
+
free(pkt_stream->pkts);
free(pkt_stream);
}
@@ -1654,6 +1657,7 @@ static bool xdp_prog_changed_tx(struct test_spec *test)
static int xsk_reattach_xdp(struct ifobject *ifobj, struct bpf_program *xdp_prog,
struct bpf_map *xskmap, enum test_mode mode)
{
+ enum test_mode prev_mode = ifobj->mode;
int err;
xsk_detach_xdp_program(ifobj->ifindex, mode_to_xdp_flags(ifobj->mode));
@@ -1663,16 +1667,19 @@ static int xsk_reattach_xdp(struct ifobject *ifobj, struct bpf_program *xdp_prog
return err;
}
- if (ifobj->mode != mode && (mode == TEST_MODE_DRV || mode == TEST_MODE_ZC))
+ /* Record the program before the mode check, so that cleanup_iface()
+ * detaches it also when the check fails.
+ */
+ ifobj->xdp_prog = xdp_prog;
+ ifobj->xskmap = xskmap;
+ ifobj->mode = mode;
+
+ if (prev_mode != mode && (mode == TEST_MODE_DRV || mode == TEST_MODE_ZC))
if (!xsk_is_in_mode(ifobj->ifindex, XDP_FLAGS_DRV_MODE)) {
ksft_print_msg("ERROR: XDP prog not in DRV mode\n");
return -EINVAL;
}
- ifobj->xdp_prog = xdp_prog;
- ifobj->xskmap = xskmap;
- ifobj->mode = mode;
-
return 0;
}
@@ -2269,6 +2276,11 @@ static int detect_ifobj_caps(struct ifobject *ifobj)
}
}
+ if (!get_hw_ring_size(ifobj->ifname, &ifobj->ring)) {
+ ifobj_set_cap(ifobj, XSK_CAP_HW_RING);
+ ifobj->caps.tx_max_pending = ifobj->ring.tx_max_pending;
+ }
+
return 0;
}
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.h b/tools/testing/selftests/net/lib/xsk/test_xsk.h
index 716ea044797c..8503ef055d37 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.h
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.h
@@ -116,6 +116,8 @@ struct xsk_umem_info {
#define XSK_CAP_MBUF (1U << 1)
#define XSK_CAP_MBUF_ZC (1U << 2)
#define XSK_CAP_HW_RING (1U << 3)
+#define XSK_CAP_DRV (1U << 4)
+#define XSK_CAP_ZC (1U << 5)
struct xsk_caps {
u32 flags;
@@ -164,6 +166,7 @@ static inline void ifobj_set_cap(struct ifobject *ifobj, u32 cap)
struct ifobject *ifobject_create(void);
void ifobject_delete(struct ifobject *ifobj);
int init_iface(struct ifobject *ifobj, thread_func_t func_ptr);
+u32 mode_to_xdp_flags(enum test_mode mode);
int xsk_configure_umem(struct ifobject *ifobj, struct xsk_umem_info *umem, void *buffer, u64 size);
int xsk_configure_socket(struct xsk_socket_info *xsk, struct xsk_umem_info *umem,
diff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.c b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
index d82224a4fa4b..97eece4c57f8 100644
--- a/tools/testing/selftests/net/lib/xsk/xskxceiver.c
+++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
@@ -81,7 +81,6 @@
#include <linux/netdev.h>
#include <linux/ethtool.h>
#include <linux/align.h>
-#include <linux/kernel.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <locale.h>
@@ -101,7 +100,6 @@
#include "kselftest.h"
#include "xsk_xdp_common.h"
-static bool opt_print_tests;
static enum test_mode opt_mode = TEST_MODE_ALL;
static u32 opt_run_test = RUN_ALL_TESTS;
@@ -185,17 +183,40 @@ static void print_usage(char **argv)
ksft_exit_xfail();
}
-static bool validate_interface(struct ifobject *ifobj)
+static void bind_iface(struct ifobject *ifobj, const char *ifname, thread_func_t func,
+ char **argv)
{
- if (!strcmp(ifobj->ifname, ""))
- return false;
- return true;
+ size_t len = ifname ? strlen(ifname) : 0;
+
+ if (!len || len >= sizeof(ifobj->ifname))
+ print_usage(argv);
+
+ memcpy(ifobj->ifname, ifname, len + 1);
+ ifobj->ifindex = if_nametoindex(ifobj->ifname);
+ if (!ifobj->ifindex) {
+ ksft_print_msg("Error: cannot resolve interface %s\n", ifobj->ifname);
+ ksft_exit_fail();
+ }
+
+ if (init_iface(ifobj, func)) {
+ ksft_print_msg("Error: cannot initialize interface %s\n", ifobj->ifname);
+ ksft_exit_fail();
+ }
+}
+
+static void print_tests(void)
+{
+ u32 i;
+
+ printf("Tests:\n");
+ for (i = 0; i < ARRAY_SIZE(tests); i++)
+ printf("%u: %s\n", i, tests[i].name);
}
static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj_rx, int argc,
char **argv)
{
- struct ifobject *ifobj;
+ const char *ifname[2] = {};
u32 interface_nb = 0;
int option_index, c;
@@ -208,21 +229,10 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
switch (c) {
case 'i':
- if (interface_nb == 0)
- ifobj = ifobj_tx;
- else if (interface_nb == 1)
- ifobj = ifobj_rx;
- else
+ if (interface_nb >= ARRAY_SIZE(ifname))
break;
- memcpy(ifobj->ifname, optarg,
- min_t(size_t, MAX_INTERFACE_NAME_CHARS, strlen(optarg)));
-
- ifobj->ifindex = if_nametoindex(ifobj->ifname);
- if (!ifobj->ifindex)
- exit_with_error(errno);
-
- interface_nb++;
+ ifname[interface_nb++] = optarg;
break;
case 'v':
opt_verbose = true;
@@ -242,7 +252,8 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
print_usage(argv);
break;
case 'l':
- opt_print_tests = true;
+ print_tests();
+ ksft_exit_pass();
break;
case 't':
errno = 0;
@@ -255,6 +266,9 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
print_usage(argv);
}
}
+
+ bind_iface(ifobj_tx, ifname[0], worker_testapp_validate_tx, argv);
+ bind_iface(ifobj_rx, ifname[1], worker_testapp_validate_rx, argv);
}
static void xsk_unload_xdp_programs(struct ifobject *ifobj)
@@ -262,7 +276,7 @@ static void xsk_unload_xdp_programs(struct ifobject *ifobj)
xsk_xdp_progs__destroy(ifobj->xdp_progs);
}
-static void run_pkt_test(struct test_spec *test)
+static int run_pkt_test(struct test_spec *test)
{
int ret;
@@ -287,6 +301,7 @@ static void run_pkt_test(struct test_spec *test)
}
pkt_stream_restore_default(test);
+ return ret;
}
static bool is_xdp_supported(int ifindex)
@@ -317,26 +332,43 @@ static bool is_xdp_supported(int ifindex)
return true;
}
-static void print_tests(void)
+static u32 detect_mode_caps(struct ifobject *ifobj)
{
- u32 i;
+ if (is_xdp_supported(ifobj->ifindex)) {
+ ifobj_set_cap(ifobj, XSK_CAP_DRV);
+ if (ifobj_zc_avail(ifobj))
+ ifobj_set_cap(ifobj, XSK_CAP_ZC);
+ }
- printf("Tests:\n");
- for (i = 0; i < ARRAY_SIZE(tests); i++)
- printf("%u: %s\n", i, tests[i].name);
+ return ifobj->caps.flags;
+}
+
+static bool mode_supported(enum test_mode mode, u32 caps)
+{
+ if (mode == TEST_MODE_SKB)
+ return true;
+ if (mode == TEST_MODE_DRV)
+ return caps & XSK_CAP_DRV;
+ return caps & XSK_CAP_ZC;
+}
+
+static void cleanup_iface(struct ifobject *ifobj)
+{
+ if (ifobj->xdp_prog)
+ xsk_detach_xdp_program(ifobj->ifindex,
+ mode_to_xdp_flags(ifobj->mode));
+ xsk_unload_xdp_programs(ifobj);
}
int main(int argc, char **argv)
{
u32 cache_line_size, max_frags, umem_tailroom;
const size_t total_tests = ARRAY_SIZE(tests);
- struct pkt_stream *rx_pkt_stream_default;
- struct pkt_stream *tx_pkt_stream_default;
struct ifobject *ifobj_tx, *ifobj_rx;
u32 i, j, failed_tests = 0, nb_tests;
- int modes = TEST_MODE_SKB + 1;
- struct test_spec test;
- int ret;
+ struct test_spec test = {};
+ int ret = TEST_FAILURE;
+ u32 caps, modes = 0;
/* Use libbpf 1.0 API mode */
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
@@ -350,6 +382,10 @@ int main(int argc, char **argv)
setlocale(LC_ALL, "");
+ parse_command_line(ifobj_tx, ifobj_rx, argc, argv);
+ /* Line-buffer stdout so verdicts reach a capturing launcher live. */
+ ksft_print_header();
+
cache_line_size = read_procfs_val(SMP_CACHE_BYTES_PATH);
if (!cache_line_size) {
ksft_print_msg("Can't get SMP_CACHE_BYTES from system, using default (64)\n");
@@ -371,90 +407,62 @@ int main(int argc, char **argv)
ifobj_tx->caps.umem_tailroom = umem_tailroom;
ifobj_rx->caps.umem_tailroom = umem_tailroom;
- parse_command_line(ifobj_tx, ifobj_rx, argc, argv);
-
- if (opt_print_tests) {
- print_tests();
- ksft_exit_xpass();
- }
if (opt_run_test != RUN_ALL_TESTS && opt_run_test >= total_tests) {
ksft_print_msg("Error: test %u does not exist.\n", opt_run_test);
ksft_exit_xfail();
}
- if (!validate_interface(ifobj_tx) || !validate_interface(ifobj_rx))
- print_usage(argv);
-
- if (is_xdp_supported(ifobj_tx->ifindex)) {
- modes++;
- if (ifobj_zc_avail(ifobj_tx))
- modes++;
- }
+ test.tx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);
+ test.rx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);
+ if (!test.tx_pkt_stream_default || !test.rx_pkt_stream_default)
+ goto out;
- ret = get_hw_ring_size(ifobj_tx->ifname, &ifobj_tx->ring);
- if (!ret) {
- ifobj_set_cap(ifobj_tx, XSK_CAP_HW_RING);
- ifobj_tx->caps.tx_max_pending = ifobj_tx->ring.tx_max_pending;
- }
+ caps = detect_mode_caps(ifobj_tx);
- if (init_iface(ifobj_rx, worker_testapp_validate_rx) ||
- init_iface(ifobj_tx, worker_testapp_validate_tx)) {
- ksft_print_msg("Error : can't initialize interfaces\n");
+ if (opt_mode != TEST_MODE_ALL && !mode_supported(opt_mode, caps)) {
+ if (opt_mode == TEST_MODE_DRV)
+ ksft_print_msg("Error: XDP_DRV mode not supported.\n");
+ else
+ ksft_print_msg("Error: zero-copy mode not supported.\n");
ksft_exit_xfail();
}
- test_init(&test, ifobj_tx, ifobj_rx, 0, &tests[0]);
- tx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);
- rx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);
- if (!tx_pkt_stream_default || !rx_pkt_stream_default)
- exit_with_error(ENOMEM);
- test.tx_pkt_stream_default = tx_pkt_stream_default;
- test.rx_pkt_stream_default = rx_pkt_stream_default;
-
+ for (i = TEST_MODE_SKB; i <= TEST_MODE_ZC; i++)
+ if ((opt_mode == TEST_MODE_ALL || i == opt_mode) && mode_supported(i, caps))
+ modes++;
if (opt_run_test == RUN_ALL_TESTS)
nb_tests = total_tests;
else
nb_tests = 1;
- if (opt_mode == TEST_MODE_ALL) {
- ksft_set_plan(modes * nb_tests);
- } else {
- if (opt_mode == TEST_MODE_DRV && modes <= TEST_MODE_DRV) {
- ksft_print_msg("Error: XDP_DRV mode not supported.\n");
- ksft_exit_xfail();
- }
- if (opt_mode == TEST_MODE_ZC && modes <= TEST_MODE_ZC) {
- ksft_print_msg("Error: zero-copy mode not supported.\n");
- ksft_exit_xfail();
- }
+ ksft_set_plan(modes * nb_tests);
- ksft_set_plan(nb_tests);
- }
-
- for (i = 0; i < modes; i++) {
+ for (i = TEST_MODE_SKB; i <= TEST_MODE_ZC; i++) {
if (opt_mode != TEST_MODE_ALL && i != opt_mode)
continue;
+ if (!mode_supported(i, caps))
+ continue;
for (j = 0; j < total_tests; j++) {
if (opt_run_test != RUN_ALL_TESTS && j != opt_run_test)
continue;
test_init(&test, ifobj_tx, ifobj_rx, i, &tests[j]);
- run_pkt_test(&test);
- usleep(USLEEP_MAX);
-
- if (test.fail)
+ if (run_pkt_test(&test) == TEST_FAILURE)
failed_tests++;
+ usleep(USLEEP_MAX);
}
}
+ ret = failed_tests ? TEST_FAILURE : TEST_PASS;
- pkt_stream_delete(tx_pkt_stream_default);
- pkt_stream_delete(rx_pkt_stream_default);
- xsk_unload_xdp_programs(ifobj_tx);
- xsk_unload_xdp_programs(ifobj_rx);
+out:
+ cleanup_iface(ifobj_tx);
+ cleanup_iface(ifobj_rx);
+ pkt_stream_delete(test.tx_pkt_stream_default);
+ pkt_stream_delete(test.rx_pkt_stream_default);
ifobject_delete(ifobj_tx);
ifobject_delete(ifobj_rx);
- if (failed_tests)
+ if (ret)
ksft_exit_fail();
else
ksft_exit_pass();
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v6 net-next 07/15] selftests: xsk: run one test case per xskxceiver invocation
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
` (5 preceding siblings ...)
2026-11-27 15:05 ` [PATCH v6 net-next 06/15] selftests: xsk: split xskxceiver main() into setup, run and cleanup Maciej Fijalkowski
@ 2026-11-27 15:05 ` Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 08/15] selftests: xsk: run the RX and TX endpoints in separate processes Maciej Fijalkowski
` (7 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:05 UTC (permalink / raw)
To: netdev
Cc: magnus.karlsson, stfomichev, kuba, pabeni, tushar.vyavahare,
kerneljasonxing, bjorn, Maciej Fijalkowski
Run one test case in one mode per xskxceiver invocation, so that each
case starts from a fresh process and a crash fails only that case.
xskxceiver now requires -m and -t and exits with the verdict of the
case; an unsupported mode skips it rather than exiting with XFAIL.
This breaks test_xsk.sh, which ran all cases in one invocation. Remove
it and xsk_prereqs.sh; drivers/net/xsk.py, added later in this series,
replaces them. As test_xsk.sh was in TEST_PROGS_EXTENDED, the default
run loses no test in between.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
MAINTAINERS | 1 -
tools/testing/selftests/net/Makefile | 2 -
tools/testing/selftests/net/lib/Makefile | 2 +-
.../selftests/net/lib/xsk/xskxceiver.c | 64 ++---
tools/testing/selftests/net/test_xsk.sh | 230 ------------------
tools/testing/selftests/net/xsk_prereqs.sh | 86 -------
6 files changed, 22 insertions(+), 363 deletions(-)
delete mode 100755 tools/testing/selftests/net/test_xsk.sh
delete mode 100755 tools/testing/selftests/net/xsk_prereqs.sh
diff --git a/MAINTAINERS b/MAINTAINERS
index 05b2d9e36b6d..8b7d54034856 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -30608,7 +30608,6 @@ F: include/net/xsk_buff_pool.h
F: include/uapi/linux/if_xdp.h
F: include/uapi/linux/xdp_diag.h
F: net/xdp/
-F: tools/testing/selftests/net/*xsk*
F: tools/testing/selftests/net/lib/xsk/
XEN BLOCK SUBSYSTEM
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index fb0a64662053..09c345f4d211 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -143,7 +143,6 @@ TEST_PROGS := \
# end of TEST_PROGS
TEST_PROGS_EXTENDED := \
- test_xsk.sh \
xfrm_policy_add_speed.sh \
# end of TEST_PROGS_EXTENDED
@@ -216,7 +215,6 @@ TEST_FILES := \
in_netns.sh \
lib.sh \
settings \
- xsk_prereqs.sh \
# end of TEST_FILES
# YNL files, must be before "include ..lib.mk"
diff --git a/tools/testing/selftests/net/lib/Makefile b/tools/testing/selftests/net/lib/Makefile
index 0a6cd733883d..2b77d960d91a 100644
--- a/tools/testing/selftests/net/lib/Makefile
+++ b/tools/testing/selftests/net/lib/Makefile
@@ -35,7 +35,7 @@ include ../../lib.mk
BPF_PROG_DIRS := xsk
include ../bpf.mk
-# AF_XDP test engine used by net/test_xsk.sh.
+# AF_XDP test engine.
XSK_SRCS := $(filter-out %.bpf.c,$(wildcard xsk/*.c)) \
$(top_srcdir)/tools/lib/find_bit.c
diff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.c b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
index 97eece4c57f8..42fb3149ca6b 100644
--- a/tools/testing/selftests/net/lib/xsk/xskxceiver.c
+++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
@@ -6,9 +6,6 @@
* Linux kernel samples/bpf/xdpsock* and modified
* for use.
*
- * See test_xsk.sh for detailed information on test topology
- * and prerequisite network setup.
- *
* This test program contains two threads, each thread is single socket with
* a unique UMEM. It validates in-order packet delivery and packet content
* by sending packets to each other.
@@ -64,11 +61,6 @@
* - Tx thread Transmits a number of packets from veth<xxxx> to veth<yyyy>
* - Rx thread verifies if all packets were received and delivered in-order,
* and have the right content
- *
- * Enable/disable packet dump mode:
- * --------------------------
- * To enable L2 - L4 headers and payload dump of each packet on STDOUT, add
- * parameter -D to params array in test_xsk.sh, i.e. params=("-S" "-D")
*/
#define _GNU_SOURCE
@@ -169,14 +161,14 @@ static struct option long_options[] = {
static void print_usage(char **argv)
{
const char *str =
- " Usage: xskxceiver [OPTIONS]\n"
+ " Usage: %s -i TX_IFACE -i RX_IFACE -m MODE -t TEST [OPTIONS]\n"
" Options:\n"
" -i, --interface Use interface\n"
" -v, --verbose Verbose output\n"
" -b, --busy-poll Enable busy poll\n"
- " -m, --mode Run only mode skb, drv, or zc\n"
+ " -m, --mode Mode to run: skb, drv or zc\n"
" -l, --list List all available tests\n"
- " -t, --test Run a specific test. Enter number from -l option.\n"
+ " -t, --test Test case to run, a number from -l\n"
" -h, --help Display this help and exit\n";
ksft_print_msg(str, basename(argv[0]));
@@ -267,6 +259,9 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
}
}
+ if (opt_run_test == RUN_ALL_TESTS || opt_mode == TEST_MODE_ALL)
+ print_usage(argv);
+
bind_iface(ifobj_tx, ifname[0], worker_testapp_validate_tx, argv);
bind_iface(ifobj_rx, ifname[1], worker_testapp_validate_rx, argv);
}
@@ -365,10 +360,9 @@ int main(int argc, char **argv)
u32 cache_line_size, max_frags, umem_tailroom;
const size_t total_tests = ARRAY_SIZE(tests);
struct ifobject *ifobj_tx, *ifobj_rx;
- u32 i, j, failed_tests = 0, nb_tests;
struct test_spec test = {};
int ret = TEST_FAILURE;
- u32 caps, modes = 0;
+ u32 caps;
/* Use libbpf 1.0 API mode */
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
@@ -419,40 +413,18 @@ int main(int argc, char **argv)
caps = detect_mode_caps(ifobj_tx);
- if (opt_mode != TEST_MODE_ALL && !mode_supported(opt_mode, caps)) {
+ if (!mode_supported(opt_mode, caps)) {
if (opt_mode == TEST_MODE_DRV)
- ksft_print_msg("Error: XDP_DRV mode not supported.\n");
+ ksft_print_msg("XDP_DRV mode not supported.\n");
else
- ksft_print_msg("Error: zero-copy mode not supported.\n");
- ksft_exit_xfail();
+ ksft_print_msg("zero-copy mode not supported.\n");
+ ret = TEST_SKIP;
+ goto out;
}
- for (i = TEST_MODE_SKB; i <= TEST_MODE_ZC; i++)
- if ((opt_mode == TEST_MODE_ALL || i == opt_mode) && mode_supported(i, caps))
- modes++;
- if (opt_run_test == RUN_ALL_TESTS)
- nb_tests = total_tests;
- else
- nb_tests = 1;
- ksft_set_plan(modes * nb_tests);
-
- for (i = TEST_MODE_SKB; i <= TEST_MODE_ZC; i++) {
- if (opt_mode != TEST_MODE_ALL && i != opt_mode)
- continue;
- if (!mode_supported(i, caps))
- continue;
-
- for (j = 0; j < total_tests; j++) {
- if (opt_run_test != RUN_ALL_TESTS && j != opt_run_test)
- continue;
-
- test_init(&test, ifobj_tx, ifobj_rx, i, &tests[j]);
- if (run_pkt_test(&test) == TEST_FAILURE)
- failed_tests++;
- usleep(USLEEP_MAX);
- }
- }
- ret = failed_tests ? TEST_FAILURE : TEST_PASS;
+ ksft_set_plan(1);
+ test_init(&test, ifobj_tx, ifobj_rx, opt_mode, &tests[opt_run_test]);
+ ret = run_pkt_test(&test);
out:
cleanup_iface(ifobj_tx);
@@ -462,6 +434,12 @@ int main(int argc, char **argv)
ifobject_delete(ifobj_tx);
ifobject_delete(ifobj_rx);
+ if (ret == TEST_SKIP && ksft_test_num()) {
+ ksft_print_cnts();
+ return KSFT_SKIP;
+ }
+ if (ret == TEST_SKIP)
+ ksft_exit_skip("mode not supported\n");
if (ret)
ksft_exit_fail();
else
diff --git a/tools/testing/selftests/net/test_xsk.sh b/tools/testing/selftests/net/test_xsk.sh
deleted file mode 100755
index fbf4551d596a..000000000000
--- a/tools/testing/selftests/net/test_xsk.sh
+++ /dev/null
@@ -1,230 +0,0 @@
-#!/bin/bash
-# SPDX-License-Identifier: GPL-2.0
-# Copyright(c) 2020 Intel Corporation, Weqaar Janjua <weqaar.a.janjua@intel.com>
-
-# AF_XDP selftests based on veth
-#
-# End-to-end AF_XDP over Veth test
-#
-# Topology:
-# ---------
-# -----------
-# _ | Process | _
-# / ----------- \
-# / | \
-# / | \
-# ----------- | -----------
-# | Thread1 | | | Thread2 |
-# ----------- | -----------
-# | | |
-# ----------- | -----------
-# | xskX | | | xskY |
-# ----------- | -----------
-# | | |
-# ----------- | ----------
-# | vethX | --------- | vethY |
-# ----------- peer ----------
-#
-# AF_XDP is an address family optimized for high performance packet processing,
-# it is XDP’s user-space interface.
-#
-# An AF_XDP socket is linked to a single UMEM which is a region of virtual
-# contiguous memory, divided into equal-sized frames.
-#
-# Refer to AF_XDP Kernel Documentation for detailed information:
-# https://www.kernel.org/doc/html/latest/networking/af_xdp.html
-#
-# Prerequisites setup by script:
-#
-# Set up veth interfaces as per the topology shown ^^:
-# * setup two veth interfaces
-# ** veth<xxxx>
-# ** veth<yyyy>
-# *** xxxx and yyyy are randomly generated 4 digit numbers used to avoid
-# conflict with any existing interface
-# * tests the veth and xsk layers of the topology
-#
-# See the source xskxceiver.c for information on each test
-#
-# Kernel configuration:
-# ---------------------
-# See "config" file for recommended kernel config options.
-#
-# Turn on XDP sockets and veth support when compiling i.e.
-# Networking support -->
-# Networking options -->
-# [ * ] XDP sockets
-#
-# Executing Tests:
-# ----------------
-# Must run with CAP_NET_ADMIN capability.
-#
-# Run:
-# sudo ./test_xsk.sh
-#
-# If running from kselftests:
-# sudo make run_tests
-#
-# Run with verbose output:
-# sudo ./test_xsk.sh -v
-#
-# Set up veth interfaces and leave them up so xskxceiver can be launched in a debugger:
-# sudo ./test_xsk.sh -d
-#
-# Run test suite in a specific mode only [skb,drv,zc]
-# sudo ./test_xsk.sh -m MODE
-#
-# List available tests
-# ./test_xsk.sh -l
-#
-# Run a specific test from the test suite
-# sudo ./test_xsk.sh -t TEST_NAME
-#
-# Display the available command line options
-# ./test_xsk.sh -h
-
-. xsk_prereqs.sh
-
-while getopts "vdm:lt:h" flag
-do
- case "${flag}" in
- v) verbose=1;;
- d) debug=1;;
- m) MODE=${OPTARG};;
- l) list=1;;
- t) TEST=${OPTARG};;
- h) help=1;;
- esac
-done
-
-if [ ! -x "./${XSKOBJ}" ]; then
- echo "xskxceiver was not built; skipping"
- exit $ksft_skip
-fi
-
-TEST_NAME="PREREQUISITES"
-
-URANDOM=/dev/urandom
-[ ! -e "${URANDOM}" ] && { echo "${URANDOM} not found. Skipping tests."; test_exit $ksft_fail; }
-
-VETH0_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
-VETH0=ve${VETH0_POSTFIX}
-VETH1_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
-VETH1=ve${VETH1_POSTFIX}
-MTU=1500
-
-trap ctrl_c INT
-
-function ctrl_c() {
- cleanup_exit ${VETH0} ${VETH1}
- exit 1
-}
-
-setup_vethPairs() {
- if [[ $verbose -eq 1 ]]; then
- echo "setting up ${VETH0}"
- fi
- ip link add ${VETH0} numtxqueues 4 numrxqueues 4 type veth peer name ${VETH1} numtxqueues 4 numrxqueues 4
- if [ -f /proc/net/if_inet6 ]; then
- echo 1 > /proc/sys/net/ipv6/conf/${VETH0}/disable_ipv6
- echo 1 > /proc/sys/net/ipv6/conf/${VETH1}/disable_ipv6
- fi
- if [[ $verbose -eq 1 ]]; then
- echo "setting up ${VETH1}"
- fi
-
- if [[ $busy_poll -eq 1 ]]; then
- echo 2 > /sys/class/net/${VETH0}/napi_defer_hard_irqs
- echo 200000 > /sys/class/net/${VETH0}/gro_flush_timeout
- echo 2 > /sys/class/net/${VETH1}/napi_defer_hard_irqs
- echo 200000 > /sys/class/net/${VETH1}/gro_flush_timeout
- fi
-
- ip link set ${VETH1} mtu ${MTU}
- ip link set ${VETH0} mtu ${MTU}
- ip link set ${VETH1} up
- ip link set ${VETH0} up
-}
-
-if [[ $list -eq 1 ]]; then
- ./${XSKOBJ} -l
- exit
-fi
-
-if [[ $help -eq 1 ]]; then
- ./${XSKOBJ}
- exit
-fi
-
-validate_root_exec
-validate_veth_support ${VETH0}
-validate_ip_utility
-setup_vethPairs
-
-retval=$?
-if [ $retval -ne 0 ]; then
- test_status $retval "${TEST_NAME}"
- cleanup_exit ${VETH0} ${VETH1}
- exit $retval
-fi
-
-
-if [[ $verbose -eq 1 ]]; then
- ARGS+="-v "
-fi
-
-if [ -n "$MODE" ]; then
- ARGS+="-m ${MODE} "
-fi
-
-if [ -n "$TEST" ]; then
- ARGS+="-t ${TEST} "
-fi
-
-retval=$?
-test_status $retval "${TEST_NAME}"
-
-## START TESTS
-
-statusList=()
-
-TEST_NAME="XSK_SELFTESTS_${VETH0}_SOFTIRQ"
-
-if [[ $debug -eq 1 ]]; then
- echo "-i" ${VETH0} "-i" ${VETH1}
- exit
-fi
-
-exec_xskxceiver
-
-cleanup_exit ${VETH0} ${VETH1}
-
-if [[ $list -eq 1 ]]; then
- exit
-fi
-
-TEST_NAME="XSK_SELFTESTS_${VETH0}_BUSY_POLL"
-busy_poll=1
-
-setup_vethPairs
-exec_xskxceiver
-
-## END TESTS
-
-cleanup_exit ${VETH0} ${VETH1}
-
-failures=0
-echo -e "\nSummary:"
-for i in "${!statusList[@]}"
-do
- if [ ${statusList[$i]} -ne 0 ]; then
- test_status ${statusList[$i]} ${nameList[$i]}
- failures=1
- fi
-done
-
-if [ $failures -eq 0 ]; then
- echo "All tests successful!"
-else
- exit 1
-fi
diff --git a/tools/testing/selftests/net/xsk_prereqs.sh b/tools/testing/selftests/net/xsk_prereqs.sh
deleted file mode 100755
index 5e5c8ef3fff2..000000000000
--- a/tools/testing/selftests/net/xsk_prereqs.sh
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/bin/bash
-# SPDX-License-Identifier: GPL-2.0
-# Copyright(c) 2020 Intel Corporation.
-
-ksft_pass=0
-ksft_fail=1
-ksft_xfail=2
-ksft_xpass=3
-ksft_skip=4
-
-XSKOBJ=lib/xskxceiver
-
-validate_root_exec()
-{
- msg="skip all tests:"
- if [ $UID != 0 ]; then
- echo $msg must be run as root >&2
- test_exit $ksft_fail
- else
- return $ksft_pass
- fi
-}
-
-validate_veth_support()
-{
- msg="skip all tests:"
- if [ $(ip link add $1 type veth 2>/dev/null; echo $?;) != 0 ]; then
- echo $msg veth kernel support not available >&2
- test_exit $ksft_skip
- else
- ip link del $1
- return $ksft_pass
- fi
-}
-
-test_status()
-{
- statusval=$1
- if [ $statusval -eq $ksft_fail ]; then
- echo "$2: [ FAIL ]"
- elif [ $statusval -eq $ksft_skip ]; then
- echo "$2: [ SKIPPED ]"
- elif [ $statusval -eq $ksft_pass ]; then
- echo "$2: [ PASS ]"
- fi
-}
-
-test_exit()
-{
- if [ $1 -ne 0 ]; then
- test_status $1 $(basename $0)
- fi
- exit 1
-}
-
-clear_configs()
-{
- [ $(ip link show $1 &>/dev/null; echo $?;) == 0 ] &&
- { ip link del $1; }
-}
-
-cleanup_exit()
-{
- clear_configs $1 $2
-}
-
-validate_ip_utility()
-{
- [ ! $(type -P ip) ] && { echo "'ip' not found. Skipping tests."; test_exit $ksft_skip; }
-}
-
-exec_xskxceiver()
-{
- if [[ $busy_poll -eq 1 ]]; then
- ARGS+="-b "
- fi
-
- ./${XSKOBJ} -i ${VETH0} -i ${VETH1} ${ARGS}
- retval=$?
-
- if [[ $list -ne 1 ]]; then
- test_status $retval "${TEST_NAME}"
- statusList+=($retval)
- nameList+=(${TEST_NAME})
- fi
-}
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v6 net-next 08/15] selftests: xsk: run the RX and TX endpoints in separate processes
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
` (6 preceding siblings ...)
2026-11-27 15:05 ` [PATCH v6 net-next 07/15] selftests: xsk: run one test case per xskxceiver invocation Maciej Fijalkowski
@ 2026-11-27 15:05 ` Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 09/15] selftests: xsk: send UDP over IPv4 or IPv6 between the interface MACs Maciej Fijalkowski
` (6 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:05 UTC (permalink / raw)
To: netdev
Cc: magnus.karlsson, stfomichev, kuba, pabeni, tushar.vyavahare,
kerneljasonxing, bjorn, Maciej Fijalkowski
Run the two endpoints of a test case as separate xskxceiver processes,
so that a later patch can put them on two hosts. Each process binds
only its -i interface, takes its role from -e rx|tx and talks to the
other endpoint over a TCP control channel (-p HOST -P PORT). A shadow
ifobject mirrors the local capabilities for the other side, so the
shared test code keeps working on both.
The pthreads and the barrier go away. The endpoints exchange three
fixed-size messages: READY, a barrier before each step; PROGRESS, the
packets RX consumed, so that TX does not overrun the RX UMEM; and
ABORT, which stops the peer after a failure.
The --listen endpoint listens and reports ksft_ready(), so that the
launcher starts the other one without polling the port. As in other
selftests, the control channel is not authenticated.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
tools/testing/selftests/net/lib/Makefile | 2 +-
.../testing/selftests/net/lib/xsk/test_xsk.c | 203 +++++++-----
.../testing/selftests/net/lib/xsk/test_xsk.h | 23 +-
.../testing/selftests/net/lib/xsk/xsk_peer.c | 293 ++++++++++++++++++
.../testing/selftests/net/lib/xsk/xsk_peer.h | 19 ++
.../selftests/net/lib/xsk/xskxceiver.c | 132 ++++++--
6 files changed, 557 insertions(+), 115 deletions(-)
create mode 100644 tools/testing/selftests/net/lib/xsk/xsk_peer.c
create mode 100644 tools/testing/selftests/net/lib/xsk/xsk_peer.h
diff --git a/tools/testing/selftests/net/lib/Makefile b/tools/testing/selftests/net/lib/Makefile
index 2b77d960d91a..b2f01c4e599b 100644
--- a/tools/testing/selftests/net/lib/Makefile
+++ b/tools/testing/selftests/net/lib/Makefile
@@ -44,7 +44,7 @@ $(OUTPUT)/xskxceiver: $(XSK_SRCS) $(wildcard xsk/*.h) \
$(call msg,CC,,$@)
$(Q)$(CC) -I$(top_srcdir)/tools/include $(CFLAGS) -I$(OUTPUT) \
-I$(SCRATCH_DIR)/include \
- $(XSK_SRCS) $(BPFOBJ) $(LDLIBS) -lelf -lz -lpthread -o $@
+ $(XSK_SRCS) $(BPFOBJ) $(LDLIBS) -lelf -lz -o $@
# TEST_GEN_FILES lacks xskxceiver when bpftool fails; clean it anyway.
EXTRA_CLEAN += $(OUTPUT)/xskxceiver
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c
index aaffa1b04ee4..1ce937fc8bdf 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c
@@ -2,12 +2,12 @@
#include <arpa/inet.h>
#include <bpf/bpf.h>
#include <errno.h>
+#include <limits.h>
#include <linux/bitmap.h>
#include <linux/if_link.h>
#include <linux/mman.h>
#include <linux/netdev.h>
#include <poll.h>
-#include <pthread.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/socket.h>
@@ -15,6 +15,7 @@
#include <unistd.h>
#include "test_xsk.h"
+#include "xsk_peer.h"
#include "xsk_xdp_common.h"
#include "xsk_xdp_progs.skel.h"
@@ -38,10 +39,40 @@
static const u8 g_mac[ETH_ALEN] = {0x55, 0x44, 0x33, 0x22, 0x11, 0x00};
bool opt_verbose;
-pthread_barrier_t barr;
-pthread_mutex_t pacing_mutex = PTHREAD_MUTEX_INITIALIZER;
int pkts_in_flight;
+static struct xsk_peer *ctrl_peer;
+
+void xsk_set_endpoint(struct xsk_peer *peer)
+{
+ ctrl_peer = peer;
+}
+
+static int pacing_rx_progress(u32 pkts)
+{
+ int err = xsk_peer_rx_progress(ctrl_peer, pkts);
+
+ if (err)
+ ksft_print_msg("RX control channel failed: %d (%s)\n", err,
+ strerror(-err));
+ return err;
+}
+
+static int pacing_tx_sync(void)
+{
+ int acked = xsk_peer_tx_sync(ctrl_peer);
+
+ /* Only forged reports can take pkts_in_flight below INT_MIN. */
+ if (acked > 0 && pkts_in_flight < INT_MIN + acked)
+ acked = -EPROTO;
+ if (acked < 0) {
+ ksft_print_msg("TX control channel failed: %d (%s)\n", acked,
+ strerror(-acked));
+ return acked;
+ }
+ pkts_in_flight -= acked;
+ return 0;
+}
/* The payload is a word consisting of a packet sequence number in the upper
* 16-bits and a intra packet data sequence number in the lower 16 bits. So the 3rd packet's
@@ -222,7 +253,6 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
test->current_step = 0;
test->total_steps = 1;
test->nb_sockets = 1;
- test->fail = false;
test->adjust_tail = false;
test->adjust_tail_support = false;
test->mtu = MAX_ETH_PKT_SIZE;
@@ -289,26 +319,31 @@ static void test_spec_set_xdp_prog(struct test_spec *test, struct bpf_program *x
test->xskmap_tx = xskmap_tx;
}
-static int test_spec_set_mtu(struct test_spec *test, int mtu)
+static int test_spec_set_mtu_ifobj(struct ifobject *ifobj, int mtu)
{
int err;
- if (test->ifobj_rx->mtu != mtu) {
- err = xsk_set_mtu(test->ifobj_rx->ifindex, mtu);
+ if (ifobj_is_local(ifobj) && ifobj->mtu != mtu) {
+ err = xsk_set_mtu(ifobj->ifindex, mtu);
if (err)
return err;
- test->ifobj_rx->mtu = mtu;
- }
- if (test->ifobj_tx->mtu != mtu) {
- err = xsk_set_mtu(test->ifobj_tx->ifindex, mtu);
- if (err)
- return err;
- test->ifobj_tx->mtu = mtu;
}
+ ifobj->mtu = mtu;
return 0;
}
+static int test_spec_set_mtu(struct test_spec *test, int mtu)
+{
+ int err;
+
+ err = test_spec_set_mtu_ifobj(test->ifobj_rx, mtu);
+ if (err)
+ return err;
+
+ return test_spec_set_mtu_ifobj(test->ifobj_tx, mtu);
+}
+
void pkt_stream_reset(struct pkt_stream *pkt_stream)
{
if (pkt_stream) {
@@ -939,6 +974,9 @@ static int __receive_pkts(struct test_spec *test, struct xsk_socket_info *xsk)
fds.fd = xsk_socket__fd(xsk->xsk);
fds.events = POLLIN;
+ if (pacing_rx_progress(0))
+ return TEST_FAILURE;
+
ret = kick_rx(xsk);
if (ret)
return TEST_FAILURE;
@@ -1038,9 +1076,8 @@ static int __receive_pkts(struct test_spec *test, struct xsk_socket_info *xsk)
if (ifobj->release_rx)
xsk_ring_cons__release(&xsk->rx, frags_processed);
- pthread_mutex_lock(&pacing_mutex);
- pkts_in_flight -= pkts_sent;
- pthread_mutex_unlock(&pacing_mutex);
+ if (pacing_rx_progress(pkts_sent))
+ return TEST_FAILURE;
pkts_sent = 0;
return TEST_CONTINUE;
@@ -1116,9 +1153,18 @@ static int __send_pkts(struct ifobject *ifobject, struct xsk_socket_info *xsk,
int ret;
buffer_len = pkt_get_buffer_len(umem, pkt_stream->max_pkt_len);
+ if (pacing_tx_sync())
+ return TEST_FAILURE;
+
/* pkts_in_flight might be negative if many invalid packets are sent */
if (pkts_in_flight >= (int)((umem_size(umem) - xsk->batch_size * buffer_len) /
buffer_len) && !test_timeout) {
+ /* Only RX progress reports can lower pkts_in_flight. */
+ if (xsk_peer_closed(ctrl_peer)) {
+ ksft_print_msg("ERROR: [%s] RX exited with %d packets in flight\n",
+ __func__, pkts_in_flight);
+ return TEST_FAILURE;
+ }
ret = kick_tx(xsk);
if (ret)
return TEST_FAILURE;
@@ -1200,9 +1246,7 @@ static int __send_pkts(struct ifobject *ifobject, struct xsk_socket_info *xsk,
valid_frags += nb_frags;
}
- pthread_mutex_lock(&pacing_mutex);
pkts_in_flight += valid_pkts;
- pthread_mutex_unlock(&pacing_mutex);
xsk_ring_prod__submit(&xsk->tx, i);
xsk->outstanding_tx += valid_frags;
@@ -1279,9 +1323,6 @@ static int send_pkts(struct test_spec *test, struct ifobject *ifobject)
if (ret != TEST_CONTINUE)
return ret;
- if (test->fail)
- return TEST_FAILURE;
-
if (!test->poll_tmout) {
ret = wait_for_tx_completion(&ifobject->xsk_arr[i]);
if (ret)
@@ -1600,36 +1641,57 @@ static int testapp_validate_rx_endpoint(struct test_spec *test,
return err;
}
-void *worker_testapp_validate_tx(void *arg)
+static int sync_endpoints(struct test_spec *test)
+{
+ int err = xsk_peer_ready(ctrl_peer);
+
+ if (err)
+ ksft_print_msg("Endpoint synchronization failed at step %u: %d (%s)\n",
+ test->current_step, err, strerror(-err));
+ return err;
+}
+
+int worker_testapp_validate_tx(struct test_spec *test)
{
- struct test_spec *test = (struct test_spec *)arg;
int err;
- err = testapp_validate_tx_endpoint(test, test->ifobj_tx);
+ err = sync_endpoints(test);
if (err)
- test->fail = true;
+ return err;
- pthread_exit(NULL);
+ err = testapp_validate_tx_endpoint(test, test->ifobj_tx);
+ if (err) {
+ ksft_print_msg("TX endpoint traffic failed at step %u: %d\n",
+ test->current_step, err);
+ xsk_peer_abort(ctrl_peer);
+ }
+ return err;
}
-void *worker_testapp_validate_rx(void *arg)
+int worker_testapp_validate_rx(struct test_spec *test)
{
- struct test_spec *test = (struct test_spec *)arg;
struct ifobject *ifobject = test->ifobj_rx;
int err;
err = testapp_prepare_rx_endpoint(test, ifobject);
+ if (err) {
+ ksft_print_msg("RX endpoint setup failed at step %u: %d\n",
+ test->current_step, err);
+ xsk_peer_abort(ctrl_peer);
+ return err;
+ }
- if (test->use_barrier)
- pthread_barrier_wait(&barr);
-
- /* We leave only now in case of error to avoid getting stuck in the barrier */
- if (!err)
- err = testapp_validate_rx_endpoint(test, ifobject);
+ err = sync_endpoints(test);
if (err)
- test->fail = true;
+ return err;
- pthread_exit(NULL);
+ err = testapp_validate_rx_endpoint(test, ifobject);
+ if (err) {
+ ksft_print_msg("RX endpoint traffic failed at step %u: %d\n",
+ test->current_step, err);
+ xsk_peer_abort(ctrl_peer);
+ }
+ return err;
}
static void testapp_clean_xsk_umem(struct ifobject *ifobj)
@@ -1688,13 +1750,13 @@ static int xsk_attach_xdp_progs(struct test_spec *test, struct ifobject *ifobj_r
{
int err = 0;
- if (xdp_prog_changed_rx(test)) {
+ if (ifobj_is_local(ifobj_rx) && xdp_prog_changed_rx(test)) {
err = xsk_reattach_xdp(ifobj_rx, test->xdp_prog_rx, test->xskmap_rx, test->mode);
if (err)
return err;
}
- if (!ifobj_tx)
+ if (!ifobj_tx || !ifobj_is_local(ifobj_tx))
return 0;
if (xdp_prog_changed_tx(test))
@@ -1707,7 +1769,7 @@ static void clean_sockets(struct test_spec *test, struct ifobject *ifobj)
{
u32 i;
- if (!ifobj || !test)
+ if (!ifobj || !test || !ifobj_is_local(ifobj))
return;
for (i = 0; i < test->nb_sockets; i++)
@@ -1719,15 +1781,15 @@ static void clean_umem(struct test_spec *test, struct ifobject *ifobj1, struct i
if (!ifobj1)
return;
- testapp_clean_xsk_umem(ifobj1);
- if (ifobj2)
+ if (ifobj_is_local(ifobj1))
+ testapp_clean_xsk_umem(ifobj1);
+ if (ifobj2 && ifobj_is_local(ifobj2))
testapp_clean_xsk_umem(ifobj2);
}
static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *ifobj1,
struct ifobject *ifobj2)
{
- pthread_t t0, t1;
u32 mbuf_cap;
int err;
@@ -1758,51 +1820,27 @@ static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *i
err, strerror(-err));
return TEST_FAILURE;
}
- test->use_barrier = !!ifobj2;
-
- if (test->use_barrier) {
- if (pthread_barrier_init(&barr, NULL, 2))
- return TEST_FAILURE;
+ if (ifobj2)
pkt_stream_reset(ifobj2->xsk->pkt_stream);
- }
-
test->current_step++;
pkt_stream_reset(ifobj1->xsk->pkt_stream);
pkts_in_flight = 0;
- /*Spawn RX thread */
- pthread_create(&t0, NULL, ifobj1->func_ptr, test);
-
- if (test->use_barrier) {
- pthread_barrier_wait(&barr);
- if (pthread_barrier_destroy(&barr)) {
- test->use_barrier = false;
- pthread_join(t0, NULL);
- clean_sockets(test, ifobj1);
- clean_umem(test, ifobj1, NULL);
- return TEST_FAILURE;
- }
- }
-
- if (ifobj2) {
- /*Spawn TX thread */
- pthread_create(&t1, NULL, ifobj2->func_ptr, test);
- pthread_join(t1, NULL);
- }
-
- pthread_join(t0, NULL);
-
- if (test->total_steps == test->current_step || test->fail) {
+ /* In a one-sided step, the idle endpoint only keeps in step. */
+ if (ifobj_is_local(ifobj1))
+ err = ifobj1->func_ptr(test);
+ else if (ifobj2 && ifobj_is_local(ifobj2))
+ err = ifobj2->func_ptr(test);
+ else
+ err = sync_endpoints(test);
+ if (test->total_steps == test->current_step || err) {
clean_sockets(test, ifobj1);
clean_sockets(test, ifobj2);
clean_umem(test, ifobj1, ifobj2);
}
- if (test->fail)
- return TEST_FAILURE;
-
- return TEST_PASS;
+ return err ? TEST_FAILURE : TEST_PASS;
}
static int testapp_validate_traffic(struct test_spec *test)
@@ -1841,7 +1879,7 @@ int testapp_teardown(struct test_spec *test)
static void swap_directions(struct ifobject **ifobj1, struct ifobject **ifobj2)
{
- thread_func_t tmp_func_ptr = (*ifobj1)->func_ptr;
+ test_func_t tmp_func_ptr = (*ifobj1)->func_ptr;
struct ifobject *tmp_ifobj = (*ifobj1);
(*ifobj1)->func_ptr = (*ifobj2)->func_ptr;
@@ -1880,6 +1918,9 @@ static int swap_xsk_resources(struct test_spec *test)
test->ifobj_tx->xsk = &test->ifobj_tx->xsk_arr[1];
test->ifobj_rx->xsk = &test->ifobj_rx->xsk_arr[1];
+ if (!ifobj_is_local(test->ifobj_rx))
+ return TEST_PASS;
+
ret = xsk_update_xskmap(test->ifobj_rx->xskmap, test->ifobj_rx->xsk->xsk, 0);
if (ret)
return TEST_FAILURE;
@@ -2228,7 +2269,7 @@ int testapp_too_many_frags(struct test_spec *test)
return ret;
}
-static int xsk_load_xdp_programs(struct ifobject *ifobj)
+int xsk_load_xdp_programs(struct ifobject *ifobj)
{
ifobj->xdp_progs = xsk_xdp_progs__open_and_load();
if (libbpf_get_error(ifobj->xdp_progs))
@@ -2284,12 +2325,10 @@ static int detect_ifobj_caps(struct ifobject *ifobj)
return 0;
}
-int init_iface(struct ifobject *ifobj, thread_func_t func_ptr)
+int init_iface(struct ifobject *ifobj)
{
int err;
- ifobj->func_ptr = func_ptr;
-
err = xsk_load_xdp_programs(ifobj);
if (err) {
ksft_print_msg("Error loading XDP program\n");
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.h b/tools/testing/selftests/net/lib/xsk/test_xsk.h
index 8503ef055d37..f1fafae2d140 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.h
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.h
@@ -77,9 +77,13 @@ enum test_mode {
struct ifobject;
struct test_spec;
typedef int (*validation_func_t)(struct ifobject *ifobj);
-typedef void *(*thread_func_t)(void *arg);
typedef int (*test_func_t)(struct test_spec *test);
+struct xsk_peer;
+
+/* The control channel to the other endpoint. */
+void xsk_set_endpoint(struct xsk_peer *peer);
+
struct xsk_socket_info {
struct xsk_ring_cons rx;
struct xsk_ring_prod tx;
@@ -132,7 +136,7 @@ struct ifobject {
struct xsk_caps caps;
struct xsk_socket_info *xsk;
struct xsk_socket_info *xsk_arr;
- thread_func_t func_ptr;
+ test_func_t func_ptr;
validation_func_t validation_func;
struct xsk_xdp_progs *xdp_progs;
struct bpf_map *xskmap;
@@ -161,11 +165,18 @@ static inline void ifobj_set_cap(struct ifobject *ifobj, u32 cap)
ifobj->caps.flags |= cap;
}
+/* The shadow of the peer's ifobject is never bound to an interface. */
+static inline bool ifobj_is_local(const struct ifobject *ifobj)
+{
+ return ifobj->ifindex;
+}
+
#define xsk_get_cap(test, cap) ((test)->ifobj_tx->caps.cap)
struct ifobject *ifobject_create(void);
void ifobject_delete(struct ifobject *ifobj);
-int init_iface(struct ifobject *ifobj, thread_func_t func_ptr);
+int init_iface(struct ifobject *ifobj);
+int xsk_load_xdp_programs(struct ifobject *ifobj);
u32 mode_to_xdp_flags(enum test_mode mode);
int xsk_configure_umem(struct ifobject *ifobj, struct xsk_umem_info *umem, void *buffer, u64 size);
@@ -215,11 +226,9 @@ struct test_spec {
u16 total_steps;
u16 current_step;
u16 nb_sockets;
- bool fail;
bool adjust_tail;
bool adjust_tail_support;
bool poll_tmout;
- bool use_barrier;
enum test_mode mode;
char name[MAX_TEST_NAME_SIZE];
};
@@ -280,8 +289,8 @@ int testapp_xdp_metadata_mb(struct test_spec *test);
int testapp_xdp_prog_cleanup(struct test_spec *test);
int testapp_xdp_shared_umem(struct test_spec *test);
-void *worker_testapp_validate_rx(void *arg);
-void *worker_testapp_validate_tx(void *arg);
+int worker_testapp_validate_rx(struct test_spec *test);
+int worker_testapp_validate_tx(struct test_spec *test);
static const struct test_spec tests[] = {
{.name = "SEND_RECEIVE", .test_func = testapp_send_receive},
diff --git a/tools/testing/selftests/net/lib/xsk/xsk_peer.c b/tools/testing/selftests/net/lib/xsk/xsk_peer.c
new file mode 100644
index 000000000000..3ff9d82aaf49
--- /dev/null
+++ b/tools/testing/selftests/net/lib/xsk/xsk_peer.c
@@ -0,0 +1,293 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <arpa/inet.h>
+#include <errno.h>
+#include <limits.h>
+#include <netdb.h>
+#include <netinet/tcp.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+#include "../ksft.h"
+#include "xsk_peer.h"
+
+#define XSK_PEER_MAGIC 0x58534b50
+#define XSK_PEER_ACCEPT_TMOUT_MS 10000
+
+/*
+ * One case per connection; the launcher owns the verdict. As with the control
+ * channels of other selftests, the test hosts are trusted: nothing
+ * authenticates the peer.
+ */
+enum xsk_peer_msg_type {
+ XSK_PEER_READY = 1,
+ XSK_PEER_PROGRESS,
+ XSK_PEER_ABORT,
+};
+
+struct xsk_peer_msg {
+ u32 magic;
+ u32 type;
+ u32 pkts;
+};
+
+struct xsk_peer {
+ int fd;
+ u32 acked;
+ bool ready_seen;
+ bool closed;
+};
+
+static int io_full(int fd, void *buf, size_t len, bool write_op)
+{
+ size_t done = 0;
+ ssize_t ret;
+
+ while (done < len) {
+ if (write_op)
+ ret = send(fd, (char *)buf + done, len - done, MSG_NOSIGNAL);
+ else
+ ret = read(fd, (char *)buf + done, len - done);
+ if (ret < 0 && errno == EINTR)
+ continue;
+ if (ret < 0)
+ return -errno;
+ if (!ret)
+ return -EPIPE;
+ done += ret;
+ }
+ return 0;
+}
+
+/*
+ * Past its last barrier the peer may exit at any time, and it resets the
+ * connection if our progress reports are still unread.
+ */
+static bool peer_gone(int err)
+{
+ return err == -EPIPE || err == -ECONNRESET;
+}
+
+static int peer_send(struct xsk_peer *peer, u32 type, u32 pkts)
+{
+ struct xsk_peer_msg msg = {
+ .magic = htonl(XSK_PEER_MAGIC),
+ .type = htonl(type),
+ .pkts = htonl(pkts),
+ };
+
+ return io_full(peer->fd, &msg, sizeof(msg), true);
+}
+
+static int peer_recv_one(struct xsk_peer *peer)
+{
+ struct xsk_peer_msg msg;
+ u32 pkts;
+ int err;
+
+ err = io_full(peer->fd, &msg, sizeof(msg), false);
+ if (peer_gone(err))
+ peer->closed = true;
+ if (err)
+ return err;
+ if (ntohl(msg.magic) != XSK_PEER_MAGIC)
+ return -EPROTO;
+
+ switch (ntohl(msg.type)) {
+ case XSK_PEER_READY:
+ /* The peer waits for our READY, so it is at most one step ahead. */
+ if (peer->ready_seen)
+ return -EPROTO;
+ peer->ready_seen = true;
+ return 0;
+ case XSK_PEER_PROGRESS:
+ /* xsk_peer_tx_sync() returns the sum as an int. */
+ pkts = ntohl(msg.pkts);
+ if (pkts > INT_MAX - peer->acked)
+ return -EPROTO;
+ peer->acked += pkts;
+ return 0;
+ case XSK_PEER_ABORT:
+ return -ECANCELED;
+ default:
+ return -EPROTO;
+ }
+}
+
+/*
+ * Consume what the peer has sent so far without blocking. A closed connection
+ * is not an error here, see peer_gone(); xsk_peer_closed() reports it.
+ */
+static int peer_drain(struct xsk_peer *peer)
+{
+ struct pollfd pfd = { .fd = peer->fd, .events = POLLIN };
+ int ret;
+
+ while (!peer->closed) {
+ ret = poll(&pfd, 1, 0);
+ if (ret < 0 && errno == EINTR)
+ continue;
+ if (ret < 0)
+ return -errno;
+ if (!ret)
+ break;
+ ret = peer_recv_one(peer);
+ if (ret && !peer->closed)
+ return ret;
+ }
+ return 0;
+}
+
+/* Return once both endpoints are set up for the next step. */
+int xsk_peer_ready(struct xsk_peer *peer)
+{
+ int err;
+
+ err = peer_send(peer, XSK_PEER_READY, 0);
+ while (!err && !peer->ready_seen)
+ err = peer_recv_one(peer);
+ if (err)
+ return err;
+
+ /* TCP ordering puts all progress of the previous step before READY. */
+ peer->ready_seen = false;
+ peer->acked = 0;
+ return 0;
+}
+
+void xsk_peer_abort(struct xsk_peer *peer)
+{
+ if (peer && !peer->closed)
+ peer_send(peer, XSK_PEER_ABORT, 0);
+}
+
+int xsk_peer_rx_progress(struct xsk_peer *peer, u32 pkts)
+{
+ int err;
+
+ if (pkts && !peer->closed) {
+ err = peer_send(peer, XSK_PEER_PROGRESS, pkts);
+ /*
+ * Leave closed to peer_drain(), which first reads what the
+ * peer sent before it went away, such as an ABORT.
+ */
+ if (err && !peer_gone(err))
+ return err;
+ }
+ return peer_drain(peer);
+}
+
+/* Return the packets RX reported consumed since the last call, or -errno. */
+int xsk_peer_tx_sync(struct xsk_peer *peer)
+{
+ int err = peer_drain(peer);
+ u32 acked = peer->acked;
+
+ if (err)
+ return err;
+ peer->acked = 0;
+ return acked;
+}
+
+bool xsk_peer_closed(struct xsk_peer *peer)
+{
+ return peer->closed;
+}
+
+static int accept_tmout(int lfd)
+{
+ struct pollfd pfd = { .fd = lfd, .events = POLLIN };
+ int ret;
+
+ do {
+ ret = poll(&pfd, 1, XSK_PEER_ACCEPT_TMOUT_MS);
+ } while (ret < 0 && errno == EINTR);
+ if (!ret)
+ errno = ETIMEDOUT;
+ return ret > 0 ? accept(lfd, NULL, NULL) : -1;
+}
+
+/*
+ * The listener tells the launcher with ksft_ready() once it listens, and the
+ * launcher starts the connector only then, so connect() needs no retry.
+ * accept() is bounded in case the connector exits before it gets that far.
+ */
+static int peer_open_tcp(const char *host, const char *port, bool listen_side)
+{
+ struct addrinfo hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_socktype = SOCK_STREAM,
+ .ai_flags = AI_NUMERICSERV,
+ };
+ int fd = -1, lfd, saved = ECONNREFUSED, one = 1, err;
+ struct addrinfo *res, *ai;
+
+ err = getaddrinfo(host, port, &hints, &res);
+ if (err)
+ return -EINVAL;
+
+ if (!listen_side)
+ goto conn;
+
+ for (ai = res; ai; ai = ai->ai_next) {
+ lfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
+ if (lfd < 0)
+ continue;
+ setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
+ if (!bind(lfd, ai->ai_addr, ai->ai_addrlen) && !listen(lfd, 1)) {
+ ksft_ready();
+ fd = accept_tmout(lfd);
+ saved = errno;
+ close(lfd);
+ break;
+ }
+ saved = errno;
+ close(lfd);
+ }
+ freeaddrinfo(res);
+ return fd >= 0 ? fd : -saved;
+
+conn:
+ for (ai = res; ai; ai = ai->ai_next) {
+ fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
+ if (fd < 0)
+ continue;
+ if (!connect(fd, ai->ai_addr, ai->ai_addrlen))
+ break;
+ saved = errno;
+ close(fd);
+ fd = -1;
+ }
+ freeaddrinfo(res);
+ return fd >= 0 ? fd : -saved;
+}
+
+struct xsk_peer *xsk_peer_open(const char *host, const char *port,
+ bool listen_side)
+{
+ int fd = peer_open_tcp(host, port, listen_side);
+ struct xsk_peer *peer;
+ int one = 1;
+
+ if (fd < 0) {
+ errno = -fd;
+ return NULL;
+ }
+ peer = calloc(1, sizeof(*peer));
+ if (!peer) {
+ close(fd);
+ return NULL;
+ }
+ peer->fd = fd;
+ setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
+ return peer;
+}
+
+void xsk_peer_close(struct xsk_peer *peer)
+{
+ if (peer) {
+ close(peer->fd);
+ free(peer);
+ }
+}
diff --git a/tools/testing/selftests/net/lib/xsk/xsk_peer.h b/tools/testing/selftests/net/lib/xsk/xsk_peer.h
new file mode 100644
index 000000000000..da4462192994
--- /dev/null
+++ b/tools/testing/selftests/net/lib/xsk/xsk_peer.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef XSK_PEER_H_
+#define XSK_PEER_H_
+
+#include <linux/types.h>
+
+struct xsk_peer;
+
+struct xsk_peer *xsk_peer_open(const char *host, const char *port,
+ bool listen_side);
+void xsk_peer_close(struct xsk_peer *peer);
+
+int xsk_peer_ready(struct xsk_peer *peer);
+void xsk_peer_abort(struct xsk_peer *peer);
+int xsk_peer_rx_progress(struct xsk_peer *peer, u32 pkts);
+int xsk_peer_tx_sync(struct xsk_peer *peer);
+bool xsk_peer_closed(struct xsk_peer *peer);
+
+#endif /* XSK_PEER_H_ */
diff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.c b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
index 42fb3149ca6b..7f6ef07e5bf5 100644
--- a/tools/testing/selftests/net/lib/xsk/xskxceiver.c
+++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
@@ -6,9 +6,9 @@
* Linux kernel samples/bpf/xdpsock* and modified
* for use.
*
- * This test program contains two threads, each thread is single socket with
- * a unique UMEM. It validates in-order packet delivery and packet content
- * by sending packets to each other.
+ * Each instance of this test program runs one endpoint, Tx or Rx, with a
+ * single socket and a unique UMEM. Two instances validate in-order packet
+ * delivery and packet content by sending packets to each other.
*
* Tests Information:
* ------------------
@@ -54,12 +54,15 @@
*
* Flow:
* -----
- * - Single process spawns two threads: Tx and Rx
- * - Each of these two threads attach to a veth interface
- * - Each thread creates one AF_XDP socket connected to a unique umem for each
+ * - Two processes run the test: Tx and Rx
+ * - Each of these two processes attach to a veth interface
+ * - Each process creates one AF_XDP socket connected to a unique umem for each
* veth interface
- * - Tx thread Transmits a number of packets from veth<xxxx> to veth<yyyy>
- * - Rx thread verifies if all packets were received and delivered in-order,
+ * - One process listens on a TCP control port (--listen), the other one
+ * connects to it and the two synchronize each test step over that
+ * connection
+ * - Tx process Transmits a number of packets from veth<xxxx> to veth<yyyy>
+ * - Rx process verifies if all packets were received and delivered in-order,
* and have the right content
*/
@@ -84,6 +87,7 @@
#include <sys/types.h>
#include "test_xsk.h"
+#include "xsk_peer.h"
#include "xsk_xdp_progs.skel.h"
#include "xsk.h"
#include "xskxceiver.h"
@@ -92,8 +96,23 @@
#include "kselftest.h"
#include "xsk_xdp_common.h"
+enum xsk_endpoint_role {
+ XSK_ENDPOINT_NONE,
+ XSK_ENDPOINT_RX,
+ XSK_ENDPOINT_TX,
+};
+
static enum test_mode opt_mode = TEST_MODE_ALL;
static u32 opt_run_test = RUN_ALL_TESTS;
+static enum xsk_endpoint_role opt_endpoint_role = XSK_ENDPOINT_NONE;
+static bool opt_listen;
+static const char *opt_peer_host;
+static const char *opt_peer_port;
+static const char *opt_ifname;
+
+enum {
+ OPT_LISTEN = 256,
+};
static void __exit_with_error(int error, const char *file, const char *func, int line)
{
@@ -154,6 +173,10 @@ static struct option long_options[] = {
{"mode", required_argument, 0, 'm'},
{"list", no_argument, 0, 'l'},
{"test", required_argument, 0, 't'},
+ {"endpoint", required_argument, 0, 'e'},
+ {"peer", required_argument, 0, 'p'},
+ {"peer-port", required_argument, 0, 'P'},
+ {"listen", no_argument, 0, OPT_LISTEN},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
@@ -161,7 +184,7 @@ static struct option long_options[] = {
static void print_usage(char **argv)
{
const char *str =
- " Usage: %s -i TX_IFACE -i RX_IFACE -m MODE -t TEST [OPTIONS]\n"
+ " Usage: %s -i IFACE -e rx|tx -m MODE -t TEST -p HOST -P PORT [OPTIONS]\n"
" Options:\n"
" -i, --interface Use interface\n"
" -v, --verbose Verbose output\n"
@@ -169,16 +192,19 @@ static void print_usage(char **argv)
" -m, --mode Mode to run: skb, drv or zc\n"
" -l, --list List all available tests\n"
" -t, --test Test case to run, a number from -l\n"
+ " -e, --endpoint Role of this endpoint: rx or tx\n"
+ " -p, --peer Control host: IPv4/IPv6 address or hostname\n"
+ " -P, --peer-port Control TCP port\n"
+ " --listen Listen on the control port instead of connecting\n"
" -h, --help Display this help and exit\n";
ksft_print_msg(str, basename(argv[0]));
ksft_exit_xfail();
}
-static void bind_iface(struct ifobject *ifobj, const char *ifname, thread_func_t func,
- char **argv)
+static void bind_iface(struct ifobject *ifobj, const char *ifname, char **argv)
{
- size_t len = ifname ? strlen(ifname) : 0;
+ size_t len = strlen(ifname);
if (!len || len >= sizeof(ifobj->ifname))
print_usage(argv);
@@ -190,7 +216,7 @@ static void bind_iface(struct ifobject *ifobj, const char *ifname, thread_func_t
ksft_exit_fail();
}
- if (init_iface(ifobj, func)) {
+ if (init_iface(ifobj)) {
ksft_print_msg("Error: cannot initialize interface %s\n", ifobj->ifname);
ksft_exit_fail();
}
@@ -208,23 +234,18 @@ static void print_tests(void)
static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj_rx, int argc,
char **argv)
{
- const char *ifname[2] = {};
- u32 interface_nb = 0;
int option_index, c;
opterr = 0;
for (;;) {
- c = getopt_long(argc, argv, "i:vbm:lt:", long_options, &option_index);
+ c = getopt_long(argc, argv, "i:vbm:lt:e:p:P:", long_options, &option_index);
if (c == -1)
break;
switch (c) {
case 'i':
- if (interface_nb >= ARRAY_SIZE(ifname))
- break;
-
- ifname[interface_nb++] = optarg;
+ opt_ifname = optarg;
break;
case 'v':
opt_verbose = true;
@@ -253,17 +274,33 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
if (errno)
print_usage(argv);
break;
+ case 'e':
+ if (!strcmp(optarg, "rx"))
+ opt_endpoint_role = XSK_ENDPOINT_RX;
+ else if (!strcmp(optarg, "tx"))
+ opt_endpoint_role = XSK_ENDPOINT_TX;
+ else
+ print_usage(argv);
+ break;
+ case 'p':
+ opt_peer_host = optarg;
+ break;
+ case 'P':
+ opt_peer_port = optarg;
+ break;
+ case OPT_LISTEN:
+ opt_listen = true;
+ break;
case 'h':
default:
print_usage(argv);
}
}
- if (opt_run_test == RUN_ALL_TESTS || opt_mode == TEST_MODE_ALL)
+ if (!opt_ifname || opt_endpoint_role == XSK_ENDPOINT_NONE || !opt_peer_host ||
+ !*opt_peer_host || !opt_peer_port || opt_run_test == RUN_ALL_TESTS ||
+ opt_mode == TEST_MODE_ALL)
print_usage(argv);
-
- bind_iface(ifobj_tx, ifname[0], worker_testapp_validate_tx, argv);
- bind_iface(ifobj_rx, ifname[1], worker_testapp_validate_rx, argv);
}
static void xsk_unload_xdp_programs(struct ifobject *ifobj)
@@ -349,17 +386,46 @@ static bool mode_supported(enum test_mode mode, u32 caps)
static void cleanup_iface(struct ifobject *ifobj)
{
+ /* A peer shadow has a skeleton but no bound interface. */
+ if (!ifobj_is_local(ifobj))
+ goto unload;
+
if (ifobj->xdp_prog)
xsk_detach_xdp_program(ifobj->ifindex,
mode_to_xdp_flags(ifobj->mode));
+unload:
xsk_unload_xdp_programs(ifobj);
}
+/* Connect the two endpoints without negotiating the remote NIC's capabilities. */
+static int setup_peer(struct ifobject *local, struct ifobject *shadow,
+ struct xsk_peer **peer)
+{
+ /* Once BIDIRECTIONAL swaps the directions, the local side attaches the
+ * shadow's programs, so the shadow needs a skeleton of its own.
+ */
+ if (xsk_load_xdp_programs(shadow))
+ return TEST_FAILURE;
+
+ *peer = xsk_peer_open(opt_peer_host, opt_peer_port, opt_listen);
+ if (!*peer) {
+ ksft_print_msg("Failed to connect XSK peer: %s\n", strerror(errno));
+ return TEST_FAILURE;
+ }
+
+ shadow->caps = local->caps;
+ xsk_set_endpoint(*peer);
+ return TEST_PASS;
+}
+
int main(int argc, char **argv)
{
u32 cache_line_size, max_frags, umem_tailroom;
const size_t total_tests = ARRAY_SIZE(tests);
struct ifobject *ifobj_tx, *ifobj_rx;
+ struct ifobject *shadow_ifobj;
+ struct ifobject *local_ifobj;
+ struct xsk_peer *peer = NULL;
struct test_spec test = {};
int ret = TEST_FAILURE;
u32 caps;
@@ -406,12 +472,26 @@ int main(int argc, char **argv)
ksft_exit_xfail();
}
+ /* swap_directions() swaps the workers, so the shadow needs one too. */
+ ifobj_tx->func_ptr = worker_testapp_validate_tx;
+ ifobj_rx->func_ptr = worker_testapp_validate_rx;
+ if (opt_endpoint_role == XSK_ENDPOINT_TX) {
+ local_ifobj = ifobj_tx;
+ shadow_ifobj = ifobj_rx;
+ } else {
+ local_ifobj = ifobj_rx;
+ shadow_ifobj = ifobj_tx;
+ }
+ bind_iface(local_ifobj, opt_ifname, argv);
+ caps = detect_mode_caps(local_ifobj);
+
test.tx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);
test.rx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);
if (!test.tx_pkt_stream_default || !test.rx_pkt_stream_default)
goto out;
- caps = detect_mode_caps(ifobj_tx);
+ if (setup_peer(local_ifobj, shadow_ifobj, &peer))
+ goto out;
if (!mode_supported(opt_mode, caps)) {
if (opt_mode == TEST_MODE_DRV)
@@ -427,8 +507,10 @@ int main(int argc, char **argv)
ret = run_pkt_test(&test);
out:
+ xsk_set_endpoint(NULL);
cleanup_iface(ifobj_tx);
cleanup_iface(ifobj_rx);
+ xsk_peer_close(peer);
pkt_stream_delete(test.tx_pkt_stream_default);
pkt_stream_delete(test.rx_pkt_stream_default);
ifobject_delete(ifobj_tx);
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v6 net-next 09/15] selftests: xsk: send UDP over IPv4 or IPv6 between the interface MACs
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
` (7 preceding siblings ...)
2026-11-27 15:05 ` [PATCH v6 net-next 08/15] selftests: xsk: run the RX and TX endpoints in separate processes Maciej Fijalkowski
@ 2026-11-27 15:05 ` Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 10/15] selftests: xsk: prepare xskxceiver for endpoints on two hosts Maciej Fijalkowski
` (5 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:05 UTC (permalink / raw)
To: netdev
Cc: magnus.karlsson, stfomichev, kuba, pabeni, tushar.vyavahare,
kerneljasonxing, bjorn, Maciej Fijalkowski
xskxceiver sends loopback-ethertype frames between made-up MAC
addresses, and its XDP programs redirect every frame to the XSKMAP.
That works on veth, but on a physical link the peer NIC filters out the
made-up addresses, and the programs take neighbour discovery, LLDP or
SSH away from the stack.
Send UDP over IPv4 or IPv6 between the interface MACs instead, with the
flow given by --src-ip, --dst-ip, --dst-mac and --udp-port; the caller
steers it to the bound queue. The XDP programs redirect only UDP to the
test port and pass the rest, and XDP_SHARED_UMEM picks the socket by
UDP source port rather than by destination MAC. PKT_HDR_SIZE and
MIN_PKT_SIZE now stand for variables set by xsk_set_flow(), so the
smallest packet grows to 64 bytes over IPv4 and 88 over IPv6.
Also have is_frag_valid() reject a fragment too short for the words it
reads, pkt_dump() print only within the given length, and
write_payload() zero the bytes after the last full word, which the IPv6
checksum covers.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
.../testing/selftests/net/lib/xsk/test_xsk.c | 212 +++++++++++++++---
.../testing/selftests/net/lib/xsk/test_xsk.h | 7 +-
tools/testing/selftests/net/lib/xsk/xsk.c | 26 +++
tools/testing/selftests/net/lib/xsk/xsk.h | 1 +
.../selftests/net/lib/xsk/xsk_xdp_common.h | 3 +-
.../selftests/net/lib/xsk/xsk_xdp_progs.bpf.c | 91 +++++++-
.../selftests/net/lib/xsk/xskxceiver.c | 56 ++++-
7 files changed, 353 insertions(+), 43 deletions(-)
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c
index 1ce937fc8bdf..b0ed41b40f82 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c
@@ -3,10 +3,14 @@
#include <bpf/bpf.h>
#include <errno.h>
#include <limits.h>
+#include <linux/align.h>
#include <linux/bitmap.h>
#include <linux/if_link.h>
#include <linux/mman.h>
#include <linux/netdev.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <linux/udp.h>
#include <poll.h>
#include <string.h>
#include <sys/mman.h>
@@ -20,14 +24,14 @@
#include "xsk_xdp_progs.skel.h"
#define DEFAULT_BATCH_SIZE 64
-#define MIN_PKT_SIZE 64
+/* Payload of the smallest packet, which is 64 bytes over IPv4 */
+#define MIN_PAYLOAD_SIZE 20
#define MAX_ETH_JUMBO_SIZE 9000
#define MAX_INTERFACES 2
#define MAX_TEARDOWN_ITER 10
#define MAX_TX_BUDGET_DEFAULT 32
#define PKT_DUMP_NB_TO_PRINT 16
-/* Just to align the data in the packet */
-#define PKT_HDR_SIZE (sizeof(struct ethhdr) + 2)
+#define PKT_HDR_SIZE pkt_hdr_size
#define POLL_TMOUT 1000
#define THREAD_TMOUT 3
#define UMEM_HEADROOM_TEST_SIZE 128
@@ -36,9 +40,17 @@
#define XSK_UMEM__LARGE_FRAME_SIZE (3 * 1024)
#define XSK_UMEM__MAX_FRAME_SIZE (4 * 1024)
-static const u8 g_mac[ETH_ALEN] = {0x55, 0x44, 0x33, 0x22, 0x11, 0x00};
+/* The test flow, UDP over IPv4 or IPv6 */
+static int flow_family;
+static union {
+ struct in_addr v4;
+ struct in6_addr v6;
+} flow_src, flow_dst;
+static u16 udp_port;
+static u32 pkt_hdr_size;
bool opt_verbose;
+int min_pkt_size;
int pkts_in_flight;
static struct xsk_peer *ctrl_peer;
@@ -80,19 +92,132 @@ static int pacing_tx_sync(void)
*/
static void write_payload(void *dest, u32 pkt_nb, u32 start, u32 size)
{
- u32 *ptr = (u32 *)dest, i;
+ u32 *ptr = (u32 *)dest, i, words = size / sizeof(*ptr);
start /= sizeof(*ptr);
- size /= sizeof(*ptr);
- for (i = 0; i < size; i++)
+ for (i = 0; i < words; i++)
ptr[i] = htonl(pkt_nb << 16 | (i + start));
+ /* The UDP checksum counts a partial last word as zero. */
+ memset(ptr + words, 0, size % sizeof(*ptr));
}
-static void gen_eth_hdr(struct xsk_socket_info *xsk, struct ethhdr *eth_hdr)
+int xsk_set_flow(const char *src_ip, const char *dst_ip, u16 port)
{
+ u32 ip_hdr_size;
+
+ if (inet_pton(AF_INET, src_ip, &flow_src) == 1 &&
+ inet_pton(AF_INET, dst_ip, &flow_dst) == 1) {
+ flow_family = AF_INET;
+ ip_hdr_size = sizeof(struct iphdr);
+ } else if (inet_pton(AF_INET6, src_ip, &flow_src) == 1 &&
+ inet_pton(AF_INET6, dst_ip, &flow_dst) == 1) {
+ flow_family = AF_INET6;
+ ip_hdr_size = sizeof(struct ipv6hdr);
+ } else {
+ return -EINVAL;
+ }
+ if (!port)
+ return -EINVAL;
+
+ udp_port = port;
+ pkt_hdr_size = sizeof(struct ethhdr) + ip_hdr_size +
+ sizeof(struct udphdr) + PKT_HDR_PAD;
+ /* A multiple of 8, so that a packet that a case puts MIN_PKT_SIZE / 2
+ * before a boundary keeps its payload 4-byte aligned.
+ */
+ min_pkt_size = ALIGN(pkt_hdr_size + MIN_PAYLOAD_SIZE, 8);
+ return 0;
+}
+
+/* Add up buf as big-endian 16-bit words, len being even. */
+static u32 csum_add(u32 sum, const void *buf, size_t len)
+{
+ const u8 *pos = buf;
+
+ for (; len > 1; len -= 2, pos += 2)
+ sum += pos[0] << 8 | pos[1];
+ return sum;
+}
+
+static u16 csum_fold(u32 sum)
+{
+ while (sum >> 16)
+ sum = (sum & 0xffff) + (sum >> 16);
+ return htons((u16)~sum);
+}
+
+/* The sum of the payload of len bytes that write_payload() writes: each
+ * word holds pkt_nb and the index of the word in its two 16-bit halves.
+ */
+static u32 payload_csum(u32 pkt_nb, u32 len)
+{
+ u32 words = len / sizeof(u32);
+
+ return words * (pkt_nb & 0xffff) + words * (words - 1) / 2;
+}
+
+static u16 udp6_csum(const struct ipv6hdr *ip6, const struct udphdr *udp, u32 pkt_nb)
+{
+ u32 len = ntohs(udp->len), sum;
+
+ sum = csum_add(0, &ip6->saddr, sizeof(ip6->saddr));
+ sum = csum_add(sum, &ip6->daddr, sizeof(ip6->daddr));
+ sum += len + IPPROTO_UDP;
+ sum = csum_add(sum, udp, sizeof(*udp));
+ /* The pad in front of the payload is zero. */
+ sum += payload_csum(pkt_nb, len - sizeof(*udp) - PKT_HDR_PAD);
+ return csum_fold(sum) ?: 0xffff;
+}
+
+static void gen_pkt_hdr(struct xsk_socket_info *xsk, void *data, u32 pkt_nb, u32 total_len)
+{
+ u32 ip_len = total_len - sizeof(struct ethhdr);
+ struct ethhdr *eth_hdr = data;
+ struct udphdr udp = {
+ .source = htons(xsk->src_port),
+ .dest = htons(udp_port),
+ };
+ void *ptr = eth_hdr + 1;
+
memcpy(eth_hdr->h_dest, xsk->dst_mac, ETH_ALEN);
memcpy(eth_hdr->h_source, xsk->src_mac, ETH_ALEN);
- eth_hdr->h_proto = htons(ETH_P_LOOPBACK);
+
+ if (flow_family == AF_INET6) {
+ struct ipv6hdr ip6 = {
+ .version = 6,
+ .payload_len = htons(ip_len - sizeof(ip6)),
+ .nexthdr = IPPROTO_UDP,
+ .hop_limit = 64,
+ .saddr = flow_src.v6,
+ .daddr = flow_dst.v6,
+ };
+
+ eth_hdr->h_proto = htons(ETH_P_IPV6);
+ udp.len = ip6.payload_len;
+ udp.check = udp6_csum(&ip6, &udp, pkt_nb);
+ memcpy(ptr, &ip6, sizeof(ip6));
+ ptr += sizeof(ip6);
+ } else {
+ /* Without a checksum, which UDP over IPv4 does not require */
+ struct iphdr ip = {
+ .version = 4,
+ .ihl = 5,
+ .ttl = 64,
+ .protocol = IPPROTO_UDP,
+ .tot_len = htons(ip_len),
+ .saddr = flow_src.v4.s_addr,
+ .daddr = flow_dst.v4.s_addr,
+ };
+
+ eth_hdr->h_proto = htons(ETH_P_IP);
+ udp.len = htons(ip_len - sizeof(ip));
+ ip.check = csum_fold(csum_add(0, &ip, sizeof(ip)));
+ memcpy(ptr, &ip, sizeof(ip));
+ ptr += sizeof(ip);
+ }
+
+ memcpy(ptr, &udp, sizeof(udp));
+ memset(ptr + sizeof(udp), 0, PKT_HDR_PAD);
}
u32 mode_to_xdp_flags(enum test_mode mode)
@@ -207,6 +332,7 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
for (i = 0; i < MAX_INTERFACES; i++) {
struct ifobject *ifobj = i ? ifobj_rx : ifobj_tx;
+ struct ifobject *peer = i ? ifobj_tx : ifobj_rx;
struct xsk_umem_info *umem;
ifobj->xsk = &ifobj->xsk_arr[0];
@@ -238,10 +364,10 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
else
xsk->pkt_stream = test->rx_pkt_stream_default;
- memcpy(xsk->src_mac, g_mac, ETH_ALEN);
- memcpy(xsk->dst_mac, g_mac, ETH_ALEN);
- xsk->src_mac[5] += ((j * 2) + 0);
- xsk->dst_mac[5] += ((j * 2) + 1);
+ memcpy(xsk->src_mac, ifobj->caps.mac, ETH_ALEN);
+ memcpy(xsk->dst_mac, peer->caps.mac, ETH_ALEN);
+ /* xsk_xdp_shared_umem() picks the socket by it. */
+ xsk->src_port = udp_port + j;
}
ifobj->xsk->umem->num_frames = DEFAULT_UMEM_BUFFERS;
@@ -442,6 +568,19 @@ static u32 pkt_nb_frags(u32 frame_size, struct pkt_stream *pkt_stream, struct pk
return nb_frags;
}
+/* A verbatim stream has one entry per descriptor, so add up the packet's. */
+static u32 pkt_total_len(struct pkt_stream *pkt_stream, struct pkt *pkt, u32 nb_frags)
+{
+ u32 i, len = 0;
+
+ if (!pkt_stream->verbatim)
+ return pkt->len;
+
+ for (i = 0; i < nb_frags; i++)
+ len += pkt[i].len;
+ return len;
+}
+
static bool set_pkt_valid(int offset, u32 len)
{
return len <= MAX_ETH_JUMBO_SIZE;
@@ -626,7 +765,7 @@ static void pkt_stream_cancel(struct pkt_stream *pkt_stream)
}
static void pkt_generate(struct xsk_socket_info *xsk, struct xsk_umem_info *umem, u64 addr, u32 len,
- u32 pkt_nb, u32 bytes_written)
+ u32 total_len, u32 pkt_nb, u32 bytes_written)
{
void *data = xsk_umem__get_data(umem->buffer, addr);
@@ -634,7 +773,7 @@ static void pkt_generate(struct xsk_socket_info *xsk, struct xsk_umem_info *umem
return;
if (!bytes_written) {
- gen_eth_hdr(xsk, data);
+ gen_pkt_hdr(xsk, data, pkt_nb, total_len);
len -= PKT_HDR_SIZE;
data += PKT_HDR_SIZE;
@@ -727,10 +866,11 @@ static void pkt_print_data(u32 *data, u32 cnt)
}
}
+/* With eth_header, len counts the bytes after the test header. */
static void pkt_dump(void *pkt, u32 len, bool eth_header)
{
struct ethhdr *ethhdr = pkt;
- u32 i, *data;
+ u32 i, words, *data;
if (eth_header) {
/*extract L2 frame */
@@ -748,12 +888,13 @@ static void pkt_dump(void *pkt, u32 len, bool eth_header)
}
/*extract L5 frame */
+ words = len / sizeof(u32);
ksft_print_msg("\nDEBUG>> L5: seqnum: ");
- pkt_print_data(data, PKT_DUMP_NB_TO_PRINT);
+ pkt_print_data(data, min_t(u32, words, PKT_DUMP_NB_TO_PRINT));
ksft_print_msg("....");
- if (len > PKT_DUMP_NB_TO_PRINT * sizeof(u32)) {
+ if (words > PKT_DUMP_NB_TO_PRINT) {
ksft_print_msg("\n.... ");
- pkt_print_data(data + len / sizeof(u32) - PKT_DUMP_NB_TO_PRINT,
+ pkt_print_data(data + words - PKT_DUMP_NB_TO_PRINT,
PKT_DUMP_NB_TO_PRINT);
}
ksft_print_msg("\n---------------------------------------\n");
@@ -817,6 +958,11 @@ static bool is_frag_valid(struct xsk_umem_info *umem, u64 addr, u32 len, u32 exp
(unsigned long long)addr, len);
return false;
}
+ if (len < (bytes_processed ? 0 : PKT_HDR_SIZE) + sizeof(*pkt_data)) {
+ ksft_print_msg("Frag too short addr: %llx len: %u\n",
+ (unsigned long long)addr, len);
+ return false;
+ }
pkt_data = data;
if (!bytes_processed) {
@@ -858,12 +1004,13 @@ static bool is_frag_valid(struct xsk_umem_info *umem, u64 addr, u32 len, u32 exp
return false;
}
-static bool is_pkt_valid(struct pkt *pkt, void *buffer, u64 addr, u32 len)
+static bool is_pkt_valid(struct pkt *pkt, void *buffer, u64 addr, u32 frag_len, u32 len)
{
if (pkt->len != len) {
ksft_print_msg("[%s] expected packet length [%d], got length [%d]\n",
__func__, pkt->len, len);
- pkt_dump(xsk_umem__get_data(buffer, addr), len, true);
+ /* Only the first fragment, which holds the header, is at addr. */
+ pkt_dump(xsk_umem__get_data(buffer, addr), frag_len - PKT_HDR_SIZE, true);
return false;
}
@@ -961,7 +1108,7 @@ static int complete_pkts(struct xsk_socket_info *xsk, int batch_size)
static int __receive_pkts(struct test_spec *test, struct xsk_socket_info *xsk)
{
- u32 frags_processed = 0, nb_frags = 0, pkt_len = 0;
+ u32 frags_processed = 0, nb_frags = 0, pkt_len = 0, first_len = 0;
u32 idx_rx = 0, idx_fq = 0, rcvd, pkts_sent = 0;
struct pkt_stream *pkt_stream = xsk->pkt_stream;
struct ifobject *ifobj = test->ifobj_rx;
@@ -1038,8 +1185,10 @@ static int __receive_pkts(struct test_spec *test, struct xsk_socket_info *xsk)
!is_metadata_correct(pkt, umem->buffer, addr)))
return TEST_FAILURE;
- if (!nb_frags++)
+ if (!nb_frags++) {
first_addr = addr;
+ first_len = desc->len;
+ }
frags_processed++;
pkt_len += desc->len;
if (ifobj->use_fill_ring)
@@ -1049,7 +1198,7 @@ static int __receive_pkts(struct test_spec *test, struct xsk_socket_info *xsk)
continue;
/* The complete packet has been received */
- if (!is_pkt_valid(pkt, umem->buffer, first_addr, pkt_len) ||
+ if (!is_pkt_valid(pkt, umem->buffer, first_addr, first_len, pkt_len) ||
!is_offset_correct(umem, pkt, addr))
return TEST_FAILURE;
@@ -1199,7 +1348,7 @@ static int __send_pkts(struct ifobject *ifobject, struct xsk_socket_info *xsk,
for (i = 0; i < xsk->batch_size; i++) {
struct pkt *pkt = pkt_stream_get_next_tx_pkt(pkt_stream);
- u32 nb_frags_left, nb_frags, bytes_written = 0;
+ u32 nb_frags_left, nb_frags, total_len, bytes_written = 0;
if (!pkt)
break;
@@ -1211,6 +1360,7 @@ static int __send_pkts(struct ifobject *ifobject, struct xsk_socket_info *xsk,
break;
}
nb_frags_left = nb_frags;
+ total_len = pkt_total_len(pkt_stream, pkt, nb_frags);
while (nb_frags_left--) {
struct xdp_desc *tx_desc = xsk_ring_prod__tx_desc(&xsk->tx, idx + i);
@@ -1227,8 +1377,8 @@ static int __send_pkts(struct ifobject *ifobject, struct xsk_socket_info *xsk,
tx_desc->options = 0;
}
if (pkt->valid)
- pkt_generate(xsk, umem, tx_desc->addr, tx_desc->len, pkt->pkt_nb,
- bytes_written);
+ pkt_generate(xsk, umem, tx_desc->addr, tx_desc->len, total_len,
+ pkt->pkt_nb, bytes_written);
bytes_written += tx_desc->len;
print_verbose("Tx addr: %llx len: %u options: %u pkt_nb: %u\n",
@@ -2275,6 +2425,8 @@ int xsk_load_xdp_programs(struct ifobject *ifobj)
if (libbpf_get_error(ifobj->xdp_progs))
return libbpf_get_error(ifobj->xdp_progs);
+ /* The shadow's copy too, swapped directions attach its programs. */
+ ifobj->xdp_progs->bss->test_port = udp_port;
return 0;
}
@@ -2335,6 +2487,12 @@ int init_iface(struct ifobject *ifobj)
return err;
}
+ err = xsk_get_mac(ifobj->ifname, ifobj->caps.mac);
+ if (err) {
+ ksft_print_msg("Error reading interface MAC address\n");
+ return err;
+ }
+
return detect_ifobj_caps(ifobj);
}
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.h b/tools/testing/selftests/net/lib/xsk/test_xsk.h
index f1fafae2d140..4690ae2ad9c6 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.h
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.h
@@ -24,7 +24,7 @@
#define DEFAULT_PKT_CNT (4 * 1024)
#define DEFAULT_UMEM_BUFFERS (DEFAULT_PKT_CNT / 4)
#define HUGEPAGE_SIZE (2 * 1024 * 1024)
-#define MIN_PKT_SIZE 64
+#define MIN_PKT_SIZE min_pkt_size
#define MAX_ETH_PKT_SIZE 1518
#define MAX_INTERFACE_NAME_CHARS 16
#define MAX_TEST_NAME_SIZE 48
@@ -35,6 +35,8 @@
#define SMP_CACHE_BYTES_PATH "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"
extern bool opt_verbose;
+/* The smallest test packet, set by xsk_set_flow() */
+extern int min_pkt_size;
#define print_verbose(x...) do { if (opt_verbose) ksft_print_msg(x); } while (0)
@@ -83,6 +85,7 @@ struct xsk_peer;
/* The control channel to the other endpoint. */
void xsk_set_endpoint(struct xsk_peer *peer);
+int xsk_set_flow(const char *src_ip, const char *dst_ip, u16 port);
struct xsk_socket_info {
struct xsk_ring_cons rx;
@@ -95,6 +98,7 @@ struct xsk_socket_info {
u32 batch_size;
u8 dst_mac[ETH_ALEN];
u8 src_mac[ETH_ALEN];
+ u16 src_port;
bool check_consumer;
};
@@ -129,6 +133,7 @@ struct xsk_caps {
u32 max_skb_frags;
u32 umem_tailroom;
u32 tx_max_pending;
+ u8 mac[ETH_ALEN];
};
struct ifobject {
diff --git a/tools/testing/selftests/net/lib/xsk/xsk.c b/tools/testing/selftests/net/lib/xsk/xsk.c
index 74c7dd12a365..b5834ba16e69 100644
--- a/tools/testing/selftests/net/lib/xsk/xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/xsk.c
@@ -801,3 +801,29 @@ int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)
close(sockfd);
return 0;
}
+
+static int xsk_ifreq_ioctl(const char *ifname, unsigned long req, struct ifreq *ifr)
+{
+ int fd, err = 0;
+
+ fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (fd < 0)
+ return -errno;
+
+ strncpy(ifr->ifr_name, ifname, sizeof(ifr->ifr_name) - 1);
+ if (ioctl(fd, req, ifr) < 0)
+ err = -errno;
+ close(fd);
+ return err;
+}
+
+int xsk_get_mac(const char *ifname, u8 mac[ETH_ALEN])
+{
+ struct ifreq ifr = {};
+ int err;
+
+ err = xsk_ifreq_ioctl(ifname, SIOCGIFHWADDR, &ifr);
+ if (!err)
+ memcpy(mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
+ return err;
+}
diff --git a/tools/testing/selftests/net/lib/xsk/xsk.h b/tools/testing/selftests/net/lib/xsk/xsk.h
index 94a56dd43f2e..263971a57e1e 100644
--- a/tools/testing/selftests/net/lib/xsk/xsk.h
+++ b/tools/testing/selftests/net/lib/xsk/xsk.h
@@ -244,6 +244,7 @@ void xsk_socket__delete(struct xsk_socket *xsk);
int xsk_set_mtu(int ifindex, int mtu);
int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
+int xsk_get_mac(const char *ifname, u8 mac[ETH_ALEN]);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/tools/testing/selftests/net/lib/xsk/xsk_xdp_common.h b/tools/testing/selftests/net/lib/xsk/xsk_xdp_common.h
index 45810ff552da..47cbceea402d 100644
--- a/tools/testing/selftests/net/lib/xsk/xsk_xdp_common.h
+++ b/tools/testing/selftests/net/lib/xsk/xsk_xdp_common.h
@@ -4,7 +4,8 @@
#define XSK_XDP_COMMON_H_
#define MAX_SOCKETS 2
-#define PKT_HDR_ALIGN (sizeof(struct ethhdr) + 2) /* Just to align the data in the packet */
+/* Pads the UDP header of a test packet so that the payload is 4-byte aligned */
+#define PKT_HDR_PAD 2
struct xdp_info {
__u64 count;
diff --git a/tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c b/tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c
index 84e5f4732289..2b55dbaf13b2 100644
--- a/tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c
+++ b/tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c
@@ -5,9 +5,17 @@
#include <bpf/bpf_helpers.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <linux/udp.h>
+#include <linux/in.h>
#include <linux/errno.h>
+#include <bpf/bpf_endian.h>
+#include <stdbool.h>
#include "xsk_xdp_common.h"
+#define IP_MF 0x2000
+#define IP_OFFSET 0x1fff
+
struct {
__uint(type, BPF_MAP_TYPE_XSKMAP);
__uint(max_entries, 2);
@@ -15,12 +23,64 @@ struct {
__uint(value_size, sizeof(int));
} xsk SEC(".maps");
-static unsigned int idx;
int adjust_value = 0;
int count = 0;
+/* UDP destination port of the test flow, other traffic goes to the stack */
+__u16 test_port;
+
+/* Return the UDP header of a test packet, and in hdr_len the size of the
+ * headers in front of its payload, or NULL for any other packet.
+ */
+static __always_inline struct udphdr *test_udp_hdr(struct xdp_md *xdp,
+ __u32 *hdr_len)
+{
+ void *data_end = (void *)(long)xdp->data_end;
+ void *data = (void *)(long)xdp->data;
+ struct ethhdr *eth = data;
+ struct ipv6hdr *ip6;
+ struct udphdr *udp;
+ struct iphdr *ip;
+
+ if ((void *)(eth + 1) > data_end)
+ return NULL;
+
+ if (eth->h_proto == bpf_htons(ETH_P_IP)) {
+ ip = (void *)(eth + 1);
+ /* Fragments go to the stack, which reassembles them. */
+ if ((void *)(ip + 1) > data_end || ip->ihl != 5 ||
+ ip->protocol != IPPROTO_UDP ||
+ ip->frag_off & bpf_htons(IP_MF | IP_OFFSET))
+ return NULL;
+ udp = (void *)(ip + 1);
+ *hdr_len = sizeof(*eth) + sizeof(*ip);
+ } else if (eth->h_proto == bpf_htons(ETH_P_IPV6)) {
+ ip6 = (void *)(eth + 1);
+ /* The test flow carries no extension headers. */
+ if ((void *)(ip6 + 1) > data_end || ip6->nexthdr != IPPROTO_UDP)
+ return NULL;
+ udp = (void *)(ip6 + 1);
+ *hdr_len = sizeof(*eth) + sizeof(*ip6);
+ } else {
+ return NULL;
+ }
+
+ if ((void *)(udp + 1) > data_end || udp->dest != bpf_htons(test_port))
+ return NULL;
+ *hdr_len += sizeof(*udp) + PKT_HDR_PAD;
+ return udp;
+}
+
+static __always_inline bool is_test_packet(struct xdp_md *xdp)
+{
+ __u32 hdr_len;
+
+ return test_udp_hdr(xdp, &hdr_len);
+}
SEC("xdp.frags") int xsk_def_prog(struct xdp_md *xdp)
{
+ if (!is_test_packet(xdp))
+ return XDP_PASS;
return bpf_redirect_map(&xsk, 0, XDP_DROP);
}
@@ -28,6 +88,8 @@ SEC("xdp.frags") int xsk_xdp_drop(struct xdp_md *xdp)
{
static unsigned int drop_idx;
+ if (!is_test_packet(xdp))
+ return XDP_PASS;
/* Drop every other packet */
if (drop_idx++ % 2)
return XDP_DROP;
@@ -41,6 +103,9 @@ SEC("xdp.frags") int xsk_xdp_populate_metadata(struct xdp_md *xdp)
struct xdp_info *meta;
int err;
+ if (!is_test_packet(xdp))
+ return XDP_PASS;
+
/* Reserve enough for all custom metadata. */
err = bpf_xdp_adjust_meta(xdp, -(int)sizeof(struct xdp_info));
if (err)
@@ -60,16 +125,17 @@ SEC("xdp.frags") int xsk_xdp_populate_metadata(struct xdp_md *xdp)
SEC("xdp") int xsk_xdp_shared_umem(struct xdp_md *xdp)
{
- void *data = (void *)(long)xdp->data;
- void *data_end = (void *)(long)xdp->data_end;
- struct ethhdr *eth = data;
+ struct udphdr *udp;
+ __u32 hdr_len;
+ __u16 idx;
- if ((void *)(eth + 1) > data_end)
- return XDP_DROP;
+ udp = test_udp_hdr(xdp, &hdr_len);
+ if (!udp)
+ return XDP_PASS;
- /* Redirecting packets based on the destination MAC address */
- idx = ((unsigned int)(eth->h_dest[5])) / 2;
- if (idx > MAX_SOCKETS)
+ /* Socket N sends from test_port + N */
+ idx = bpf_ntohs(udp->source) - test_port;
+ if (idx >= MAX_SOCKETS)
return XDP_DROP;
return bpf_redirect_map(&xsk, idx, XDP_DROP);
@@ -77,9 +143,12 @@ SEC("xdp") int xsk_xdp_shared_umem(struct xdp_md *xdp)
SEC("xdp.frags") int xsk_xdp_adjust_tail(struct xdp_md *xdp)
{
- __u32 buff_len, curr_buff_len;
+ __u32 buff_len, curr_buff_len, hdr_len;
int ret;
+ if (!test_udp_hdr(xdp, &hdr_len))
+ return XDP_PASS;
+
buff_len = bpf_xdp_get_buff_len(xdp);
if (buff_len == 0)
return XDP_DROP;
@@ -106,7 +175,7 @@ SEC("xdp.frags") int xsk_xdp_adjust_tail(struct xdp_md *xdp)
__u32 *pkt_data = (void *)(long)xdp->data;
__u32 len, words_to_end, seq_num;
- len = curr_buff_len - PKT_HDR_ALIGN;
+ len = curr_buff_len - hdr_len;
words_to_end = len / sizeof(*pkt_data) - 1;
seq_num = words_to_end;
diff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.c b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
index 7f6ef07e5bf5..f7fa9ab93512 100644
--- a/tools/testing/selftests/net/lib/xsk/xskxceiver.c
+++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
@@ -61,7 +61,9 @@
* - One process listens on a TCP control port (--listen), the other one
* connects to it and the two synchronize each test step over that
* connection
- * - Tx process Transmits a number of packets from veth<xxxx> to veth<yyyy>
+ * - Tx process transmits a number of UDP packets over IPv4 or IPv6 from
+ * veth<xxxx> to veth<yyyy>, and the XDP program of Rx passes other traffic
+ * to the stack
* - Rx process verifies if all packets were received and delivered in-order,
* and have the right content
*/
@@ -78,6 +80,7 @@
#include <linux/align.h>
#include <arpa/inet.h>
#include <net/if.h>
+#include <netinet/ether.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
@@ -109,9 +112,18 @@ static bool opt_listen;
static const char *opt_peer_host;
static const char *opt_peer_port;
static const char *opt_ifname;
+static const char *opt_src_ip;
+static const char *opt_dst_ip;
+static const struct ether_addr *opt_dst_mac;
+static struct ether_addr dst_mac;
+static u16 opt_udp_port;
enum {
OPT_LISTEN = 256,
+ OPT_SRC_IP,
+ OPT_DST_IP,
+ OPT_DST_MAC,
+ OPT_UDP_PORT,
};
static void __exit_with_error(int error, const char *file, const char *func, int line)
@@ -177,6 +189,10 @@ static struct option long_options[] = {
{"peer", required_argument, 0, 'p'},
{"peer-port", required_argument, 0, 'P'},
{"listen", no_argument, 0, OPT_LISTEN},
+ {"src-ip", required_argument, 0, OPT_SRC_IP},
+ {"dst-ip", required_argument, 0, OPT_DST_IP},
+ {"dst-mac", required_argument, 0, OPT_DST_MAC},
+ {"udp-port", required_argument, 0, OPT_UDP_PORT},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
@@ -184,7 +200,8 @@ static struct option long_options[] = {
static void print_usage(char **argv)
{
const char *str =
- " Usage: %s -i IFACE -e rx|tx -m MODE -t TEST -p HOST -P PORT [OPTIONS]\n"
+ " Usage: %s -i IFACE -e rx|tx -m MODE -t TEST -p HOST -P PORT\n"
+ " --src-ip IP --dst-ip IP --dst-mac MAC --udp-port PORT [OPTIONS]\n"
" Options:\n"
" -i, --interface Use interface\n"
" -v, --verbose Verbose output\n"
@@ -196,6 +213,11 @@ static void print_usage(char **argv)
" -p, --peer Control host: IPv4/IPv6 address or hostname\n"
" -P, --peer-port Control TCP port\n"
" --listen Listen on the control port instead of connecting\n"
+ " --src-ip IP IPv4 or IPv6 source address of the test packets\n"
+ " --dst-ip IP Destination address, of the same family\n"
+ " --dst-mac MAC Destination MAC address of the test packets\n"
+ " --udp-port PORT UDP destination port, and source port of socket 0;\n"
+ " the caller steers the test flow to the bound queue\n"
" -h, --help Display this help and exit\n";
ksft_print_msg(str, basename(argv[0]));
@@ -235,6 +257,7 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
char **argv)
{
int option_index, c;
+ unsigned long val;
opterr = 0;
@@ -291,6 +314,26 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
case OPT_LISTEN:
opt_listen = true;
break;
+ case OPT_SRC_IP:
+ opt_src_ip = optarg;
+ break;
+ case OPT_DST_IP:
+ opt_dst_ip = optarg;
+ break;
+ case OPT_DST_MAC:
+ opt_dst_mac = ether_aton_r(optarg, &dst_mac);
+ if (!opt_dst_mac)
+ print_usage(argv);
+ break;
+ case OPT_UDP_PORT:
+ /* XDP_SHARED_UMEM sends from the port plus the
+ * socket index.
+ */
+ val = strtoul(optarg, NULL, 10);
+ if (!val || val > 0xffff - (MAX_SOCKETS - 1))
+ print_usage(argv);
+ opt_udp_port = val;
+ break;
case 'h':
default:
print_usage(argv);
@@ -299,7 +342,8 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
if (!opt_ifname || opt_endpoint_role == XSK_ENDPOINT_NONE || !opt_peer_host ||
!*opt_peer_host || !opt_peer_port || opt_run_test == RUN_ALL_TESTS ||
- opt_mode == TEST_MODE_ALL)
+ opt_mode == TEST_MODE_ALL || !opt_src_ip || !opt_dst_ip || !opt_dst_mac ||
+ !opt_udp_port)
print_usage(argv);
}
@@ -414,6 +458,8 @@ static int setup_peer(struct ifobject *local, struct ifobject *shadow,
}
shadow->caps = local->caps;
+ memcpy(shadow->caps.mac, opt_dst_mac->ether_addr_octet, ETH_ALEN);
+
xsk_set_endpoint(*peer);
return TEST_PASS;
}
@@ -472,6 +518,10 @@ int main(int argc, char **argv)
ksft_exit_xfail();
}
+ /* Before the default packet streams, which have its minimum size. */
+ if (xsk_set_flow(opt_src_ip, opt_dst_ip, opt_udp_port))
+ print_usage(argv);
+
/* swap_directions() swaps the workers, so the shadow needs one too. */
ifobj_tx->func_ptr = worker_testapp_validate_tx;
ifobj_rx->func_ptr = worker_testapp_validate_rx;
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v6 net-next 10/15] selftests: xsk: prepare xskxceiver for endpoints on two hosts
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
` (8 preceding siblings ...)
2026-11-27 15:05 ` [PATCH v6 net-next 09/15] selftests: xsk: send UDP over IPv4 or IPv6 between the interface MACs Maciej Fijalkowski
@ 2026-11-27 15:05 ` Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 11/15] selftests: xsk: wait up to --timeout for the RX stats and a busy bind Maciej Fijalkowski
` (4 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:05 UTC (permalink / raw)
To: netdev
Cc: magnus.karlsson, stfomichev, kuba, pabeni, tushar.vyavahare,
kerneljasonxing, bjorn, Maciej Fijalkowski
drivers/net/xsk.py, added later in this series, runs each hardware case
between a zero-copy endpoint on the DUT and an SKB-mode endpoint on a
remote host. Add what such a pair needs:
- --queue, the queue to bind
- --max-frags, the DUT limit for TOO_MANY_FRAGS, so that both endpoints
build the same packets
- --timeout, the RX and TX loop timeout, which also bounds the wait for
the link, as an MTU or XDP change can reset a NIC
- a SKIP message, so that the peer of an endpoint that skips a case
skips too rather than failing
- an endpoint probes only its own mode, and takes zero-copy support
from NETDEV_XDP_ACT_XSK_ZEROCOPY rather than from a probe bind
- an SKB-mode endpoint runs the multi-buffer cases if its max MTU
allows, whatever its driver advertises, as generic XDP handles frags
- a TX-only endpoint attaches an XDP program only in zero-copy mode,
where a driver can need one for TX wakeups
- an RX endpoint fills its fill ring before the bind, when a zero-copy
driver posts its RX buffers
Cases now default to an MTU of 1500 rather than 1518: IFLA_MTU is the
L3 MTU, so the old default changed it for every case, which can reset a
NIC. An SKB-mode endpoint raises
its MTU only when a case needs more, and cleanup_iface() restores it
after the XDP detach, retrying for up to --timeout, as a driver can
refuse it while it holds the pool of a closed socket.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
.../testing/selftests/net/lib/xsk/test_xsk.c | 153 ++++++++++++++----
.../testing/selftests/net/lib/xsk/test_xsk.h | 7 +
tools/testing/selftests/net/lib/xsk/xsk.c | 102 ++++++++++++
tools/testing/selftests/net/lib/xsk/xsk.h | 3 +
.../testing/selftests/net/lib/xsk/xsk_peer.c | 46 ++++++
.../testing/selftests/net/lib/xsk/xsk_peer.h | 2 +
.../selftests/net/lib/xsk/xskxceiver.c | 153 ++++++++++++------
7 files changed, 384 insertions(+), 82 deletions(-)
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c
index b0ed41b40f82..4b8cf5a3d387 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c
@@ -48,6 +48,8 @@ static union {
} flow_src, flow_dst;
static u16 udp_port;
static u32 pkt_hdr_size;
+static u32 max_frags_override;
+static u32 thread_tmout = THREAD_TMOUT;
bool opt_verbose;
int min_pkt_size;
@@ -129,6 +131,16 @@ int xsk_set_flow(const char *src_ip, const char *dst_ip, u16 port)
return 0;
}
+void xsk_set_max_frags(u32 max_frags)
+{
+ max_frags_override = max_frags;
+}
+
+void xsk_set_timeout(u32 timeout)
+{
+ thread_tmout = timeout;
+}
+
/* Add up buf as big-endian 16-bit words, len being even. */
static u32 csum_add(u32 sum, const void *buf, size_t len)
{
@@ -322,7 +334,8 @@ int xsk_configure_socket(struct xsk_socket_info *xsk, struct xsk_umem_info *umem
txr = ifobject->tx_on ? &xsk->tx : NULL;
rxr = ifobject->rx_on ? &xsk->rx : NULL;
- return xsk_socket__create(&xsk->xsk, ifobject->ifindex, 0, umem->umem, rxr, txr, &cfg);
+ return xsk_socket__create(&xsk->xsk, ifobject->ifindex, ifobject->queue_id,
+ umem->umem, rxr, txr, &cfg);
}
static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
@@ -381,7 +394,7 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
test->nb_sockets = 1;
test->adjust_tail = false;
test->adjust_tail_support = false;
- test->mtu = MAX_ETH_PKT_SIZE;
+ test->mtu = ETH_DATA_LEN;
test->xdp_prog_rx = ifobj_rx->xdp_progs->progs.xsk_def_prog;
test->xskmap_rx = ifobj_rx->xdp_progs->maps.xsk;
test->xdp_prog_tx = ifobj_tx->xdp_progs->progs.xsk_def_prog;
@@ -445,14 +458,25 @@ static void test_spec_set_xdp_prog(struct test_spec *test, struct bpf_program *x
test->xskmap_tx = xskmap_tx;
}
-static int test_spec_set_mtu_ifobj(struct ifobject *ifobj, int mtu)
+/* An MTU change can reset a NIC. An SKB-mode endpoint runs a case at any
+ * larger MTU, as generic XDP does not limit it, so only raise its MTU.
+ */
+static bool mtu_change_needed(struct ifobject *ifobj, enum test_mode mode, int mtu)
+{
+ if (mode == TEST_MODE_SKB)
+ return ifobj->dev_mtu < mtu;
+ return ifobj->dev_mtu != mtu;
+}
+
+static int test_spec_set_mtu_ifobj(struct ifobject *ifobj, enum test_mode mode, int mtu)
{
int err;
- if (ifobj_is_local(ifobj) && ifobj->mtu != mtu) {
+ if (ifobj_is_local(ifobj) && mtu_change_needed(ifobj, mode, mtu)) {
err = xsk_set_mtu(ifobj->ifindex, mtu);
if (err)
return err;
+ ifobj->dev_mtu = mtu;
}
ifobj->mtu = mtu;
@@ -463,11 +487,11 @@ static int test_spec_set_mtu(struct test_spec *test, int mtu)
{
int err;
- err = test_spec_set_mtu_ifobj(test->ifobj_rx, mtu);
+ err = test_spec_set_mtu_ifobj(test->ifobj_rx, test->mode, mtu);
if (err)
return err;
- return test_spec_set_mtu_ifobj(test->ifobj_tx, mtu);
+ return test_spec_set_mtu_ifobj(test->ifobj_tx, test->mode, mtu);
}
void pkt_stream_reset(struct pkt_stream *pkt_stream)
@@ -1253,7 +1277,7 @@ bool all_packets_received(struct test_spec *test, struct xsk_socket_info *xsk, u
static int receive_pkts(struct test_spec *test)
{
- struct timeval tv_end, tv_now, tv_timeout = {THREAD_TMOUT, 0};
+ struct timeval tv_end, tv_now, tv_timeout = {thread_tmout, 0};
DECLARE_BITMAP(bitmap, test->nb_sockets);
struct xsk_socket_info *xsk;
u32 sock_num = 0;
@@ -1309,6 +1333,11 @@ static int __send_pkts(struct ifobject *ifobject, struct xsk_socket_info *xsk,
if (pkts_in_flight >= (int)((umem_size(umem) - xsk->batch_size * buffer_len) /
buffer_len) && !test_timeout) {
/* Only RX progress reports can lower pkts_in_flight. */
+ if (xsk_peer_skipped(ctrl_peer)) {
+ ksft_print_msg("RX skipped the case with %d packets in flight\n",
+ pkts_in_flight);
+ return TEST_SKIP;
+ }
if (xsk_peer_closed(ctrl_peer)) {
ksft_print_msg("ERROR: [%s] RX exited with %d packets in flight\n",
__func__, pkts_in_flight);
@@ -1425,7 +1454,7 @@ static int __send_pkts(struct ifobject *ifobject, struct xsk_socket_info *xsk,
static int wait_for_tx_completion(struct xsk_socket_info *xsk)
{
- struct timeval tv_end, tv_now, tv_timeout = {THREAD_TMOUT, 0};
+ struct timeval tv_end, tv_now, tv_timeout = {thread_tmout, 0};
int ret;
ret = gettimeofday(&tv_now, NULL);
@@ -1708,20 +1737,26 @@ static int thread_common_ops(struct test_spec *test, struct ifobject *ifobject)
if (ret)
return ret;
+ ifobject->xsk = &ifobject->xsk_arr[0];
+
+ /* Before the bind: a zero-copy driver posts its RX buffers then, or in
+ * a poll it schedules then. Otherwise it waits for a wakeup, and the
+ * peer can send before the RX endpoint gets to it.
+ */
+ if (ifobject->rx_on) {
+ ret = xsk_populate_fill_ring(umem, ifobject->xsk->pkt_stream,
+ ifobject->use_fill_ring);
+ if (ret)
+ return ret;
+ }
+
ret = xsk_configure(test, ifobject, umem);
if (ret)
return ret;
- ifobject->xsk = &ifobject->xsk_arr[0];
-
if (!ifobject->rx_on)
return 0;
- ret = xsk_populate_fill_ring(umem, ifobject->xsk->pkt_stream,
- ifobject->use_fill_ring);
- if (ret)
- return ret;
-
for (i = 0; i < test->nb_sockets; i++) {
ret = xsk_update_xskmap(ifobject->xskmap, ifobject->xsk_arr[i].xsk, i);
if (ret)
@@ -1791,14 +1826,43 @@ static int testapp_validate_rx_endpoint(struct test_spec *test,
return err;
}
+/* An MTU or XDP program change can reset a NIC, which takes the link down on
+ * both hosts. Each endpoint makes those changes before it is ready, so once
+ * both are, wait while the local link is down. This is best effort: it misses
+ * a reset that a driver has yet to start, and one on the bind of a TX socket,
+ * which comes after the wait.
+ */
+static int wait_link_up(struct test_spec *test)
+{
+ struct ifobject *ifobj = test->ifobj_tx;
+ int err;
+
+ if (!ifobj_is_local(ifobj))
+ ifobj = test->ifobj_rx;
+ err = xsk_wait_link_up(ifobj->ifname, thread_tmout * 1000);
+ if (err) {
+ ksft_print_msg("Link on %s is not up at step %u: %d (%s)\n",
+ ifobj->ifname, test->current_step, err, strerror(-err));
+ xsk_peer_abort(ctrl_peer);
+ }
+ return err;
+}
+
static int sync_endpoints(struct test_spec *test)
{
int err = xsk_peer_ready(ctrl_peer);
- if (err)
+ if (err && xsk_peer_skipped(ctrl_peer)) {
+ ksft_print_msg("The peer endpoint skipped the case at step %u\n",
+ test->current_step);
+ return TEST_SKIP;
+ }
+ if (err) {
ksft_print_msg("Endpoint synchronization failed at step %u: %d (%s)\n",
test->current_step, err, strerror(-err));
- return err;
+ return err;
+ }
+ return wait_link_up(test);
}
int worker_testapp_validate_tx(struct test_spec *test)
@@ -1810,7 +1874,7 @@ int worker_testapp_validate_tx(struct test_spec *test)
return err;
err = testapp_validate_tx_endpoint(test, test->ifobj_tx);
- if (err) {
+ if (err && err != TEST_SKIP) {
ksft_print_msg("TX endpoint traffic failed at step %u: %d\n",
test->current_step, err);
xsk_peer_abort(ctrl_peer);
@@ -1895,12 +1959,22 @@ static int xsk_reattach_xdp(struct ifobject *ifobj, struct bpf_program *xdp_prog
return 0;
}
+/* An endpoint that only transmits needs XDP only in zero-copy mode, where a
+ * driver can require it for TX wakeups.
+ */
+static bool xdp_prog_needed(struct test_spec *test, struct ifobject *ifobj)
+{
+ return ifobj->rx_on || test->mode == TEST_MODE_ZC;
+}
+
static int xsk_attach_xdp_progs(struct test_spec *test, struct ifobject *ifobj_rx,
struct ifobject *ifobj_tx)
{
int err = 0;
- if (ifobj_is_local(ifobj_rx) && xdp_prog_changed_rx(test)) {
+ /* A single-threaded step can pass a TX-only ifobj as ifobj_rx. */
+ if (ifobj_is_local(ifobj_rx) && xdp_prog_needed(test, ifobj_rx) &&
+ xdp_prog_changed_rx(test)) {
err = xsk_reattach_xdp(ifobj_rx, test->xdp_prog_rx, test->xskmap_rx, test->mode);
if (err)
return err;
@@ -1909,7 +1983,7 @@ static int xsk_attach_xdp_progs(struct test_spec *test, struct ifobject *ifobj_r
if (!ifobj_tx || !ifobj_is_local(ifobj_tx))
return 0;
- if (xdp_prog_changed_tx(test))
+ if (xdp_prog_needed(test, ifobj_tx) && xdp_prog_changed_tx(test))
err = xsk_reattach_xdp(ifobj_tx, test->xdp_prog_tx, test->xskmap_tx, test->mode);
return err;
@@ -1990,6 +2064,8 @@ static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *i
clean_umem(test, ifobj1, ifobj2);
}
+ if (err == TEST_SKIP)
+ return TEST_SKIP;
return err ? TEST_FAILURE : TEST_PASS;
}
@@ -2016,11 +2092,12 @@ static int testapp_validate_traffic_single_thread(struct test_spec *test, struct
int testapp_teardown(struct test_spec *test)
{
- int i;
+ int i, ret;
for (i = 0; i < MAX_TEARDOWN_ITER; i++) {
- if (testapp_validate_traffic(test))
- return TEST_FAILURE;
+ ret = testapp_validate_traffic(test);
+ if (ret)
+ return ret;
test_spec_reset(test);
}
@@ -2046,8 +2123,9 @@ int testapp_bidirectional(struct test_spec *test)
test->ifobj_tx->rx_on = true;
test->ifobj_rx->tx_on = true;
test->total_steps = 2;
- if (testapp_validate_traffic(test))
- return TEST_FAILURE;
+ res = testapp_validate_traffic(test);
+ if (res)
+ return res;
print_verbose("Switching Tx/Rx direction\n");
swap_directions(&test->ifobj_rx, &test->ifobj_tx);
@@ -2080,10 +2158,13 @@ static int swap_xsk_resources(struct test_spec *test)
int testapp_xdp_prog_cleanup(struct test_spec *test)
{
+ int ret;
+
test->total_steps = 2;
test->nb_sockets = 2;
- if (testapp_validate_traffic(test))
- return TEST_FAILURE;
+ ret = testapp_validate_traffic(test);
+ if (ret)
+ return ret;
if (swap_xsk_resources(test)) {
clean_sockets(test, test->ifobj_rx);
@@ -2365,7 +2446,9 @@ int testapp_too_many_frags(struct test_spec *test)
u32 max_frags, i;
int ret = TEST_FAILURE;
- if (test->mode == TEST_MODE_ZC) {
+ if (max_frags_override) {
+ max_frags = max_frags_override;
+ } else if (test->mode == TEST_MODE_ZC) {
max_frags = xsk_get_cap(test, xdp_zc_max_segs);
} else {
max_frags = xsk_get_cap(test, max_skb_frags);
@@ -2461,6 +2544,7 @@ static int detect_ifobj_caps(struct ifobject *ifobj)
if (query_opts.feature_flags & NETDEV_XDP_ACT_RX_SG)
ifobj_set_cap(ifobj, XSK_CAP_MBUF);
if (query_opts.feature_flags & NETDEV_XDP_ACT_XSK_ZEROCOPY) {
+ ifobj_set_cap(ifobj, XSK_CAP_ZC_ADVERTISED);
if (query_opts.xdp_zc_max_segs > 1) {
ifobj_set_cap(ifobj, XSK_CAP_MBUF_ZC);
ifobj->caps.xdp_zc_max_segs = query_opts.xdp_zc_max_segs;
@@ -2713,9 +2797,18 @@ int testapp_adjust_tail_shrink_mb(struct test_spec *test)
return testapp_adjust_tail(test, -XSK_UMEM__MAX_FRAME_SIZE, XSK_UMEM__LARGE_FRAME_SIZE * 2);
}
+/* Generic XDP leaves no room to grow the tail. Only the RX endpoint runs the
+ * program on the test flow, and the TX endpoint, which does not know the mode
+ * of its peer, learns about the skip from it.
+ */
+static bool adjust_tail_grow_skip(struct test_spec *test)
+{
+ return ifobj_is_local(test->ifobj_rx) && test->mode == TEST_MODE_SKB;
+}
+
int testapp_adjust_tail_grow(struct test_spec *test)
{
- if (test->mode == TEST_MODE_SKB)
+ if (adjust_tail_grow_skip(test))
return TEST_SKIP;
/* Grow by 4 bytes for testing purpose */
@@ -2726,7 +2819,7 @@ int testapp_adjust_tail_grow_mb(struct test_spec *test)
{
u32 grow_size;
- if (test->mode == TEST_MODE_SKB)
+ if (adjust_tail_grow_skip(test))
return TEST_SKIP;
/* worst case scenario is when underlying setup will work on 3k
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.h b/tools/testing/selftests/net/lib/xsk/test_xsk.h
index 4690ae2ad9c6..15534f4ec8f4 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.h
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.h
@@ -86,6 +86,8 @@ struct xsk_peer;
/* The control channel to the other endpoint. */
void xsk_set_endpoint(struct xsk_peer *peer);
int xsk_set_flow(const char *src_ip, const char *dst_ip, u16 port);
+void xsk_set_max_frags(u32 max_frags);
+void xsk_set_timeout(u32 timeout);
struct xsk_socket_info {
struct xsk_ring_cons rx;
@@ -126,6 +128,7 @@ struct xsk_umem_info {
#define XSK_CAP_HW_RING (1U << 3)
#define XSK_CAP_DRV (1U << 4)
#define XSK_CAP_ZC (1U << 5)
+#define XSK_CAP_ZC_ADVERTISED (1U << 6)
struct xsk_caps {
u32 flags;
@@ -149,7 +152,11 @@ struct ifobject {
struct ethtool_ringparam ring;
enum test_mode mode;
int ifindex;
+ u32 queue_id;
int mtu;
+ /* Device MTU, which an SKB-mode endpoint may keep above mtu. */
+ int dev_mtu;
+ int orig_mtu;
u32 bind_flags;
bool tx_on;
bool rx_on;
diff --git a/tools/testing/selftests/net/lib/xsk/xsk.c b/tools/testing/selftests/net/lib/xsk/xsk.c
index b5834ba16e69..a9a6ff3409e3 100644
--- a/tools/testing/selftests/net/lib/xsk/xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/xsk.c
@@ -421,6 +421,75 @@ int xsk_set_mtu(int ifindex, int mtu)
return ret;
}
+/* A max MTU of 0 means no limit. */
+int xsk_get_max_mtu(int ifindex, u32 *max_mtu)
+{
+ struct nl_mtu_req req = {
+ .nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
+ .nh.nlmsg_type = RTM_GETLINK,
+ .nh.nlmsg_flags = NLM_F_REQUEST,
+ .msg.ifi_family = AF_UNSPEC,
+ .msg.ifi_index = ifindex,
+ };
+ struct iovec iov = {};
+ struct msghdr mhdr = {
+ .msg_iov = &iov,
+ .msg_iovlen = 1,
+ };
+ struct nlmsghdr *nh;
+ struct rtattr *rta;
+ int fd, len, ret;
+
+ fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
+ if (fd < 0)
+ return -errno;
+
+ if (send(fd, &req, req.nh.nlmsg_len, 0) < 0) {
+ ret = -errno;
+ goto out;
+ }
+
+ /* The reply carries all the link attributes, so size it first. */
+ len = netlink_recvmsg(fd, &mhdr, MSG_PEEK | MSG_TRUNC);
+ if (len < 0) {
+ ret = len;
+ goto out;
+ }
+ ret = alloc_iov(&iov, len);
+ if (ret)
+ goto out;
+ len = netlink_recvmsg(fd, &mhdr, 0);
+ if (len < 0) {
+ ret = len;
+ goto out;
+ }
+
+ ret = -EPROTO;
+ nh = iov.iov_base;
+ if (!NLMSG_OK(nh, len))
+ goto out;
+ if (nh->nlmsg_type == NLMSG_ERROR) {
+ ret = ((struct nlmsgerr *)NLMSG_DATA(nh))->error ?: -EPROTO;
+ goto out;
+ }
+ if (nh->nlmsg_type != RTM_NEWLINK)
+ goto out;
+
+ *max_mtu = 0;
+ len = IFLA_PAYLOAD(nh);
+ for (rta = IFLA_RTA(NLMSG_DATA(nh)); RTA_OK(rta, len);
+ rta = RTA_NEXT(rta, len)) {
+ if (rta->rta_type == IFLA_MAX_MTU &&
+ RTA_PAYLOAD(rta) == sizeof(*max_mtu))
+ memcpy(max_mtu, RTA_DATA(rta), sizeof(*max_mtu));
+ }
+ ret = 0;
+out:
+ free(iov.iov_base);
+ close(fd);
+ return ret;
+}
+
int xsk_attach_xdp_program(struct bpf_program *prog, int ifindex, u32 xdp_flags)
{
int prog_fd;
@@ -827,3 +896,36 @@ int xsk_get_mac(const char *ifname, u8 mac[ETH_ALEN])
memcpy(mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
return err;
}
+
+int xsk_get_mtu(const char *ifname, int *mtu)
+{
+ struct ifreq ifr = {};
+ int err;
+
+ err = xsk_ifreq_ioctl(ifname, SIOCGIFMTU, &ifr);
+ if (!err)
+ *mtu = ifr.ifr_mtu;
+ return err;
+}
+
+/* ETHTOOL_GLINK reports the carrier. SIOCGIFFLAGS cannot: IFF_LOWER_UP does
+ * not fit in ifr_flags, and IFF_RUNNING follows the carrier only once the link
+ * watch runs. A driver without .get_link has nothing to wait for, and one
+ * that resets detaches the device, which fails the ioctl until it is back.
+ */
+int xsk_wait_link_up(const char *ifname, int timeout_ms)
+{
+ struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
+ struct ifreq ifr = { .ifr_data = (void *)&edata };
+ int err;
+
+ for (;;) {
+ err = xsk_ifreq_ioctl(ifname, SIOCETHTOOL, &ifr);
+ if (err == -EOPNOTSUPP || (!err && edata.data))
+ return 0;
+ if (timeout_ms <= 0)
+ return err ?: -ETIMEDOUT;
+ usleep(100 * 1000);
+ timeout_ms -= 100;
+ }
+}
diff --git a/tools/testing/selftests/net/lib/xsk/xsk.h b/tools/testing/selftests/net/lib/xsk/xsk.h
index 263971a57e1e..dca8045b4745 100644
--- a/tools/testing/selftests/net/lib/xsk/xsk.h
+++ b/tools/testing/selftests/net/lib/xsk/xsk.h
@@ -242,9 +242,12 @@ int xsk_umem__delete(struct xsk_umem *umem);
void xsk_socket__delete(struct xsk_socket *xsk);
int xsk_set_mtu(int ifindex, int mtu);
+int xsk_get_max_mtu(int ifindex, u32 *max_mtu);
int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
int xsk_get_mac(const char *ifname, u8 mac[ETH_ALEN]);
+int xsk_get_mtu(const char *ifname, int *mtu);
+int xsk_wait_link_up(const char *ifname, int timeout_ms);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/tools/testing/selftests/net/lib/xsk/xsk_peer.c b/tools/testing/selftests/net/lib/xsk/xsk_peer.c
index 3ff9d82aaf49..9b9b4db7fad6 100644
--- a/tools/testing/selftests/net/lib/xsk/xsk_peer.c
+++ b/tools/testing/selftests/net/lib/xsk/xsk_peer.c
@@ -24,6 +24,7 @@ enum xsk_peer_msg_type {
XSK_PEER_READY = 1,
XSK_PEER_PROGRESS,
XSK_PEER_ABORT,
+ XSK_PEER_SKIP,
};
struct xsk_peer_msg {
@@ -37,6 +38,7 @@ struct xsk_peer {
u32 acked;
bool ready_seen;
bool closed;
+ bool skipped;
};
static int io_full(int fd, void *buf, size_t len, bool write_op)
@@ -110,6 +112,11 @@ static int peer_recv_one(struct xsk_peer *peer)
return 0;
case XSK_PEER_ABORT:
return -ECANCELED;
+ case XSK_PEER_SKIP:
+ /* The peer skips the case and closes the connection. */
+ peer->closed = true;
+ peer->skipped = true;
+ return -EOPNOTSUPP;
default:
return -EPROTO;
}
@@ -145,6 +152,16 @@ int xsk_peer_ready(struct xsk_peer *peer)
int err;
err = peer_send(peer, XSK_PEER_READY, 0);
+ /*
+ * Read what a gone peer left, such as a SKIP, up to the end, even if its
+ * READY came early.
+ */
+ if (peer_gone(err)) {
+ do {
+ err = peer_recv_one(peer);
+ } while (!err);
+ return err;
+ }
while (!err && !peer->ready_seen)
err = peer_recv_one(peer);
if (err)
@@ -162,6 +179,30 @@ void xsk_peer_abort(struct xsk_peer *peer)
peer_send(peer, XSK_PEER_ABORT, 0);
}
+/*
+ * Tell the peer that this endpoint skips the case, so that it skips too.
+ * Closing with unread data, or getting data once closed, resets the
+ * connection and drops the SKIP if the peer has yet to acknowledge it, as
+ * when a NIC reset holds the link down. So read until the peer closes.
+ */
+void xsk_peer_skip(struct xsk_peer *peer, int timeout_ms)
+{
+ struct pollfd pfd = { .events = POLLIN };
+ struct xsk_peer_msg msg;
+ int ret;
+
+ if (!peer || peer->closed || peer_send(peer, XSK_PEER_SKIP, 0))
+ return;
+
+ shutdown(peer->fd, SHUT_WR);
+ pfd.fd = peer->fd;
+ do {
+ ret = poll(&pfd, 1, timeout_ms);
+ if (ret > 0)
+ ret = read(peer->fd, &msg, sizeof(msg));
+ } while (ret > 0 || (ret < 0 && errno == EINTR));
+}
+
int xsk_peer_rx_progress(struct xsk_peer *peer, u32 pkts)
{
int err;
@@ -195,6 +236,11 @@ bool xsk_peer_closed(struct xsk_peer *peer)
return peer->closed;
}
+bool xsk_peer_skipped(struct xsk_peer *peer)
+{
+ return peer->skipped;
+}
+
static int accept_tmout(int lfd)
{
struct pollfd pfd = { .fd = lfd, .events = POLLIN };
diff --git a/tools/testing/selftests/net/lib/xsk/xsk_peer.h b/tools/testing/selftests/net/lib/xsk/xsk_peer.h
index da4462192994..26ae6b1bb384 100644
--- a/tools/testing/selftests/net/lib/xsk/xsk_peer.h
+++ b/tools/testing/selftests/net/lib/xsk/xsk_peer.h
@@ -12,8 +12,10 @@ void xsk_peer_close(struct xsk_peer *peer);
int xsk_peer_ready(struct xsk_peer *peer);
void xsk_peer_abort(struct xsk_peer *peer);
+void xsk_peer_skip(struct xsk_peer *peer, int timeout_ms);
int xsk_peer_rx_progress(struct xsk_peer *peer, u32 pkts);
int xsk_peer_tx_sync(struct xsk_peer *peer);
bool xsk_peer_closed(struct xsk_peer *peer);
+bool xsk_peer_skipped(struct xsk_peer *peer);
#endif /* XSK_PEER_H_ */
diff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.c b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
index f7fa9ab93512..7ef6f08538bd 100644
--- a/tools/testing/selftests/net/lib/xsk/xskxceiver.c
+++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
@@ -117,6 +117,9 @@ static const char *opt_dst_ip;
static const struct ether_addr *opt_dst_mac;
static struct ether_addr dst_mac;
static u16 opt_udp_port;
+static u32 opt_queue;
+static u32 opt_max_frags;
+static u32 opt_timeout = 3;
enum {
OPT_LISTEN = 256,
@@ -124,6 +127,9 @@ enum {
OPT_DST_IP,
OPT_DST_MAC,
OPT_UDP_PORT,
+ OPT_QUEUE,
+ OPT_MAX_FRAGS,
+ OPT_TIMEOUT,
};
static void __exit_with_error(int error, const char *file, const char *func, int line)
@@ -135,49 +141,6 @@ static void __exit_with_error(int error, const char *file, const char *func, int
#define exit_with_error(error) __exit_with_error(error, __FILE__, __func__, __LINE__)
-static bool ifobj_zc_avail(struct ifobject *ifobject)
-{
- size_t umem_sz = DEFAULT_UMEM_BUFFERS * XSK_UMEM__DEFAULT_FRAME_SIZE;
- int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE;
- struct xsk_socket_info *xsk;
- struct xsk_umem_info *umem;
- bool zc_avail = false;
- void *bufs;
- int ret;
-
- bufs = mmap(NULL, umem_sz, PROT_READ | PROT_WRITE, mmap_flags, -1, 0);
- if (bufs == MAP_FAILED)
- exit_with_error(errno);
-
- umem = calloc(1, sizeof(struct xsk_umem_info));
- if (!umem) {
- munmap(bufs, umem_sz);
- exit_with_error(ENOMEM);
- }
- umem->frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE;
- ret = xsk_configure_umem(ifobject, umem, bufs, umem_sz);
- if (ret)
- exit_with_error(-ret);
-
- xsk = calloc(1, sizeof(struct xsk_socket_info));
- if (!xsk)
- goto out;
- ifobject->bind_flags = XDP_USE_NEED_WAKEUP | XDP_ZEROCOPY;
- ifobject->rx_on = true;
- xsk->rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS;
- ret = xsk_configure_socket(xsk, umem, ifobject, false);
- if (!ret)
- zc_avail = true;
-
- xsk_socket__delete(xsk->xsk);
- free(xsk);
-out:
- munmap(umem->buffer, umem_sz);
- xsk_umem__delete(umem->umem);
- free(umem);
- return zc_avail;
-}
-
static struct option long_options[] = {
{"interface", required_argument, 0, 'i'},
{"busy-poll", no_argument, 0, 'b'},
@@ -193,6 +156,9 @@ static struct option long_options[] = {
{"dst-ip", required_argument, 0, OPT_DST_IP},
{"dst-mac", required_argument, 0, OPT_DST_MAC},
{"udp-port", required_argument, 0, OPT_UDP_PORT},
+ {"queue", required_argument, 0, OPT_QUEUE},
+ {"max-frags", required_argument, 0, OPT_MAX_FRAGS},
+ {"timeout", required_argument, 0, OPT_TIMEOUT},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
@@ -218,6 +184,9 @@ static void print_usage(char **argv)
" --dst-mac MAC Destination MAC address of the test packets\n"
" --udp-port PORT UDP destination port, and source port of socket 0;\n"
" the caller steers the test flow to the bound queue\n"
+ " --queue N AF_XDP queue to bind (default 0)\n"
+ " --max-frags N Fragment limit for TOO_MANY_FRAGS (default by mode)\n"
+ " --timeout SEC Traffic and link timeout (default 3)\n"
" -h, --help Display this help and exit\n";
ksft_print_msg(str, basename(argv[0]));
@@ -242,6 +211,11 @@ static void bind_iface(struct ifobject *ifobj, const char *ifname, char **argv)
ksft_print_msg("Error: cannot initialize interface %s\n", ifobj->ifname);
ksft_exit_fail();
}
+ if (xsk_get_mtu(ifobj->ifname, &ifobj->dev_mtu)) {
+ ksft_print_msg("Error: cannot read MTU of interface %s\n", ifobj->ifname);
+ ksft_exit_fail();
+ }
+ ifobj->orig_mtu = ifobj->dev_mtu;
}
static void print_tests(void)
@@ -258,6 +232,7 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
{
int option_index, c;
unsigned long val;
+ char *end;
opterr = 0;
@@ -334,6 +309,27 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
print_usage(argv);
opt_udp_port = val;
break;
+ case OPT_QUEUE:
+ errno = 0;
+ val = strtoul(optarg, &end, 10);
+ if (errno || end == optarg || *end || val > UINT32_MAX)
+ print_usage(argv);
+ opt_queue = val;
+ break;
+ case OPT_MAX_FRAGS:
+ /* It sizes the packet array of TOO_MANY_FRAGS. */
+ val = strtoul(optarg, NULL, 10);
+ if (val > 0xffff)
+ print_usage(argv);
+ opt_max_frags = val;
+ break;
+ case OPT_TIMEOUT:
+ /* Passed on in milliseconds, as an int. */
+ val = strtoul(optarg, NULL, 10);
+ if (!val || val > 0xffff)
+ print_usage(argv);
+ opt_timeout = val;
+ break;
case 'h':
default:
print_usage(argv);
@@ -357,7 +353,12 @@ static int run_pkt_test(struct test_spec *test)
int ret;
ret = test->test_func(test);
+ pkt_stream_restore_default(test);
+ return ret;
+}
+static void report_pkt_test(struct test_spec *test, int ret)
+{
switch (ret) {
case TEST_PASS:
ksft_test_result_pass("PASS: %s %s%s\n", mode_string(test), busy_poll_string(test),
@@ -375,9 +376,6 @@ static int run_pkt_test(struct test_spec *test)
ksft_test_result_fail("FAIL: %s %s%s -- Unexpected returned value (%d)\n",
mode_string(test), busy_poll_string(test), test->name, ret);
}
-
- pkt_stream_restore_default(test);
- return ret;
}
static bool is_xdp_supported(int ifindex)
@@ -408,12 +406,29 @@ static bool is_xdp_supported(int ifindex)
return true;
}
+/* Probe only the mode that the endpoint runs in. */
static u32 detect_mode_caps(struct ifobject *ifobj)
{
- if (is_xdp_supported(ifobj->ifindex)) {
+ u32 max_mtu;
+
+ if (opt_mode == TEST_MODE_ZC && ifobj_has_cap(ifobj, XSK_CAP_ZC_ADVERTISED)) {
+ /* Trust the advertised flag; an XDP_ZEROCOPY bind never falls back to copy. */
+ ifobj_set_cap(ifobj, XSK_CAP_DRV | XSK_CAP_ZC);
+ } else if (opt_mode == TEST_MODE_DRV && is_xdp_supported(ifobj->ifindex)) {
ifobj_set_cap(ifobj, XSK_CAP_DRV);
- if (ifobj_zc_avail(ifobj))
- ifobj_set_cap(ifobj, XSK_CAP_ZC);
+ } else if (opt_mode == TEST_MODE_SKB) {
+ if (xsk_get_max_mtu(ifobj->ifindex, &max_mtu)) {
+ ksft_print_msg("Error: cannot read max MTU of interface %s\n",
+ ifobj->ifname);
+ ksft_exit_fail();
+ }
+ /* Generic XDP handles frags whatever the driver supports, so
+ * the multi-buffer cases need only a jumbo MTU.
+ */
+ if (!max_mtu || max_mtu >= MAX_ETH_JUMBO_SIZE)
+ ifobj_set_cap(ifobj, XSK_CAP_MBUF);
+ else
+ ifobj->caps.flags &= ~XSK_CAP_MBUF;
}
return ifobj->caps.flags;
@@ -428,8 +443,10 @@ static bool mode_supported(enum test_mode mode, u32 caps)
return caps & XSK_CAP_ZC;
}
-static void cleanup_iface(struct ifobject *ifobj)
+static int cleanup_iface(struct ifobject *ifobj)
{
+ int err = 0;
+
/* A peer shadow has a skeleton but no bound interface. */
if (!ifobj_is_local(ifobj))
goto unload;
@@ -437,8 +454,27 @@ static void cleanup_iface(struct ifobject *ifobj)
if (ifobj->xdp_prog)
xsk_detach_xdp_program(ifobj->ifindex,
mode_to_xdp_flags(ifobj->mode));
+ /* After the detach, as an attached program can cap the MTU. A driver
+ * can also refuse it while it holds the pool of a closed socket, which
+ * the kernel releases from a work item.
+ */
+ if (ifobj->dev_mtu != ifobj->orig_mtu) {
+ int wait_ms = opt_timeout * 1000;
+
+ for (;;) {
+ err = xsk_set_mtu(ifobj->ifindex, ifobj->orig_mtu);
+ if (!err || wait_ms <= 0)
+ break;
+ usleep(100 * 1000);
+ wait_ms -= 100;
+ }
+ if (err)
+ ksft_print_msg("Failed to restore MTU %d on %s\n",
+ ifobj->orig_mtu, ifobj->ifname);
+ }
unload:
xsk_unload_xdp_programs(ifobj);
+ return err;
}
/* Connect the two endpoints without negotiating the remote NIC's capabilities. */
@@ -475,6 +511,7 @@ int main(int argc, char **argv)
struct test_spec test = {};
int ret = TEST_FAILURE;
u32 caps;
+ int err;
/* Use libbpf 1.0 API mode */
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
@@ -518,6 +555,8 @@ int main(int argc, char **argv)
ksft_exit_xfail();
}
+ xsk_set_max_frags(opt_max_frags);
+ xsk_set_timeout(opt_timeout);
/* Before the default packet streams, which have its minimum size. */
if (xsk_set_flow(opt_src_ip, opt_dst_ip, opt_udp_port))
print_usage(argv);
@@ -533,6 +572,7 @@ int main(int argc, char **argv)
shadow_ifobj = ifobj_tx;
}
bind_iface(local_ifobj, opt_ifname, argv);
+ local_ifobj->queue_id = opt_queue;
caps = detect_mode_caps(local_ifobj);
test.tx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);
@@ -558,8 +598,17 @@ int main(int argc, char **argv)
out:
xsk_set_endpoint(NULL);
- cleanup_iface(ifobj_tx);
- cleanup_iface(ifobj_rx);
+ err = cleanup_iface(ifobj_tx);
+ err |= cleanup_iface(ifobj_rx);
+ /* A passed or skipped case still fails if it cannot restore the MTU. */
+ if (err)
+ ret = TEST_FAILURE;
+ /* After the cleanup, which can still fail a case that ran. */
+ if (test.test_func)
+ report_pkt_test(&test, ret);
+ /* The peer skips the case too, rather than fail on the closed connection. */
+ if (ret == TEST_SKIP)
+ xsk_peer_skip(peer, opt_timeout * 1000);
xsk_peer_close(peer);
pkt_stream_delete(test.tx_pkt_stream_default);
pkt_stream_delete(test.rx_pkt_stream_default);
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v6 net-next 11/15] selftests: xsk: wait up to --timeout for the RX stats and a busy bind
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
` (9 preceding siblings ...)
2026-11-27 15:05 ` [PATCH v6 net-next 10/15] selftests: xsk: prepare xskxceiver for endpoints on two hosts Maciej Fijalkowski
@ 2026-11-27 15:05 ` Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 12/15] selftests: xsk: list the endpoint roles of the test cases Maciej Fijalkowski
` (3 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:05 UTC (permalink / raw)
To: netdev
Cc: magnus.karlsson, stfomichev, kuba, pabeni, tushar.vyavahare,
kerneljasonxing, bjorn, Maciej Fijalkowski
Two waits are too short on a slow kernel, e.g. a debug one:
- STAT_RX_FULL and STAT_FILL_EMPTY check a stat 1 ms after RX took its
share, while TX can still be sending the rest. Poll the stat instead.
- TEARDOWN rebinds to the queue of a socket it just closed, which the
kernel releases from a work item, but xsk_configure() gives up after
10 tries 10 ms apart. Retry only on EBUSY, and bind TX before READY,
as RX does, so that the retries do not eat into the RX timeout.
Both now wait for up to --timeout seconds.
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
.../testing/selftests/net/lib/xsk/test_xsk.c | 113 +++++++++++-------
.../testing/selftests/net/lib/xsk/test_xsk.h | 1 -
.../selftests/net/lib/xsk/xskxceiver.c | 2 +-
.../selftests/net/lib/xsk/xskxceiver.h | 1 -
4 files changed, 71 insertions(+), 46 deletions(-)
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c
index 4b8cf5a3d387..a0ad1df00212 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c
@@ -1563,46 +1563,57 @@ static int validate_rx_dropped(struct ifobject *ifobject)
return TEST_FAILURE;
}
-static int validate_rx_full(struct ifobject *ifobject)
+/* TX sends more packets than RX takes, and the stat counts those that find the
+ * RX ring full or the fill ring empty. RX can take its share well before TX
+ * sends the rest, so wait for the stat to count one.
+ */
+static int wait_rx_stat(struct ifobject *ifobject, bool fill_empty)
{
+ struct timeval tv_end, tv_now, tv_timeout = {thread_tmout, 0};
struct xsk_socket *xsk = ifobject->xsk->xsk;
struct xdp_statistics stats;
+ u64 cnt;
int err;
- usleep(1000);
- err = kick_rx(ifobject->xsk);
+ err = gettimeofday(&tv_now, NULL);
if (err)
return TEST_FAILURE;
+ timeradd(&tv_now, &tv_timeout, &tv_end);
- err = get_xsk_stats(xsk, &stats);
- if (err)
- return TEST_FAILURE;
+ do {
+ usleep(1000);
+ err = kick_rx(ifobject->xsk);
+ if (err)
+ return TEST_FAILURE;
- if (stats.rx_ring_full)
- return TEST_PASS;
+ err = get_xsk_stats(xsk, &stats);
+ if (err)
+ return TEST_FAILURE;
+
+ cnt = fill_empty ? stats.rx_fill_ring_empty_descs :
+ stats.rx_ring_full;
+ if (cnt)
+ return TEST_PASS;
+
+ err = gettimeofday(&tv_now, NULL);
+ if (err)
+ return TEST_FAILURE;
+ } while (!timercmp(&tv_now, &tv_end, >));
+ ksft_print_msg("ERROR: [%s] %s is 0 after %u s\n", __func__,
+ fill_empty ? "rx_fill_ring_empty_descs" : "rx_ring_full",
+ thread_tmout);
return TEST_FAILURE;
}
-static int validate_fill_empty(struct ifobject *ifobject)
+static int validate_rx_full(struct ifobject *ifobject)
{
- struct xsk_socket *xsk = ifobject->xsk->xsk;
- struct xdp_statistics stats;
- int err;
-
- usleep(1000);
- err = kick_rx(ifobject->xsk);
- if (err)
- return TEST_FAILURE;
-
- err = get_xsk_stats(xsk, &stats);
- if (err)
- return TEST_FAILURE;
-
- if (stats.rx_fill_ring_empty_descs)
- return TEST_PASS;
+ return wait_rx_stat(ifobject, false);
+}
- return TEST_FAILURE;
+static int validate_fill_empty(struct ifobject *ifobject)
+{
+ return wait_rx_stat(ifobject, true);
}
static int validate_tx_invalid_descs(struct ifobject *ifobject)
@@ -1635,23 +1646,32 @@ static int validate_tx_invalid_descs(struct ifobject *ifobject)
static int xsk_configure(struct test_spec *test, struct ifobject *ifobject,
struct xsk_umem_info *umem)
{
+ struct timeval tv_end, tv_now, tv_timeout = {thread_tmout, 0};
int i, ret;
+ if (gettimeofday(&tv_now, NULL))
+ return -errno;
+ timeradd(&tv_now, &tv_timeout, &tv_end);
+
for (i = 0; i < test->nb_sockets; i++) {
bool shared = !!i;
- u32 ctr = 0;
- while (ctr++ < SOCK_RECONF_CTR) {
+ /* The kernel releases the queue of a closed socket
+ * asynchronously, so a bind to it can fail with EBUSY for a
+ * while after the previous step or test case.
+ */
+ do {
ret = xsk_configure_socket(&ifobject->xsk_arr[i], umem,
- ifobject, shared);
- if (!ret)
+ ifobject, shared);
+ if (ret != -EBUSY)
break;
-
- /* Retry if it fails as xsk_socket__create() is asynchronous */
- if (ctr >= SOCK_RECONF_CTR)
- return ret;
usleep(USLEEP_MAX);
- }
+ if (gettimeofday(&tv_now, NULL))
+ return -errno;
+ } while (!timercmp(&tv_now, &tv_end, >));
+ if (ret)
+ return ret;
+
if (ifobject->busy_poll) {
ret = enable_busy_poll(&ifobject->xsk_arr[i]);
if (ret)
@@ -1771,12 +1791,6 @@ static int testapp_validate_tx_endpoint(struct test_spec *test,
{
int err;
- if (test->current_step == 1) {
- err = thread_common_ops(test, ifobject);
- if (err)
- return err;
- }
-
err = send_pkts(test, ifobject);
if (!err && ifobject->validation_func)
@@ -1829,8 +1843,7 @@ static int testapp_validate_rx_endpoint(struct test_spec *test,
/* An MTU or XDP program change can reset a NIC, which takes the link down on
* both hosts. Each endpoint makes those changes before it is ready, so once
* both are, wait while the local link is down. This is best effort: it misses
- * a reset that a driver has yet to start, and one on the bind of a TX socket,
- * which comes after the wait.
+ * a reset that a driver has yet to start.
*/
static int wait_link_up(struct test_spec *test)
{
@@ -1867,13 +1880,27 @@ static int sync_endpoints(struct test_spec *test)
int worker_testapp_validate_tx(struct test_spec *test)
{
+ struct ifobject *ifobject = test->ifobj_tx;
int err;
+ /* Bind before READY, as RX does, so that a bind retry does not take
+ * from the receive timeout of RX, which starts after READY.
+ */
+ if (test->current_step == 1) {
+ err = thread_common_ops(test, ifobject);
+ if (err) {
+ ksft_print_msg("TX endpoint setup failed at step %u: %d\n",
+ test->current_step, err);
+ xsk_peer_abort(ctrl_peer);
+ return err;
+ }
+ }
+
err = sync_endpoints(test);
if (err)
return err;
- err = testapp_validate_tx_endpoint(test, test->ifobj_tx);
+ err = testapp_validate_tx_endpoint(test, ifobject);
if (err && err != TEST_SKIP) {
ksft_print_msg("TX endpoint traffic failed at step %u: %d\n",
test->current_step, err);
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.h b/tools/testing/selftests/net/lib/xsk/test_xsk.h
index 15534f4ec8f4..ee840ccdfcbf 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.h
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.h
@@ -28,7 +28,6 @@
#define MAX_ETH_PKT_SIZE 1518
#define MAX_INTERFACE_NAME_CHARS 16
#define MAX_TEST_NAME_SIZE 48
-#define SOCK_RECONF_CTR 10
#define USLEEP_MAX 10000
#define MAX_SKB_FRAGS_PATH "/proc/sys/net/core/max_skb_frags"
diff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.c b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
index 7ef6f08538bd..07e4cadfb164 100644
--- a/tools/testing/selftests/net/lib/xsk/xskxceiver.c
+++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
@@ -186,7 +186,7 @@ static void print_usage(char **argv)
" the caller steers the test flow to the bound queue\n"
" --queue N AF_XDP queue to bind (default 0)\n"
" --max-frags N Fragment limit for TOO_MANY_FRAGS (default by mode)\n"
- " --timeout SEC Traffic and link timeout (default 3)\n"
+ " --timeout SEC Traffic, link and bind timeout (default 3)\n"
" -h, --help Display this help and exit\n";
ksft_print_msg(str, basename(argv[0]));
diff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.h b/tools/testing/selftests/net/lib/xsk/xskxceiver.h
index 3ca518df23ad..2365bda57a4b 100644
--- a/tools/testing/selftests/net/lib/xsk/xskxceiver.h
+++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.h
@@ -24,7 +24,6 @@
#define MAX_TEARDOWN_ITER 10
#define MAX_ETH_JUMBO_SIZE 9000
-#define SOCK_RECONF_CTR 10
#define RX_FULL_RXQSIZE 32
#define UMEM_HEADROOM_TEST_SIZE 128
#define XSK_UMEM__INVALID_FRAME_SIZE (MAX_ETH_JUMBO_SIZE + 1)
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v6 net-next 12/15] selftests: xsk: list the endpoint roles of the test cases
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
` (10 preceding siblings ...)
2026-11-27 15:05 ` [PATCH v6 net-next 11/15] selftests: xsk: wait up to --timeout for the RX stats and a busy bind Maciej Fijalkowski
@ 2026-11-27 15:05 ` Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 13/15] selftests: drv-net: rename nsim_test to sw_test Maciej Fijalkowski
` (2 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:05 UTC (permalink / raw)
To: netdev
Cc: magnus.karlsson, stfomichev, kuba, pabeni, tushar.vyavahare,
kerneljasonxing, bjorn, Maciej Fijalkowski
On a NIC, drivers/net/xsk.py, added later in this series, runs each
case with the DUT endpoint as RX, as TX or both. Rather than keep a
list of case IDs there, split tests[] by the role that a case tests:
both, RX, TX, or none for the cases that run only on veth:
BIDIRECTIONAL, and STAT_RX_DROPPED and TX_QUEUE_CONSUMER, which skip in
zero-copy mode. The test IDs follow the new order, and -l lists each
test with its roles, e.g. "0: SEND_RECEIVE rx tx", so that one list
serves both runs.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
.../testing/selftests/net/lib/xsk/test_xsk.h | 68 +++++++++++++------
.../selftests/net/lib/xsk/xskxceiver.c | 33 +++++++--
2 files changed, 72 insertions(+), 29 deletions(-)
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.h b/tools/testing/selftests/net/lib/xsk/test_xsk.h
index ee840ccdfcbf..872e15206b48 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.h
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.h
@@ -303,49 +303,73 @@ int testapp_xdp_shared_umem(struct test_spec *test);
int worker_testapp_validate_rx(struct test_spec *test);
int worker_testapp_validate_tx(struct test_spec *test);
-static const struct test_spec tests[] = {
+/* Tests by the role of the endpoint that they check, which xskxceiver -l
+ * lists after the name. A hardware run gives that role to its zero-copy
+ * endpoint. It does not do the generic tests: BIDIRECTIONAL swaps the
+ * directions, which a hardware run tests one at a time, and the others
+ * skip in zero-copy mode.
+ */
+static const struct test_spec hw_rx_tx_tests[] = {
{.name = "SEND_RECEIVE", .test_func = testapp_send_receive},
{.name = "SEND_RECEIVE_2K_FRAME", .test_func = testapp_send_receive_2k_frame},
{.name = "SEND_RECEIVE_SINGLE_PKT", .test_func = testapp_single_pkt},
+ {.name = "SEND_RECEIVE_9K_PACKETS", .test_func = testapp_send_receive_mb},
+ {.name = "SEND_RECEIVE_UNALIGNED", .test_func = testapp_send_receive_unaligned},
+ {.name = "SEND_RECEIVE_UNALIGNED_9K_PACKETS",
+ .test_func = testapp_send_receive_unaligned_mb},
+ {.name = "HW_SW_MAX_RING_SIZE", .test_func = testapp_hw_sw_max_ring_size},
+ {.name = "TEARDOWN", .test_func = testapp_teardown},
+ {.name = "XDP_SHARED_UMEM", .test_func = testapp_xdp_shared_umem},
+};
+
+static const struct test_spec hw_rx_tests[] = {
{.name = "POLL_RX", .test_func = testapp_poll_rx},
- {.name = "POLL_TX", .test_func = testapp_poll_tx},
{.name = "POLL_RXQ_FULL", .test_func = testapp_poll_rxq_tmout},
- {.name = "POLL_TXQ_FULL", .test_func = testapp_poll_txq_tmout},
- {.name = "ALIGNED_INV_DESC", .test_func = testapp_aligned_inv_desc},
- {.name = "ALIGNED_INV_DESC_2K_FRAME_SIZE", .test_func = testapp_aligned_inv_desc_2k_frame},
{.name = "UMEM_HEADROOM", .test_func = testapp_headroom},
- {.name = "BIDIRECTIONAL", .test_func = testapp_bidirectional},
- {.name = "STAT_RX_DROPPED", .test_func = testapp_stats_rx_dropped},
- {.name = "STAT_TX_INVALID", .test_func = testapp_stats_tx_invalid_descs},
{.name = "STAT_RX_FULL", .test_func = testapp_stats_rx_full},
{.name = "STAT_FILL_EMPTY", .test_func = testapp_stats_fill_empty},
{.name = "XDP_PROG_CLEANUP", .test_func = testapp_xdp_prog_cleanup},
{.name = "XDP_DROP_HALF", .test_func = testapp_xdp_drop},
- {.name = "XDP_SHARED_UMEM", .test_func = testapp_xdp_shared_umem},
{.name = "XDP_METADATA_COPY", .test_func = testapp_xdp_metadata},
{.name = "XDP_METADATA_COPY_MULTI_BUFF", .test_func = testapp_xdp_metadata_mb},
- {.name = "ALIGNED_INV_DESC_MULTI_BUFF", .test_func = testapp_aligned_inv_desc_mb},
- {.name = "TOO_MANY_FRAGS", .test_func = testapp_too_many_frags},
{.name = "XDP_ADJUST_TAIL_SHRINK", .test_func = testapp_adjust_tail_shrink},
- {.name = "TX_QUEUE_CONSUMER", .test_func = testapp_tx_queue_consumer},
- /* Flaky tests */
{.name = "XDP_ADJUST_TAIL_SHRINK_MULTI_BUFF", .test_func = testapp_adjust_tail_shrink_mb},
{.name = "XDP_ADJUST_TAIL_GROW", .test_func = testapp_adjust_tail_grow},
{.name = "XDP_ADJUST_TAIL_GROW_MULTI_BUFF", .test_func = testapp_adjust_tail_grow_mb},
- {.name = "SEND_RECEIVE_9K_PACKETS", .test_func = testapp_send_receive_mb},
- /* Tests with huge page dependency */
- {.name = "SEND_RECEIVE_UNALIGNED", .test_func = testapp_send_receive_unaligned},
+};
+
+static const struct test_spec hw_tx_tests[] = {
+ {.name = "POLL_TX", .test_func = testapp_poll_tx},
+ {.name = "POLL_TXQ_FULL", .test_func = testapp_poll_txq_tmout},
+ {.name = "ALIGNED_INV_DESC", .test_func = testapp_aligned_inv_desc},
+ {.name = "ALIGNED_INV_DESC_2K_FRAME_SIZE", .test_func = testapp_aligned_inv_desc_2k_frame},
+ {.name = "STAT_TX_INVALID", .test_func = testapp_stats_tx_invalid_descs},
+ {.name = "ALIGNED_INV_DESC_MULTI_BUFF", .test_func = testapp_aligned_inv_desc_mb},
+ {.name = "TOO_MANY_FRAGS", .test_func = testapp_too_many_frags},
{.name = "UNALIGNED_INV_DESC", .test_func = testapp_unaligned_inv_desc},
{.name = "UNALIGNED_INV_DESC_4001_FRAME_SIZE",
.test_func = testapp_unaligned_inv_desc_4001_frame},
- {.name = "SEND_RECEIVE_UNALIGNED_9K_PACKETS",
- .test_func = testapp_send_receive_unaligned_mb},
{.name = "UNALIGNED_INV_DESC_MULTI_BUFF", .test_func = testapp_unaligned_inv_desc_mb},
- /* Test with HW ring size dependency */
{.name = "HW_SW_MIN_RING_SIZE", .test_func = testapp_hw_sw_min_ring_size},
- {.name = "HW_SW_MAX_RING_SIZE", .test_func = testapp_hw_sw_max_ring_size},
- /* Too long test */
- {.name = "TEARDOWN", .test_func = testapp_teardown},
+};
+
+static const struct test_spec generic_tests[] = {
+ {.name = "BIDIRECTIONAL", .test_func = testapp_bidirectional},
+ {.name = "STAT_RX_DROPPED", .test_func = testapp_stats_rx_dropped},
+ {.name = "TX_QUEUE_CONSUMER", .test_func = testapp_tx_queue_consumer},
+};
+
+/* A test ID is the index of the test in these arrays taken in order. */
+static const struct test_group {
+ const struct test_spec *tests;
+ u32 nb_tests;
+ bool hw_rx;
+ bool hw_tx;
+} test_groups[] = {
+ {hw_rx_tx_tests, ARRAY_SIZE(hw_rx_tx_tests), true, true},
+ {hw_rx_tests, ARRAY_SIZE(hw_rx_tests), true, false},
+ {hw_tx_tests, ARRAY_SIZE(hw_tx_tests), false, true},
+ {generic_tests, ARRAY_SIZE(generic_tests), false, false},
};
diff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.c b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
index 07e4cadfb164..7d6aa464c660 100644
--- a/tools/testing/selftests/net/lib/xsk/xskxceiver.c
+++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
@@ -173,7 +173,7 @@ static void print_usage(char **argv)
" -v, --verbose Verbose output\n"
" -b, --busy-poll Enable busy poll\n"
" -m, --mode Mode to run: skb, drv or zc\n"
- " -l, --list List all available tests\n"
+ " -l, --list List all tests and the roles they test on hardware\n"
" -t, --test Test case to run, a number from -l\n"
" -e, --endpoint Role of this endpoint: rx or tx\n"
" -p, --peer Control host: IPv4/IPv6 address or hostname\n"
@@ -218,13 +218,31 @@ static void bind_iface(struct ifobject *ifobj, const char *ifname, char **argv)
ifobj->orig_mtu = ifobj->dev_mtu;
}
+/* List each test followed by the roles that it tests on hardware, if any. */
static void print_tests(void)
{
- u32 i;
+ const struct test_group *group;
+ u32 i, j, id = 0;
printf("Tests:\n");
- for (i = 0; i < ARRAY_SIZE(tests); i++)
- printf("%u: %s\n", i, tests[i].name);
+ for (i = 0; i < ARRAY_SIZE(test_groups); i++) {
+ group = &test_groups[i];
+ for (j = 0; j < group->nb_tests; j++, id++)
+ printf("%u: %s%s%s\n", id, group->tests[j].name,
+ group->hw_rx ? " rx" : "", group->hw_tx ? " tx" : "");
+ }
+}
+
+static const struct test_spec *find_test(u32 id)
+{
+ u32 i;
+
+ for (i = 0; i < ARRAY_SIZE(test_groups); i++) {
+ if (id < test_groups[i].nb_tests)
+ return &test_groups[i].tests[id];
+ id -= test_groups[i].nb_tests;
+ }
+ return NULL;
}
static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj_rx, int argc,
@@ -503,8 +521,8 @@ static int setup_peer(struct ifobject *local, struct ifobject *shadow,
int main(int argc, char **argv)
{
u32 cache_line_size, max_frags, umem_tailroom;
- const size_t total_tests = ARRAY_SIZE(tests);
struct ifobject *ifobj_tx, *ifobj_rx;
+ const struct test_spec *test_to_run;
struct ifobject *shadow_ifobj;
struct ifobject *local_ifobj;
struct xsk_peer *peer = NULL;
@@ -550,7 +568,8 @@ int main(int argc, char **argv)
ifobj_tx->caps.umem_tailroom = umem_tailroom;
ifobj_rx->caps.umem_tailroom = umem_tailroom;
- if (opt_run_test != RUN_ALL_TESTS && opt_run_test >= total_tests) {
+ test_to_run = find_test(opt_run_test);
+ if (!test_to_run) {
ksft_print_msg("Error: test %u does not exist.\n", opt_run_test);
ksft_exit_xfail();
}
@@ -593,7 +612,7 @@ int main(int argc, char **argv)
}
ksft_set_plan(1);
- test_init(&test, ifobj_tx, ifobj_rx, opt_mode, &tests[opt_run_test]);
+ test_init(&test, ifobj_tx, ifobj_rx, opt_mode, test_to_run);
ret = run_pkt_test(&test);
out:
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v6 net-next 13/15] selftests: drv-net: rename nsim_test to sw_test
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
` (11 preceding siblings ...)
2026-11-27 15:05 ` [PATCH v6 net-next 12/15] selftests: xsk: list the endpoint roles of the test cases Maciej Fijalkowski
@ 2026-11-27 15:05 ` Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 14/15] selftests: drv-net: decouple local link setup from netdevsim Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 15/15] selftests: drv-net: run the AF_XDP tests over veth or a NIC Maciej Fijalkowski
14 siblings, 0 replies; 16+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:05 UTC (permalink / raw)
To: netdev
Cc: magnus.karlsson, stfomichev, kuba, pabeni, tushar.vyavahare,
kerneljasonxing, bjorn, Maciej Fijalkowski
NetDrvEnv and NetDrvEpEnv take nsim_test to limit a test to the
netdevsim devices that they create without NETIF (True), or to the
NETIF device (False). With a following patch, NetDrvEpEnv can create a
veth pair instead of netdevsim, so rename the argument to sw_test.
require_nsim() keeps nsim_test, as it checks for nsim itself.
No functional change.
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
tools/testing/selftests/drivers/net/hw/csum.py | 2 +-
.../drivers/net/hw/devlink_rate_cross_esw.py | 2 +-
.../selftests/drivers/net/hw/devlink_rate_tc_bw.py | 2 +-
tools/testing/selftests/drivers/net/hw/gro_stats.py | 2 +-
.../testing/selftests/drivers/net/hw/ipsec_vxlan.py | 2 +-
tools/testing/selftests/drivers/net/hw/irq.py | 2 +-
.../selftests/drivers/net/hw/nic_timestamp.py | 2 +-
tools/testing/selftests/drivers/net/hw/ntuple.py | 2 +-
tools/testing/selftests/drivers/net/hw/pause.py | 2 +-
.../selftests/drivers/net/hw/pp_alloc_fail.py | 2 +-
| 2 +-
| 2 +-
| 2 +-
| 2 +-
tools/testing/selftests/drivers/net/hw/tso.py | 2 +-
.../testing/selftests/drivers/net/hw/xsk_reconfig.py | 2 +-
tools/testing/selftests/drivers/net/lib/py/env.py | 12 ++++++------
tools/testing/selftests/drivers/net/perf/devmem.py | 2 +-
tools/testing/selftests/drivers/net/perf/iperf.py | 2 +-
19 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/hw/csum.py b/tools/testing/selftests/drivers/net/hw/csum.py
index 0e99198f8d39..0deef7812b5e 100755
--- a/tools/testing/selftests/drivers/net/hw/csum.py
+++ b/tools/testing/selftests/drivers/net/hw/csum.py
@@ -85,7 +85,7 @@ def check_nic_features(cfg) -> None:
def main() -> None:
- with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEpEnv(__file__, sw_test=False) as cfg:
check_nic_features(cfg)
cfg.bin_local = cfg.net_lib_dir / "csum"
diff --git a/tools/testing/selftests/drivers/net/hw/devlink_rate_cross_esw.py b/tools/testing/selftests/drivers/net/hw/devlink_rate_cross_esw.py
index 4416f024cb76..91cab142fc3d 100755
--- a/tools/testing/selftests/drivers/net/hw/devlink_rate_cross_esw.py
+++ b/tools/testing/selftests/drivers/net/hw/devlink_rate_cross_esw.py
@@ -278,7 +278,7 @@ def test_tx_rates_on_cross_esw(cfg):
def main() -> None:
"""Main function."""
- with NetDrvEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEnv(__file__, sw_test=False) as cfg:
cfg.devnl = DevlinkFamily()
ksft_run(
diff --git a/tools/testing/selftests/drivers/net/hw/devlink_rate_tc_bw.py b/tools/testing/selftests/drivers/net/hw/devlink_rate_tc_bw.py
index 38d712755257..4fc02259ff35 100755
--- a/tools/testing/selftests/drivers/net/hw/devlink_rate_tc_bw.py
+++ b/tools/testing/selftests/drivers/net/hw/devlink_rate_tc_bw.py
@@ -416,7 +416,7 @@ def main() -> None:
"""
Main entry point for running the test cases.
"""
- with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEpEnv(__file__, sw_test=False) as cfg:
cfg.devnl = DevlinkFamily()
cfg.pci = os.path.basename(
diff --git a/tools/testing/selftests/drivers/net/hw/gro_stats.py b/tools/testing/selftests/drivers/net/hw/gro_stats.py
index 70e76e3888bd..32b5c766741f 100755
--- a/tools/testing/selftests/drivers/net/hw/gro_stats.py
+++ b/tools/testing/selftests/drivers/net/hw/gro_stats.py
@@ -292,7 +292,7 @@ def test_gro_order(cfg, num_flows):
def main() -> None:
""" Ksft boiler plate main """
- with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEpEnv(__file__, sw_test=False) as cfg:
cfg.netnl = NetdevFamily()
ksft_run([test_gro_stats_single,
test_gro_stats_full,
diff --git a/tools/testing/selftests/drivers/net/hw/ipsec_vxlan.py b/tools/testing/selftests/drivers/net/hw/ipsec_vxlan.py
index 0740a4d85240..88d79e9fd0ec 100755
--- a/tools/testing/selftests/drivers/net/hw/ipsec_vxlan.py
+++ b/tools/testing/selftests/drivers/net/hw/ipsec_vxlan.py
@@ -195,7 +195,7 @@ def test_vxlan_ipsec_crypto_offload(cfg, outer_ipver, inner_ipver):
def main():
"""Runs VXLAN+IPsec crypto-offload GSO selftest."""
- with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEpEnv(__file__, sw_test=False) as cfg:
ksft_run([test_vxlan_ipsec_crypto_offload], args=(cfg,))
ksft_exit()
diff --git a/tools/testing/selftests/drivers/net/hw/irq.py b/tools/testing/selftests/drivers/net/hw/irq.py
index 0699d6a8b4e2..364f270081c1 100755
--- a/tools/testing/selftests/drivers/net/hw/irq.py
+++ b/tools/testing/selftests/drivers/net/hw/irq.py
@@ -85,7 +85,7 @@ def check_down(cfg) -> None:
def main() -> None:
- with NetDrvEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEnv(__file__, sw_test=False) as cfg:
cfg.ethnl = EthtoolFamily()
cfg.netnl = NetdevFamily()
diff --git a/tools/testing/selftests/drivers/net/hw/nic_timestamp.py b/tools/testing/selftests/drivers/net/hw/nic_timestamp.py
index c632b41e7a23..7e512b62ffbc 100755
--- a/tools/testing/selftests/drivers/net/hw/nic_timestamp.py
+++ b/tools/testing/selftests/drivers/net/hw/nic_timestamp.py
@@ -213,7 +213,7 @@ def test_hwtstamp_rx_ioctl(cfg):
def main() -> None:
""" Ksft boiler plate main """
- with NetDrvEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEnv(__file__, sw_test=False) as cfg:
cfg.ethnl = EthtoolFamily()
ksft_run([test_hwtstamp_tx_ioctl, test_hwtstamp_tx_netlink,
test_hwtstamp_rx_ioctl, test_hwtstamp_rx_netlink],
diff --git a/tools/testing/selftests/drivers/net/hw/ntuple.py b/tools/testing/selftests/drivers/net/hw/ntuple.py
index ef4604bfa8ef..5f9fa3b61bd9 100755
--- a/tools/testing/selftests/drivers/net/hw/ntuple.py
+++ b/tools/testing/selftests/drivers/net/hw/ntuple.py
@@ -154,7 +154,7 @@ def queue(cfg, ipver, proto, fields):
def main() -> None:
"""Ksft boilerplate main."""
- with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEpEnv(__file__, sw_test=False) as cfg:
cfg.ethnl = EthtoolFamily()
cfg.netdevnl = NetdevFamily()
ksft_run([queue], args=(cfg,))
diff --git a/tools/testing/selftests/drivers/net/hw/pause.py b/tools/testing/selftests/drivers/net/hw/pause.py
index c3398c7452e0..a18d3d7f2653 100755
--- a/tools/testing/selftests/drivers/net/hw/pause.py
+++ b/tools/testing/selftests/drivers/net/hw/pause.py
@@ -932,7 +932,7 @@ def pause_autoneg_link_autoneg(cfg):
def main():
""" Entry point """
- with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEpEnv(__file__, sw_test=False) as cfg:
ksft_run([pause_test_support,
pause_advertising_test,
pause_aneg_resolution,
diff --git a/tools/testing/selftests/drivers/net/hw/pp_alloc_fail.py b/tools/testing/selftests/drivers/net/hw/pp_alloc_fail.py
index 2a51b60df8a1..db37538c0168 100755
--- a/tools/testing/selftests/drivers/net/hw/pp_alloc_fail.py
+++ b/tools/testing/selftests/drivers/net/hw/pp_alloc_fail.py
@@ -134,7 +134,7 @@ def test_pp_alloc(cfg, netdevnl):
def main() -> None:
""" Ksft boiler plate main """
netdevnl = NetdevFamily()
- with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEpEnv(__file__, sw_test=False) as cfg:
ksft_run([test_pp_alloc], args=(cfg, netdevnl, ))
ksft_exit()
--git a/tools/testing/selftests/drivers/net/hw/rss_api.py b/tools/testing/selftests/drivers/net/hw/rss_api.py
index 19847f3d4a00..e7f79179d8d5 100755
--- a/tools/testing/selftests/drivers/net/hw/rss_api.py
+++ b/tools/testing/selftests/drivers/net/hw/rss_api.py
@@ -466,7 +466,7 @@ def test_rss_ctx_ntf(cfg):
def main() -> None:
""" Ksft boiler plate main """
- with NetDrvEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEnv(__file__, sw_test=False) as cfg:
cfg.ethnl = EthtoolFamily()
ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, ))
ksft_exit()
--git a/tools/testing/selftests/drivers/net/hw/rss_ctx.py b/tools/testing/selftests/drivers/net/hw/rss_ctx.py
index 5b25fa89c629..dbd8893c8a73 100755
--- a/tools/testing/selftests/drivers/net/hw/rss_ctx.py
+++ b/tools/testing/selftests/drivers/net/hw/rss_ctx.py
@@ -1015,7 +1015,7 @@ def test_rss_context_persist_ifdown_and_create(cfg):
def main() -> None:
- with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEpEnv(__file__, sw_test=False) as cfg:
cfg.context_cnt = None
cfg.ethnl = EthtoolFamily()
cfg.netdevnl = NetdevFamily()
--git a/tools/testing/selftests/drivers/net/hw/rss_flow_label.py b/tools/testing/selftests/drivers/net/hw/rss_flow_label.py
index 7dc80070884a..39baf07f3842 100755
--- a/tools/testing/selftests/drivers/net/hw/rss_flow_label.py
+++ b/tools/testing/selftests/drivers/net/hw/rss_flow_label.py
@@ -161,7 +161,7 @@ def test_rss_flow_label_6only(cfg):
def main() -> None:
- with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEpEnv(__file__, sw_test=False) as cfg:
ksft_run([test_rss_flow_label,
test_rss_flow_label_6only],
args=(cfg, ))
--git a/tools/testing/selftests/drivers/net/hw/rss_input_xfrm.py b/tools/testing/selftests/drivers/net/hw/rss_input_xfrm.py
index 503f1a2a2872..1b8ee94ac553 100755
--- a/tools/testing/selftests/drivers/net/hw/rss_input_xfrm.py
+++ b/tools/testing/selftests/drivers/net/hw/rss_input_xfrm.py
@@ -111,7 +111,7 @@ def test_rss_input_xfrm_ipv6(cfg):
def main() -> None:
- with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEpEnv(__file__, sw_test=False) as cfg:
cfg.ethnl = EthtoolFamily()
cfg.netdevnl = NetdevFamily()
diff --git a/tools/testing/selftests/drivers/net/hw/tso.py b/tools/testing/selftests/drivers/net/hw/tso.py
index 176ddf97fabb..1b1d61f53ac4 100755
--- a/tools/testing/selftests/drivers/net/hw/tso.py
+++ b/tools/testing/selftests/drivers/net/hw/tso.py
@@ -379,7 +379,7 @@ def query_nic_features(cfg) -> None:
def main() -> None:
- with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEpEnv(__file__, sw_test=False) as cfg:
cfg.ethnl = EthtoolFamily()
cfg.netnl = NetdevFamily()
diff --git a/tools/testing/selftests/drivers/net/hw/xsk_reconfig.py b/tools/testing/selftests/drivers/net/hw/xsk_reconfig.py
index d19d1d518208..f80beb3ce098 100755
--- a/tools/testing/selftests/drivers/net/hw/xsk_reconfig.py
+++ b/tools/testing/selftests/drivers/net/hw/xsk_reconfig.py
@@ -51,7 +51,7 @@ def check_rx_resize(cfg):
ethtool(f"-G %s rx %d" % (cfg.ifname, rx_ring))
def main():
- with NetDrvEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEnv(__file__, sw_test=False) as cfg:
ksft_run([check_xdp_bind, check_rx_resize],
args=(cfg, ))
ksft_exit()
diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
index 6262080a8bf4..20affe55750d 100644
--- a/tools/testing/selftests/drivers/net/lib/py/env.py
+++ b/tools/testing/selftests/drivers/net/lib/py/env.py
@@ -93,18 +93,18 @@ class NetDrvEnv(NetDrvEnvBase):
"""
Class for a single NIC / host env, with no remote end
"""
- def __init__(self, src_path, nsim_test=None, **kwargs):
+ def __init__(self, src_path, sw_test=None, **kwargs):
super().__init__(src_path)
self._ns = None
if 'NETIF' in self.env:
- if nsim_test is True:
+ if sw_test is True:
raise KsftXfailEx("Test only works on netdevsim")
self.dev = ip("-d link show dev " + self.env['NETIF'], json=True)[0]
else:
- if nsim_test is False:
+ if sw_test is False:
raise KsftXfailEx("Test does not work on netdevsim")
self._ns = NetdevSimDev(**kwargs)
@@ -132,7 +132,7 @@ class NetDrvEpEnv(NetDrvEnvBase):
nsim_v4_pfx = "192.0.2."
nsim_v6_pfx = "2001:db8::"
- def __init__(self, src_path, nsim_test=None, queue_count=None):
+ def __init__(self, src_path, sw_test=None, queue_count=None):
super().__init__(src_path)
self._stats_settle_time = None
@@ -149,7 +149,7 @@ class NetDrvEpEnv(NetDrvEnvBase):
self.remote_addr_v = { "4": None, "6": None }
if "NETIF" in self.env:
- if nsim_test is True:
+ if sw_test is True:
raise KsftXfailEx("Test only works on netdevsim")
self._check_env()
@@ -162,7 +162,7 @@ class NetDrvEpEnv(NetDrvEnvBase):
kind = self.env["REMOTE_TYPE"]
args = self.env["REMOTE_ARGS"]
else:
- if nsim_test is False:
+ if sw_test is False:
raise KsftXfailEx("Test does not work on netdevsim")
self.create_local()
diff --git a/tools/testing/selftests/drivers/net/perf/devmem.py b/tools/testing/selftests/drivers/net/perf/devmem.py
index 4c1fb9b51fff..6014358e291e 100755
--- a/tools/testing/selftests/drivers/net/perf/devmem.py
+++ b/tools/testing/selftests/drivers/net/perf/devmem.py
@@ -87,7 +87,7 @@ def kperf(cfg) -> None:
def main() -> None:
"""Run the devmem performance test."""
- with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEpEnv(__file__, sw_test=False) as cfg:
ksft_run([kperf], args=(cfg,))
ksft_exit()
diff --git a/tools/testing/selftests/drivers/net/perf/iperf.py b/tools/testing/selftests/drivers/net/perf/iperf.py
index 5b6f0bce2a03..53afe0e70851 100755
--- a/tools/testing/selftests/drivers/net/perf/iperf.py
+++ b/tools/testing/selftests/drivers/net/perf/iperf.py
@@ -14,7 +14,7 @@ def tcp(cfg):
def main():
"""Run the iperf performance test."""
- with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+ with NetDrvEpEnv(__file__, sw_test=False) as cfg:
ksft_run([tcp], args=(cfg,))
ksft_exit()
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v6 net-next 14/15] selftests: drv-net: decouple local link setup from netdevsim
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
` (12 preceding siblings ...)
2026-11-27 15:05 ` [PATCH v6 net-next 13/15] selftests: drv-net: rename nsim_test to sw_test Maciej Fijalkowski
@ 2026-11-27 15:05 ` Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 15/15] selftests: drv-net: run the AF_XDP tests over veth or a NIC Maciej Fijalkowski
14 siblings, 0 replies; 16+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:05 UTC (permalink / raw)
To: netdev
Cc: magnus.karlsson, stfomichev, kuba, pabeni, tushar.vyavahare,
kerneljasonxing, bjorn, Maciej Fijalkowski
Without NETIF, NetDrvEpEnv addresses its pair of netdevsim devices from
nsim_v4_pfx and nsim_v6_pfx and brings them up in create_local(). A
following patch lets the env create a veth pair instead, which needs the
same addresses and setup.
Rename the prefixes to sw_v4_pfx and sw_v6_pfx, as they serve any
software interface pair, and update tso.py, which builds its tunnel
addresses from them. Move the address and link setup out of
create_local() into _setup_sw_ifaces(), which takes the names of the
local interface and its peer.
No functional change.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
tools/testing/selftests/drivers/net/hw/tso.py | 8 ++---
.../selftests/drivers/net/lib/py/env.py | 29 +++++++++++--------
2 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/hw/tso.py b/tools/testing/selftests/drivers/net/hw/tso.py
index 1b1d61f53ac4..4307537b49cd 100755
--- a/tools/testing/selftests/drivers/net/hw/tso.py
+++ b/tools/testing/selftests/drivers/net/hw/tso.py
@@ -245,10 +245,10 @@ def run_big_tcp_stream(cfg, ipver, remote_v4, remote_v6):
def build_tunnel(cfg, outer_ipver, tun_info):
- local_v4 = NetDrvEpEnv.nsim_v4_pfx + "1"
- local_v6 = NetDrvEpEnv.nsim_v6_pfx + "1"
- remote_v4 = NetDrvEpEnv.nsim_v4_pfx + "2"
- remote_v6 = NetDrvEpEnv.nsim_v6_pfx + "2"
+ local_v4 = NetDrvEpEnv.sw_v4_pfx + "1"
+ local_v6 = NetDrvEpEnv.sw_v6_pfx + "1"
+ remote_v4 = NetDrvEpEnv.sw_v4_pfx + "2"
+ remote_v6 = NetDrvEpEnv.sw_v6_pfx + "2"
local_addr = cfg.addr_v[outer_ipver]
remote_addr = cfg.remote_addr_v[outer_ipver]
diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
index 20affe55750d..ab404f81521f 100644
--- a/tools/testing/selftests/drivers/net/lib/py/env.py
+++ b/tools/testing/selftests/drivers/net/lib/py/env.py
@@ -129,8 +129,8 @@ class NetDrvEpEnv(NetDrvEnvBase):
"""
# Network prefixes used for local tests
- nsim_v4_pfx = "192.0.2."
- nsim_v6_pfx = "2001:db8::"
+ sw_v4_pfx = "192.0.2."
+ sw_v6_pfx = "2001:db8::"
def __init__(self, src_path, sw_test=None, queue_count=None):
super().__init__(src_path)
@@ -169,10 +169,10 @@ class NetDrvEpEnv(NetDrvEnvBase):
self.dev = self._ns.nsims[0].dev
- self.addr_v["4"] = self.nsim_v4_pfx + "1"
- self.addr_v["6"] = self.nsim_v6_pfx + "1"
- self.remote_addr_v["4"] = self.nsim_v4_pfx + "2"
- self.remote_addr_v["6"] = self.nsim_v6_pfx + "2"
+ self.addr_v["4"] = self.sw_v4_pfx + "1"
+ self.addr_v["6"] = self.sw_v6_pfx + "1"
+ self.remote_addr_v["4"] = self.sw_v4_pfx + "2"
+ self.remote_addr_v["6"] = self.sw_v6_pfx + "2"
kind = "netns"
args = self._netns.name
@@ -208,13 +208,18 @@ class NetDrvEpEnv(NetDrvEnvBase):
NetdevSimDev.ctrl_write('link_device',
f'{nsfd0.fileno()}:{ifi0} {nsfd1.fileno()}:{ifi1}')
- ip(f" addr add dev {self._ns.nsims[0].ifname} {self.nsim_v4_pfx}1/24")
- ip(f"-6 addr add dev {self._ns.nsims[0].ifname} {self.nsim_v6_pfx}1/64 nodad")
- ip(f" link set dev {self._ns.nsims[0].ifname} up")
+ self._setup_sw_ifaces(self._ns.nsims[0].ifname,
+ self._ns_peer.nsims[0].ifname)
- ip(f" addr add dev {self._ns_peer.nsims[0].ifname} {self.nsim_v4_pfx}2/24", ns=self._netns)
- ip(f"-6 addr add dev {self._ns_peer.nsims[0].ifname} {self.nsim_v6_pfx}2/64 nodad", ns=self._netns)
- ip(f" link set dev {self._ns_peer.nsims[0].ifname} up", ns=self._netns)
+ def _setup_sw_ifaces(self, ifname, peer_ifname):
+ """Address and bring up a local interface and its peer in _netns."""
+ ip(f" addr add dev {ifname} {self.sw_v4_pfx}1/24")
+ ip(f"-6 addr add dev {ifname} {self.sw_v6_pfx}1/64 nodad")
+ ip(f" link set dev {ifname} up")
+
+ ip(f" addr add dev {peer_ifname} {self.sw_v4_pfx}2/24", ns=self._netns)
+ ip(f"-6 addr add dev {peer_ifname} {self.sw_v6_pfx}2/64 nodad", ns=self._netns)
+ ip(f" link set dev {peer_ifname} up", ns=self._netns)
def _check_env(self):
vars_needed = [
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v6 net-next 15/15] selftests: drv-net: run the AF_XDP tests over veth or a NIC
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
` (13 preceding siblings ...)
2026-11-27 15:05 ` [PATCH v6 net-next 14/15] selftests: drv-net: decouple local link setup from netdevsim Maciej Fijalkowski
@ 2026-11-27 15:05 ` Maciej Fijalkowski
14 siblings, 0 replies; 16+ messages in thread
From: Maciej Fijalkowski @ 2026-11-27 15:05 UTC (permalink / raw)
To: netdev
Cc: magnus.karlsson, stfomichev, kuba, pabeni, tushar.vyavahare,
kerneljasonxing, bjorn, Maciej Fijalkowski
Add drivers/net/xsk.py, which runs each AF_XDP case as a pair of
xskxceiver processes: a local one, and a remote one in SKB mode, so that
the remote needs no zero-copy support. Each case skips if either
interface has an XDP program, sets up what it needs, undoes it with
defer(), and detaches XDP and restores the MTU on both sides after the
endpoints exit, as a killed endpoint cannot.
Without NETIF, the endpoints run over a veth pair, the remote end in a
namespace, and each case runs with the local endpoint in SKB and DRV
mode, as test_xsk.sh did. For this, NetDrvEpEnv takes sw_drv,
"netdevsim" by default, to ask for a veth pair instead. Cases that veth
cannot pass are expected failures.
With NETIF, the local endpoint runs in zero-copy mode, once per role
that xskxceiver -l lists for the case. Each case takes the DUT queue
out of RSS, as a zero-copy TX queue drops what it receives, and steers
the test flow to the bound queues and the control connection to DUT
queue 0 with ntuple rules, over IPv4 if a host rejects IPv6 ones. A DUT
without zero-copy or a second queue skips.
Every case also runs with the local endpoint busy polling, which veth
supports since commit c6d21717a602 ("veth: link RX queues to their NAPI
instances"). Over veth, that endpoint only receives, so unlike
test_xsk.sh, the run does not busy poll a TX socket. The UNALIGNED
cases are expected failures without huge pages on both hosts.
Also fix hugepages_present(), which since commit 041b68f688a3
("selftests/xsx: test for huge pages only once") has passed
MAP_HUGE_2MB to mmap() as the offset rather than as a flag.
List xsk.py in TEST_PROGS, as a SW run passes.
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
MAINTAINERS | 1 +
tools/testing/selftests/drivers/net/Makefile | 1 +
tools/testing/selftests/drivers/net/config | 3 +
.../selftests/drivers/net/lib/py/env.py | 44 +-
tools/testing/selftests/drivers/net/xsk.py | 453 ++++++++++++++++++
tools/testing/selftests/net/lib/Makefile | 2 +-
.../testing/selftests/net/lib/xsk/test_xsk.c | 3 +-
.../selftests/net/lib/xsk/xskxceiver.c | 37 +-
8 files changed, 516 insertions(+), 28 deletions(-)
create mode 100755 tools/testing/selftests/drivers/net/xsk.py
diff --git a/MAINTAINERS b/MAINTAINERS
index 8b7d54034856..a143009f8cc8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -30608,6 +30608,7 @@ F: include/net/xsk_buff_pool.h
F: include/uapi/linux/if_xdp.h
F: include/uapi/linux/xdp_diag.h
F: net/xdp/
+F: tools/testing/selftests/drivers/net/xsk.py
F: tools/testing/selftests/net/lib/xsk/
XEN BLOCK SUBSYSTEM
diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/selftests/drivers/net/Makefile
index 79c6f998e704..81e0f4a9499e 100644
--- a/tools/testing/selftests/drivers/net/Makefile
+++ b/tools/testing/selftests/drivers/net/Makefile
@@ -30,6 +30,7 @@ TEST_PROGS := \
so_txtime.py \
stats.py \
xdp.py \
+ xsk.py \
# end of TEST_PROGS
TEST_FILES := \
diff --git a/tools/testing/selftests/drivers/net/config b/tools/testing/selftests/drivers/net/config
index 4838adf27fa1..98762922b1ae 100644
--- a/tools/testing/selftests/drivers/net/config
+++ b/tools/testing/selftests/drivers/net/config
@@ -1,6 +1,8 @@
+CONFIG_BPF_SYSCALL=y
CONFIG_CONFIGFS_FS=y
CONFIG_DEBUG_INFO_BTF=y
CONFIG_DEBUG_INFO_BTF_MODULES=n
+CONFIG_HUGETLBFS=y
CONFIG_INET_PSP=y
CONFIG_IPV6=y
CONFIG_MACSEC=m
@@ -22,5 +24,6 @@ CONFIG_NET_SCH_PRIO=m
CONFIG_PPP=y
CONFIG_PPPOE=y
CONFIG_TLS=y
+CONFIG_VETH=y
CONFIG_VLAN_8021Q=m
CONFIG_XDP_SOCKETS=y
diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
index ab404f81521f..e089f4e79cd5 100644
--- a/tools/testing/selftests/drivers/net/lib/py/env.py
+++ b/tools/testing/selftests/drivers/net/lib/py/env.py
@@ -125,16 +125,21 @@ class NetDrvEpEnv(NetDrvEnvBase):
which can be used to send traffic in.
For local testing it creates two network namespaces and a pair
- of netdevsim devices.
+ of sw_drv devices, netdevsim by default or veth. The sw_drv
+ attribute holds the driver of that pair, and is None with NETIF.
"""
# Network prefixes used for local tests
sw_v4_pfx = "192.0.2."
sw_v6_pfx = "2001:db8::"
- def __init__(self, src_path, sw_test=None, queue_count=None):
+ def __init__(self, src_path, sw_test=None, queue_count=None,
+ sw_drv="netdevsim"):
super().__init__(src_path)
+ if sw_drv not in ("netdevsim", "veth"):
+ raise ValueError(f"Unsupported sw_drv: {sw_drv}")
+
self._stats_settle_time = None
self._queue_count = queue_count
@@ -144,13 +149,15 @@ class NetDrvEpEnv(NetDrvEnvBase):
self._netns = None
self._ns = None
self._ns_peer = None
+ self._veth = None
+ self.sw_drv = None
self.addr_v = { "4": None, "6": None }
self.remote_addr_v = { "4": None, "6": None }
if "NETIF" in self.env:
if sw_test is True:
- raise KsftXfailEx("Test only works on netdevsim")
+ raise KsftXfailEx(f"Test only works on {sw_drv}")
self._check_env()
self.dev = ip("-d link show dev " + self.env['NETIF'], json=True)[0]
@@ -163,11 +170,15 @@ class NetDrvEpEnv(NetDrvEnvBase):
args = self.env["REMOTE_ARGS"]
else:
if sw_test is False:
- raise KsftXfailEx("Test does not work on netdevsim")
+ raise KsftXfailEx(f"Test does not work on {sw_drv}")
- self.create_local()
-
- self.dev = self._ns.nsims[0].dev
+ self.sw_drv = sw_drv
+ if sw_drv == "veth":
+ self.create_local_veth()
+ self.dev = ip("-d link show dev " + self._veth, json=True)[0]
+ else:
+ self.create_local()
+ self.dev = self._ns.nsims[0].dev
self.addr_v["4"] = self.sw_v4_pfx + "1"
self.addr_v["6"] = self.sw_v6_pfx + "1"
@@ -211,6 +222,22 @@ class NetDrvEpEnv(NetDrvEnvBase):
self._setup_sw_ifaces(self._ns.nsims[0].ifname,
self._ns_peer.nsims[0].ifname)
+ def create_local_veth(self):
+ """Create a veth pair, with the peer in a network namespace."""
+ self._netns = NetNS()
+
+ queues = ""
+ if self._queue_count:
+ queues = (f" numtxqueues {self._queue_count}"
+ f" numrxqueues {self._queue_count}")
+ # The peer takes the same name in its own network namespace.
+ veth = "veth" + self._netns.name
+ ip(f"link add {veth}{queues} type veth "
+ f"peer name {veth}{queues} netns {self._netns.name}")
+ self._veth = veth
+
+ self._setup_sw_ifaces(veth, veth)
+
def _setup_sw_ifaces(self, ifname, peer_ifname):
"""Address and bring up a local interface and its peer in _netns."""
ip(f" addr add dev {ifname} {self.sw_v4_pfx}1/24")
@@ -283,6 +310,9 @@ class NetDrvEpEnv(NetDrvEnvBase):
if self._ns_peer:
self._ns_peer.remove()
self._ns_peer = None
+ if self._veth:
+ cmd(f"ip link del dev {self._veth}", fail=False)
+ self._veth = None
if self._netns:
del self._netns
self._netns = None
diff --git a/tools/testing/selftests/drivers/net/xsk.py b/tools/testing/selftests/drivers/net/xsk.py
new file mode 100755
index 000000000000..ebde81fa5140
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/xsk.py
@@ -0,0 +1,453 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+"""
+AF_XDP tests over veth or a NIC.
+
+Each case runs two xskxceiver processes, an endpoint on the local interface
+and one on the remote interface. They build the frames that they send each
+other themselves, and send them to the MAC address of their next hop to the
+other. The remote endpoint always runs in SKB mode and does not busy poll,
+so the remote needs no zero-copy support. The local endpoint listens on a
+TCP control port, which the remote endpoint connects to over the tested
+link, and the XDP programs of both pass all but the test flow to the stack.
+"xskxceiver -l" lists the cases, each with the roles that it tests on a NIC,
+if any. test_xsk_busy_poll runs each case again with the local endpoint
+busy polling.
+
+Without NETIF, the interfaces are a veth pair with the remote end in a
+network namespace of its own. Each case runs with the local endpoint
+receiving in SKB and in DRV mode, e.g. test_xsk.drv_SEND_RECEIVE. The cases
+in VETH_XFAIL cannot pass over veth and are expected failures without being
+run. Only the initial network namespace has the net.core.max_skb_frags
+sysctl, so the remote endpoint assumes the default of 17. The cases in
+TAILROOM_CASES size the UMEM tailroom of each endpoint by its own value, so
+they are expected failures if the sysctl is not 17.
+
+With NETIF, the local endpoint runs in zero-copy mode once in each role that
+a case lists, e.g. test_xsk.rx_SEND_RECEIVE. It binds to the last queue of
+NETIF, which each case takes out of RSS, as a TX endpoint in zero-copy mode
+fills no RX buffers, so its queue drops what it receives. ntuple rules steer
+the test flow to the queue of the receiving endpoint, and the control
+connection away from the queue of the local one. If either host rejects
+them for IPv6, the case runs over IPv4. NETIF thus needs RSS, and both hosts
+ntuple filters. The cases in RING_SIZES set the rings that they test with
+ethtool -G.
+
+The UNALIGNED cases need 32 huge pages of 2 MiB on both hosts, and are
+expected failures without them.
+"""
+
+import re
+import shlex
+import socket
+import time
+from dataclasses import dataclass
+
+from lib.py import (CmdExitFailure, EthtoolFamily, KsftFailEx,
+ KsftNamedVariant, KsftSkipEx, KsftXfailEx, NetdevFamily,
+ NetDrvEpEnv, NlError, bkg, cmd, ctl_file_write, defer,
+ ethtool, ip, ksft_disruptive, ksft_eq, ksft_exit, ksft_pr,
+ ksft_run, ksft_variants, rand_port, set_ethtool_feat)
+
+# cmd() and bkg() stop waiting for an endpoint that hangs but leave it
+# running, as killing ssh does on the remote, and bkg() waits for the local
+# endpoint to listen without a time limit, so timeout(1) ends each endpoint.
+VETH_CASE_TIMEOUT = 20
+NIC_CASE_TIMEOUT = 120
+SKIP_CODE = 4
+# Traffic and link timeout of the endpoints. veth takes the xskxceiver
+# default, and a NIC can take seconds to bring its link back after an MTU,
+# XDP or ntuple-filters change.
+VETH_XSK_TIMEOUT = 3
+NIC_XSK_TIMEOUT = 20
+# The TX ring of the sender and the RX ring of the receiver that a case
+# needs at a given size, 64 being the default batch size of xskxceiver.
+RING_SIZES = {
+ "HW_SW_MIN_RING_SIZE": {"tx": 64},
+ "HW_SW_MAX_RING_SIZE": {"tx": "max", "rx": "max"},
+}
+RING_BUSY_TIMEOUT = 5
+NR_HUGEPAGES = 32
+# xskxceiver maps the UMEMs of the UNALIGNED cases with MAP_HUGE_2MB.
+HUGEPAGES = "/sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages"
+MAX_SKB_FRAGS = "/proc/sys/net/core/max_skb_frags"
+# What xskxceiver takes when it cannot read MAX_SKB_FRAGS.
+DEFAULT_SKB_FRAGS = 17
+# The ip link option that detaches the XDP program of an endpoint mode.
+XDP_OFF = {"skb": "xdpgeneric off", "drv": "xdpdrv off", "zc": "xdpdrv off"}
+# Why a case cannot pass over veth, by the mode, None for any, and the name.
+VETH_XFAIL = {
+ # Generic XDP leaves no room to grow the tail, so the RX endpoint skips.
+ ("skb", "XDP_ADJUST_TAIL_GROW"): "generic XDP has no tailroom",
+ ("skb", "XDP_ADJUST_TAIL_GROW_MULTI_BUFF"): "generic XDP has no tailroom",
+ # veth copies each frame into a page_pool fragment that leaves no room
+ # to grow the small frames of the case unless it is the last one of its
+ # page, so the XDP program drops most frames.
+ ("drv", "XDP_ADJUST_TAIL_GROW"): "veth frames have no tailroom",
+ # veth registers its XDP RX queues without a frag size, so
+ # bpf_xdp_adjust_tail() cannot grow a frag and the RX endpoint skips.
+ ("drv", "XDP_ADJUST_TAIL_GROW_MULTI_BUFF"): "veth cannot grow frags",
+ # bpf_xdp_adjust_tail() frees a frag that it trims off as the memory type
+ # of the XDP RX queue, which veth and generic XDP leave at
+ # MEM_TYPE_PAGE_SHARED for frames they copy into page_pool pages, so
+ # page_frag_free() frees a page that its pool still owns. The endpoints
+ # pass regardless, so running the case would only harm the kernel.
+ (None, "XDP_ADJUST_TAIL_SHRINK_MULTI_BUFF"): "trimmed frags leak",
+ (None, "HW_SW_MIN_RING_SIZE"): "veth has no HW rings",
+ (None, "HW_SW_MAX_RING_SIZE"): "veth has no HW rings",
+}
+# Cases not in VETH_XFAIL that size the UMEM tailroom by
+# net.core.max_skb_frags.
+TAILROOM_CASES = ("STAT_RX_DROPPED",)
+
+
+@dataclass
+class Case:
+ """The mode and direction of the local endpoint in a case, which
+ xskxceiver -t takes as test_id."""
+ mode: str
+ direction: str
+ test_id: int
+ name: str
+
+
+def _get_cases(cfg):
+ """
+ Each test case from xskxceiver -l comes out in a form below, with the
+ roles that it tests on hardware, if any:
+ 0: SEND_RECEIVE rx tx
+ 9: POLL_RX rx
+ 33: BIDIRECTIONAL
+ """
+ ret = []
+ out = cmd([str(cfg.bin_local), "-l"]).stdout
+ cases = re.findall(r"^(\d+): (\w+)((?: rx| tx)*)$", out, re.MULTILINE)
+ if cfg.sw_drv:
+ for mode in ("skb", "drv"):
+ for test_id, name, _ in cases:
+ case = Case(mode, "rx", int(test_id), name)
+ ret.append(KsftNamedVariant(f"{mode}_{name}", case))
+ return ret
+
+ for test_id, name, roles in cases:
+ for direction in roles.split():
+ case = Case("zc", direction, int(test_id), name)
+ ret.append(KsftNamedVariant(f"{direction}_{name}", case))
+ return ret
+
+
+def _reserve_hugepages(host=None):
+ """Raise the count of 2 MiB huge pages on host to what the UNALIGNED
+ cases need until the case ends. A host without the pool or the rights
+ to resize it has no huge pages for them."""
+ try:
+ have = int(cmd(f"cat {HUGEPAGES}", host=host).stdout)
+ if have >= NR_HUGEPAGES:
+ return
+ if host:
+ # ctl_file_write() only writes local files.
+ cmd(f"echo {NR_HUGEPAGES} > {HUGEPAGES}", shell=True, host=host)
+ defer(cmd, f"echo {have} > {HUGEPAGES}", shell=True, host=host)
+ else:
+ ctl_file_write(HUGEPAGES, NR_HUGEPAGES)
+ have = int(cmd(f"cat {HUGEPAGES}", host=host).stdout)
+ except (CmdExitFailure, OSError) as e:
+ raise KsftXfailEx("no huge pages") from e
+ if have < NR_HUGEPAGES:
+ raise KsftXfailEx("no huge pages")
+
+
+def _setup_veth(case):
+ """Return the frags per packet of the endpoints over veth, or report a
+ case that cannot pass over veth as an expected failure without running
+ it."""
+ try:
+ with open(MAX_SKB_FRAGS, encoding="utf-8") as fp:
+ max_skb_frags = int(fp.read())
+ except OSError:
+ max_skb_frags = DEFAULT_SKB_FRAGS
+
+ reason = VETH_XFAIL.get((case.mode, case.name),
+ VETH_XFAIL.get((None, case.name)))
+ if not reason and case.name in TAILROOM_CASES and \
+ max_skb_frags != DEFAULT_SKB_FRAGS:
+ reason = (f"the remote endpoint takes max_skb_frags as "
+ f"{DEFAULT_SKB_FRAGS}, not {max_skb_frags}")
+ if reason:
+ raise KsftXfailEx(reason)
+ # An skb takes a descriptor for its linear part and one per frag.
+ return max_skb_frags + 1
+
+
+def _restore_rss(cfg, indir):
+ """Restore the RSS indirection table of the DUT. Reset it first, which
+ leaves it to the driver again, and write indir back only if it was not
+ the default."""
+ req = {"header": {"dev-index": cfg.ifindex}}
+ cfg.ethnl.rss_set({**req, "indir": []})
+ if cfg.ethnl.rss_get(req).get("indir") != indir:
+ cfg.ethnl.rss_set({**req, "indir": indir})
+
+
+def _add_rule(ifname, rule, host=None):
+ """Add an ntuple rule to ifname until the case ends. Return the defer()
+ that deletes it, or None if ifname rejects the rule."""
+ try:
+ res = ethtool(f"-N {ifname} {rule}", host=host)
+ except CmdExitFailure:
+ return None
+ rule_id = re.search(r"ID (\d+)", res.stdout).group(1)
+ return defer(ethtool, f"-N {ifname} delete {rule_id}", host=host)
+
+
+def _steer(cfg, queue, udp_port, ctrl_port):
+ """Steer the test flow to the queue of the receiving endpoint on each
+ host, and the control connection to queue 0 of the DUT, until the case
+ ends. The TCP rule also turns off i40e ATR, which would steer the control
+ connection to the queue that it sends on. Fall back to IPv4 if either
+ host rejects the rules for IPv6, as ixgbe does."""
+ for ipver in ("6", "4"):
+ if not (cfg.addr_v[ipver] and cfg.remote_addr_v[ipver]):
+ continue
+ rules = []
+ for ifname, host, flow, port, action in (
+ (cfg.ifname, None, "udp", udp_port, queue),
+ (cfg.remote_ifname, cfg.remote, "udp", udp_port, 0),
+ (cfg.ifname, None, "tcp", ctrl_port, 0)):
+ rule = _add_rule(ifname, f"flow-type {flow}{ipver} "
+ f"dst-port {port} action {action}", host)
+ if not rule:
+ break
+ rules.append(rule)
+ else:
+ cfg.set_ipver(ipver)
+ return
+ for rule in reversed(rules):
+ rule.exec()
+ raise KsftSkipEx("the hosts reject the ntuple rules of the test")
+
+
+def _setup_nic(cfg, udp_port, ctrl_port):
+ """Take the last queue with both an RX and a TX ring out of RSS and steer
+ the flows of a case until it ends. Return the queue and the frags per
+ packet that the DUT takes in zero-copy mode."""
+ dev = cfg.netnl.dev_get({"ifindex": cfg.ifindex})
+ if "xsk-zerocopy" not in dev["xdp-features"]:
+ raise KsftSkipEx(f"{cfg.ifname} does not support AF_XDP zero-copy")
+
+ req = {"header": {"dev-index": cfg.ifindex}}
+ try:
+ ch = cfg.ethnl.channels_get(req)
+ indir = cfg.ethnl.rss_get(req).get("indir")
+ except NlError as e:
+ raise KsftSkipEx(f"cannot get the channels or RSS of {cfg.ifname}") \
+ from e
+ queue = ch.get("combined-count", 0) + min(ch.get("rx-count", 0),
+ ch.get("tx-count", 0)) - 1
+ if queue < 1:
+ raise KsftSkipEx("Test requires NETIF with at least 2 channels")
+ if not indir:
+ raise KsftSkipEx(f"{cfg.ifname} has no RSS indirection table")
+
+ # Restore the table last, once ntuple-filters are off again, as turning
+ # them on or off can reset the NIC.
+ defer(_restore_rss, cfg, indir)
+ for ifname, host in ((cfg.ifname, None), (cfg.remote_ifname, cfg.remote)):
+ feat = ethtool(f"-k {ifname}", json=True, host=host)[0]
+ set_ethtool_feat(ifname, feat, {"ntuple-filters": True}, host=host)
+ try:
+ ethtool(f"-X {cfg.ifname} equal {queue}")
+ except CmdExitFailure as e:
+ raise KsftSkipEx(f"{cfg.ifname} cannot take queue {queue} "
+ "out of RSS") from e
+ _steer(cfg, queue, udp_port, ctrl_port)
+ return queue, dev.get("xdp-zc-max-segs", 1)
+
+
+def _next_hop_mac(cfg, addr, peer_mac, ifname, host=None):
+ """Return the MAC address that host sends packets for addr to: peer_mac
+ if addr is on link, else the MAC address of the gateway."""
+ route = ip(f"-{cfg.addr_ipver} route get {addr}", json=True,
+ host=host)[0]
+ gw = route.get("gateway")
+ if not gw:
+ return peer_mac
+
+ # Resolve the gateway, from ifname as an IPv6 one is likely link-local.
+ # The ping only triggers ARP or neighbour discovery, so the gateway
+ # may ignore it, and the link may still be down after a NIC reset.
+ deadline = time.monotonic() + NIC_XSK_TIMEOUT
+ while True:
+ cmd(f"ping -c1 -W1 -I{ifname} {gw}", host=host, fail=False)
+ # Unlike "neigh get", "neigh show" has JSON output in older iproute2.
+ neigh = ip(f"neigh show {gw} dev {ifname}", json=True, host=host)
+ if neigh and "lladdr" in neigh[0]:
+ return neigh[0]["lladdr"]
+ if time.monotonic() > deadline:
+ raise KsftFailEx(f"cannot resolve the MAC address of gateway {gw}")
+ time.sleep(0.1)
+
+
+def _set_ring(ifname, ring, size, host=None):
+ """Set a ring of ifname with ethtool -G. A driver can refuse that while
+ an XSK socket that just closed still holds a queue, as ice does until a
+ work item releases the buffer pool of the socket, so retry for a while."""
+ deadline = time.monotonic() + RING_BUSY_TIMEOUT
+ while True:
+ try:
+ ethtool(f"-G {ifname} {ring} {size}", host=host)
+ return
+ except CmdExitFailure as e:
+ if "Device or resource busy" not in e.cmd.stderr or \
+ time.monotonic() > deadline:
+ raise
+ time.sleep(0.1)
+
+
+def _size_rings(cfg, name, direction):
+ """Set the rings that case name needs, and restore them after it."""
+ for ring, size in RING_SIZES[name].items():
+ # The DUT endpoint sends for tx, and receives for rx.
+ if ring == direction:
+ host, ifname = None, cfg.ifname
+ else:
+ host, ifname = cfg.remote, cfg.remote_ifname
+ try:
+ cur = ethtool(f"-g {ifname}", json=True, host=host)[0]
+ except CmdExitFailure:
+ cur = {}
+ if ring not in cur:
+ raise KsftSkipEx(f"cannot read the {ring} ring size of {ifname}")
+ if size == "max":
+ size = cur[f"{ring}-max"]
+ if cur[ring] == size:
+ continue
+ _set_ring(ifname, ring, size, host)
+ defer(_set_ring, ifname, ring, cur[ring], host)
+
+
+def _run(cfg, local_args, remote_args, timeout):
+ """Start the local endpoint, and the remote one once the local one
+ listens. Log the output of an endpoint that does not pass, and return
+ their exit codes."""
+ # Wait for each endpoint until timeout(1) has ended it, not just the 20 s
+ # that bkg() waits for the local one to exit.
+ wait = timeout + 10
+ with bkg(local_args, ksft_ready=True, exit_wait=True, fail=False) as local:
+ remote = cmd(shlex.join(remote_args), host=cfg.remote, fail=False,
+ timeout=wait)
+ local.process(terminate=False, fail=False, timeout=wait)
+ for endpoint in (local, remote):
+ if endpoint.ret:
+ ksft_pr(endpoint)
+ return local.ret, remote.ret
+
+
+def _test(cfg, case, busy_poll):
+ # A case that fails to clean up can leave an XDP program behind.
+ for ifname, host in ((cfg.ifname, None), (cfg.remote_ifname, cfg.remote)):
+ if "xdp" in ip(f"link show dev {ifname}", json=True, host=host)[0]:
+ raise KsftSkipEx(f"{ifname} already has an XDP program")
+ if "UNALIGNED" in case.name:
+ _reserve_hugepages()
+ _reserve_hugepages(cfg.remote)
+
+ udp_port = rand_port(socket.SOCK_DGRAM)
+ ctrl_port = rand_port()
+ if cfg.sw_drv:
+ # Both endpoints bind queue 0 of their end of the veth pair.
+ timeout, xsk_timeout = VETH_CASE_TIMEOUT, VETH_XSK_TIMEOUT
+ queue, max_frags = 0, _setup_veth(case)
+ else:
+ timeout, xsk_timeout = NIC_CASE_TIMEOUT, NIC_XSK_TIMEOUT
+ queue, max_frags = _setup_nic(cfg, udp_port, ctrl_port)
+
+ if busy_poll:
+ # So that SO_PREFER_BUSY_POLL of xskxceiver -b keeps the IRQs masked.
+ for attr, val in (("napi_defer_hard_irqs", 2),
+ ("gro_flush_timeout", 200000)):
+ ctl_file_write(f"/sys/class/net/{cfg.ifname}/{attr}", val)
+ if case.name in RING_SIZES:
+ _size_rings(cfg, case.name, case.direction)
+
+ # The endpoints detach their XDP programs and restore the MTU, but cannot
+ # tell whether the detach worked, and one that gets killed does neither.
+ # Defers run in reverse, so the XDP programs, which can cap the MTU, go
+ # first.
+ defer(ip, f"link set dev {cfg.ifname} mtu {cfg.dev['mtu']}")
+ defer(ip, f"link set dev {cfg.remote_ifname} mtu {cfg.remote_dev['mtu']}",
+ host=cfg.remote)
+ defer(ip, f"link set dev {cfg.ifname} {XDP_OFF[case.mode]}")
+ defer(ip, f"link set dev {cfg.remote_ifname} {XDP_OFF['skb']}",
+ host=cfg.remote)
+
+ local_dmac = _next_hop_mac(cfg, cfg.remote_addr,
+ cfg.remote_dev["address"], cfg.ifname)
+ remote_dmac = _next_hop_mac(cfg, cfg.addr, cfg.dev["address"],
+ cfg.remote_ifname, cfg.remote)
+
+ args = ["-p", cfg.addr,
+ "-P", str(ctrl_port),
+ "-t", str(case.test_id),
+ "--udp-port", str(udp_port),
+ "--max-frags", str(max_frags),
+ "--timeout", str(xsk_timeout)]
+ local = ["timeout", "-k", "5", str(timeout), str(cfg.bin_local),
+ "-i", cfg.ifname,
+ "--queue", str(queue),
+ "--listen",
+ "-m", case.mode,
+ "-e", case.direction,
+ *(["-b"] if busy_poll else []),
+ "--src-ip", cfg.addr,
+ "--dst-ip", cfg.remote_addr,
+ "--dst-mac", local_dmac,
+ *args]
+ remote = ["timeout", "-k", "5", str(timeout), str(cfg.bin_remote),
+ "-i", cfg.remote_ifname,
+ "--queue", "0",
+ "-m", "skb",
+ "-e", "tx" if case.direction == "rx" else "rx",
+ "--src-ip", cfg.remote_addr,
+ "--dst-ip", cfg.addr,
+ "--dst-mac", remote_dmac,
+ *args]
+
+ local_ret, remote_ret = _run(cfg, local, remote, timeout)
+ rets = {local_ret, remote_ret}
+ # An endpoint that skips the case tells its peer, which skips it too.
+ if SKIP_CODE in rets and rets <= {0, SKIP_CODE}:
+ raise KsftSkipEx("xskxceiver skipped the case")
+ ksft_eq(local_ret, 0, "local endpoint exit code")
+ ksft_eq(remote_ret, 0, "remote endpoint exit code")
+
+
+@ksft_disruptive
+def test_xsk(cfg, case):
+ """Run a case with the endpoints driven by interrupts."""
+ _test(cfg, case, busy_poll=False)
+
+
+@ksft_disruptive
+def test_xsk_busy_poll(cfg, case):
+ """Run a case with the local endpoint busy polling."""
+ _test(cfg, case, busy_poll=True)
+
+
+def main():
+ """Run the cases over veth without NETIF, else on NETIF."""
+ with NetDrvEpEnv(__file__, sw_drv="veth") as cfg:
+ cfg.bin_local = cfg.net_lib_dir / "xskxceiver"
+ cases = _get_cases(cfg)
+ cfg.bin_remote = cfg.remote.deploy(cfg.bin_local)
+ cfg.ethnl = EthtoolFamily()
+ cfg.netnl = NetdevFamily()
+
+ ksft_run([ksft_variants(cases)(test_xsk),
+ ksft_variants(cases)(test_xsk_busy_poll)], args=(cfg,))
+ ksft_exit()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tools/testing/selftests/net/lib/Makefile b/tools/testing/selftests/net/lib/Makefile
index b2f01c4e599b..675b1b31571d 100644
--- a/tools/testing/selftests/net/lib/Makefile
+++ b/tools/testing/selftests/net/lib/Makefile
@@ -35,7 +35,7 @@ include ../../lib.mk
BPF_PROG_DIRS := xsk
include ../bpf.mk
-# AF_XDP test engine.
+# AF_XDP test engine used by drivers/net/xsk.py.
XSK_SRCS := $(filter-out %.bpf.c,$(wildcard xsk/*.c)) \
$(top_srcdir)/tools/lib/find_bit.c
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c
index a0ad1df00212..2aadb95c61fa 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c
@@ -2546,7 +2546,8 @@ static bool hugepages_present(void)
void *bufs;
bufs = mmap(NULL, mmap_sz, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, MAP_HUGE_2MB);
+ MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_HUGE_2MB,
+ -1, 0);
if (bufs == MAP_FAILED)
return false;
diff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.c b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
index 7d6aa464c660..bc92de5e8323 100644
--- a/tools/testing/selftests/net/lib/xsk/xskxceiver.c
+++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
@@ -6,14 +6,18 @@
* Linux kernel samples/bpf/xdpsock* and modified
* for use.
*
+ * See drivers/net/xsk.py for detailed information on test topology
+ * and prerequisite network setup.
+ *
* Each instance of this test program runs one endpoint, Tx or Rx, with a
* single socket and a unique UMEM. Two instances validate in-order packet
* delivery and packet content by sending packets to each other.
*
* Tests Information:
* ------------------
- * These selftests test AF_XDP SKB and Native/DRV modes using veth
- * Virtual Ethernet interfaces.
+ * These selftests test AF_XDP SKB and Native/DRV modes over a veth pair.
+ * On a physical device, they test the hardware cases in zero-copy mode,
+ * with an SKB-mode peer on a remote host.
*
* For each mode, the following tests are run:
* a. nopoll - soft-irq processing in run-to-completion mode
@@ -38,32 +42,27 @@
* Reduce the size of the RX ring to a fraction of the fill ring size.
* iv. fill queue empty
* Do not populate the fill queue and then try to receive pkts.
- * f. bpf_link resource persistence
- * Configure sockets at indexes 0 and 1, run a traffic on queue ids 0,
- * then remove xsk sockets from queue 0 on both veth interfaces and
- * finally run a traffic on queues ids 1
- * g. unaligned mode
- * h. tests for invalid and corner case Tx descriptors so that the correct ones
+ * f. unaligned mode
+ * g. tests for invalid and corner case Tx descriptors so that the correct ones
* are discarded and let through, respectively.
- * i. 2K frame size tests
- * j. If multi-buffer is supported, send 9k packets divided into 3 frames
- * k. If multi-buffer and huge pages are supported, send 9k packets in a single frame
+ * h. 2K frame size tests
+ * i. If multi-buffer is supported, send 9k packets divided into 3 frames
+ * j. If multi-buffer and huge pages are supported, send 9k packets in a single frame
* using unaligned mode
- * l. If multi-buffer is supported, try various nasty combinations of descriptors to
+ * k. If multi-buffer is supported, try various nasty combinations of descriptors to
* check if they pass the validation or not
*
* Flow:
* -----
- * - Two processes run the test: Tx and Rx
- * - Each of these two processes attach to a veth interface
- * - Each process creates one AF_XDP socket connected to a unique umem for each
- * veth interface
+ * - drivers/net/xsk.py starts two processes: Tx and Rx
+ * - Each process attaches to one end of the link: a veth interface, or the
+ * NIC under test or its peer on the remote host
+ * - Each process creates one AF_XDP socket connected to a unique umem
* - One process listens on a TCP control port (--listen), the other one
* connects to it and the two synchronize each test step over that
* connection
- * - Tx process transmits a number of UDP packets over IPv4 or IPv6 from
- * veth<xxxx> to veth<yyyy>, and the XDP program of Rx passes other traffic
- * to the stack
+ * - Tx process transmits a number of UDP packets over IPv4 or IPv6 to Rx,
+ * and the XDP program of Rx passes other traffic to the stack
* - Rx process verifies if all packets were received and delivered in-order,
* and have the right content
*/
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
end of thread, other threads:[~2026-11-27 15:06 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 15:05 [PATCH v6 net-next 00/15] selftests: net: adjust xskxceiver to drv-net Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 01/15] selftests: xsk: fix the stack overrun in is_adjust_tail_supported() Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 02/15] selftests: xsk: factor endpoint work out of pthread wrappers Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 03/15] selftests: xsk: size the TX UMEM in HW_SW_MAX_RING_SIZE Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 04/15] selftests: xsk: drop the single-interface loopback mode Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 05/15] selftests: xsk: collect interface capabilities in struct xsk_caps Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 06/15] selftests: xsk: split xskxceiver main() into setup, run and cleanup Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 07/15] selftests: xsk: run one test case per xskxceiver invocation Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 08/15] selftests: xsk: run the RX and TX endpoints in separate processes Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 09/15] selftests: xsk: send UDP over IPv4 or IPv6 between the interface MACs Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 10/15] selftests: xsk: prepare xskxceiver for endpoints on two hosts Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 11/15] selftests: xsk: wait up to --timeout for the RX stats and a busy bind Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 12/15] selftests: xsk: list the endpoint roles of the test cases Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 13/15] selftests: drv-net: rename nsim_test to sw_test Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 14/15] selftests: drv-net: decouple local link setup from netdevsim Maciej Fijalkowski
2026-11-27 15:05 ` [PATCH v6 net-next 15/15] selftests: drv-net: run the AF_XDP tests over veth or a NIC Maciej Fijalkowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox