Skip to contentSkip to conversation

selftests: net: migrate AF_XDP test suite over to net

PATCH In review Maciej Fijalkowski 5 participants 36 messages Oct 16 – Oct 23

Subsystems (8)
lore
Share & tools
lore

Maciej Fijalkowski

author maintainer
#0 lore raw

v4 cover selftests: net: migrate AF_XDP test suite over to net

v3: https://lore.kernel.org/netdev/[email protected]/
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/[email protected]/
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/[email protected]/
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,

This work moves the AF_XDP test suite over to selftests/net and adds a hardware test on top of the python-based drv-net infrastructure. Since a non-zero effort went into implementing xskxceiver's (not so great testing app name) test cases, we did not want to completely abandon it and start everything from scratch within different infra. However, hooking it up to the networking CI will allow us to run cyclic tests on real HW; before that, all of our HW tests were manual local runs.

Tests were based on a process with two threads responsible for the RX and TX paths, whereas the new infra expects two separate processes for the DUT and remote side, where each side has either rx or tx role.

To satisfy this requirement, this series makes each xskxceiver endpoint a process of its own, so that the RX and TX sides of a case can run on different hosts, and adds drivers/net/hw/xsk.py, which runs the existing test cases with the DUT in zero-copy mode against an SKB-mode xskxceiver on a remote host or on the peer port of the same host in a network namespace. The veth test moves with the engine from selftests/bpf to selftests/net as test_xsk.py. It replaces test_xsk.sh and runs all of its cases but XDP_ADJUST_TAIL_SHRINK_MULTI_BUFF, which leaks page_pool pages on veth, and XDP_ADJUST_TAIL_GROW, as veth leaves no room to grow most frames.

ZC tests used to expect a single NIC in loopback mode, with both sockets on one of its queues sharing a UMEM. Now we step away from it:
the DUT and the remote are separate interfaces, on two hosts or on one host with the remote in a namespace, and an ntuple rule steers the test traffic to the AF_XDP queue.

The remote endpoint is xskxceiver in SKB mode rather than a plain socket, so both ends keep sharing the packet stream generation and validation of the existing cases. This reduces the need for remote interface being a NIC from narrow set of NICs that are AF_XDP ZC capable.

This implies that during the test run only one side is actually exercised, so let's introduce the concept of direction per test case. For example, this means rx_SEND_RECEIVE will test the ice_clean_rx_irq_zc() routine and tx_SEND_RECEIVE the ice_xmit_zc().

BPF's 'test_progs -t xsk' is removed, as well as single interface mode, which was used for ZC tests. BPF CI therefore no longer runs the xskxceiver cases. The veth test is kept, as it is the only run that needs no hardware and not all tests are currently covered by the HW test side.
We can decide whether to keep the delta test cases, drop them or somehow enable within HW tests.

Thread-based approach had a pacing mechanism that was a simple in-flight packet counter updated within critical section by both ends. Process-based way now is going to do this pacing via xsk_peer.

xsk_peer, the control channel, carries four fixed-size messages: READY is the barrier between steps, PROGRESS tells TX how many packets RX has consumed so that TX does not overrun the RX UMEM, ABORT stops the peer after a failure, and SKIP makes the peer skip a case that its endpoint skips.

The test table in test_xsk.h is grouped by the endpoint role that each case tests, which a hardware run gives to the DUT: RX, TX, both, or none for the generic cases, which run on veth only. xskxceiver -L lists each hardware case once per role, and xsk.py makes the variants ksft_variants() named rx_<case> and tx_<case> from that list, so -t, -T and -l work as for any other test.

Patches 1-4 prepare the split. Patch 1 moves the endpoint work out of the pthread entry points. Patch 2 sizes the TX UMEM of HW_SW_MAX_RING_SIZE like the RX one, as the case only worked with the UMEM that the single-interface mode shares. Patches 3 and 4 drop the single-interface loopback mode and the test_progs wrapper, which runs both endpoints as threads of test_progs; neither can work with one endpoint per process. Nothing else runs a subset of the cases, so patch 4 also merges the cases that the wrapper left out into the main list.

Patch 5 adds a generic rule for BPF skeletons to net/bpf.mk, as Jakub suggested in the review of the xdp_features move [1]; xskxceiver is its first user. If that series lands first with the same rule, this patch can be dropped.

Patch 6 moves the engine, its XDP program and the veth launcher to selftests/net. xsk.py needs xskxceiver, and a drv-net test can only rely on net/lib: the selftests build pulls net/lib in for net, drivers/net and drivers/net/hw, while it skips selftests/bpf by default. The veth test is software-only, so it goes to selftests/net, as the drv-net README asks. selftests/bpf keeps building xsk.c from its new place for xdp_hw_metadata and the xdp_metadata test.

Patches 7-10 split the engine. The interface capabilities move into one struct, so that a process can mirror them for the endpoint it does not own (7). main() is split into setup, run and cleanup (8). xskxceiver runs one case per invocation, and test_xsk.py, which replaces test_xsk.sh, owns the mode x case matrix (9). Finally, the RX and TX endpoints become separate processes that meet over a small TCP control channel (10).

Patch 11 makes the endpoints send UDP over IPv4 or IPv6 between the interface MACs, on veth as on hardware, and lets the XDP programs pass all other traffic to the stack. Patch 12 adds what endpoints on two hosts need, and patch 13 groups the test table by endpoint role and lists the hardware cases with xskxceiver -L. Patch 14 adds xsk.py on top of them, and patch 15 documents both setups.

Known issues:
- Every case pays for process start-up, XDP attach and detach and, on hardware, its remote commands. We used to configure resources once and then execute the whole test suite; it doesn't seem to be CI-friendly and it is preferred to have each case's resource management separated; that on the other hand increases the execution time of the whole test suite. Only what all cases share, the huge pages and, on hardware, the queue taken out of RSS and the ntuple rules, is set up once per run.

- The control channel goes to the remote address with either remote type, so it shares the tested link. A zero-copy TX socket fills no RX buffers and its queue would drop that traffic, so the DUT queue stays out of RSS in both directions, and a DUT with fewer than two queues skips the run.

- The control channel is unauthenticated TCP, and the remote endpoint listens on the remote address while its case runs.

- Both endpoints get only the case number, and the control channel does not check that they run the same case. xsk.py copies the DUT's xskxceiver to the remote with cfg.remote.deploy(), so that both ends number the cases alike.

- Not on hardware (yet, or ever):
* BIDIRECTIONAL, which needs both directions set up in one case; i think it should be removed as we sort of achieve the bi-directional coverage via the rx_ and tx_ variants, and it currently does not fit our KISS-policy on remote side;
* STAT_RX_DROPPED and TX_QUEUE_CONSUMER, which do not run in zero-copy mode.

[1]: https://lore.kernel.org/netdev/[email protected]/

Thanks,
Maciej

Maciej Fijalkowski (15):
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/bpf: drop the test_progs AF_XDP wrapper
selftests: net: add a generic rule for BPF skeletons
selftests: xsk: move the AF_XDP test suite to selftests/net
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: list the hardware test cases
selftests: drv-net: test AF_XDP zero-copy with an SKB peer
selftests: xsk: document generic and hardware endpoint runs

 Documentation/networking/af_xdp.rst           |   6 +-
 MAINTAINERS                                   |   5 +-
 tools/testing/selftests/bpf/.gitignore        |   1 -
 tools/testing/selftests/bpf/Makefile          |  29 +-
 tools/testing/selftests/bpf/network_helpers.c |  48 -
 tools/testing/selftests/bpf/network_helpers.h |   2 -
 tools/testing/selftests/bpf/prog_tests/xsk.c  | 170 ----
 tools/testing/selftests/bpf/test_xsk.sh       | 246 -----
 tools/testing/selftests/bpf/xsk_prereqs.sh    |  93 --
 tools/testing/selftests/bpf/xskxceiver.c      | 479 ----------
 .../testing/selftests/drivers/net/hw/Makefile |   1 +
 tools/testing/selftests/drivers/net/hw/config |   1 +
 .../drivers/net/hw/lib/py/__init__.py         |   5 +
 tools/testing/selftests/drivers/net/hw/xsk.py | 368 ++++++++
 tools/testing/selftests/net/Makefile          |   1 +
 tools/testing/selftests/net/bpf.mk            |   6 +
 tools/testing/selftests/net/config            |   1 +
 tools/testing/selftests/net/lib/.gitignore    |   2 +
 tools/testing/selftests/net/lib/Makefile      |  34 +
 .../testing/selftests/net/lib/py/__init__.py  |   4 +
 tools/testing/selftests/net/lib/py/xsk.py     |  96 ++
 .../testing/selftests/net/lib/xsk/README.rst  | 194 ++++
 .../prog_tests => net/lib/xsk}/test_xsk.c     | 876 +++++++++++-------
 .../prog_tests => net/lib/xsk}/test_xsk.h     | 155 +++-
 .../selftests/{bpf => net/lib/xsk}/xsk.c      |  85 +-
 .../selftests/{bpf => net/lib/xsk}/xsk.h      |   6 +
 .../testing/selftests/net/lib/xsk/xsk_peer.c  | 339 +++++++
 .../testing/selftests/net/lib/xsk/xsk_peer.h  |  21 +
 .../{bpf => net/lib/xsk}/xsk_xdp_common.h     |   3 +-
 .../lib/xsk/xsk_xdp_progs.bpf.c}              |  91 +-
 .../selftests/net/lib/xsk/xskxceiver.c        | 620 +++++++++++++
 .../{bpf => net/lib/xsk}/xskxceiver.h         |   0
 tools/testing/selftests/net/test_xsk.py       | 163 ++++
 33 files changed, 2697 insertions(+), 1454 deletions(-)
 delete mode 100644 tools/testing/selftests/bpf/prog_tests/xsk.c
 delete mode 100755 tools/testing/selftests/bpf/test_xsk.sh
 delete mode 100755 tools/testing/selftests/bpf/xsk_prereqs.sh
 delete mode 100644 tools/testing/selftests/bpf/xskxceiver.c
 create mode 100755 tools/testing/selftests/drivers/net/hw/xsk.py
 create mode 100644 tools/testing/selftests/net/lib/py/xsk.py
 create mode 100644 tools/testing/selftests/net/lib/xsk/README.rst
 rename tools/testing/selftests/{bpf/prog_tests => net/lib/xsk}/test_xsk.c (79%)
 rename tools/testing/selftests/{bpf/prog_tests => net/lib/xsk}/test_xsk.h (78%)
 rename tools/testing/selftests/{bpf => net/lib/xsk}/xsk.c (90%)
 rename tools/testing/selftests/{bpf => net/lib/xsk}/xsk.h (96%)
 create mode 100644 tools/testing/selftests/net/lib/xsk/xsk_peer.c
 create mode 100644 tools/testing/selftests/net/lib/xsk/xsk_peer.h
 rename tools/testing/selftests/{bpf => net/lib/xsk}/xsk_xdp_common.h (67%)
 rename tools/testing/selftests/{bpf/progs/xsk_xdp_progs.c => net/lib/xsk/xsk_xdp_progs.bpf.c} (57%)
 create mode 100644 tools/testing/selftests/net/lib/xsk/xskxceiver.c
 rename tools/testing/selftests/{bpf => net/lib/xsk}/xskxceiver.h (100%)
 create mode 100755 tools/testing/selftests/net/test_xsk.py
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH v4 1/15 selftests: xsk: factor endpoint work out of pthread wrappers

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.

---
 .../selftests/bpf/prog_tests/test_xsk.c       | 98 +++++++++++--------
 1 file changed, 59 insertions(+), 39 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_xsk.c +59 -39
index 4549358cc8c2..2a1362874092 100644
@@ -1623,40 +1623,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) {
@@ -1669,35 +1660,64 @@ 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)
+{
+	bool supported;
+	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 {
-			bool supported;
+	if (!test->adjust_tail)
+		return err;
 
-			if (is_adjust_tail_supported(ifobject->xdp_progs, &supported))
-				test->fail = true;
-			else if (!supported)
-				test->adjust_tail_support = false;
-			else
-				test->fail = true;
-		}
+	if (is_adjust_tail_supported(ifobject->xdp_progs, &supported))
+		return TEST_FAILURE;
+	if (!supported) {
+		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);
 }
 
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH v4 2/15 selftests: xsk: size the TX UMEM in HW_SW_MAX_RING_SIZE

In reply to Maciej Fijalkowski

HW_SW_MAX_RING_SIZE gives the RX UMEM 8k frames and 8k rings, then sends batches of 2k and of the maximum HW TX ring size minus 8. This only works in the single-interface mode, where the TX socket uses the RX UMEM, and veth, which cannot change its ring sizes, skips the case. With two interfaces, TX has its own UMEM of DEFAULT_UMEM_BUFFERS (1k) frames and 2k rings: the in-flight limit in __send_pkts() turns negative for a 2k batch, so TX never sends and RX times out, and the second batch would not fit in the TX ring anyway.

The next patch removes the single-interface mode, so size the TX UMEM like the RX one. The shared UMEM setup copies the RX UMEM over the TX one and is not affected.

With a HW TX ring of more than 8200 descriptors, the second batch would also outgrow the 8k XSK TX ring, and __send_pkts() would spin forever waiting to reserve it, so cap the batch below the XSK ring size.

---
 tools/testing/selftests/bpf/prog_tests/test_xsk.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_xsk.c +9 -3
index 2a1362874092..05457f77ca52 100644
@@ -2504,6 +2504,7 @@ 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;
 
 	test->set_ring = true;
@@ -2513,6 +2514,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;
 
@@ -2521,10 +2525,12 @@ int testapp_hw_sw_max_ring_size(struct test_spec *test)
 		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.
+	 * updating the Rx HW tail register. __send_pkts() waits until a whole batch fits
+	 * in the XSK TX ring, so keep it below that ring's size on NICs with larger rings.
 	 */
-	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);
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH v4 net-next 02/15] selftests: xsk: size the TX UMEM in HW_SW_MAX_RING_SIZE

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] bpf: integer underflow calculating xsk batch_size - [Low] bpf: multi-line comment does not…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] bpf: integer underflow calculating xsk batch_size
- [Low] bpf: multi-line comment does not follow kernel style
--

commit 743c541687fdf2d7592285088f7c482d5114a852
Author: Maciej Fijalkowski <[email protected]>

selftests: xsk: size the TX UMEM in HW_SW_MAX_RING_SIZE

This commit sizes the TX UMEM like the RX one to avoid failures in dual-interface mode and caps the batch size below the XSK ring size to avoid infinite loops.

Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +0 -0
index 2a13628740924..05457f77ca52c 100644

[ ... ]

tools/testing/selftests/bpf/prog_tests/test_xsk.c int testapp_hw_sw_max_ring_size(struct test_spec *test) · line 2530

Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +2 -1
@@ -2521,10 +2525,12 @@ int testapp_hw_sw_max_ring_size(struct test_spec *test)
 		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.
+	 * updating the Rx HW tail register. __send_pkts() waits until a whole batch fits
+	 * in the XSK TX ring, so keep it below that ring's size on NICs with larger rings.
 	 */

[Severity: Low]
This isn't a bug, but does this multi-line comment follow the BPF subsystem style guidelines?

The guidelines request the opening /* to be on its own line.

tools/testing/selftests/bpf/prog_tests/test_xsk.c int testapp_hw_sw_max_ring_size(struct test_spec *test) · line 2531

Quoted 3 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +1 -2
-	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;

[Severity: Medium]
Can this subtraction underflow if tx_max_pending is less than 8?

If an interface supports ethtool get_ringparam but reports a tx_max_pending smaller than 8 (such as netdevsim altered via debugfs or drivers that leave it 0), the unsigned subtraction would underflow and produce a massive batch_size.

Could this cause __send_pkts() to infinite loop or hang the test while trying to reserve descriptors that exceed the ring capacity?

Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +2 -0
+	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);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#4 lore raw

Re: [PATCH v4 net-next 02/15] selftests: xsk: size the TX UMEM in HW_SW_MAX_RING_SIZE

In reply to Maciej Fijalkowski
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] This patch fixes a hang that exists in the tree today, but it has no Fixes: tag.

--

selftests: xsk: size the TX UMEM in HW_SW_MAX_RING_SIZE

This commit gives the TX UMEM in testapp_hw_sw_max_ring_size() the same size as the RX UMEM (8k frames and 8k rings). That way the test still works with two interfaces once the single-interface mode is removed. It also caps the second batch below the 8k XSK TX ring, so that __send_pkts() cannot spin forever on NICs with large HW TX rings.

Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +0 -0
index 2a13628740924..05457f77ca52c 100644

[ ... ]

tools/testing/selftests/bpf/prog_tests/test_xsk.c int testapp_hw_sw_max_ring_size(struct test_spec *test) · line 2533

Quoted 13 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +5 -3
@@ -2521,10 +2525,12 @@ int testapp_hw_sw_max_ring_size(struct test_spec *test)
 		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.
+	 * updating the Rx HW tail register. __send_pkts() waits until a whole batch fits
+	 * in the XSK TX ring, so keep it below that ring's size on NICs with larger rings.
 	 */
-	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;

[Severity: Low]
Should this patch carry a Fixes: tag?

The commit message describes the change as preparation for removing the single-interface mode. The min() cap, though, fixes a hang that can already happen in the current tree.

In the single-interface (shared UMEM) mode, thread_common_ops_tx() copies the RX UMEM. xsk_configure_socket() then creates the XSK TX ring with tx_size = umem->comp_size = 8192.

Before this patch the second batch was tx_max_pending - 8. On a NIC that reports tx_max_pending above 8200, the reserve in __send_pkts() can never succeed:

tools/testing/selftests/bpf/prog_tests/test_xsk.c:__send_pkts() {
    ...
	while (xsk_ring_prod__reserve(&xsk->tx, xsk->batch_size, &idx) < xsk->batch_size) {
    ...
}

When use_poll is false this loop has no timeout, so the test spins forever.

This looks reachable on real hardware. nfp supports AF_XDP zero-copy and reports tx_max_pending as max_qc_size / tx_min_desc_per_pkt, with max_qc_size being SZ_64K or SZ_256K.

The two-interface case is also broken before this patch. With a 1024-frame TX UMEM and a 2048 batch, the in-flight limit in __send_pkts() goes negative and TX never sends.

Would a Fixes: tag pointing at the commit that added HW_SW_MAX_RING_SIZE help stable maintainers and backporters pick this up?

Quoted 3 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +0 -0
 	if (pkt_stream_replace(test, max_descs, MIN_PKT_SIZE)) {
 		clean_sockets(test, test->ifobj_tx);
 		clean_sockets(test, test->ifobj_rx);
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261016174338.787135-1-maciej.fijalkowski%40intel.com
author maintainer
#5 lore raw

PATCH v4 3/15 selftests: xsk: drop the single-interface loopback mode

In reply to Maciej Fijalkowski

xskxceiver -i ethX -i ethX, used for HW tests, bound both sockets to queue 0 of one interface, which the kernel only allows with a shared UMEM. With the endpoints about to become separate processes, they would have to share the UMEM mapping and the socket fd.

The mode also relied on the interface being set up by hand with a single queue and promiscuous mode, which does not suit CI. The hardware test added later in this series steers its traffic with ntuple and RSS configuration instead.

Remove the shared-UMEM TX setup, the split UMEM addressing and the POLL_TXQ_FULL workaround it needed, and drop the -i IFACE option of test_xsk.sh that used it. XDP_SHARED_UMEM (two sockets of one endpoint) is unaffected.

test_xsk.sh ran HW_SW_MIN_RING_SIZE and HW_SW_MAX_RING_SIZE only in this mode, as veth has no ring parameters. xskxceiver resized the rings for them and restored the sizes it had found only when it exited, so a killed run left the test sizes behind for the next run to take as the defaults. Drop the resizing with the mode, and set_hw_ring_size() with it, as nothing else uses it: the hardware test sizes the rings with ethtool -G and restores them after each case, however the endpoints end. Both cases still skip on interfaces without ring parameters, and HW_SW_MAX_RING_SIZE still reads the maximum TX ring size for its batches.

---
 tools/testing/selftests/bpf/network_helpers.c |  24 ---
 tools/testing/selftests/bpf/network_helpers.h |   1 -
 .../selftests/bpf/prog_tests/test_xsk.c       | 162 ++++--------------
 .../selftests/bpf/prog_tests/test_xsk.h       |  12 --
 tools/testing/selftests/bpf/prog_tests/xsk.c  |  12 +-
 tools/testing/selftests/bpf/test_xsk.sh       |  49 ++----
 tools/testing/selftests/bpf/xsk_prereqs.sh    |   7 -
 tools/testing/selftests/bpf/xskxceiver.c      |  13 +-
 8 files changed, 51 insertions(+), 229 deletions(-)
tools/testing/selftests/bpf/network_helpers.c +0 -24
index cdf2d7d3ab32..888f03609175 100644
@@ -646,30 +646,6 @@ int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)
 	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;
-}
-
 struct send_recv_arg {
 	int		fd;
 	uint32_t	bytes;
tools/testing/selftests/bpf/network_helpers.h +0 -1
index 75133119c04a..c7c52597c33f 100644
@@ -90,7 +90,6 @@ int make_sockaddr(int family, const char *addr_str, __u16 port,
 char *ping_command(int family);
 int get_socket_local_port(int sock_fd);
 int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
-int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
 
 int open_tuntap(const char *dev_name, bool need_mac);
 
tools/testing/selftests/bpf/prog_tests/test_xsk.c +35 -127

333 lines not on this page · raw message

tools/testing/selftests/bpf/prog_tests/test_xsk.h +0 -12
index 03753ddc5dcd..33331fbee6f5 100644
@@ -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;
tools/testing/selftests/bpf/prog_tests/xsk.c +1 -11
index 6e2f63ee2a6c..af67e2605818 100644
@@ -53,10 +53,6 @@ int configure_ifobj(struct ifobject *tx, struct ifobject *rx)
 	if (!ASSERT_OK_FD(tx->ifindex, "get TX ifindex"))
 		return -1;
 
-	tx->shared_umem = false;
-	rx->shared_umem = false;
-
-
 	return 0;
 }
 
@@ -79,11 +75,8 @@ static void test_xsk(const struct test_spec *test_to_run, enum test_mode mode)
 		goto delete_rx;
 
 	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;
-	}
 
 	cache_line_size = read_procfs_val(SMP_CACHE_BYTES_PATH);
 	if (!cache_line_size)
@@ -124,9 +117,6 @@ static void test_xsk(const struct test_spec *test_to_run, enum test_mode mode)
 		ASSERT_OK(ret, "Run test");
 	pkt_stream_restore_default(&test);
 
-	if (ifobj_tx->hw_ring_size_supp)
-		hw_ring_size_reset(ifobj_tx);
-
 	pkt_stream_delete(test.tx_pkt_stream_default);
 	pkt_stream_delete(test.rx_pkt_stream_default);
 	xsk_xdp_progs__destroy(ifobj_tx->xdp_progs);
tools/testing/selftests/bpf/test_xsk.sh +14 -35

87 lines not on this page · raw message

tools/testing/selftests/bpf/xsk_prereqs.sh +0 -7
index 47c7b8064f38..ebff0f95d14b 100755
@@ -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 ] &&
tools/testing/selftests/bpf/xskxceiver.c +1 -12
index 7dad8556a722..300cb354f421 100644
@@ -341,7 +341,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 */
@@ -388,10 +387,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);
 
@@ -402,11 +397,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)) {
@@ -462,9 +454,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);
Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH v4 net-next 03/15] selftests: xsk: drop the single-interface loopback mode

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] bpf: Multi-line comments do not start with /* on its own line --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] bpf: Multi-line comments do not start with /* on its own line
--

commit f56c850eb3f84acec00c6d23c81d2796961df979
Author: Maciej Fijalkowski <[email protected]>

selftests: xsk: drop the single-interface loopback mode

This commit drops the single-interface loopback mode from xsk selftests, removes the shared-UMEM TX setup and resizing code, and sets up hardware-based traffic testing using ntuple and RSS configuration instead.

Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +0 -0
index 05457f77ca52c..b9126fe66e1a7 100644

[ ... ]

tools/testing/selftests/bpf/prog_tests/test_xsk.c int testapp_xdp_metadata_mb(struct test_spec *test) · line 2384

Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +3 -0
@@ -2481,14 +2379,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.
+ */

[Severity: Low]
This isn't a bug, but does the comment for testapp_hw_sw_min_ring_size in tools/testing/selftests/bpf/prog_tests/test_xsk.c violate the BPF subsystem multi-line comment style? The BPF guidelines specify that multi-line comments should start with an empty /* line instead of putting text on the opening line.

Quoted 3 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +0 -0
 int testapp_hw_sw_min_ring_size(struct test_spec *test)
 {
 	int ret;

[ ... ]

tools/testing/selftests/bpf/prog_tests/test_xsk.c int testapp_hw_sw_min_ring_size(struct test_spec *test) · line 2409

Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +3 -0
@@ -2501,16 +2404,21 @@ 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.
+ */

[Severity: Low]
This isn't a bug, but does the comment for testapp_hw_sw_max_ring_size in tools/testing/selftests/bpf/prog_tests/test_xsk.c violate the BPF subsystem multi-line comment style? Similar to the previous finding, BPF multi-line comments should start with the opening /* on its own line.

Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +0 -0
 int testapp_hw_sw_max_ring_size(struct test_spec *test)
 {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#7 lore raw

Re: [PATCH v4 net-next 03/15] selftests: xsk: drop the single-interface loopback mode

In reply to Maciej Fijalkowski
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

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

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

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] testapp_hw_sw_min_ring_size() and testapp_hw_sw_max_ring_size() no longer resize the HW rings, and they…
- [Low] The two new multi-line comments above testapp_hw_sw_min_ring_size() and testapp_hw_sw_max_ring_size() in…
- [Low] The commit message says xskxceiver 'resized the rings for them and restored the sizes it had found only when it exited'.

--

selftests: xsk: drop the single-interface loopback mode

This patch removes the xskxceiver mode that bound both endpoints to queue 0 of one interface through a shared UMEM, along with the -i IFACE option of test_xsk.sh. It also drops the HW ring resizing for HW_SW_MIN_RING_SIZE and HW_SW_MAX_RING_SIZE, and set_hw_ring_size(). Ring sizing is left to the hardware test runner added later in the series.

Quoted 5 lines

test_xsk.sh ran HW_SW_MIN_RING_SIZE and HW_SW_MAX_RING_SIZE only in this mode, as veth has no ring parameters. xskxceiver resized the rings for them and restored the sizes it had found only when it exited, so a killed run left the test sizes behind for the next run to take as the defaults.

[Severity: Low]
Is the "only when it exited" part accurate? Before this patch, __test_spec_init() also restored the saved sizes:

    if (ifobj_tx->hw_ring_size_supp)
        hw_ring_size_reset(ifobj_tx);

__test_spec_init() is called from test_init(), which main() calls before every test, and from test_spec_reset(). So the defaults were restored before each test case, and not only at exit.

A run killed during HW_SW_MIN_RING_SIZE or HW_SW_MAX_RING_SIZE would still leave the test sizes behind, because the next restore only happens at the next test init or at exit. Could the rationale describe that window instead?

Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +0 -0
index 05457f77ca52c..b9126fe66e1a7 100644

[ ... ]

Quoted 18 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +0 -12
@@ -1897,18 +1827,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);
 }

[ ... ]

tools/testing/selftests/bpf/prog_tests/test_xsk.c int testapp_xdp_metadata_mb(struct test_spec *test) · line 2384

Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +3 -0
@@ -2481,14 +2379,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.
+ */

[Severity: Low]
This isn't a bug, but the BPF selftests use multi-line comments with the opening /* on its own line. The same goes for the new comment above testapp_hw_sw_max_ring_size().

Quoted 16 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +5 -3
 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);

[ ... ]

Quoted 12 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +3 -0
@@ -2501,16 +2404,21 @@ 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;

tools/testing/selftests/bpf/prog_tests/test_xsk.c int testapp_hw_sw_min_ring_size(struct test_spec *test) · line 2513

Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/test_xsk.c +5 -3
 
-	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 = test->ifobj_tx->ring.tx_max_pending;
-	test->ifobj_tx->ring.rx_pending  = test->ifobj_tx->ring.rx_max_pending;

[Severity: Medium]
With the resizing gone, testapp_hw_sw_min_ring_size() and testapp_hw_sw_max_ring_size() only check hw_ring_size_supp, which main() sets when get_hw_ring_size() succeeds.

Nothing compares ring.tx_pending with DEFAULT_BATCH_SIZE for the min case, or with tx_max_pending and rx_max_pending for the max case. The max case still sizes its batches from the device maximum:

    batch_size = min(test->ifobj_tx->ring.tx_max_pending, max_descs) - 8;

Before this patch, testapp_validate_traffic() resized the sender's rings whenever set_ring and hw_ring_size_supp were both set, two-NIC xskxceiver runs included.

Could a manual xskxceiver run on NICs at their default ring sizes now pass HW_SW_MIN_RING_SIZE or HW_SW_MAX_RING_SIZE without testing the boundary the new comments describe? Would it be worth skipping these cases when the ring sizes read at startup don't match what they expect?

These cases skip under test_xsk.sh, because veth has no get_ringparam. The test_progs wrapper doesn't run them either, since they are in ci_skip_tests.

Later in the series, "selftests: drv-net: test AF_XDP zero-copy with an SKB peer" adds drivers/net/hw/xsk.py. Its _size_rings() sets the rings with ethtool -G before each case and restores them afterwards. That leaves the gap only for manual runs between this patch and that one.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261016174338.787135-1-maciej.fijalkowski%40intel.com
author maintainer
#8 lore raw

PATCH v4 4/15 selftests/bpf: drop the test_progs AF_XDP wrapper

In reply to Maciej Fijalkowski

prog_tests/xsk.c runs the xskxceiver cases inside test_progs, driving the TX and RX sockets of a veth pair from two threads. The following patches turn each endpoint into a process of its own that can run against a peer on another host. Keeping the wrapper would mean rewiring it at every step of that split and teaching test_progs to spawn and synchronize peer processes, so drop it. BPF CI loses the ns_xsk_skb and ns_xsk_drv entries; the same veth coverage stays with test_xsk.sh, which moves to selftests/net together with the engine.

ci_skip_tests[] held the cases that the wrapper left out: flaky and slow ones and those that need hugepages or HW ring size support. Nothing runs only one of the lists anymore, so fold ci_skip_tests[] into tests[]. The test IDs do not change.

---
 .../selftests/bpf/prog_tests/test_xsk.h       |   3 -
 tools/testing/selftests/bpf/prog_tests/xsk.c  | 160 ------------------
 tools/testing/selftests/bpf/xskxceiver.c      |  10 +-
 3 files changed, 2 insertions(+), 171 deletions(-)
 delete mode 100644 tools/testing/selftests/bpf/prog_tests/xsk.c
tools/testing/selftests/bpf/prog_tests/test_xsk.h +0 -3
index 33331fbee6f5..b3007923e8ac 100644
@@ -285,9 +285,6 @@ static const struct test_spec tests[] = {
 	{.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},
-	};
-
-static const struct test_spec ci_skip_tests[] = {
 	/* 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},
tools/testing/selftests/bpf/prog_tests/xsk.c deleted +0 -160

160 lines not on this page · raw message

tools/testing/selftests/bpf/xskxceiver.c +2 -8
index 300cb354f421..102283480a9a 100644
@@ -327,14 +327,12 @@ static void print_tests(void)
 	printf("Tests:\n");
 	for (i = 0; i < ARRAY_SIZE(tests); i++)
 		printf("%u: %s\n", i, tests[i].name);
-	for (i = ARRAY_SIZE(tests); i < ARRAY_SIZE(tests) + ARRAY_SIZE(ci_skip_tests); i++)
-		printf("%u: %s\n", i, ci_skip_tests[i - ARRAY_SIZE(tests)].name);
 }
 
 int main(int argc, char **argv)
 {
-	const size_t total_tests = ARRAY_SIZE(tests) + ARRAY_SIZE(ci_skip_tests);
 	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;
@@ -441,11 +439,7 @@ int main(int argc, char **argv)
 			if (opt_run_test != RUN_ALL_TESTS && j != opt_run_test)
 				continue;
 
-			if (j < ARRAY_SIZE(tests))
-				test_init(&test, ifobj_tx, ifobj_rx, i, &tests[j]);
-			else
-				test_init(&test, ifobj_tx, ifobj_rx, i,
-					  &ci_skip_tests[j - ARRAY_SIZE(tests)]);
+			test_init(&test, ifobj_tx, ifobj_rx, i, &tests[j]);
 			run_pkt_test(&test);
 			usleep(USLEEP_MAX);
 
Signature · 1 line
2.43.0
author maintainer
#9 lore raw

PATCH v4 5/15 selftests: net: add a generic rule for BPF skeletons

In reply to Maciej Fijalkowski

net/bpf.mk builds the BPF programs of the networking selftests, but a test that loads its program through a bpftool-generated skeleton has to bring its own rule for the header. Add a pattern rule that generates $(OUTPUT)/<name>.skel.h from $(OUTPUT)/<name>.bpf.o with $(BPFTOOL), which defaults to the bpftool in PATH. A failing bpftool leaves no partial header behind for a later build to take as up to date.

xskxceiver, which moves to net/lib in the next patch, is the first user.

---
 tools/testing/selftests/net/bpf.mk | 6 ++++++
 1 file changed, 6 insertions(+)
tools/testing/selftests/net/bpf.mk +6 -0
index a4f6755dd894..0eca0c5de5b5 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 # Rules to generate bpf objs
 CLANG ?= clang
+BPFTOOL ?= bpftool
 SCRATCH_DIR := $(OUTPUT)/tools
 BUILD_DIR := $(SCRATCH_DIR)/build
 BPFDIR := $(top_srcdir)/tools/lib/bpf
@@ -42,6 +43,11 @@ $(BPF_PROG_OBJS): $(OUTPUT)/%.o : %.c $(BPFOBJ) | $(MAKE_DIRS)
 	$(Q)$(CLANG) -O2 -g --target=bpf $(CCINCLUDE) $(CLANG_SYS_INCLUDES) \
 	-c $< -o $@
 
+$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o
+	$(call msg,GEN-SKEL,,$@)
+	$(Q)$(BPFTOOL) gen skeleton $< name $(notdir $*) > $@ || \
+		{ rm -f $@; exit 1; }
+
 $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile)		       \
 	   $(APIDIR)/linux/bpf.h					       \
 	   | $(BUILD_DIR)/libbpf
Signature · 1 line
2.43.0
author maintainer
#10 lore raw

PATCH v4 6/15 selftests: xsk: move the AF_XDP test suite to selftests/net

In reply to Maciej Fijalkowski

Move the xskxceiver engine, the AF_XDP userspace library, the test definitions and the XDP program to net/lib/xsk, and test_xsk.sh with its prerequisites script to selftests/net. A later patch drives the same engine against real NICs from drivers/net/hw, and net/lib is where both suites take shared helpers from.

net/lib builds xskxceiver with its XDP program and skeleton, using the bpftool in PATH, and skips it with a warning when bpftool is missing or does not run; test_xsk.sh then skips too. xskxceiver links -lpthread, which glibc older than 2.34 needs for the threads of test_xsk.c.

Like the rest of net/lib, xskxceiver builds against the installed uapi headers, so include linux/kernel.h for min_t() directly rather than via the tools copy of linux/netlink.h. tools/include goes ahead of CFLAGS, so that O= builds take linux/kernel.h and linux/types.h from it rather than from a source tree usr/include.

Move the ethtool ring helper from network_helpers into xsk.c and point the kselftest.h include of test_xsk.h at the net/lib include path. The XDP program moves unchanged; its Ethernet header bound check compares pointers of distinct types, so net/lib builds it with -Wno-compare-distinct-pointer-types, as the bpf selftests do. xdp_hw_metadata and the xdp_metadata test keep using xsk.c and xsk.h from their new location. Update the AF_XDP entry in MAINTAINERS.

---
 Documentation/networking/af_xdp.rst           |  6 ++--
 MAINTAINERS                                   |  3 +-
 tools/testing/selftests/bpf/.gitignore        |  1 -
 tools/testing/selftests/bpf/Makefile          | 29 +++++++--------
 tools/testing/selftests/bpf/network_helpers.c | 24 -------------
 tools/testing/selftests/bpf/network_helpers.h |  1 -
 tools/testing/selftests/net/Makefile          |  2 ++
 tools/testing/selftests/net/config            |  1 +
 tools/testing/selftests/net/lib/.gitignore    |  2 ++
 tools/testing/selftests/net/lib/Makefile      | 35 +++++++++++++++++++
 .../prog_tests => net/lib/xsk}/test_xsk.c     |  2 +-
 .../prog_tests => net/lib/xsk}/test_xsk.h     |  2 +-
 .../selftests/{bpf => net/lib/xsk}/xsk.c      | 25 ++++++++++++-
 .../selftests/{bpf => net/lib/xsk}/xsk.h      |  3 ++
 .../{bpf => net/lib/xsk}/xsk_xdp_common.h     |  0
 .../lib/xsk/xsk_xdp_progs.bpf.c}              |  0
 .../{bpf => net/lib/xsk}/xskxceiver.c         |  7 ++--
 .../{bpf => net/lib/xsk}/xskxceiver.h         |  0
 .../selftests/{bpf => net}/test_xsk.sh        |  5 +++
 .../selftests/{bpf => net}/xsk_prereqs.sh     |  2 +-
 20 files changed, 94 insertions(+), 56 deletions(-)
 rename tools/testing/selftests/{bpf/prog_tests => net/lib/xsk}/test_xsk.c (99%)
 rename tools/testing/selftests/{bpf/prog_tests => net/lib/xsk}/test_xsk.h (99%)
 rename tools/testing/selftests/{bpf => net/lib/xsk}/xsk.c (97%)
 rename tools/testing/selftests/{bpf => net/lib/xsk}/xsk.h (98%)
 rename tools/testing/selftests/{bpf => net/lib/xsk}/xsk_xdp_common.h (100%)
 rename tools/testing/selftests/{bpf/progs/xsk_xdp_progs.c => net/lib/xsk/xsk_xdp_progs.bpf.c} (100%)
 rename tools/testing/selftests/{bpf => net/lib/xsk}/xskxceiver.c (99%)
 rename tools/testing/selftests/{bpf => net/lib/xsk}/xskxceiver.h (100%)
 rename tools/testing/selftests/{bpf => net}/test_xsk.sh (98%)
 rename tools/testing/selftests/{bpf => net}/xsk_prereqs.sh (98%)
Documentation/networking/af_xdp.rst +3 -3
index cc3f0d16b28f..538e71adb759 100644
@@ -211,7 +211,7 @@ Libbpf
 
 Libbpf is a helper library for eBPF and XDP that makes using these
 technologies a lot simpler. It also contains specific helper functions
-in tools/testing/selftests/bpf/xsk.h for facilitating the use of
+in tools/testing/selftests/net/lib/xsk/xsk.h for facilitating the use of
 AF_XDP. It contains two types of functions: those that can be used to
 make the setup of AF_XDP socket easier and ones that can be used in the
 data plane to access the rings safely and quickly.
@@ -751,7 +751,7 @@ return values:
      returned number signifies the max number of frags supported.
 
 For an example on how these are used through libbpf, please take a
-look at tools/testing/selftests/bpf/xskxceiver.c.
+look at tools/testing/selftests/net/lib/xsk/xskxceiver.c.
 
 Multi-Buffer Support for Zero-Copy Drivers
 ------------------------------------------
@@ -785,7 +785,7 @@ can be displayed with "-h", as usual.
 This sample application uses libbpf to make the setup and usage of
 AF_XDP simpler. If you want to know how the raw uapi of AF_XDP is
 really used to make something more advanced, take a look at the libbpf
-code in tools/testing/selftests/bpf/xsk.[ch].
+code in tools/testing/selftests/net/lib/xsk/xsk.[ch].
 
 FAQ
 =======
MAINTAINERS +2 -1
index 509b35b5a0e7..1fc9eaedd744 100644
@@ -29783,7 +29783,8 @@ 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/bpf/*xsk*
+F:	tools/testing/selftests/net/*xsk*
+F:	tools/testing/selftests/net/lib/xsk/
 
 XEN BLOCK SUBSYSTEM
 M:	Roger Pau Monné <[email protected]>
tools/testing/selftests/bpf/.gitignore +0 -1
index 986a6389186b..3c3183ea3c83 100644
@@ -37,7 +37,6 @@ test_cpp
 /uprobe_multi
 *.ko
 *.tmp
-xskxceiver
 xdp_redirect_multi
 xdp_synproxy
 xdp_hw_metadata
tools/testing/selftests/bpf/Makefile +12 -17
index 93c707116fad..a2d357781c0f 100644
@@ -62,7 +62,8 @@ COMMON_CFLAGS = -g $(OPT_FLAGS) -rdynamic -std=gnu11				\
 	  $(GENFLAGS) $(SAN_CFLAGS) $(LIBELF_CFLAGS)			\
 	  -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR)		\
 	  -I$(TOOLSINCDIR) -I$(TOOLSARCHINCDIR) -I$(APIDIR) -I$(OUTPUT)	\
-	  -I$(CURDIR)/libarena/include
+	  -I$(CURDIR)/libarena/include					\
+	  -I$(CURDIR)/../net/lib/xsk
 LDFLAGS += $(SAN_LDFLAGS)
 LDLIBS += $(LIBELF_LIBS) -lz -lrt -lpthread
 
@@ -118,14 +119,13 @@ TEST_GEN_PROGS += test_progs-cpuv4
 TEST_INST_SUBDIRS += cpuv4
 endif
 
-TEST_FILES = xsk_prereqs.sh $(wildcard progs/btf_dump_test_case_*.c)
+TEST_FILES = $(wildcard progs/btf_dump_test_case_*.c)
 
 # Order correspond to 'make run_tests' order
 TEST_PROGS := test_kmod.sh \
 	test_lirc_mode2.sh \
 	test_bpftool_build.sh \
 	test_doc_build.sh \
-	test_xsk.sh \
 	test_xdp_features.sh
 
 TEST_PROGS_EXTENDED := \
@@ -144,8 +144,7 @@ TEST_GEN_PROGS_EXTENDED = \
 	veristat \
 	xdp_features \
 	xdp_hw_metadata \
-	xdp_synproxy \
-	xskxceiver
+	xdp_synproxy
 
 TEST_GEN_FILES += $(TEST_KMODS) liburandom_read.so urandom_read sign-file uprobe_multi
 
@@ -542,7 +541,6 @@ linked_maps.skel.h-deps := linked_maps1.bpf.o linked_maps2.bpf.o
 test_subskeleton.skel.h-deps := test_subskeleton_lib2.bpf.o test_subskeleton_lib.bpf.o test_subskeleton.bpf.o
 test_subskeleton_lib.skel.h-deps := test_subskeleton_lib2.bpf.o test_subskeleton_lib.bpf.o
 test_usdt.skel.h-deps := test_usdt.bpf.o test_usdt_multispec.bpf.o
-xsk_xdp_progs.skel.h-deps := xsk_xdp_progs.bpf.o
 xdp_hw_metadata.skel.h-deps := xdp_hw_metadata.bpf.o
 xdp_features.skel.h-deps := xdp_features.bpf.o
 tracing_multi.skel.h-deps := tracing_multi_attach.bpf.o tracing_multi_check.bpf.o
@@ -769,6 +767,8 @@ $(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o:				\
 	$$(call msg,EXT-OBJ,$(TRUNNER_BINARY),$$@)
 	$(Q)$$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@
 
+$(TRUNNER_OUTPUT)/xsk.o: ../net/lib/xsk/xsk.h
+
 $(TRUNNER_LIB_OBJS): $(TRUNNER_OUTPUT)/%.o:$(TOOLSDIR)/lib/%.c
 	$$(call msg,LIB-OBJ,$(TRUNNER_BINARY),$$@)
 	$(Q)$$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@
@@ -845,6 +845,10 @@ $(LIBARENA_ASAN_SKEL): $(INCLUDE_DIR)/vmlinux.h $(BPFOBJ) $(LIBARENA_BPF_DEPS)
 	+$(MAKE) -C libarena libarena_asan.skel.h $(LIBARENA_MAKE_ARGS)
 endif
 
+# xsk.c lives in ../net/lib/xsk so it can be shared with selftests/net;
+# let make find it there instead of keeping a local copy.
+vpath %.c ../net/lib/xsk
+
 # Define test_progs test runner.
 TRUNNER_TESTS_DIR := prog_tests
 TRUNNER_BPF_PROGS_DIR := progs
@@ -931,18 +935,9 @@ $(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT)
 	$(call msg,BINARY,,$@)
 	$(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
 
-# Keep xskxceiver independent from test_progs object dependencies.
-$(OUTPUT)/xskxceiver: xskxceiver.c xsk.c network_helpers.c \
-			   $(TOOLSDIR)/lib/find_bit.c prog_tests/test_xsk.c \
-			   xskxceiver.h xsk.h network_helpers.h \
-			   prog_tests/test_xsk.h test_progs.h bpf_util.h \
-			   $(OUTPUT)/xsk_xdp_progs.skel.h $(BPFOBJ) | $(OUTPUT)
-	$(call msg,BINARY,,$@)
-	$(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
-
-$(OUTPUT)/xdp_hw_metadata: xdp_hw_metadata.c xsk.c network_helpers.c \
+$(OUTPUT)/xdp_hw_metadata: xdp_hw_metadata.c ../net/lib/xsk/xsk.c network_helpers.c \
 			   $(TOOLSDIR)/lib/find_bit.c xdp_metadata.h \
-			   xsk.h network_helpers.h test_progs.h bpf_util.h \
+			   ../net/lib/xsk/xsk.h network_helpers.h test_progs.h bpf_util.h \
 			   $(OUTPUT)/xdp_hw_metadata.skel.h $(BPFOBJ) | $(OUTPUT)
 	$(call msg,BINARY,,$@)
 	$(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
tools/testing/selftests/bpf/network_helpers.c +0 -24
index 888f03609175..d72d7022cc69 100644
@@ -622,30 +622,6 @@ int get_socket_local_port(int sock_fd)
 	return -1;
 }
 
-int get_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_GRINGPARAM;
-	ifr.ifr_data = (char *)ring_param;
-
-	if (ioctl(sockfd, SIOCETHTOOL, &ifr) < 0) {
-		err = errno;
-		close(sockfd);
-		return -err;
-	}
-
-	close(sockfd);
-	return 0;
-}
-
 struct send_recv_arg {
 	int		fd;
 	uint32_t	bytes;
tools/testing/selftests/bpf/network_helpers.h +0 -1
index c7c52597c33f..e7333b769150 100644
@@ -89,7 +89,6 @@ int make_sockaddr(int family, const char *addr_str, __u16 port,
 		  struct sockaddr_storage *addr, socklen_t *len);
 char *ping_command(int family);
 int get_socket_local_port(int sock_fd);
-int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
 
 int open_tuntap(const char *dev_name, bool need_mac);
 
tools/testing/selftests/net/Makefile +2 -0
index 54beea2e348c..aa31b6216dd1 100644
@@ -118,6 +118,7 @@ TEST_PROGS := \
 	test_vxlan_under_vrf.sh \
 	test_vxlan_vnifilter_notify.sh \
 	test_vxlan_vnifiltering.sh \
+	test_xsk.sh \
 	tfo_passive.sh \
 	traceroute.sh \
 	txtimestamp.sh \
@@ -209,6 +210,7 @@ TEST_FILES := \
 	in_netns.sh \
 	lib.sh \
 	settings \
+	xsk_prereqs.sh \
 # end of TEST_FILES
 
 # YNL files, must be before "include ..lib.mk"
tools/testing/selftests/net/config +1 -0
index d355cf980597..bdaa052eb052 100644
@@ -137,5 +137,6 @@ CONFIG_USER_NS=y
 CONFIG_VETH=y
 CONFIG_VLAN_8021Q=y
 CONFIG_VXLAN=m
+CONFIG_XDP_SOCKETS=y
 CONFIG_XFRM_INTERFACE=m
 CONFIG_XFRM_USER=m
tools/testing/selftests/net/lib/.gitignore +2 -0
index 6cd2b762af5d..1106fef3041f 100644
@@ -2,3 +2,5 @@
 csum
 gro
 xdp_helper
+xsk_xdp_progs.skel.h
+xskxceiver
tools/testing/selftests/net/lib/Makefile +35 -0
index ff83603397d0..c26088da0489 100644
@@ -5,6 +5,15 @@ CFLAGS += -I../../../../../usr/include/ $(KHDR_INCLUDES)
 # Additional include paths needed by kselftest.h
 CFLAGS += -I../../
 
+# xskxceiver needs a working bpftool to generate its skeleton
+BPFTOOL ?= bpftool
+HAS_BPFTOOL := $(shell $(BPFTOOL) version >/dev/null 2>&1 && echo y)
+ifeq ($(HAS_BPFTOOL),y)
+COND_GEN_FILES += xskxceiver
+else
+$(warning excluding xskxceiver, bpftool not installed or not working)
+endif
+
 TEST_FILES := \
 	../../../../net/ynl \
 	../../../../../Documentation/netlink/specs \
@@ -13,6 +22,7 @@ TEST_FILES := \
 
 TEST_GEN_FILES := \
 	$(patsubst %.c,%.o,$(wildcard *.bpf.c)) \
+	$(COND_GEN_FILES) \
 	csum \
 	gro \
 	xdp_helper \
@@ -23,3 +33,28 @@ TEST_INCLUDES := $(wildcard py/*.py sh/*.sh)
 include ../../lib.mk
 
 include ../bpf.mk
+
+# AF_XDP test engine used by net/test_xsk.sh.
+XSK_DIR := xsk
+XSK_BPF_OBJ := $(OUTPUT)/xsk_xdp_progs.bpf.o
+XSK_SKEL := $(OUTPUT)/xsk_xdp_progs.skel.h
+XSK_SOURCES := $(addprefix $(XSK_DIR)/,xskxceiver.c xsk.c test_xsk.c) \
+	$(top_srcdir)/tools/lib/find_bit.c
+XSK_HEADERS := $(wildcard $(XSK_DIR)/*.h)
+
+PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
+XSK_LDLIBS := $(shell $(PKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) -lz
+XSK_LDLIBS += -lpthread
+
+$(XSK_BPF_OBJ): $(XSK_DIR)/xsk_xdp_progs.bpf.c $(XSK_DIR)/xsk_xdp_common.h $(BPFOBJ)
+	$(call msg,BPF_PROG,,$@)
+	$(Q)$(CLANG) -O2 -g --target=bpf $(CCINCLUDE) $(CLANG_SYS_INCLUDES) \
+		-Wno-compare-distinct-pointer-types -c $< -o $@
+
+$(OUTPUT)/xskxceiver: $(XSK_SOURCES) $(XSK_HEADERS) $(XSK_SKEL) $(BPFOBJ)
+	$(call msg,CC,,$@)
+	$(Q)$(CC) -I$(top_srcdir)/tools/include $(CFLAGS) -I$(OUTPUT) \
+		-I$(SCRATCH_DIR)/include \
+		$(XSK_SOURCES) $(BPFOBJ) $(LDLIBS) $(XSK_LDLIBS) -o $@
+
+EXTRA_CLEAN += $(XSK_BPF_OBJ) $(XSK_SKEL)
tools/testing/selftests/net/lib/xsk/test_xsk.c renamed from tools/testing/selftests/bpf/prog_tests/test_xsk.c +1 -1
similarity index 99%
rename from tools/testing/selftests/bpf/prog_tests/test_xsk.c
rename to tools/testing/selftests/net/lib/xsk/test_xsk.c
index b9126fe66e1a..63267d886b17 100644
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
+#include <arpa/inet.h>
 #include <bpf/bpf.h>
 #include <errno.h>
 #include <linux/bitmap.h>
@@ -13,7 +14,6 @@
 #include <sys/time.h>
 #include <unistd.h>
 
-#include "network_helpers.h"
 #include "test_xsk.h"
 #include "xsk_xdp_common.h"
 #include "xsk_xdp_progs.skel.h"
tools/testing/selftests/net/lib/xsk/test_xsk.h renamed from tools/testing/selftests/bpf/prog_tests/test_xsk.h +1 -1
similarity index 99%
rename from tools/testing/selftests/bpf/prog_tests/test_xsk.h
rename to tools/testing/selftests/net/lib/xsk/test_xsk.h
index b3007923e8ac..410702f89dc9 100644
@@ -5,7 +5,7 @@
 #include <linux/ethtool.h>
 #include <linux/if_xdp.h>
 
-#include "../kselftest.h"
+#include "kselftest.h"
 #include "xsk.h"
 
 #ifndef SO_PREFER_BUSY_POLL
tools/testing/selftests/net/lib/xsk/xsk.c renamed from tools/testing/selftests/bpf/xsk.c +24 -1
similarity index 97%
rename from tools/testing/selftests/bpf/xsk.c
rename to tools/testing/selftests/net/lib/xsk/xsk.c
index 25d568abf0f2..660540efc46e 100644
@@ -35,7 +35,6 @@
 #include <bpf/bpf.h>
 #include <bpf/libbpf.h>
 #include "xsk.h"
-#include "bpf_util.h"
 
 #ifndef SOL_XDP
  #define SOL_XDP 283
@@ -779,3 +778,27 @@ void xsk_socket__delete(struct xsk_socket *xsk)
 		close(xsk->fd);
 	free(xsk);
 }
+
+int get_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_GRINGPARAM;
+	ifr.ifr_data = (char *)ring_param;
+
+	if (ioctl(sockfd, SIOCETHTOOL, &ifr) < 0) {
+		err = errno;
+		close(sockfd);
+		return -err;
+	}
+
+	close(sockfd);
+	return 0;
+}
tools/testing/selftests/net/lib/xsk/xsk.h renamed from tools/testing/selftests/bpf/xsk.h +3 -0
similarity index 98%
rename from tools/testing/selftests/bpf/xsk.h
rename to tools/testing/selftests/net/lib/xsk/xsk.h
index 48729da142c2..94a56dd43f2e 100644
@@ -15,6 +15,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <linux/ethtool.h>
 #include <linux/if_xdp.h>
 
 #include <bpf/libbpf.h>
@@ -242,6 +243,8 @@ 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);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
tools/testing/selftests/net/lib/xsk/xsk_xdp_common.h renamed from tools/testing/selftests/bpf/xsk_xdp_common.h +0 -0
similarity index 100%
rename from tools/testing/selftests/bpf/xsk_xdp_common.h
rename to tools/testing/selftests/net/lib/xsk/xsk_xdp_common.h
tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c renamed from tools/testing/selftests/bpf/progs/xsk_xdp_progs.c +0 -0
similarity index 100%
rename from tools/testing/selftests/bpf/progs/xsk_xdp_progs.c
rename to tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c
tools/testing/selftests/net/lib/xsk/xskxceiver.c renamed from tools/testing/selftests/bpf/xskxceiver.c +2 -5
similarity index 99%
rename from tools/testing/selftests/bpf/xskxceiver.c
rename to tools/testing/selftests/net/lib/xsk/xskxceiver.c
index 102283480a9a..7876ad47ed0f 100644
@@ -81,6 +81,7 @@
 #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>
@@ -91,7 +92,7 @@
 #include <sys/mman.h>
 #include <sys/types.h>
 
-#include "prog_tests/test_xsk.h"
+#include "test_xsk.h"
 #include "xsk_xdp_progs.skel.h"
 #include "xsk.h"
 #include "xskxceiver.h"
@@ -100,14 +101,10 @@
 #include "kselftest.h"
 #include "xsk_xdp_common.h"
 
-#include <network_helpers.h>
-
 static bool opt_print_tests;
 static enum test_mode opt_mode = TEST_MODE_ALL;
 static u32 opt_run_test = RUN_ALL_TESTS;
 
-void test__fail(void) { /* for network_helpers.c */ }
-
 static void __exit_with_error(int error, const char *file, const char *func, int line)
 {
 	ksft_test_result_fail("[%s:%s:%i]: ERROR: %d/\"%s\"\n", file, func, line,
tools/testing/selftests/net/lib/xsk/xskxceiver.h renamed from tools/testing/selftests/bpf/xskxceiver.h +0 -0
similarity index 100%
rename from tools/testing/selftests/bpf/xskxceiver.h
rename to tools/testing/selftests/net/lib/xsk/xskxceiver.h
tools/testing/selftests/net/test_xsk.sh renamed from tools/testing/selftests/bpf/test_xsk.sh +5 -0
similarity index 98%
rename from tools/testing/selftests/bpf/test_xsk.sh
rename to tools/testing/selftests/net/test_xsk.sh
index 69fac65f073c..fbf4551d596a 100755
@@ -97,6 +97,11 @@ do
 	esac
 done
 
+if [ ! -x "./${XSKOBJ}" ]; then
+	echo "xskxceiver was not built; skipping"
+	exit $ksft_skip
+fi
+
 TEST_NAME="PREREQUISITES"
 
 URANDOM=/dev/urandom
tools/testing/selftests/net/xsk_prereqs.sh renamed from tools/testing/selftests/bpf/xsk_prereqs.sh +1 -1
similarity index 98%
rename from tools/testing/selftests/bpf/xsk_prereqs.sh
rename to tools/testing/selftests/net/xsk_prereqs.sh
index ebff0f95d14b..5e5c8ef3fff2 100755
@@ -8,7 +8,7 @@ ksft_xfail=2
 ksft_xpass=3
 ksft_skip=4
 
-XSKOBJ=xskxceiver
+XSKOBJ=lib/xskxceiver
 
 validate_root_exec()
 {
Signature · 1 line
2.43.0
#11 lore raw

Re: [PATCH v4 net-next 06/15] selftests: xsk: move the AF_XDP test suite to selftests/net

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

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

Critical: 0 · High: 0 · Medium: 2 · Low: 0 (1)

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] This patch moves get_hw_ring_size() out of tools/testing/selftests/bpf/network_helpers.c and appends it to…
- [Medium] The new $(XSK_BPF_OBJ) rule in tools/testing/selftests/net/lib/Makefile compiles xsk_xdp_progs.bpf.c…

Pre-existing issues:
- [Low] At this commit, test_exit() in tools/testing/selftests/net/xsk_prereqs.sh ends with an unconditional…

--

selftests: xsk: move the AF_XDP test suite to selftests/net

This commit moves xskxceiver, the AF_XDP library, the test definitions and the XDP program from selftests/bpf to selftests/net/lib/xsk. It also moves test_xsk.sh and xsk_prereqs.sh to selftests/net, and net/lib now builds xskxceiver and its skeleton when a working bpftool is available. The ethtool ring helper get_hw_ring_size() moves from network_helpers.c into xsk.c.

Quoted 4 lines
tools/testing/selftests/net/lib/Makefile +0 -0
index ff83603397d06..c26088da04892 100644

[ ... ]

Quoted 9 lines
tools/testing/selftests/net/lib/Makefile +5 -0
@@ -23,3 +33,28 @@ TEST_INCLUDES := $(wildcard py/*.py sh/*.sh)
 include ../../lib.mk
 
 include ../bpf.mk
+
+# AF_XDP test engine used by net/test_xsk.sh.
+XSK_DIR := xsk
+XSK_BPF_OBJ := $(OUTPUT)/xsk_xdp_progs.bpf.o
+XSK_SKEL := $(OUTPUT)/xsk_xdp_progs.skel.h

[ ... ]

tools/testing/selftests/net/lib/Makefile TEST_INCLUDES := $(wildcard py/*.py sh/*.sh) · line 52

Quoted 4 lines

+$(XSK_BPF_OBJ): $(XSK_DIR)/xsk_xdp_progs.bpf.c $(XSK_DIR)/xsk_xdp_common.h $(BPFOBJ)

tools/testing/selftests/net/lib/Makefile +3 -0
+	$(call msg,BPF_PROG,,$@)
+	$(Q)$(CLANG) -O2 -g --target=bpf $(CCINCLUDE) $(CLANG_SYS_INCLUDES) \
+		-Wno-compare-distinct-pointer-types -c $< -o $@

[Severity: Medium]
Could this produce a BPF object with the wrong byte order when cross-compiling for a big-endian target?

Plain --target=bpf uses the build host's byte order. xskxceiver itself is built with $(CC), and lib.mk sets that to $(CROSS_COMPILE)gcc. So a build for s390x on an x86_64 host would put a little-endian object into the skeleton of a big-endian xskxceiver.

On the target, xsk_xdp_progs__open_and_load() would then fail in bpf_object_load():

tools/lib/bpf/libbpf.c:bpf_object_load() {
    ...
	} else if (!is_native_endianness(obj)) {
		pr_warn("object '%s': loading non-native endianness is unsupported\n", obj->name);
		return libbpf_err(-LIBBPF_ERRNO__ENDIAN);
	}
    ...
}

The bpf selftests Makefile, which built this program before the move, picks the target based on $(CC):

BPF_TARGET_ENDIAN:=$(if $(IS_LITTLE_ENDIAN),--target=bpfel,--target=bpfeb)

The existing rule in net/bpf.mk also uses plain --target=bpf. Should the new rule pick bpfel or bpfeb the same way the bpf selftests do?

Quoted 2 lines

+
+$(OUTPUT)/xskxceiver: $(XSK_SOURCES) $(XSK_HEADERS) $(XSK_SKEL) $(BPFOBJ)

[ ... ]

Quoted 7 lines
tools/testing/selftests/net/lib/xsk/xsk.c renamed from tools/testing/selftests/bpf/xsk.c +0 -0
similarity index 97%
rename from tools/testing/selftests/bpf/xsk.c
rename to tools/testing/selftests/net/lib/xsk/xsk.c
index 25d568abf0f20..660540efc46e0 100644

[ ... ]

tools/testing/selftests/net/lib/xsk/xsk.c void xsk_socket__delete(struct xsk_socket *xsk) · line 782

Quoted 6 lines
tools/testing/selftests/net/lib/xsk/xsk.c renamed from tools/testing/selftests/bpf/xsk.c +2 -0
@@ -779,3 +778,27 @@ void xsk_socket__delete(struct xsk_socket *xsk)
 		close(xsk->fd);
 	free(xsk);
 }
+
+int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)

[Severity: Medium]
Can this function move into xsk.c without its license being addressed?

get_hw_ring_size() comes from tools/testing/selftests/bpf/network_helpers.c, which carries:

// SPDX-License-Identifier: GPL-2.0-only

xsk.c carries:

// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)

The function was contributed as GPL-2.0-only in commit 90a695c3d31e1c (Tushar Vyavahare). After this move, the xsk.c file tag offers it under LGPL-2.1 or BSD-2-Clause. Neither the SPDX header nor the function gets a license note.

The commit message only says:

"Move the ethtool ring helper from network_helpers into xsk.c"

It does not mention a relicense or carry an ack from the original author. Could the relicense be acked explicitly, or could the helper live in a GPL-2.0 file such as test_xsk.c instead?

Quoted 3 lines
tools/testing/selftests/net/lib/xsk/xsk.c renamed from tools/testing/selftests/bpf/xsk.c +3 -0
+{
+	struct ifreq ifr = {0};
+	int sockfd, err;

[ ... ]

Quoted 8 lines
tools/testing/selftests/net/test_xsk.sh renamed from tools/testing/selftests/bpf/test_xsk.sh +0 -0
similarity index 98%
rename from tools/testing/selftests/bpf/test_xsk.sh
rename to tools/testing/selftests/net/test_xsk.sh
index 69fac65f073c5..fbf4551d596a4 100755

tools/testing/selftests/net/test_xsk.sh do · line 104

Quoted 8 lines
tools/testing/selftests/net/test_xsk.sh renamed from tools/testing/selftests/bpf/test_xsk.sh +5 -0
@@ -97,6 +97,11 @@ do
 	esac
 done
 
+if [ ! -x "./${XSKOBJ}" ]; then
+	echo "xskxceiver was not built; skipping"
+	exit $ksft_skip
+fi
+

[Severity: Low]
This isn't a bug introduced by this patch, but the new check exits with $ksft_skip, while the other skip paths go through test_exit() in xsk_prereqs.sh, and that always exits 1:

tools/testing/selftests/net/xsk_prereqs.sh:test_exit() {
	if [ $1 -ne 0 ]; then
		test_status $1 $(basename $0)
	fi
	exit 1
}

validate_veth_support() and validate_ip_utility() both call "test_exit $ksft_skip". So when veth support or the ip utility is missing, the result is a failure rather than a skip.

Later in the series, "selftests: xsk: run one test case per xskxceiver invocation" replaces test_xsk.sh and xsk_prereqs.sh with test_xsk.py, which skips with exit code 4. By the end of the series this is gone.

Should test_exit() pass its argument to exit for the commits in between?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261016174338.787135-1-maciej.fijalkowski%40intel.com
maintainer
#12 lore raw

Re: [PATCH v4 net-next 06/15] selftests: xsk: move the AF_XDP test suite to selftests/net

In reply to Maciej Fijalkowski
Quoted 11 lines · On Fri, 16 Oct 2026 19:43:29 +0200 Maciej Fijalkowski wrote:

Move the xskxceiver engine, the AF_XDP userspace library, the test definitions and the XDP program to net/lib/xsk, and test_xsk.sh with its prerequisites script to selftests/net. A later patch drives the same engine against real NICs from drivers/net/hw, and net/lib is where both suites take shared helpers from.

net/lib builds xskxceiver with its XDP program and skeleton, using the bpftool in PATH, and skips it with a warning when bpftool is missing or does not run; test_xsk.sh then skips too. xskxceiver links -lpthread, which glibc older than 2.34 needs for the threads of test_xsk.c.

Quoted 5 lines

Like the rest of net/lib, xskxceiver builds against the installed uapi headers, so include linux/kernel.h for min_t() directly rather than via the tools copy of linux/netlink.h. tools/include goes ahead of CFLAGS, so that O= builds take linux/kernel.h and linux/types.h from it rather than from a source tree usr/include.

To be clear the expectation is that user runs

make headers

first, so installed != system headers. There's no requirement that selftests build without running make headers first.

Quoted 21 lines

Move the ethtool ring helper from network_helpers into xsk.c and point the kselftest.h include of test_xsk.h at the net/lib include path. The XDP program moves unchanged; its Ethernet header bound check compares pointers of distinct types, so net/lib builds it with -Wno-compare-distinct-pointer-types, as the bpf selftests do. xdp_hw_metadata and the xdp_metadata test keep using xsk.c and xsk.h from their new location. Update the AF_XDP entry in MAINTAINERS.

tools/testing/selftests/net/lib/Makefile +12 -0
+# AF_XDP test engine used by net/test_xsk.sh.
+XSK_DIR := xsk
+XSK_BPF_OBJ := $(OUTPUT)/xsk_xdp_progs.bpf.o
+XSK_SKEL := $(OUTPUT)/xsk_xdp_progs.skel.h
+XSK_SOURCES := $(addprefix $(XSK_DIR)/,xskxceiver.c xsk.c test_xsk.c) \
+	$(top_srcdir)/tools/lib/find_bit.c
+XSK_HEADERS := $(wildcard $(XSK_DIR)/*.h)
+
+PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
+XSK_LDLIBS := $(shell $(PKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) -lz
+XSK_LDLIBS += -lpthread
+

tools/testing/selftests/net/lib/Makefile TEST_INCLUDES := $(wildcard py/*.py sh/*.sh) · line 58

Quoted 10 lines
tools/testing/selftests/net/lib/Makefile +10 -0
+$(XSK_BPF_OBJ): $(XSK_DIR)/xsk_xdp_progs.bpf.c $(XSK_DIR)/xsk_xdp_common.h $(BPFOBJ)
+	$(call msg,BPF_PROG,,$@)
+	$(Q)$(CLANG) -O2 -g --target=bpf $(CCINCLUDE) $(CLANG_SYS_INCLUDES) \
+		-Wno-compare-distinct-pointer-types -c $< -o $@
+
+$(OUTPUT)/xskxceiver: $(XSK_SOURCES) $(XSK_HEADERS) $(XSK_SKEL) $(BPFOBJ)
+	$(call msg,CC,,$@)
+	$(Q)$(CC) -I$(top_srcdir)/tools/include $(CFLAGS) -I$(OUTPUT) \
+		-I$(SCRATCH_DIR)/include \
+		$(XSK_SOURCES) $(BPFOBJ) $(LDLIBS) $(XSK_LDLIBS) -o $@

Why do we need all these extra rules to build the xsk stuff? bpf.mk should build all %.bpf.c into objects
You seem to do similar thing for skel.
We shouldn't need 20 lines of Makefile for each test. We are not using any bleeding edge toolchain features here

Quoted 1 line

+EXTRA_CLEAN += $(XSK_BPF_OBJ) $(XSK_SKEL)

This should also somehow be covered by wildcards not obj by obj.

author maintainer
#13 lore raw

PATCH v4 7/15 selftests: xsk: collect interface capabilities in struct xsk_caps

In reply to Maciej Fijalkowski

A later patch runs the TX and RX endpoints of a case as separate processes, possibly on different hosts, each binding only its own interface. The shared test code still looks at the capabilities of both ifobjects, e.g. to check both for multi-buffer support or to size the RX batch from the TX ring limit. As the endpoints do not exchange capabilities, a process will represent the other side by a shadow ifobject that mirrors the local ones.

Prepare for that by replacing the per-interface support booleans and limits in struct ifobject with one struct xsk_caps, so that mirroring takes a single struct assignment and a capability added later cannot be left out of the copy. The maximum TX ring size, which comes from the ethtool ring parameters that a shadow does not mirror, is copied there too. ifobj_has_cap() and ifobj_set_cap() test and set the flags, and xsk_get_cap() reads a limit from the TX ifobject, the only one that has all of them set, as the open-coded reads did.

---
 .../testing/selftests/net/lib/xsk/test_xsk.c  | 82 +++++++++++--------
 .../testing/selftests/net/lib/xsk/test_xsk.h  | 34 ++++++--
 .../selftests/net/lib/xsk/xskxceiver.c        | 14 ++--
 3 files changed, 82 insertions(+), 48 deletions(-)
tools/testing/selftests/net/lib/xsk/test_xsk.c +47 -35
index 63267d886b17..edb1feb54c54 100644
@@ -1743,20 +1743,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");
@@ -1821,8 +1825,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;
 	}
@@ -1922,7 +1928,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");
@@ -2184,9 +2190,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;
 	}
 
@@ -2246,7 +2252,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;
@@ -2262,21 +2267,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) {
@@ -2284,19 +2281,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);
@@ -2386,7 +2398,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;
 	}
@@ -2413,7 +2425,7 @@ 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;
 	}
@@ -2436,7 +2448,7 @@ int testapp_hw_sw_max_ring_size(struct test_spec *test)
 	 * updating the Rx HW tail register. __send_pkts() waits until a whole batch fits
 	 * in the XSK TX ring, so keep it below that ring's size on NICs with larger rings.
 	 */
-	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)) {
@@ -2531,7 +2543,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);
tools/testing/selftests/net/lib/xsk/test_xsk.h +27 -7
index 410702f89dc9..716ea044797c 100644
@@ -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);
tools/testing/selftests/net/lib/xsk/xskxceiver.c +8 -6
index 7876ad47ed0f..d82224a4fa4b 100644
@@ -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)) {
Signature · 1 line
2.43.0
author maintainer
#14 lore raw

PATCH v4 8/15 selftests: xsk: split xskxceiver main() into setup, run and cleanup

In reply to Maciej Fijalkowski

Prepare xskxceiver for running a single endpoint per process by untangling main():

- bind_iface() sets up one interface from its -i argument, so that interfaces can get their roles after parsing; -l needs none
- 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, which main() counts instead of test->fail, as not every failing path sets it
- cleanup_iface() detaches and unloads one interface and copes with partially initialized objects, as does pkt_stream_delete(NULL), so main() has a single exit path; it takes the XDP flags from mode_to_xdp_flags(), now exported, so that they match the attach

Call ksft_print_header(), which also switches stdout to line buffering, right after parsing the command line: xskxceiver never called it, so a launcher reading through a pipe only saw the output at exit. -l prints no TAP header and exits with 0 instead of KSFT_XPASS, as listing the tests is not a test result.

---
 .../testing/selftests/net/lib/xsk/test_xsk.c  |  10 +-
 .../testing/selftests/net/lib/xsk/test_xsk.h  |   3 +
 .../selftests/net/lib/xsk/xskxceiver.c        | 180 +++++++++---------
 3 files changed, 106 insertions(+), 87 deletions(-)
tools/testing/selftests/net/lib/xsk/test_xsk.c +9 -1
index edb1feb54c54..76d079d8be23 100644
@@ -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);
 }
@@ -2291,6 +2294,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;
 }
 
tools/testing/selftests/net/lib/xsk/test_xsk.h +3 -0
index 716ea044797c..8503ef055d37 100644
@@ -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,
tools/testing/selftests/net/lib/xsk/xskxceiver.c +94 -86

294 lines not on this page · raw message

Signature · 1 line
2.43.0
#15 lore raw

Re: [PATCH v4 net-next 08/15] selftests: xsk: split xskxceiver main() into setup, run and cleanup

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In tools/testing/selftests/net/lib/xsk/test_xsk.c, xsk_reattach_xdp() attaches the new program with…
- [Low] Baseline decision: not a valid finding at the end of the series.

--

selftests: xsk: split xskxceiver main() into setup, run and cleanup

This splits xskxceiver main() into the bind_iface(), detect_mode_caps(), mode_supported() and cleanup_iface() helpers, to prepare for running a single endpoint per process. run_pkt_test() now returns its result, and main() gets a common out label for teardown. ksft_print_header() is called right after parsing, so stdout is line buffered.

Quoted 4 lines
tools/testing/selftests/net/lib/xsk/xskxceiver.c +0 -0
index d82224a4fa4b0..97eece4c57f89 100644

[ ... ]

Quoted 1 line
tools/testing/selftests/net/lib/xsk/xskxceiver.c +0 -0
@@ -317,26 +332,43 @@ static bool is_xdp_supported(int ifindex)

[ ... ]

tools/testing/selftests/net/lib/xsk/xskxceiver.c static bool is_xdp_supported(int ifindex)

Quoted 7 lines
tools/testing/selftests/net/lib/xsk/xskxceiver.c +7 -0
+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);
+}

[Severity: Low]
Can a native XDP program stay attached to the interface after xskxceiver exits?

cleanup_iface() uses ifobj->xdp_prog and ifobj->mode to decide whether to detach, and which flags to pass. Both fields are set only at the end of xsk_reattach_xdp() in test_xsk.c, after the DRV mode check:

test_xsk.c:xsk_reattach_xdp() {
    ...
	err = xsk_attach_xdp_program(xdp_prog, ifobj->ifindex, mode_to_xdp_flags(mode));
	if (err) {
		...
	}

	if (ifobj->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;
    ...
}

xsk_is_in_mode() returns false if bpf_xdp_query() fails, for example on a netlink socket or recv error. That can happen even though the attach with XDP_FLAGS_DRV_MODE succeeded. The error path then returns without detaching the new program and without recording it.

If this is the first DRV/ZC attach, ifobj->xdp_prog is still NULL from ifobject_create(), so cleanup_iface() skips the detach. If an earlier SKB attach succeeded, cleanup_iface() detaches with XDP_FLAGS_SKB_MODE, and that doesn't remove the native program.

In this patch, this only matters when the failing attach is the last one for that ifobj. A later successful reattach in the same mode fixes the bookkeeping. Later in the series, xskxceiver runs one test per invocation with a fixed mode. Every DRV/ZC run then hits this check on its first attach, and xsk_reattach_xdp() and cleanup_iface() are still unchanged.

The old main() never detached XDP programs at all. So this is a gap in the new teardown, which the commit message describes as using flags "so that they match the attach".

Would it make sense to record xdp_prog and mode right after the attach succeeds, before the mode check? Detaching on that error path would also work.

Quoted 1 line
tools/testing/selftests/net/lib/xsk/xskxceiver.c +0 -0
@@ -371,90 +407,62 @@ int main(int argc, char **argv)

[ ... ]

Quoted 5 lines
tools/testing/selftests/net/lib/xsk/xskxceiver.c +0 -0
 	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();
 	}

[ ... ]

Quoted 5 lines
tools/testing/selftests/net/lib/xsk/xskxceiver.c +4 -0
+	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;

[ ... ]

Quoted 2 lines
tools/testing/selftests/net/lib/xsk/xskxceiver.c +1 -0
+	caps = detect_mode_caps(ifobj_tx);

[ ... ]

tools/testing/selftests/net/lib/xsk/xskxceiver.c int main(int argc, char **argv) · line 428

Quoted 7 lines
tools/testing/selftests/net/lib/xsk/xskxceiver.c +5 -0
+	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();
 	}

[Severity: Low]
The commit message says:

cleanup_iface() detaches and unloads one interface and copes with partially initialized objects, as does pkt_stream_delete(NULL), so main() has a single exit path

Is that accurate for this patch? main() still calls ksft_exit_xfail() after setup in two places, and both skip the out label:

- when the requested test index does not exist. This check now runs after both interfaces are bound.
- here, when the requested mode is unsupported. This runs after the packet streams are allocated.

bind_iface() can also call ksft_exit_fail() from parse_command_line() for the rx interface. By that point the tx interface's skeleton is already loaded.

None of these exits leaves an XDP program attached. is_xdp_supported() detaches its probe program, ifobj_zc_avail() deletes its socket, and process exit frees the skeletons and heap memory.

This is resolved later in the series. There, find_test() and xsk_set_flow() run before any interface is bound, and only the local interface is bound. The unsupported-mode case also becomes ret = TEST_SKIP followed by goto out.

Could the commit message for this patch be reworded? Another option is to convert these exits to goto out in this patch.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261016174338.787135-1-maciej.fijalkowski%40intel.com
author maintainer
#16 lore raw

PATCH v4 9/15 selftests: xsk: run one test case per xskxceiver invocation

In reply to Maciej Fijalkowski

Replace test_xsk.sh and xsk_prereqs.sh with test_xsk.py, which runs xskxceiver once per mode and case, so that every case starts from a fresh process and a crash fails only its own case. A single case is also the unit that the next patch splits into RX and TX processes.

xskxceiver now requires -m and -t, runs exactly that case, reports one KTAP result and exits with its verdict. An unsupported mode skips the case instead of exiting with XFAIL.

test_xsk.py uses the networking selftests Python library, as does the hardware test added later, so every case is a KTAP case of its own:
test_xsk runs each case that xskxceiver -l lists in skb and drv mode, e.g. test_xsk.drv_SEND_RECEIVE, and test_xsk_busy_poll runs them again with busy polling. The usual -t and -T options select cases in place of the script's -l, -m and -t, and -v and -d go away, as the output of a run that does not pass is logged. Each case runs on a veth pair of its own, so an MTU or an XDP program that a crashed case leaves behind cannot reach the next one. The pair stays in the current network namespace, as only the initial one has the net.core.max_skb_frags sysctl that xskxceiver reads. A case is killed and fails after 20s, so that the run ends within the net timeout even if all cases hang. xskxceiver is also killed if the wait for it is interrupted, and the test skips when xskxceiver was not built.

test_xsk.py reserves 32 huge pages of 2 MiB, the size that xskxceiver maps the UNALIGNED UMEMs with, and restores the count however the run ends, -l and -h included. When it cannot, as without hugetlb or root, it restores the count at once and leaves the UNALIGNED cases out. The huge page, busy-poll and endpoint wait helpers, which the hardware test shares, go to net/lib/py/xsk.py, which joins the AF_XDP entry in MAINTAINERS.

test_xsk.py leaves out two cases that test_progs skipped as flaky:

- XDP_ADJUST_TAIL_SHRINK_MULTI_BUFF: bpf_xdp_adjust_tail() frees the trimmed fragment as the memory type of the XDP RX queue, which veth and generic XDP leave at MEM_TYPE_PAGE_SHARED for frames that they copy into page_pool pages, so the page leaks from its pool and the pool's shutdown stalls
- XDP_ADJUST_TAIL_GROW: it skips in skb mode, and in drv mode veth copies each frame into a page_pool fragment that leaves no room to grow the 128-byte frames of the case unless it is the last one of its page, so the XDP program drops most frames

Drop the xskxceiver.c note on enabling packet dumps with -D in test_xsk.sh; xskxceiver has no such option and dumps packets on validation errors.

---
 MAINTAINERS                                   |   1 +
 tools/testing/selftests/net/Makefile          |   3 +-
 tools/testing/selftests/net/lib/Makefile      |   2 +-
 .../testing/selftests/net/lib/py/__init__.py  |   4 +
 tools/testing/selftests/net/lib/py/xsk.py     |  73 ++++++
 .../selftests/net/lib/xsk/xskxceiver.c        |  63 ++---
 tools/testing/selftests/net/test_xsk.py       | 139 +++++++++++
 tools/testing/selftests/net/test_xsk.sh       | 230 ------------------
 tools/testing/selftests/net/xsk_prereqs.sh    |  86 -------
 9 files changed, 241 insertions(+), 360 deletions(-)
 create mode 100644 tools/testing/selftests/net/lib/py/xsk.py
 create mode 100755 tools/testing/selftests/net/test_xsk.py
 delete mode 100755 tools/testing/selftests/net/test_xsk.sh
 delete mode 100755 tools/testing/selftests/net/xsk_prereqs.sh
MAINTAINERS +1 -0
index 1fc9eaedd744..6985a42bc09c 100644
@@ -29784,6 +29784,7 @@ 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/py/xsk.py
 F:	tools/testing/selftests/net/lib/xsk/
 
 XEN BLOCK SUBSYSTEM
tools/testing/selftests/net/Makefile +1 -2
index aa31b6216dd1..8c8219703bd7 100644
@@ -118,7 +118,7 @@ TEST_PROGS := \
 	test_vxlan_under_vrf.sh \
 	test_vxlan_vnifilter_notify.sh \
 	test_vxlan_vnifiltering.sh \
-	test_xsk.sh \
+	test_xsk.py \
 	tfo_passive.sh \
 	traceroute.sh \
 	txtimestamp.sh \
@@ -210,7 +210,6 @@ TEST_FILES := \
 	in_netns.sh \
 	lib.sh \
 	settings \
-	xsk_prereqs.sh \
 # end of TEST_FILES
 
 # YNL files, must be before "include ..lib.mk"
tools/testing/selftests/net/lib/Makefile +1 -1
index c26088da0489..5c1612315062 100644
@@ -34,7 +34,7 @@ include ../../lib.mk
 
 include ../bpf.mk
 
-# AF_XDP test engine used by net/test_xsk.sh.
+# AF_XDP test engine used by net/test_xsk.py.
 XSK_DIR := xsk
 XSK_BPF_OBJ := $(OUTPUT)/xsk_xdp_progs.bpf.o
 XSK_SKEL := $(OUTPUT)/xsk_xdp_progs.skel.h
tools/testing/selftests/net/lib/py/__init__.py +4 -0
index 71df5880b356..1a93ab8b1e60 100644
@@ -16,6 +16,8 @@ from .utils import CmdExitFailure, fd_read_timeout, cmd, bkg, defer, \
     bpftool, ip, ethtool, bpftrace, rand_port, rand_ports, wait_port_listen, \
     ctl_file_write, wait_file, tool, tc
 from .bpf import bpf_map_set, bpf_map_dump, bpf_prog_map_ids
+from .xsk import xsk_reserve_hugepages, xsk_release_hugepages, \
+    xsk_setup_busy_poll, xsk_wait_endpoint_exit
 from .ynl import NlError, NlctrlFamily, YnlFamily, \
     EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily, RtnlRouteFamily
 from .ynl import NetshaperFamily, DevlinkFamily, PSPFamily, Netlink
@@ -31,6 +33,8 @@ __all__ = ["KSRC",
            "bpftool", "ip", "ethtool", "bpftrace", "rand_port", "rand_ports",
            "wait_port_listen", "ctl_file_write", "wait_file", "tool", "tc",
            "bpf_map_set", "bpf_map_dump", "bpf_prog_map_ids",
+           "xsk_reserve_hugepages", "xsk_release_hugepages",
+           "xsk_setup_busy_poll", "xsk_wait_endpoint_exit",
            "NetdevSim", "NetdevSimDev",
            "NetshaperFamily", "DevlinkFamily", "PSPFamily", "NlError",
            "YnlFamily", "EthtoolFamily", "NetdevFamily", "RtnlFamily",
tools/testing/selftests/net/lib/py/xsk.py new file +73 -0

73 lines not on this page · raw message

tools/testing/selftests/net/lib/xsk/xskxceiver.c +22 -41

116 lines not on this page · raw message

tools/testing/selftests/net/test_xsk.py new file +139 -0

139 lines not on this page · raw message

tools/testing/selftests/net/test_xsk.sh deleted +0 -230

230 lines not on this page · raw message

tools/testing/selftests/net/xsk_prereqs.sh deleted +0 -86

86 lines not on this page · raw message

Signature · 1 line
2.43.0
#17 lore raw

Re: [PATCH v4 net-next 09/15] selftests: xsk: run one test case per xskxceiver invocation

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] selftests: missing prerequisites (root, veth) cause hard failure instead of skip --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] selftests: missing prerequisites (root, veth) cause hard failure instead of skip --

commit 621c952e0f68b97c93b16b3262842ed60506e7fc
Author: Maciej Fijalkowski <[email protected]>

selftests: xsk: run one test case per xskxceiver invocation

Replace test_xsk.sh and xsk_prereqs.sh with test_xsk.py to run xskxceiver once per mode and case. The new Python script relies on the networking selftests Python library to manage test cases and resources.

Quoted 5 lines
tools/testing/selftests/net/test_xsk.py new file +0 -0
new file mode 100755
index 0000000000000..80ac67cdebb66

[ ... ]

tools/testing/selftests/net/test_xsk.py line 85

Quoted 5 lines
tools/testing/selftests/net/test_xsk.py new file +5 -0
+def _veth_pair(busy_poll):
+    pfx = f"xsk{random.randrange(1 << 20):05x}"
+    veths = (pfx + "a", pfx + "b")
+    ip(f"link add {veths[0]} numtxqueues 4 numrxqueues 4 type veth "
+       f"peer name {veths[1]} numtxqueues 4 numrxqueues 4")

[Severity: Medium]
When the test suite is run as a non-root user or on a system without veth module support, will this cause a hard failure rather than a skip?

The previous xsk_prereqs.sh script explicitly checked for root privileges and veth support, returning ksft_skip gracefully if they were missing. Here, the ip() command will raise a CmdExitFailure exception if the privileges or driver are missing, which the test runner catches and reports as a failure.

Could this turn an environment difference into a false regression signal?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
#18 lore raw

Re: [PATCH v4 net-next 09/15] selftests: xsk: run one test case per xskxceiver invocation

In reply to Maciej Fijalkowski
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

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

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

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] test_xsk.py reserves the 2 MiB pool only (/sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages), on the…
- [Low] In xsk_wait_endpoint_exit() (tools/testing/selftests/net/lib/py/xsk.py), the TimeoutExpired…
- [Low] Concern: xsk_reserve_hugepages()/xsk_release_hugepages() read, modify and restore the global 2 MiB nr_hugepages with no protection…

--

selftests: xsk: run one test case per xskxceiver invocation

This replaces test_xsk.sh and xsk_prereqs.sh with test_xsk.py, which runs xskxceiver once per mode and case on a fresh veth pair. It moves the huge page, busy-poll and endpoint wait helpers into net/lib/py/xsk.py. xskxceiver now requires -m and -t and runs exactly one case.

Quoted 6 lines
tools/testing/selftests/net/lib/py/xsk.py new file +0 -0
new file mode 100644
index 0000000000000..ffaf4b2d35b9d
@@ -0,0 +1,73 @@

[ ... ]

tools/testing/selftests/net/lib/py/xsk.py line 14

Quoted 3 lines
tools/testing/selftests/net/lib/py/xsk.py new file +3 -0
+NR_HUGEPAGES = 32
+# xskxceiver maps the UMEMs of the UNALIGNED cases with MAP_HUGE_2MB.
+HUGEPAGES = "/sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages"

[Severity: Medium]
This comment, and the commit message line "test_xsk.py reserves 32 huge pages of 2 MiB, the size that xskxceiver maps the UNALIGNED UMEMs with", hold for thread_common_ops(). Do they also hold for the probe that decides whether the UNALIGNED cases can run?

hugepages_present() in lib/xsk/test_xsk.c does:

	bufs = mmap(NULL, mmap_sz, PROT_READ | PROT_WRITE,
		    MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, MAP_HUGE_2MB);

Here MAP_HUGE_2MB goes in as the offset and is not OR-ed into the flags. That leaves no size bits in flags, so the kernel uses the default hstate.

Take a host booted with default_hugepagesz=1G, or arm64 with 64K pages. The probe checks the wrong pool there. The 0x54000000 offset is also not aligned to the default huge page size, so the mmap fails with -EINVAL.

On such a host the sequence is:

xsk_reserve_hugepages() fills the 2 MiB pool and returns True _get_cases() keeps the UNALIGNED cases detect_ifobj_caps()->hugepages_present() fails XSK_CAP_UNALIGNED stays clear
testapp_validate_traffic() prints "No huge pages present." and skips

Every UNALIGNED case then skips, even though the 2 MiB pages were reserved. The docstring says these cases are left out only without huge pages.

The probe was already wrong before this patch, but this patch is the first to rely on xskxceiver using the 2 MiB pool. Should hugepages_present() put MAP_HUGE_2MB in the flags, the way thread_common_ops() does?

Quoted 3 lines
tools/testing/selftests/net/lib/py/xsk.py new file +3 -0
+
+
+def xsk_reserve_hugepages(saved, host=None):

[ ... ]

Quoted 9 lines
tools/testing/selftests/net/lib/py/xsk.py new file +9 -0
+    have = cmd(f"cat {HUGEPAGES}", fail=False, host=host)
+    if have.ret:
+        return False
+    have = int(have.stdout)
+    if have >= NR_HUGEPAGES:
+        return True
+    saved.append((host, have))
+    cmd(f"echo {NR_HUGEPAGES} > {HUGEPAGES}", shell=True, fail=False,
+        host=host)

[ ... ]

tools/testing/selftests/net/lib/py/xsk.py line 42

Quoted 5 lines
tools/testing/selftests/net/lib/py/xsk.py new file +5 -0
+def xsk_release_hugepages(saved):
+    """Restore the counts that xsk_reserve_hugepages() added to saved, the
+    last one first, as two hosts can share the pool."""
+    for host, have in reversed(saved):
+        cmd(f"echo {have} > {HUGEPAGES}", shell=True, fail=False, host=host)

[Severity: Low]
This probably isn't a problem in practice. The kselftest runner runs tests one at a time, and saving and restoring nr_hugepages is the usual pattern (mm's run_vmtests.sh does the same).

Still, the 2 MiB nr_hugepages count is global, and it is read, changed and restored here with no coordination. If something else on the host changes it during the run, would this restore overwrite that change?

[ ... ]

Quoted 1 line

+def xsk_wait_endpoint_exit(endpoint, label, timeout):

[ ... ]

tools/testing/selftests/net/lib/py/xsk.py line 63

Quoted 5 lines
tools/testing/selftests/net/lib/py/xsk.py new file +5 -0
+    try:
+        endpoint.process(terminate=False, fail=False, timeout=timeout)
+    except subprocess.TimeoutExpired:
+        endpoint.proc.kill()
+        endpoint.process(terminate=False, fail=False)

[Severity: Low]
Can this second process() call time out too? That could happen if xskxceiver is in uninterruptible sleep, for example blocked in the kernel on a hung page_pool or XDP teardown, so the SIGKILL does not take effect.

cmd.process() defaults to timeout=20, so this is another bounded proc.communicate(timeout=20). A TimeoutExpired raised inside this handler is not caught by the except BaseException clause next to it.

The exception would then escape without the "killed after" log, without the captured stdout and stderr, and with the child left unreaped. ksft_run() would mark the case failed with a traceback.

The case would also take about 2 x CASE_TIMEOUT. The commit message says:

A case is killed and fails after 20s, so that the run ends within the net timeout even if all cases hang.

Quoted 5 lines
tools/testing/selftests/net/lib/py/xsk.py new file +5 -0
+        ksft_pr(f"killed after {timeout}s", line_pfx=f"{label}|")
+    except BaseException:
+        endpoint.proc.kill()
+        endpoint.proc.wait()
+        raise

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261016174338.787135-1-maciej.fijalkowski%40intel.com
maintainer
#19 lore raw

Re: [PATCH v4 net-next 09/15] selftests: xsk: run one test case per xskxceiver invocation

In reply to Maciej Fijalkowski
Quoted 9 lines · On Fri, 16 Oct 2026 19:43:32 +0200 Maciej Fijalkowski wrote:

Replace test_xsk.sh and xsk_prereqs.sh with test_xsk.py, which runs xskxceiver once per mode and case, so that every case starts from a fresh process and a crash fails only its own case. A single case is also the unit that the next patch splits into RX and TX processes.

MAINTAINERS +0 -0
index 1fc9eaedd744..6985a42bc09c 100644

MAINTAINERS F: include/uapi/linux/if_xdp.h · line 29788

Quoted 5 lines
MAINTAINERS +1 -0
@@ -29784,6 +29784,7 @@ 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/py/xsk.py
 F:	tools/testing/selftests/net/lib/xsk/

pylint has some complaints, about main(), I think? Could you make it clean?

MAINTAINERS F: include/uapi/linux/if_xdp.h · line 29789

Quoted 1 line
MAINTAINERS +1 -0
+++ b/tools/testing/selftests/net/lib/py/xsk.py

Really not loving the amount of "library" code added here. Do you need this just to run it over veth in net/ and over real HW in drivers/net/ ? Are the test cases very different?

I wonder if we could solve this by parameterizing the env class to use veth instead of netdevsim and then have unified tests?

MAINTAINERS F: include/uapi/linux/if_xdp.h · line 29790

Quoted 1 line
MAINTAINERS +1 -0
+def xsk_wait_endpoint_exit(endpoint, label, timeout):

odd, the existing cmd() / bkg() stuff doesn't work for you? It works for many other tests...

Signature · 1 line
pw-bot: cr
author maintainer
#20 lore raw

Re: [PATCH v4 net-next 09/15] selftests: xsk: run one test case per xskxceiver invocation

Quoted 19 lines · Jakub Kicinski
Quoted 9 lines · On Fri, 16 Oct 2026 19:43:32 +0200 Maciej Fijalkowski wrote:

Replace test_xsk.sh and xsk_prereqs.sh with test_xsk.py, which runs xskxceiver once per mode and case, so that every case starts from a fresh process and a crash fails only its own case. A single case is also the unit that the next patch splits into RX and TX processes.

MAINTAINERS +0 -0
index 1fc9eaedd744..6985a42bc09c 100644

MAINTAINERS F: include/uapi/linux/if_xdp.h · line 29788

Quoted 5 lines
MAINTAINERS +1 -0
@@ -29784,6 +29784,7 @@ 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/py/xsk.py
 F:	tools/testing/selftests/net/lib/xsk/

pylint has some complaints, about main(), I think? Could you make it clean?

Quoted 5 lines

MAINTAINERS F: include/uapi/linux/if_xdp.h · line 29789

Quoted 1 line
MAINTAINERS +1 -0
+++ b/tools/testing/selftests/net/lib/py/xsk.py

Really not loving the amount of "library" code added here. Do you need this just to run it over veth in net/ and over real HW in drivers/net/ ? Are the test cases very different?

Now that you bring this up, would be good to clarify expectations of this work. The lib input is what veth and hw runners share to avoid code repetition. The separation comes from a fact that we still want to cover SKB and DRV modes (via veth at net/test_xsk.py) and ZC mode is covered by drivers/net/hw/xsk.py.

My assumption was that would not hurt much to carry common code within lib file. I might have been wrong tho.

Quoted 3 lines

I wonder if we could solve this by parameterizing the env class to use veth instead of netdevsim and then have unified tests?

Tell me more regarding the unified tests. Is that okay'ish to run veth-based tests from drivers/net/hw ? I thought it was not and I shared my insights on similar work which does the same kind of migration (xdp_features bpf->drivers/net/hw) and it seemed to be heavily veth dedicated - the bpf sh runner was basically veth based, but so does the xskxceiver and I moved away from this after Bjorn's input (turned out to be a good thing).

each runner can have single ksft_run() call, right? So, do you think separate files for veth and hw runners is still okay?

In veth runner I don't even instantiate NetDrvEpEnv as I have veth pair being created 'manually', however having a param similar to existing netdevsim one would be nice and xdp-features set could benefit from that as well.

Quoted 6 lines

MAINTAINERS F: include/uapi/linux/if_xdp.h · line 29790

Quoted 3 lines
MAINTAINERS +1 -0
+def xsk_wait_endpoint_exit(endpoint, label, timeout):

odd, the existing cmd() / bkg() stuff doesn't work for you? It works for many other tests...

This has been mostly about grabbing output from failed cases, let me dig and see if bkg() is indeed enough or if we could adjust it. Good point!

Quoted 2 lines
Signature · 1 line
pw-bot: cr
maintainer
#21 lore raw

Re: [PATCH v4 net-next 09/15] selftests: xsk: run one test case per xskxceiver invocation

Quoted 4 lines · On Thu, 22 Oct 2026 17:44:14 +0200 Maciej Fijalkowski wrote:
Quoted 3 lines

Really not loving the amount of "library" code added here. Do you need this just to run it over veth in net/ and over real HW in drivers/net/ ? Are the test cases very different?

Quoted 8 lines

Now that you bring this up, would be good to clarify expectations of this work. The lib input is what veth and hw runners share to avoid code repetition. The separation comes from a fact that we still want to cover SKB and DRV modes (via veth at net/test_xsk.py) and ZC mode is covered by drivers/net/hw/xsk.py.

My assumption was that would not hurt much to carry common code within lib file. I might have been wrong tho.

We should try to avoid pushing things into lib whenever possible.

Quoted 10 lines
Quoted 2 lines

I wonder if we could solve this by parameterizing the env class to use veth instead of netdevsim and then have unified tests?

Tell me more regarding the unified tests. Is that okay'ish to run veth-based tests from drivers/net/hw ? I thought it was not and I shared my insights on similar work which does the same kind of migration (xdp_features bpf->drivers/net/hw) and it seemed to be heavily veth dedicated - the bpf sh runner was basically veth based, but so does the xskxceiver and I moved away from this after Bjorn's input (turned out to be a good thing).

The other way around. We can add mixed HW and non-HW tests in drivers/net When run against non-HW we need to be careful to XFail instead of failing or Skipping, so that SW CI "is green".

Quoted 2 lines

each runner can have single ksft_run() call, right? So, do you think separate files for veth and hw runners is still okay?

SW and HW testing are done by separate executors. We'd have some trouble (read: we'd need extra wrapping) if we we needed multiple envs for SW testing, but SW vs HW is easy. Executor will either run with no env exports and get the SW test, or it will be exporting $NETIF etc and test will run against $NETIF.

Quoted 4 lines

In veth runner I don't even instantiate NetDrvEpEnv as I have veth pair being created 'manually', however having a param similar to existing netdevsim one would be nice and xdp-features set could benefit from that as well.

Yup!

author maintainer
#22 lore raw

PATCH v4 10/15 selftests: xsk: run the RX and TX endpoints in separate processes

In reply to Maciej Fijalkowski

Run the two endpoints of a test case as separate xskxceiver processes, so that a later patch can run them on two hosts. A process binds only the interface given with -i, takes its role from -e rx|tx and meets the other endpoint over a small TCP control channel (-p HOST -P PORT). The other side is represented by a shadow ifobject that mirrors the local capabilities and holds a loaded copy of the XDP skeleton, so the shared test code keeps addressing both sides while only the local interface is programmed. Once BIDIRECTIONAL swaps the directions, the local interface runs the shadow's programs.

The pthreads, the barrier, test->fail and -lpthread go away. Each process runs the worker of its local ifobject, and the endpoints exchange three fixed-size messages:

- READY, exchanged before each step, works as a barrier; TCP ordering puts all progress of the previous step before it
- PROGRESS carries the number of packets RX consumed, which TX subtracts from its in-flight count so as not to overrun the RX UMEM
- ABORT tells the other endpoint to stop waiting after a failure

The endpoint given --listen listens and the other one connects, whichever its role. The listener says on stderr when it listens, so the launcher starts the connector then rather than polling for the port, which could also find a foreign listener. The listener waits 30s for the connector, and -P goes to getaddrinfo() as given. As with the control channels of other selftests, the hosts are trusted and the channel is not authenticated. Test selection, interface capabilities, option ranges and verdicts stay with the launcher.

test_xsk.py starts TX as the listener on a random control port on 127.0.0.1 and RX once TX listens, and kills TX and fails the case when it does not listen within 30s. The case passes when both endpoints pass, and is skipped when one skips and neither fails. Only the output of an endpoint that does not pass is logged, prefixed with its role. xsk_wait_listen(), which reads the TX stderr up to the listen line, joins the library helpers, and xsk_wait_endpoint_exit() logs that output along with the rest.

---
 tools/testing/selftests/net/lib/Makefile      |   3 +-
 .../testing/selftests/net/lib/py/__init__.py  |   4 +-
 tools/testing/selftests/net/lib/py/xsk.py     |  37 ++-
 .../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        | 131 ++++++--
 tools/testing/selftests/net/test_xsk.py       |  68 ++--
 9 files changed, 629 insertions(+), 152 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
tools/testing/selftests/net/lib/Makefile +1 -2
index 5c1612315062..49dac776202b 100644
@@ -38,13 +38,12 @@ include ../bpf.mk
 XSK_DIR := xsk
 XSK_BPF_OBJ := $(OUTPUT)/xsk_xdp_progs.bpf.o
 XSK_SKEL := $(OUTPUT)/xsk_xdp_progs.skel.h
-XSK_SOURCES := $(addprefix $(XSK_DIR)/,xskxceiver.c xsk.c test_xsk.c) \
+XSK_SOURCES := $(addprefix $(XSK_DIR)/,xskxceiver.c xsk.c test_xsk.c xsk_peer.c) \
 	$(top_srcdir)/tools/lib/find_bit.c
 XSK_HEADERS := $(wildcard $(XSK_DIR)/*.h)
 
 PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
 XSK_LDLIBS := $(shell $(PKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) -lz
-XSK_LDLIBS += -lpthread
 
 $(XSK_BPF_OBJ): $(XSK_DIR)/xsk_xdp_progs.bpf.c $(XSK_DIR)/xsk_xdp_common.h $(BPFOBJ)
 	$(call msg,BPF_PROG,,$@)
tools/testing/selftests/net/lib/py/__init__.py +2 -2
index 1a93ab8b1e60..a82bac8a6b47 100644
@@ -17,7 +17,7 @@ from .utils import CmdExitFailure, fd_read_timeout, cmd, bkg, defer, \
     ctl_file_write, wait_file, tool, tc
 from .bpf import bpf_map_set, bpf_map_dump, bpf_prog_map_ids
 from .xsk import xsk_reserve_hugepages, xsk_release_hugepages, \
-    xsk_setup_busy_poll, xsk_wait_endpoint_exit
+    xsk_setup_busy_poll, xsk_wait_endpoint_exit, xsk_wait_listen
 from .ynl import NlError, NlctrlFamily, YnlFamily, \
     EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily, RtnlRouteFamily
 from .ynl import NetshaperFamily, DevlinkFamily, PSPFamily, Netlink
@@ -34,7 +34,7 @@ __all__ = ["KSRC",
            "wait_port_listen", "ctl_file_write", "wait_file", "tool", "tc",
            "bpf_map_set", "bpf_map_dump", "bpf_prog_map_ids",
            "xsk_reserve_hugepages", "xsk_release_hugepages",
-           "xsk_setup_busy_poll", "xsk_wait_endpoint_exit",
+           "xsk_setup_busy_poll", "xsk_wait_endpoint_exit", "xsk_wait_listen",
            "NetdevSim", "NetdevSimDev",
            "NetshaperFamily", "DevlinkFamily", "PSPFamily", "NlError",
            "YnlFamily", "EthtoolFamily", "NetdevFamily", "RtnlFamily",
tools/testing/selftests/net/lib/py/xsk.py +30 -7
index ffaf4b2d35b9..7ba7afe10db3 100644
@@ -5,9 +5,10 @@ Helpers to run xskxceiver, the AF_XDP test program in net/lib/xsk.
 """
 
 import subprocess
+import time
 
 from .ksft import ksft_pr
-from .utils import cmd, ctl_file_write
+from .utils import cmd, ctl_file_write, fd_read_timeout
 
 NR_HUGEPAGES = 32
 # xskxceiver maps the UMEMs of the UNALIGNED cases with MAP_HUGE_2MB.
@@ -51,11 +52,33 @@ def xsk_setup_busy_poll(ifname):
     ctl_file_write(f"{sysfs}/gro_flush_timeout", 200000)
 
 
-def xsk_wait_endpoint_exit(endpoint, label, timeout):
-    """Wait up to timeout seconds for xskxceiver to exit, kill it if it does
-    not or if the wait is interrupted, and return its exit code. Log its
-    output, a KTAP stream of its own, prefixed with label, only if it did
-    not pass."""
+def xsk_wait_listen(endpoint, port, timeout):
+    """Wait up to timeout seconds for an xskxceiver endpoint to print on
+    stderr that it listens on the control port. Unlike polling for the port,
+    this never takes a foreign listener for it and costs no SSH login per
+    try on a remote host. Return the stderr read so far and whether that
+    line came."""
+    line = f"Listening for XSK peer on port {port}\n".encode()
+    fd = endpoint.proc.stderr.fileno()
+    head = b""
+    deadline = time.monotonic() + timeout
+    while line not in head:
+        try:
+            data = fd_read_timeout(fd, max(deadline - time.monotonic(), 0))
+        except TimeoutError:
+            break
+        if not data:
+            break
+        head += data
+    return head.decode(), line in head
+
+
+def xsk_wait_endpoint_exit(endpoint, label, timeout, head=""):
+    """Wait up to timeout seconds for an xskxceiver endpoint to exit, kill it
+    if it does not or if the wait is interrupted, and return its exit code.
+    Log its output, a KTAP stream of its own, prefixed with label, only if
+    it did not pass. head is the start of its stderr, if xsk_wait_listen()
+    took it off the pipe."""
     try:
         endpoint.process(terminate=False, fail=False, timeout=timeout)
     except subprocess.TimeoutExpired:
@@ -67,7 +90,7 @@ def xsk_wait_endpoint_exit(endpoint, label, timeout):
         endpoint.proc.wait()
         raise
     if endpoint.ret:
-        for out in (endpoint.stdout, endpoint.stderr):
+        for out in (endpoint.stdout, head + endpoint.stderr):
             if out:
                 ksft_pr(out.rstrip(), line_pfx=f"{label}|")
     return endpoint.ret
tools/testing/selftests/net/lib/xsk/test_xsk.c +121 -82

378 lines not on this page · raw message

tools/testing/selftests/net/lib/xsk/test_xsk.h +16 -7
index 8503ef055d37..f1fafae2d140 100644
@@ -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},
tools/testing/selftests/net/lib/xsk/xsk_peer.c new file +293 -0

293 lines not on this page · raw message

tools/testing/selftests/net/lib/xsk/xsk_peer.h new file +19 -0
new file mode 100644
index 000000000000..da4462192994
@@ -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_ */
tools/testing/selftests/net/lib/xsk/xskxceiver.c +106 -25

254 lines not on this page · raw message

tools/testing/selftests/net/test_xsk.py +41 -27

93 lines not on this page · raw message

Signature · 1 line
2.43.0
#23 lore raw

Re: [PATCH v4 net-next 10/15] selftests: xsk: run the RX and TX endpoints in separate processes

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] Skip handling in the launcher and the endpoints don't match.

--

selftests: xsk: run the RX and TX endpoints in separate processes

This commit splits xskxceiver into separate RX and TX processes. The two processes stay in step over a TCP control channel that carries READY, PROGRESS and ABORT messages. test_xsk.py starts TX as the listener on 127.0.0.1, starts RX once TX listens, and builds the verdict from both exit codes.

Quoted 4 lines
tools/testing/selftests/net/lib/xsk/xskxceiver.c +0 -0
index b4f9cd3715037..fbfff586e0e5e 100644

[ ... ]

Quoted 1 line
tools/testing/selftests/net/lib/xsk/xskxceiver.c +0 -0
@@ -409,12 +474,26 @@ int main(int argc, char **argv)

[ ... ]

tools/testing/selftests/net/lib/xsk/xskxceiver.c int main(int argc, char **argv) · line 499

Quoted 11 lines
tools/testing/selftests/net/lib/xsk/xskxceiver.c +2 -1
 	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)

[Severity: Low]

Suppose this endpoint skips here because of its local caps. It then goes to out: and closes the control socket without telling the peer. The control protocol in xsk_peer.c has only these message types:

enum xsk_peer_msg_type {
	XSK_PEER_READY = 1,
	XSK_PEER_PROGRESS,
	XSK_PEER_ABORT,
};

Would a peer that is still waiting in xsk_peer_ready() get -EPIPE and fail in sync_endpoints(), instead of skipping?

In test_xsk.py, _test() reports a skip only when neither endpoint fails:

if SKIP_CODE in rets and rets <= {0, SKIP_CODE}:

That means the exit codes would be {4, 1}, and the case would be reported as a failure. Other local skips work the same way, for example the multi-buffer check in __testapp_validate_traffic() and the unaligned check in testapp_validate_traffic().

This doesn't look reachable in this commit. With the veth runner both ends have the same caps, so these early skips happen on both sides and give {4, 4}. The problem would only show up with endpoints on two hosts.

The later commit "selftests: xsk: prepare xskxceiver for endpoints on two hosts" seems to close this gap. It adds XSK_PEER_SKIP, xsk_peer_skip() (called from main() when ret == TEST_SKIP) and xsk_peer_skipped() checks in sync_endpoints() and __send_pkts().

Could the skip message move into this patch? Or could the commit message say that, until then, skips are expected to happen on both endpoints?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261016174338.787135-1-maciej.fijalkowski%40intel.com
author maintainer
#24 lore raw

PATCH v4 11/15 selftests: xsk: send UDP over IPv4 or IPv6 between the interface MACs

In reply to Maciej Fijalkowski

xskxceiver sends frames of the loopback ethertype between made-up MAC addresses, and its XDP programs redirect every frame to the XSKMAP. That suits a veth pair that carries nothing else, but not a physical link, where the peer NIC filters out the made-up addresses and the programs take neighbour discovery, LLDP or SSH away from the stack.

Send the test packets as UDP between the MAC addresses of the two interfaces on any link. Each endpoint takes the IPv4 or IPv6 addresses of the flow (--src-ip, --dst-ip), the MAC address of its peer (--dst-mac) and the UDP port (--udp-port), and reads its own MAC address from the interface. Over IPv4 the UDP checksum is left at zero, as IPv4 allows; over IPv6 it is computed from the known payload. PKT_HDR_SIZE and MIN_PKT_SIZE now stand for variables that xsk_set_flow() sets, so the smallest packet grows with the headers to 64 bytes over IPv4 and 88 over IPv6, and a verbatim stream adds up the descriptors of a packet for its IP and UDP lengths.

The XDP programs redirect only the UDP packets to the test port and pass everything else to the stack, all IPv4 fragments included. The port is written when a skeleton is loaded, so it also reaches the shadow endpoint's copy, whose programs the local side attaches once BIDIRECTIONAL swaps the directions. XDP_SHARED_UMEM picks the socket by the UDP source port, the test port plus the socket index, rather than by a made-up destination MAC, and xsk_xdp_adjust_tail() numbers a grown tail after the UDP header.

test_xsk.py sends from 2001:db8::1 to 2001:db8::2 between the MAC addresses of the veth pair. The veths need not have the addresses, as the XDP program takes the packets before the stack, and IPv6 stays on.

is_adjust_tail_supported() copied all of .bss into an int with bpf_map_lookup_elem(), past the end of the int even before the port grew .bss; read adjust_value through the skeleton instead. is_frag_valid() now rejects a fragment too short for the words it reads, and pkt_dump() prints only the words within the length it is given, which is_pkt_valid() gives as the first fragment's length. write_payload() zeroes the bytes after the last full word, which the IPv6 UDP checksum counts.

---
 .../testing/selftests/net/lib/xsk/test_xsk.c  | 240 ++++++++++++++----
 .../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        |  48 +++-
 tools/testing/selftests/net/test_xsk.py       |  30 ++-
 8 files changed, 368 insertions(+), 78 deletions(-)
tools/testing/selftests/net/lib/xsk/test_xsk.c +188 -52
index ce88218fef00..9c401a43da43 100644
@@ -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");
@@ -792,31 +933,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,
@@ -836,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) {
@@ -877,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;
 	}
 
@@ -980,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;
@@ -1057,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)
@@ -1068,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;
 
@@ -1218,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;
@@ -1230,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);
@@ -1246,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",
@@ -1640,7 +1771,6 @@ static int testapp_prepare_rx_endpoint(struct test_spec *test,
 static int testapp_validate_rx_endpoint(struct test_spec *test,
 					struct ifobject *ifobject)
 {
-	bool supported;
 	int err;
 
 	err = receive_pkts(test);
@@ -1653,9 +1783,7 @@ static int testapp_validate_rx_endpoint(struct test_spec *test,
 	if (!test->adjust_tail)
 		return err;
 
-	if (is_adjust_tail_supported(ifobject->xdp_progs, &supported))
-		return TEST_FAILURE;
-	if (!supported) {
+	if (!is_adjust_tail_supported(ifobject->xdp_progs)) {
 		test->adjust_tail_support = false;
 		return TEST_PASS;
 	}
@@ -2293,6 +2421,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;
 }
 
@@ -2353,6 +2483,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);
 }
 
tools/testing/selftests/net/lib/xsk/test_xsk.h +6 -1
index f1fafae2d140..4690ae2ad9c6 100644
@@ -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 {
tools/testing/selftests/net/lib/xsk/xsk.c +26 -0
index 660540efc46e..54e6808e3fe4 100644
@@ -802,3 +802,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;
+}
tools/testing/selftests/net/lib/xsk/xsk.h +1 -0
index 94a56dd43f2e..263971a57e1e 100644
@@ -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" */
tools/testing/selftests/net/lib/xsk/xsk_xdp_common.h +2 -1
index 45810ff552da..47cbceea402d 100644
@@ -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;
tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c +80 -11

145 lines not on this page · raw message

tools/testing/selftests/net/lib/xsk/xskxceiver.c +45 -3

111 lines not on this page · raw message

tools/testing/selftests/net/test_xsk.py +20 -10
index 7f9d2c04f0e5..6ca54bafc03d 100755
@@ -21,7 +21,9 @@ Topology:
 Each case runs a TX and an RX xskxceiver process on a veth pair that the case
 creates in the current network namespace and deletes when it ends. The TX
 process listens (--listen) on a TCP control port on 127.0.0.1, and the RX
-process connects to it once TX says on stderr that it listens.
+process connects to it once TX says on stderr that it listens. The test
+packets are UDP over IPv6 between the MAC addresses of the veth pair, and the
+XDP programs pass other traffic to the stack.
 
 test_xsk runs every case that "xskxceiver -l" lists but EXCLUDED_CASES in SKB
 and DRV mode, and test_xsk_busy_poll runs them again with busy polling.
@@ -46,6 +48,9 @@ CASE_TIMEOUT = 20
 # xskxceiver waits as long for its peer to connect.
 LISTEN_TIMEOUT = 30
 SKIP_CODE = 4
+# Source addresses of the TX and RX endpoints, which the veths do not have.
+TX_ADDR = "2001:db8::1"
+RX_ADDR = "2001:db8::2"
 EXCLUDED_CASES = {
     # 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
@@ -53,9 +58,9 @@ EXCLUDED_CASES = {
     # page leaks from its pool.
     "XDP_ADJUST_TAIL_SHRINK_MULTI_BUFF",
     # The case skips in SKB mode. In DRV mode, veth copies each frame into a
-    # page_pool fragment that leaves no room to grow the 128-byte frames of
-    # the case unless it is the last one of its page, so the XDP program
-    # drops most frames.
+    # 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.
     "XDP_ADJUST_TAIL_GROW",
 }
 
@@ -85,10 +90,6 @@ def _veth_pair(busy_poll):
        f"peer name {veths[1]} numtxqueues 4 numrxqueues 4")
     defer(ip, f"link del {veths[0]}")
     for dev in veths:
-        # The XDP program redirects all traffic, keep IPv6 off the link.
-        ipv6 = Path("/proc/sys/net/ipv6/conf", dev, "disable_ipv6")
-        if ipv6.exists():
-            ipv6.write_text("1", encoding="utf-8")
         if busy_poll:
             xsk_setup_busy_poll(dev)
     for dev in veths:
@@ -96,6 +97,10 @@ def _veth_pair(busy_poll):
     return veths
 
 
+def _mac(dev):
+    return ip(f"link show dev {dev}", json=True)[0]["address"]
+
+
 def _start(args):
     return cmd([str(XSK_BIN), *args], background=True, fail=False)
 
@@ -107,15 +112,20 @@ def _test(mode, test_id, busy_poll):
             "-t", str(test_id),
             "-p", "127.0.0.1",
             "-P", str(port),
+            "--udp-port", str(rand_port()),
             *(["-b"] if busy_poll else [])]
-    tx = _start(["-i", tx_if, "-e", "tx", "--listen", *args])
+    tx = _start(["-i", tx_if, "-e", "tx", "--listen",
+                 "--src-ip", TX_ADDR, "--dst-ip", RX_ADDR,
+                 "--dst-mac", _mac(rx_if), *args])
     head = ""
     try:
         head, listening = xsk_wait_listen(tx, port, LISTEN_TIMEOUT)
         if not listening:
             tx.proc.kill()
             raise KsftFailEx(f"TX endpoint did not listen on port {port}")
-        rx = _start(["-i", rx_if, "-e", "rx", *args])
+        rx = _start(["-i", rx_if, "-e", "rx",
+                     "--src-ip", RX_ADDR, "--dst-ip", TX_ADDR,
+                     "--dst-mac", _mac(tx_if), *args])
         rx_ret = xsk_wait_endpoint_exit(rx, "rx", CASE_TIMEOUT)
     finally:
         tx_ret = xsk_wait_endpoint_exit(tx, "tx", CASE_TIMEOUT, head)
Signature · 1 line
2.43.0
#25 lore raw

Re: [PATCH v4 net-next 11/15] selftests: xsk: send UDP over IPv4 or IPv6 between the interface MACs

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] bpf: multi-line comment style violation --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] bpf: multi-line comment style violation
--

commit c93ec22f2ead9dd358b23391b62cb4c9037e31b7
Author: Maciej Fijalkowski <[email protected]>

selftests: xsk: send UDP over IPv4 or IPv6 between the interface MACs

xskxceiver sends frames of the loopback ethertype between made-up MAC addresses, and its XDP programs redirect every frame to the XSKMAP. That suits a veth pair that carries nothing else, but not a physical link, where the peer NIC filters out the made-up addresses and the programs take neighbour discovery, LLDP or SSH away from the stack.

Send the test packets as UDP between the MAC addresses of the two interfaces on any link. Each endpoint takes the IPv4 or IPv6 addresses of the flow (--src-ip, --dst-ip), the MAC address of its peer (--dst-mac) and the UDP port (--udp-port), and reads its own MAC address from the interface. Over IPv4 the UDP checksum is left at zero, as IPv4 allows; over IPv6 it is computed from the known payload. PKT_HDR_SIZE and MIN_PKT_SIZE now stand for variables that xsk_set_flow() sets, so the smallest packet grows with the headers to 64 bytes over IPv4 and 88 over IPv6, and a verbatim stream adds up the descriptors of a packet for its IP and UDP lengths.

Quoted 7 lines
tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c +0 -0
index 023d8befd4cab..2b55dbaf13b24 100644
@@ -15,12 +23,64 @@ struct {
 	__uint(value_size, sizeof(int));
 } xsk SEC(".maps");

tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c struct { · line 33

Quoted 10 lines
tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c +6 -1
 
-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.
+ */

[Severity: Low]
This is a minor coding style observation. The BPF subsystem prefers the opening of multi-line comments to be on its own line. Should this be formatted as follows?

/*
* 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. */

Quoted 9 lines
tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c +9 -0
+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;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
#26 lore raw

Re: [PATCH v4 net-next 11/15] selftests: xsk: send UDP over IPv4 or IPv6 between the interface MACs

In reply to Maciej Fijalkowski
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

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

Critical: 0 · High: 0 · Medium: 2 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The new XDP filter makes the INVALID_DESC tests less able to catch a kernel that transmits a descriptor it should reject.
- [Medium] (Baseline: not a defect, handled later in the series.) The
concern: on a multi-queue physical NIC, nothing steers the new UDP…
- [Low] This feature commit, which changes the wire format, the XDP programs and the CLI, also carries three fixes for bugs that predate…
- [Low] (Baseline: intentional design, the launchers validate.) The
concern: parse_command_line() stores strtoul(optarg, NULL, 10) in…

--

selftests: xsk: send UDP over IPv4 or IPv6 between the interface MACs

This patch changes the xskxceiver test traffic from loopback-ethertype frames between made-up MACs to UDP over IPv4 or IPv6 between the real interface MACs. The XDP programs now redirect only UDP to the test port and pass everything else to the stack. The patch also fixes several helpers in test_xsk.c that could overrun buffers.

Quoted 4 lines
tools/testing/selftests/net/lib/xsk/test_xsk.c +0 -0
index ce88218fef00b..9c401a43da435 100644

[ ... ]

tools/testing/selftests/net/lib/xsk/test_xsk.c static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, · line 371

Quoted 13 lines
tools/testing/selftests/net/lib/xsk/test_xsk.c +4 -4
@@ -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;
 		}

[Severity: Medium]
On a multi-queue physical NIC, what steers this flow to the queue the AF_XDP socket is bound to?

If RSS hashes L4 ports, the flow could land on another queue, and xsk_rcv_check() would reject the redirect there. With XDP_SHARED_UMEM, socket 1 sends from udp_port + 1. Its flow could therefore hash to a different queue even when socket 0's flow lands on the right one.

At this patch the only in-tree runner is veth, so nothing breaks yet. Two later patches in the series cover this:

"selftests: drv-net: test AF_XDP zero-copy with an SKB peer" adds drivers/net/hw/xsk.py. Its _reserve_queue() takes the bound queue out of RSS with "ethtool -X <if> equal <queue>". Its _steer_udp() installs a dst-port ntuple rule, which matches both sockets' flows.

"selftests: xsk: document generic and hardware endpoint runs" documents the ntuple and RSS requirement in README.rst.

This commit message is aimed at physical links. Should it, or the header comment in xskxceiver.c, mention the steering requirement too?

[ ... ]

Quoted 22 lines
tools/testing/selftests/net/lib/xsk/test_xsk.c +1 -16
@@ -792,31 +933,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;

tools/testing/selftests/net/lib/xsk/test_xsk.c static bool is_metadata_correct(struct pkt *pkt, void *buffer, u64 addr) · line 942

Quoted 10 lines
tools/testing/selftests/net/lib/xsk/test_xsk.c +1 -5
-	}
-
 	/* 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;
 }

[Severity: Low]
This isn't a bug, but this feature patch also carries three fixes for bugs that existed before the series:

1) is_adjust_tail_supported() used bpf_map_lookup_elem() to copy the whole xsk_xdp_.bss map into one stack int. At the baseline, .bss held idx, adjust_value, count and drop_idx, 16 bytes in all. That overwrote 12 bytes of stack past adjust_value, and the int got the first word of .bss, which is not necessarily adjust_value.

2) is_frag_valid() did len -= PKT_HDR_SIZE on a first fragment shorter than the header. len wrapped, and the later reads went out of bounds.

3) is_pkt_valid() passed the total packet length to pkt_dump(). On a multi-buffer packet, pkt_dump() read past the end of the first fragment.

The commit message describes all three. But because they ship with the wire format, XDP program and CLI changes, they can't be backported or reverted on their own. Older trees still have the original code in tools/testing/selftests/bpf/prog_tests/test_xsk.c.

Could these go into a separate patch at the start of the series, with
Fixes: tags?

[ ... ]

Quoted 4 lines
tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c +0 -0
index 023d8befd4cab..2b55dbaf13b24 100644

[ ... ]

Quoted 1 line
tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c +0 -0
@@ -15,12 +23,64 @@ struct {

[ ... ]

Quoted 9 lines
tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c +9 -0
+	} 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;
+}

[ ... ]

tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c struct { · line 85

Quoted 6 lines

SEC("xdp.frags") int xsk_def_prog(struct xdp_md *xdp) {

tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c +2 -0
+	if (!is_test_packet(xdp))
+		return XDP_PASS;
 	return bpf_redirect_map(&xsk, 0, XDP_DROP);
 }

[Severity: Medium]
Could this filter hide a kernel that wrongly transmits a descriptor that the INVALID_DESC cases expect it to reject?

Before this patch, xsk_def_prog() redirected every frame to the XSKMAP. An unexpected frame on RX then failed is_frag_valid() on the pkt_nb or seqnum check. Now any frame that test_udp_hdr() does not see as UDP to test_port gets XDP_PASS and never reaches __receive_pkts().

__send_pkts() writes a header only for valid entries:

    if (pkt->valid)
        pkt_generate(xsk, umem, tx_desc->addr, tx_desc->len, total_len,
                     pkt->pkt_nb, bytes_written);

pkt_get_addr() also gives invalid entries their raw pkt->offset. So the bytes behind a negative descriptor are usually not a test header. For example, this entry in testapp_invalid_desc():

    /* Straddle a 4K boundary */
    {0x1000 - MIN_PKT_SIZE / 2, MIN_PKT_SIZE, 0, false},

starts in the zero-filled tail of UMEM frame 0, so h_proto is 0.

The "Straddle the end of umem" entry starts inside the payload of the packet at umem_sz - MIN_PKT_SIZE. The invalid-options and chunk-crossing entries in testapp_invalid_desc_mb() look the same, for example:

    {0, XSK_UMEM__LARGE_FRAME_SIZE, 0, false, XSK_DESC__INVALID_OPTION},

If the kernel transmitted any of these, the RX program would pass them to the stack, and the case would still pass.

The TX side would not catch it either. __send_pkts() adds every frag to outstanding_tx (valid_frags += nb_frags), and these cases don't check the tx_invalid_descs statistic.

Could these cases check tx_invalid_descs? Alternatively, could the RX program redirect or count non-test frames while they run?

[ ... ]

Quoted 4 lines
tools/testing/selftests/net/lib/xsk/xskxceiver.c +0 -0
index fbfff586e0e5e..9704702f60fc9 100644

[ ... ]

Quoted 1 line
tools/testing/selftests/net/lib/xsk/xskxceiver.c +0 -0
@@ -293,6 +314,20 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj

[ ... ]

tools/testing/selftests/net/lib/xsk/xskxceiver.c static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj · line 330

Quoted 3 lines
tools/testing/selftests/net/lib/xsk/xskxceiver.c +3 -0
+		case OPT_UDP_PORT:
+			opt_udp_port = strtoul(optarg, NULL, 10);
+			break;

[Severity: Low]
Should this check errno, the end pointer and the range? The strtoul() result goes straight into a u16, so:

    65536 becomes 0, which is rejected
    70000 becomes 4464
    "-1" becomes 65535
    "123junk" becomes 123

Only values that truncate to 0 are rejected, here by !opt_udp_port and in xsk_set_flow().

With --udp-port 65535, socket 1's source port in __test_spec_init() wraps to 0:

    xsk->src_port = udp_port + j;

Both endpoints truncate the same way, so the flow stays consistent. xsk_xdp_shared_umem() still gets idx 1 for source port 0 through the __u16 wrap-around.

Later commit messages in the series say the launchers own the range checks. drivers/net/hw/xsk.py calls _check_opt("--udp-port", cfg.udp_port, 1, 0xffff), and test_xsk.py takes the port from rand_port(). Within xskxceiver, only --max-frags is range-checked, since it sizes an array. A hand-run xskxceiver could still quietly use a different port than the one requested.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261016174338.787135-1-maciej.fijalkowski%40intel.com
author maintainer
#27 lore raw

Re: [PATCH v4 net-next 11/15] selftests: xsk: send UDP over IPv4 or IPv6 between the interface MACs

Quoted 5 lines · On Tue, Oct 20, 2026 at 07:30:27PM +0000, [email protected] wrote:

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

Critical: 0 · High: 0 · Medium: 2 · Low: 2

Quoted 8 lines

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The new XDP filter makes the INVALID_DESC tests less able to catch a kernel that transmits a descriptor it should reject.

I took a look at reports on v4 and besides one above nothing major stood out that would need a fix, imo.

This one *could* be a follow-up as a hardening of invalid descs handling. Indeed it would be worth generating udp header on invalid descs so if such descriptor make it to rx side it should be redirected to rx socket and test should catch that desc and fail the test case.

Let me know if this set still could be considered to be taken in or I should send rebased v5 once net-next opens.

Thanks,
MF

Quoted 239 lines

- [Medium] (Baseline: not a defect, handled later in the series.) The
concern: on a multi-queue physical NIC, nothing steers the new UDP…
- [Low] This feature commit, which changes the wire format, the XDP programs and the CLI, also carries three fixes for bugs that predate…
- [Low] (Baseline: intentional design, the launchers validate.) The
concern: parse_command_line() stores strtoul(optarg, NULL, 10) in…

--

selftests: xsk: send UDP over IPv4 or IPv6 between the interface MACs

This patch changes the xskxceiver test traffic from loopback-ethertype frames between made-up MACs to UDP over IPv4 or IPv6 between the real interface MACs. The XDP programs now redirect only UDP to the test port and pass everything else to the stack. The patch also fixes several helpers in test_xsk.c that could overrun buffers.

Quoted 4 lines
tools/testing/selftests/net/lib/xsk/test_xsk.c +0 -0
index ce88218fef00b..9c401a43da435 100644

[ ... ]

tools/testing/selftests/net/lib/xsk/test_xsk.c static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, · line 371

Quoted 13 lines
tools/testing/selftests/net/lib/xsk/test_xsk.c +4 -4
@@ -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;
 		}

[Severity: Medium]
On a multi-queue physical NIC, what steers this flow to the queue the AF_XDP socket is bound to?

If RSS hashes L4 ports, the flow could land on another queue, and xsk_rcv_check() would reject the redirect there. With XDP_SHARED_UMEM, socket 1 sends from udp_port + 1. Its flow could therefore hash to a different queue even when socket 0's flow lands on the right one.

At this patch the only in-tree runner is veth, so nothing breaks yet. Two later patches in the series cover this:

"selftests: drv-net: test AF_XDP zero-copy with an SKB peer" adds drivers/net/hw/xsk.py. Its _reserve_queue() takes the bound queue out of RSS with "ethtool -X <if> equal <queue>". Its _steer_udp() installs a dst-port ntuple rule, which matches both sockets' flows.

"selftests: xsk: document generic and hardware endpoint runs" documents the ntuple and RSS requirement in README.rst.

This commit message is aimed at physical links. Should it, or the header comment in xskxceiver.c, mention the steering requirement too?

[ ... ]

Quoted 22 lines
tools/testing/selftests/net/lib/xsk/test_xsk.c +1 -16
@@ -792,31 +933,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;

tools/testing/selftests/net/lib/xsk/test_xsk.c static bool is_metadata_correct(struct pkt *pkt, void *buffer, u64 addr) · line 942

Quoted 10 lines
tools/testing/selftests/net/lib/xsk/test_xsk.c +1 -5
-	}
-
 	/* 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;
 }

[Severity: Low]
This isn't a bug, but this feature patch also carries three fixes for bugs that existed before the series:

1) is_adjust_tail_supported() used bpf_map_lookup_elem() to copy the whole xsk_xdp_.bss map into one stack int. At the baseline, .bss held idx, adjust_value, count and drop_idx, 16 bytes in all. That overwrote 12 bytes of stack past adjust_value, and the int got the first word of .bss, which is not necessarily adjust_value.

2) is_frag_valid() did len -= PKT_HDR_SIZE on a first fragment shorter than the header. len wrapped, and the later reads went out of bounds.

3) is_pkt_valid() passed the total packet length to pkt_dump(). On a multi-buffer packet, pkt_dump() read past the end of the first fragment.

The commit message describes all three. But because they ship with the wire format, XDP program and CLI changes, they can't be backported or reverted on their own. Older trees still have the original code in tools/testing/selftests/bpf/prog_tests/test_xsk.c.

Could these go into a separate patch at the start of the series, with
Fixes: tags?

[ ... ]

Quoted 4 lines
tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c +0 -0
index 023d8befd4cab..2b55dbaf13b24 100644

[ ... ]

Quoted 1 line
tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c +0 -0
@@ -15,12 +23,64 @@ struct {

[ ... ]

Quoted 9 lines
tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c +9 -0
+	} 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;
+}

[ ... ]

tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c struct { · line 85

Quoted 6 lines

SEC("xdp.frags") int xsk_def_prog(struct xdp_md *xdp) {

tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c +2 -0
+	if (!is_test_packet(xdp))
+		return XDP_PASS;
 	return bpf_redirect_map(&xsk, 0, XDP_DROP);
 }

[Severity: Medium]
Could this filter hide a kernel that wrongly transmits a descriptor that the INVALID_DESC cases expect it to reject?

Before this patch, xsk_def_prog() redirected every frame to the XSKMAP. An unexpected frame on RX then failed is_frag_valid() on the pkt_nb or seqnum check. Now any frame that test_udp_hdr() does not see as UDP to test_port gets XDP_PASS and never reaches __receive_pkts().

__send_pkts() writes a header only for valid entries:

    if (pkt->valid)
        pkt_generate(xsk, umem, tx_desc->addr, tx_desc->len, total_len,
                     pkt->pkt_nb, bytes_written);

pkt_get_addr() also gives invalid entries their raw pkt->offset. So the bytes behind a negative descriptor are usually not a test header. For example, this entry in testapp_invalid_desc():

    /* Straddle a 4K boundary */
    {0x1000 - MIN_PKT_SIZE / 2, MIN_PKT_SIZE, 0, false},

starts in the zero-filled tail of UMEM frame 0, so h_proto is 0.

The "Straddle the end of umem" entry starts inside the payload of the packet at umem_sz - MIN_PKT_SIZE. The invalid-options and chunk-crossing entries in testapp_invalid_desc_mb() look the same, for example:

    {0, XSK_UMEM__LARGE_FRAME_SIZE, 0, false, XSK_DESC__INVALID_OPTION},

If the kernel transmitted any of these, the RX program would pass them to the stack, and the case would still pass.

The TX side would not catch it either. __send_pkts() adds every frag to outstanding_tx (valid_frags += nb_frags), and these cases don't check the tx_invalid_descs statistic.

Could these cases check tx_invalid_descs? Alternatively, could the RX program redirect or count non-test frames while they run?

[ ... ]

Quoted 4 lines
tools/testing/selftests/net/lib/xsk/xskxceiver.c +0 -0
index fbfff586e0e5e..9704702f60fc9 100644

[ ... ]

Quoted 1 line
tools/testing/selftests/net/lib/xsk/xskxceiver.c +0 -0
@@ -293,6 +314,20 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj

[ ... ]

tools/testing/selftests/net/lib/xsk/xskxceiver.c static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj · line 330

Quoted 3 lines
tools/testing/selftests/net/lib/xsk/xskxceiver.c +3 -0
+		case OPT_UDP_PORT:
+			opt_udp_port = strtoul(optarg, NULL, 10);
+			break;

[Severity: Low]
Should this check errno, the end pointer and the range? The strtoul() result goes straight into a u16, so:

    65536 becomes 0, which is rejected
    70000 becomes 4464
    "-1" becomes 65535
    "123junk" becomes 123

Only values that truncate to 0 are rejected, here by !opt_udp_port and in xsk_set_flow().

With --udp-port 65535, socket 1's source port in __test_spec_init() wraps to 0:

    xsk->src_port = udp_port + j;

Both endpoints truncate the same way, so the flow stays consistent. xsk_xdp_shared_umem() still gets idx 1 for source port 0 through the __u16 wrap-around.

Later commit messages in the series say the launchers own the range checks. drivers/net/hw/xsk.py calls _check_opt("--udp-port", cfg.udp_port, 1, 0xffff), and test_xsk.py takes the port from rand_port(). Within xskxceiver, only --max-frags is range-checked, since it sizes an array. A hand-run xskxceiver could still quietly use a different port than the one requested.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261016174338.787135-1-maciej.fijalkowski%40intel.com
author maintainer
#28 lore raw

PATCH v4 12/15 selftests: xsk: prepare xskxceiver for endpoints on two hosts

In reply to Maciej Fijalkowski

drivers/net/hw/xsk.py, added later in this series, runs each hardware AF_XDP case with a zero-copy endpoint on the device under test and an SKB-mode endpoint on a remote host, without negotiating capabilities between them. Add what such a pair needs:

- --queue binds a queue other than 0
- --max-frags, up to 0xffff as it sizes a packet array, hands both endpoints the DUT limit for TOO_MANY_FRAGS, as each one builds the packet stream from its own view of it
- --timeout sets the RX and TX loop timeout, 3s by default, and once both endpoints are ready, each waits up to as long while its link is down, as an MTU or XDP program change on either host can reset a NIC
- an endpoint probes only the mode it runs in, taking zero-copy support from NETDEV_XDP_ACT_XSK_ZEROCOPY rather than from a probe bind; its XDP_ZEROCOPY bind fails rather than falling back to copy mode, so a false advertisement still fails the case
- an endpoint that only transmits attaches the XDP program only in zero-copy mode, where a driver can require one for TX wakeups
- an RX endpoint fills its fill ring before the bind, as a zero-copy driver posts its RX buffers then and would otherwise wait for the first wakeup, which comes only after READY lets the peer send
- an endpoint that skips a case sends SKIP on the control channel, so that its peer skips too rather than failing on the closed connection; this is how a TX endpoint learns that both XDP_ADJUST_TAIL_GROW cases skip on an SKB-mode RX endpoint. It then reads until the peer closes, for up to the timeout, as closing with unread data resets the connection, which drops a SKIP that the peer has yet to acknowledge

Cases now default to an MTU of 1500 (ETH_DATA_LEN) rather than the 1518 byte frame size: IFLA_MTU counts the L3 MTU, so the old default changed a standard MTU, which can reset a NIC, for every case. An SKB-mode endpoint raises its MTU only when a case needs a larger one, so a jumbo-MTU peer is not reset twice per case. cleanup_iface() restores the MTU that bind_iface() found once the XDP program, which can cap it, is detached, and fails the endpoint if it cannot, so the result is reported after cleanup_iface().

---
 .../testing/selftests/net/lib/xsk/test_xsk.c  | 143 ++++++++++++++----
 .../testing/selftests/net/lib/xsk/test_xsk.h  |   7 +
 tools/testing/selftests/net/lib/xsk/xsk.c     |  34 +++++
 tools/testing/selftests/net/lib/xsk/xsk.h     |   2 +
 .../testing/selftests/net/lib/xsk/xsk_peer.c  |  46 ++++++
 .../testing/selftests/net/lib/xsk/xsk_peer.h  |   2 +
 .../selftests/net/lib/xsk/xskxceiver.c        | 117 +++++++-------
 7 files changed, 271 insertions(+), 80 deletions(-)
tools/testing/selftests/net/lib/xsk/test_xsk.c +115 -28
index 9c401a43da43..16669f7e0c9f 100644
@@ -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);
@@ -1905,6 +1969,10 @@ static int xsk_attach_xdp_progs(struct test_spec *test, struct ifobject *ifobj_r
 	if (!ifobj_tx || !ifobj_is_local(ifobj_tx))
 		return 0;
 
+	/* A ZC driver can require XDP to be enabled for TX wakeups. */
+	if (!ifobj_tx->rx_on && test->mode != TEST_MODE_ZC)
+		return 0;
+
 	if (xdp_prog_changed_tx(test))
 		err = xsk_reattach_xdp(ifobj_tx, test->xdp_prog_tx, test->xskmap_tx, test->mode);
 
@@ -1986,6 +2054,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;
 }
 
@@ -2012,11 +2082,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);
 	}
 
@@ -2042,8 +2113,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);
@@ -2076,10 +2148,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);
@@ -2361,7 +2436,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);
@@ -2457,6 +2534,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;
@@ -2700,9 +2778,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 */
@@ -2713,7 +2800,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
tools/testing/selftests/net/lib/xsk/test_xsk.h +7 -0
index 4690ae2ad9c6..15534f4ec8f4 100644
@@ -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;
tools/testing/selftests/net/lib/xsk/xsk.c +34 -0
index 54e6808e3fe4..6249a4955b64 100644
@@ -828,3 +828,37 @@ 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.
+ */
+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)
+			return 0;
+		if (err || edata.data)
+			return err;
+		if (timeout_ms <= 0)
+			return -ETIMEDOUT;
+		usleep(100 * 1000);
+		timeout_ms -= 100;
+	}
+}
tools/testing/selftests/net/lib/xsk/xsk.h +2 -0
index 263971a57e1e..181c706cb418 100644
@@ -245,6 +245,8 @@ 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]);
+int xsk_get_mtu(const char *ifname, int *mtu);
+int xsk_wait_link_up(const char *ifname, int timeout_ms);
 
 #ifdef __cplusplus
 } /* extern "C" */
tools/testing/selftests/net/lib/xsk/xsk_peer.c +46 -0

82 lines not on this page · raw message

tools/testing/selftests/net/lib/xsk/xsk_peer.h +2 -0
index da4462192994..26ae6b1bb384 100644
@@ -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_ */
tools/testing/selftests/net/lib/xsk/xskxceiver.c +65 -52

220 lines not on this page · raw message

Signature · 1 line
2.43.0
#29 lore raw

Re: [PATCH v4 net-next 12/15] selftests: xsk: prepare xskxceiver for endpoints on two hosts

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] parse_command_line() does not fully validate the new numeric options.
- [Low] In the adjust-tail cases, RX can decide to skip only after the traffic has run: testapp_validate_rx_endpoint() clears…

--

selftests: xsk: prepare xskxceiver for endpoints on two hosts

This prepares xskxceiver to run a case with its two endpoints on two hosts. It adds --queue, --max-frags and --timeout options, a SKIP message on the control channel, and a wait for the link to come up once the endpoints are in sync. It also changes the default case MTU to ETH_DATA_LEN and restores the original MTU in cleanup_iface().

Quoted 4 lines
tools/testing/selftests/net/lib/xsk/xsk_peer.c +0 -0
index e3e353d6abd95..256e63196f923 100644

[ ... ]

tools/testing/selftests/net/lib/xsk/xsk_peer.c void xsk_peer_abort(struct xsk_peer *peer) · line 188

Quoted 11 lines
tools/testing/selftests/net/lib/xsk/xsk_peer.c +7 -0
@@ -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)

[Severity: Low]
Is "so that it skips too" accurate for the adjust-tail cases?

In those cases the RX endpoint decides to skip only after the traffic has run. testapp_validate_rx_endpoint() clears the support flag:

    if (!is_adjust_tail_supported(ifobject->xdp_progs)) {
        test->adjust_tail_support = false;
        return TEST_PASS;
    }

and then testapp_adjust_tail() returns TEST_SKIP:

    if (!test->adjust_tail_support) {
        ...
        return TEST_SKIP;
    }

By that point the TX endpoint has usually finished with TEST_PASS. It never sees the SKIP, so it does not skip.

The final verdict still comes out right, because xsk.py later in the series reports a pass plus a skip as a skipped case. Could the comment say that the peer either skips or passes?

[ ... ]

Quoted 4 lines
tools/testing/selftests/net/lib/xsk/xskxceiver.c +0 -0
index 9704702f60fc9..56ea5ac6a3c63 100644

[ ... ]

Quoted 6 lines
tools/testing/selftests/net/lib/xsk/xskxceiver.c +2 -0
@@ -328,6 +302,18 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
 		case OPT_UDP_PORT:
 			opt_udp_port = strtoul(optarg, NULL, 10);
 			break;
+		case OPT_QUEUE:
+			opt_queue = strtoul(optarg, NULL, 10);

tools/testing/selftests/net/lib/xsk/xskxceiver.c static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj · line 316

Quoted 10 lines
tools/testing/selftests/net/lib/xsk/xskxceiver.c +10 -0
+			break;
+		case OPT_MAX_FRAGS:
+			/* It sizes the packet array of TOO_MANY_FRAGS. */
+			opt_max_frags = strtoul(optarg, NULL, 10);
+			if (opt_max_frags > 0xffff)
+				print_usage(argv);
+			break;
+		case OPT_TIMEOUT:
+			opt_timeout = strtoul(optarg, NULL, 10);
+			break;

[Severity: Low]
Should --timeout and --max-frags get a full range check here?

strtoul() returns an unsigned long, and the result is truncated to u32 before the > 0xffff check. A --max-frags value of 2^32 or more can therefore pass the check.

--timeout accepts any u32, including 0. Later the value is multiplied by 1000 in u32 and passed on as an int:

    wait_link_up()
        err = xsk_wait_link_up(ifobj->ifname, thread_tmout * 1000);

    main()
        xsk_peer_skip(peer, opt_timeout * 1000);

A timeout of 2147484 seconds or more, or a negative string (which strtoul() wraps), gives a negative timeout_ms. With a negative timeout_ms, the poll() in xsk_peer_skip() blocks with no limit.

In this series, xsk.py checks --max-frags and --timeout against 1-0xffff before passing them on. So this only happens when xskxceiver is run by hand.

Could xskxceiver reject these out-of-range values itself, as it already does for the --max-frags upper bound?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261016174338.787135-1-maciej.fijalkowski%40intel.com
author maintainer
#30 lore raw

PATCH v4 13/15 selftests: xsk: list the hardware test cases

In reply to Maciej Fijalkowski

The hardware test that the next patch adds runs each case with its zero-copy endpoint as RX, as TX or as both. A list of the cases by ID in that runner would repeat the test table and silently go stale when a case is added or moved.

Split tests[] into the tests that check both endpoint roles, those that check the RX endpoint, those that check the TX endpoint, and the generic ones, which a hardware run does not do: BIDIRECTIONAL swaps the directions, and STAT_RX_DROPPED and TX_QUEUE_CONSUMER skip in zero-copy mode. The test IDs follow the order of these arrays, so they change, and the runners take them from xskxceiver. The notes that came with ci_skip_tests[] go.

-L lists each hardware test once per role that it tests, as "ID: NAME rx" or "ID: NAME tx", while -l still lists every test by ID.

---
 .../testing/selftests/net/lib/xsk/test_xsk.h  | 68 +++++++++++++------
 .../selftests/net/lib/xsk/xskxceiver.c        | 47 ++++++++++---
 2 files changed, 84 insertions(+), 31 deletions(-)
tools/testing/selftests/net/lib/xsk/test_xsk.h +46 -22
index 15534f4ec8f4..a59b34b156d7 100644
@@ -304,49 +304,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. A hardware run, see
+ * xskxceiver -L, gives that role to its zero-copy endpoint. It does not do
+ * the generic tests: BIDIRECTIONAL swaps the directions, which
+ * drivers/net/hw/xsk.py sets up 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},
 };
 
 
tools/testing/selftests/net/lib/xsk/xskxceiver.c +38 -9

99 lines not on this page · raw message

Signature · 1 line
2.43.0
#31 lore raw

Re: [PATCH v4 net-next 13/15] selftests: xsk: list the hardware test cases

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The new comment above the test tables in tools/testing/selftests/net/lib/xsk/test_xsk.h (lines 307-312) names…

--

selftests: xsk: list the hardware test cases

This splits tests[] in test_xsk.h into hw_rx_tx_tests[], hw_rx_tests[], hw_tx_tests[] and generic_tests[], grouped in test_groups[], and test IDs now follow the order of those arrays. It also adds a -L option to xskxceiver, which lists each hardware test once per role it covers.

Quoted 5 lines
tools/testing/selftests/net/lib/xsk/test_xsk.h +0 -0
index 15534f4ec8f4b..a59b34b156d79 100644

tools/testing/selftests/net/lib/xsk/test_xsk.h int testapp_xdp_shared_umem(struct test_spec *test); · line 312

Quoted 10 lines
tools/testing/selftests/net/lib/xsk/test_xsk.h +6 -1
@@ -304,49 +304,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. A hardware run, see
+ * xskxceiver -L, gives that role to its zero-copy endpoint. It does not do
+ * the generic tests: BIDIRECTIONAL swaps the directions, which
+ * drivers/net/hw/xsk.py sets up one at a time, and the others skip in
+ * zero-copy mode.
+ */

[Severity: Low]
This isn't a bug, but the comment above hw_rx_tx_tests[] points to drivers/net/hw/xsk.py, and that file is not in the tree at this commit.

The only xsk script under tools/testing/selftests/drivers/net/hw/ here is xsk_reconfig.py. Nothing reads the hw_rx/hw_tx fields of struct test_group or the -L output yet. The in-tree runner, net/test_xsk.py, still uses -l.

The next patch in the series, "selftests: drv-net: test AF_XDP zero-copy with an SKB peer", adds drivers/net/hw/xsk.py. Its _get_cases() runs xskxceiver -L and parses the "ID: NAME rx|tx" lines. So the reference is correct once the whole series is applied.

Could the comment be added in the patch that adds xsk.py instead, so it is accurate at every point in the series?

Quoted 4 lines
tools/testing/selftests/net/lib/xsk/test_xsk.h +1 -0
+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},

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261016174338.787135-1-maciej.fijalkowski%40intel.com
author maintainer
#32 lore raw

PATCH v4 14/15 selftests: drv-net: test AF_XDP zero-copy with an SKB peer

In reply to Maciej Fijalkowski

Run the AF_XDP cases that a physical link can carry as pairs of xskxceiver processes: a zero-copy endpoint on the DUT and an SKB-mode endpoint on the remote, which needs no zero-copy support. xsk.py runs the cases that xskxceiver -L lists, in the DUT directions listed with them, as KTAP variants named <rx|tx>_<CASE>. test_xsk runs them with the DUT socket driven by interrupts and test_xsk_busy_poll with it busy polling, after xsk_setup_busy_poll() sets napi_defer_hard_irqs and gro_flush_timeout on the DUT so that SO_PREFER_BUSY_POLL keeps its IRQs masked, as on veth.

The endpoints send UDP over IPv6 if LOCAL_V6 and REMOTE_V6 are set, and over IPv4 otherwise, each to the MAC address of its next hop to the
other: the peer's if the peer's address is on link, else the gateway's.

main() sets up what the cases share once, as defer() works only within a case, and an ExitStack undoes it however the run ends, -l and -h included, with each step registered as soon as it is done:

- the DUT endpoint binds the last queue with both an RX and a TX ring, which is taken out of RSS with ethtool -X equal; a TX endpoint fills no RX buffers, so in zero-copy mode its queue drops what it receives and TX cases need the queue out of RSS as much as RX cases do. A DUT with fewer than two such queues, or that cannot take one out of RSS, skips. ethtool -X default then hands the indirection table back to the driver, and the saved table is written back if it was not the default
- an ntuple rule on each host steers the test UDP flow to the receiving
endpoint: the DUT queue in RX cases and queue 0 of the remote, where its endpoint binds, in TX cases. A host without ntuple support, or that rejects the rule, skips. Setting the rules once spares each TX case the ssh round trips of a remote rule and toggles ntuple-filters, which resets some NICs, once per run rather than per case
- huge pages are reserved on both hosts or on neither, and the UNALIGNED cases are left out without them
- both endpoints get the DUT's xdp-zc-max-segs for TOO_MANY_FRAGS, which is left out without multi-buffer zero-copy

A DUT that does not advertise AF_XDP zero-copy skips the run.

The remote endpoint listens on the remote address, and the DUT endpoint connects once the remote says on stderr that it listens. The control connection shares the tested link, where the XDP programs pass it to the stack. Killing an ssh client does not stop the command it runs, so timeout(1) bounds the remote endpoint, and the runner waits for it to exit before the case ends. xskxceiver takes its numeric options as given, so the runner checks their values before it puts them on the command lines. The endpoints are waited for with the test_xsk.py helpers, so the output of one that does not pass is logged, timeouts included, and the DUT endpoint is killed if the wait for it is interrupted. They get a traffic and link timeout of 20s, as a NIC can take seconds to bring its link back after an MTU or XDP change.

The endpoints detach their XDP programs and restore the MTU when they exit; the runner detaches the programs and restores the MTU only after one fails or is killed. An endpoint that skips a case tells its peer, which skips it too, and the case is reported as skipped unless an endpoint fails.

The runner sizes the rings for HW_SW_MIN_RING_SIZE, a TX ring of 64 descriptors on the sender, and for HW_SW_MAX_RING_SIZE, the largest TX ring on the sender and RX ring on the receiver, with ethtool -G, and restores them after the case however the endpoints end. It retries while the driver returns EBUSY, as ice does until the buffer pool of a closed XSK socket is released, which happens in a work item. A case skips when ethtool cannot read the rings that it sizes.

xsk.py runs the xskxceiver that net/lib builds, which drv-net already installs, and copies it to the remote with cfg.remote.deploy(). Add xsk.py to TEST_PROGS and to the AF_XDP entry in MAINTAINERS, CONFIG_XDP_SOCKETS to the drivers/net/hw config, and the xskxceiver helpers to the drivers/net/hw library exports.

---
 MAINTAINERS                                   |   1 +
 .../testing/selftests/drivers/net/hw/Makefile |   1 +
 tools/testing/selftests/drivers/net/hw/config |   1 +
 .../drivers/net/hw/lib/py/__init__.py         |   5 +
 tools/testing/selftests/drivers/net/hw/xsk.py | 368 ++++++++++++++++++
 tools/testing/selftests/net/lib/Makefile      |   2 +-
 .../selftests/net/lib/xsk/xskxceiver.c        |   3 +
 7 files changed, 380 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/drivers/net/hw/xsk.py
MAINTAINERS +1 -0
index 6985a42bc09c..69c158d42877 100644
@@ -29783,6 +29783,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/hw/xsk.py
 F:	tools/testing/selftests/net/*xsk*
 F:	tools/testing/selftests/net/lib/py/xsk.py
 F:	tools/testing/selftests/net/lib/xsk/
tools/testing/selftests/drivers/net/hw/Makefile +1 -0
index 18ce235a77f8..02e48e74f6c6 100644
@@ -52,6 +52,7 @@ TEST_PROGS = \
 	uso.py \
 	vlan.py \
 	xdp_metadata.py \
+	xsk.py \
 	xsk_reconfig.py \
 	#
 
tools/testing/selftests/drivers/net/hw/config +1 -0
index c6c2b64bb712..f28335170d6b 100644
@@ -26,4 +26,5 @@ CONFIG_UDMABUF=y
 CONFIG_USER_NS=y
 CONFIG_VLAN_8021Q=m
 CONFIG_VXLAN=y
+CONFIG_XDP_SOCKETS=y
 CONFIG_XFRM_USER=y
tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +5 -0
index 4077f5f1a1be..aee6cdb4575b 100644
@@ -26,6 +26,8 @@ try:
         fd_read_timeout, ip, rand_port, rand_ports, wait_port_listen, \
         wait_file, ctl_file_write, tool
     from net.lib.py import bpf_map_set, bpf_map_dump, bpf_prog_map_ids
+    from net.lib.py import xsk_reserve_hugepages, xsk_release_hugepages, \
+        xsk_setup_busy_poll, xsk_wait_endpoint_exit, xsk_wait_listen
     from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx
     from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \
         ksft_setup, ksft_variants, KsftNamedVariant
@@ -43,6 +45,9 @@ try:
                "fd_read_timeout", "ip", "rand_port", "rand_ports",
                "wait_port_listen", "wait_file", "ctl_file_write", "tool",
                "bpf_map_set", "bpf_map_dump", "bpf_prog_map_ids",
+               "xsk_reserve_hugepages", "xsk_release_hugepages",
+               "xsk_setup_busy_poll", "xsk_wait_endpoint_exit",
+               "xsk_wait_listen",
                "KsftSkipEx", "KsftFailEx", "KsftXfailEx",
                "ksft_disruptive", "ksft_exit", "ksft_pr", "ksft_run",
                "ksft_setup", "ksft_variants", "KsftNamedVariant",
tools/testing/selftests/drivers/net/hw/xsk.py new file +368 -0

368 lines not on this page · raw message

tools/testing/selftests/net/lib/Makefile +1 -1
index 49dac776202b..c2524cacffd3 100644
@@ -34,7 +34,7 @@ include ../../lib.mk
 
 include ../bpf.mk
 
-# AF_XDP test engine used by net/test_xsk.py.
+# AF_XDP test engine shared by net/test_xsk.py and drivers/net/hw/xsk.py.
 XSK_DIR := xsk
 XSK_BPF_OBJ := $(OUTPUT)/xsk_xdp_progs.bpf.o
 XSK_SKEL := $(OUTPUT)/xsk_xdp_progs.skel.h
tools/testing/selftests/net/lib/xsk/xskxceiver.c +3 -0
index c52e3e376bc5..a4a66c9ebde2 100644
@@ -55,6 +55,9 @@
  *    l. If multi-buffer is supported, try various nasty combinations of descriptors to
  *       check if they pass the validation or not
  *
+ * drivers/net/hw/xsk.py runs the hardware cases on a physical device in
+ * zero-copy mode, with an SKB-mode peer on a remote host.
+ *
  * Flow:
  * -----
  * - test_xsk.py starts two processes: Tx and Rx
Signature · 1 line
2.43.0
#33 lore raw

Re: [PATCH v4 net-next 14/15] selftests: drv-net: test AF_XDP zero-copy with an SKB peer

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

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

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

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] On ixgbe, the queue that main() takes out of RSS goes back into RSS before or during every case.
- [Low] Two ring-size cases check the wrong host's capabilities.
- [Low] The runner drops its XDP-detach fallback on the strength of an exit code that does not cover detach failures.

--

selftests: drv-net: test AF_XDP zero-copy with an SKB peer

This adds drivers/net/hw/xsk.py. It runs the xskxceiver cases as pairs of
endpoints: zero-copy on the DUT and SKB mode on the remote host. Once per run, main() takes the last DUT queue out of RSS, adds ntuple rules on both hosts and reserves huge pages. Each case sizes the rings for the HW_SW ring size cases and registers XDP and MTU fallbacks, which are cancelled when both endpoints pass or skip.

Quoted 6 lines
tools/testing/selftests/drivers/net/hw/xsk.py new file +0 -0
new file mode 100755
index 0000000000000..dbcd687fea3d8
@@ -0,0 +1,368 @@

[ ... ]

tools/testing/selftests/drivers/net/hw/xsk.py line 60

Quoted 6 lines
tools/testing/selftests/drivers/net/hw/xsk.py new file +6 -0
+# 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"},
+}

[Severity: Low]
Do these ring requirements match what the C side checks? In test_xsk.c, testapp_hw_sw_min_ring_size() and testapp_hw_sw_max_ring_size() both skip unless the tx ifobj has XSK_CAP_HW_RING:

tools/testing/selftests/net/lib/xsk/test_xsk.c:testapp_hw_sw_min_ring_size() {
    ...
	if (!ifobj_has_cap(test->ifobj_tx, XSK_CAP_HW_RING)) {
		ksft_print_msg("HW ring sizes not supported.\n");
    ...
}

On the receiving endpoint, ifobj_tx is the peer shadow. setup_peer() in xskxceiver.c fills it with the local caps:

	shadow->caps = local->caps;

So the receiver ends up checking whether its own NIC can report ring sizes.

In tx_HW_SW_MIN_RING_SIZE the remote is the SKB-mode receiver. If the remote NIC has no get_ringparam, the remote endpoint skips and tells the DUT to skip too. The case is then reported as skipped, even though xsk.py never needs the remote ring and has already resized the DUT TX ring.

testapp_hw_sw_max_ring_size() has a similar issue:

	batch_size = min(xsk_get_cap(test, tx_max_pending), max_descs) - 8;

xsk_get_cap() reads test->ifobj_tx->caps, so each host takes tx_max_pending from its own NIC. If the two NICs have different TX maximums, can the two endpoints end up using different batch sizes?

[ ... ]

Quoted 5 lines
tools/testing/selftests/drivers/net/hw/xsk.py new file +5 -0
+def _reserve_queue(cfg, undo):
+    """Take the last queue with both an RX and a TX ring out of RSS until
+    undo, return None if the DUT cannot. A TX endpoint fills no RX buffers,
+    so in zero-copy mode its queue drops what it receives, the control
+    connection included."""

[ ... ]

tools/testing/selftests/drivers/net/hw/xsk.py line 115

Quoted 6 lines
tools/testing/selftests/drivers/net/hw/xsk.py new file +6 -0
+    queue = count - 1
+    if cmd(f"ethtool -X {cfg.ifname} equal {queue}", fail=False).ret:
+        print(f"1..0 # SKIP {cfg.ifname} cannot take queue {queue} out of RSS")
+        return None
+    undo.callback(_restore_rss, cfg, rss.get("indir"))
+    return queue

[Severity: Medium]
Does the indirection table set here stay in place for the rest of the run on every zero-copy driver? ixgbe advertises xsk-zerocopy, but ixgbe_setup_reta() rebuilds the table on every configure. It never checks netif_is_rxfh_configured():

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c:ixgbe_setup_reta() {
    ...
	/* Fill out redirection table */
	memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
    ...
}

The first rebuild happens right after _reserve_queue(), when _steer_udp() turns ntuple-filters on:

_steer_udp() "ethtool -K <if> ntuple-filters on"
ixgbe_set_features() (need_reset)

    ixgbe_do_reset()
      ixgbe_up()
        ixgbe_configure()
          ixgbe_configure_rx()
            ixgbe_setup_mrqc()
              ixgbe_setup_reta()

It also happens inside every case. xskxceiver's driver-mode XDP attach and detach go through ixgbe_xdp_setup(), which closes and reopens the device:

	err = ixgbe_setup_tc(dev, adapter->hw_tcs);

MTU and ring changes reinit the device as well.

ixgbe_fdir_filter_restore() puts the ntuple rule back, but it does not restore the RETA, so the reserved queue gets RSS traffic again. In TX cases the zero-copy socket on that queue fills no RX buffers. Anything hashed to that queue is dropped, including the TCP control connection on the random ctrl_port.

Would this show up as intermittent timeouts on ixgbe DUTs rather than as a skip? The runner never reads the table back with rss_get to detect it.

[ ... ]

Quoted 1 line

+def _test(cfg, direction, test_id, name, busy_poll):

[ ... ]

tools/testing/selftests/drivers/net/hw/xsk.py line 272

Quoted 8 lines
tools/testing/selftests/drivers/net/hw/xsk.py new file +8 -0
+    dut_ret, remote_ret = _run(cfg, local, remote, ctrl_port)
+    if dut_ret is None:
+        raise KsftFailEx(f"remote endpoint did not listen on port {ctrl_port}")
+    rets = {dut_ret, remote_ret}
+    if rets <= {0, SKIP_CODE}:
+        # Both endpoints detached their XDP programs and restored the MTU.
+        for fallback in fallbacks:
+            fallback.cancel()

[Severity: Low]
Does a 0 or skip exit code actually show that the XDP programs were detached? cleanup_iface() in xskxceiver.c does not check the result of the detach:

	if (ifobj->xdp_prog)
		xsk_detach_xdp_program(ifobj->ifindex,
				       mode_to_xdp_flags(ifobj->mode));

xsk_detach_xdp_program() in xsk.c also throws away the return value of bpf_xdp_detach():

void xsk_detach_xdp_program(int ifindex, u32 xdp_flags)

{
	bpf_xdp_detach(ifindex, xdp_flags, NULL);
}

Only an MTU restore error changes the endpoint's exit code.

Suppose bpf_xdp_detach() fails, for example because the driver's ndo_bpf rejects the reconfiguration. The endpoint still exits 0, and this loop also cancels the "xdpdrv off" and "xdpgeneric off" fallbacks. After the last case, the program and its XSKMAP would stay attached to the interface.

Running "xdpdrv off" when no program is attached does nothing. Could the XDP fallbacks be kept, and only the MTU fallbacks be cancelled?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261016174338.787135-1-maciej.fijalkowski%40intel.com
author maintainer
#34 lore raw

PATCH v4 15/15 selftests: xsk: document generic and hardware endpoint runs

In reply to Maciej Fijalkowski

Document the frames that the endpoints exchange, the per-case veth runner and the two-host hardware setup with a zero-copy DUT and an SKB-mode remote: how each runner drives the endpoints, what the hardware runner sets up and restores, what both hosts need and how to run the cases. Point the xskxceiver header comment to the new README.

---
 .../testing/selftests/net/lib/xsk/README.rst  | 194 ++++++++++++++++++
 .../selftests/net/lib/xsk/xskxceiver.c        |   2 +
 2 files changed, 196 insertions(+)
 create mode 100644 tools/testing/selftests/net/lib/xsk/README.rst
tools/testing/selftests/net/lib/xsk/README.rst new file +194 -0
new file mode 100644
index 000000000000..00d626125a99
@@ -0,0 +1,194 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==========
+xskxceiver
+==========
+
+The AF_XDP engine in ``net/lib/xsk`` is built as ``net/lib/xskxceiver``.
+The generic ``net/test_xsk.py`` test runs SKB and DRV modes over veth.
+
+Each ``xskxceiver`` endpoint generates and validates raw UDP frames over
+IPv4 or IPv6. It sends them from ``--src-ip`` to ``--dst-ip``, the address
+of its peer, via ``--dst-mac``, the MAC address of its next hop to the
+peer, and to UDP port ``--udp-port``. Over IPv4, the UDP checksum is
+zero. The UDP source port tells the sockets of ``XDP_SHARED_UMEM`` apart.
+The endpoints do not use AF_INET sockets for the test traffic. The XDP
+programs redirect only UDP packets to ``--udp-port`` and pass all other
+traffic to the stack.
+
+Generic veth test
+=================
+
+Two ``xskxceiver`` processes own the TX and RX veth interfaces. The TX
+process listens on a TCP control port (``--listen``) and the RX process
+connects. The Python runner starts a fresh process pair for each mode and
+case. A small control channel reports readiness, packet progress, skips,
+and aborts. For example::
+
+  make -C tools/testing/selftests/net/lib
+  cd tools/testing/selftests/net
+  sudo ./test_xsk.py
+
+Each case creates its own veth pair and picks a random control port and
+UDP port. The endpoints send UDP over IPv6 between two documentation
+addresses, which the veths do not need to have, and to the MAC address of
+the peer veth.
+``test_xsk`` runs each case that ``xskxceiver -l`` lists in SKB and DRV
+mode, and ``test_xsk_busy_poll`` runs them again with busy polling.
+``XDP_ADJUST_TAIL_SHRINK_MULTI_BUFF`` is left out, as it leaks page_pool
+pages on veth, and so is ``XDP_ADJUST_TAIL_GROW``, as veth leaves no room
+to grow most frames. The runner reserves 32 huge pages of 2 MiB for the
+UNALIGNED cases and restores the count however the run ends, and leaves
+those cases out when it cannot reserve them.
+``-t`` selects cases, e.g. ``-t 'test_xsk.drv_*'``, and ``-l`` lists them.
+
+Hardware zero-copy test
+=======================
+
+``drivers/net/hw/xsk.py`` runs each case that ``xskxceiver -L`` lists, in
+each DUT direction listed with it, and owns the TAP results.
+``test_xsk.h`` groups the cases by the DUT directions in which they run.
+
+It starts one ``xskxceiver`` process on each host for each case. The DUT
+runs in ZC mode; the remote runs in SKB mode and does not need zero-copy.
+RX and TX cases are named separately in TAP, e.g.
+``test_xsk.rx_SEND_RECEIVE`` and ``test_xsk.tx_SEND_RECEIVE``. The
+hardware runner skips a DUT that does not advertise AF_XDP zero-copy. The
+DUT endpoint binds with ``XDP_ZEROCOPY``, which fails instead of falling
+back to copy mode, so an advertised device that cannot bind or run a case
+fails it.
+
+``xsk.py`` starts the remote XSK endpoint first. It listens on a TCP
+control port on the remote address, and the DUT endpoint connects to it
+over the tested link. The listener prints a line on stderr once it
+listens, so ``xsk.py`` starts the DUT endpoint without polling the remote
+for the port. The listener waits 30 seconds for its peer, and ``xsk.py``
+as long for that line. The small per-case channel reports readiness,
+packet progress, skips, and aborts. It has no capabilities or verdict
+handshake. ``xsk.py`` chooses the case, sets the timeouts, and reports
+the result from both process exit codes. Each endpoint sees only its own
+device and mode. One that skips a case tells its peer on the control
+channel, which skips the case as well, and ``xsk.py`` reports a case as
+skipped when one endpoint skips it and the other skips or passes it.
+Killing an SSH client does not stop the command it runs, so the remote
+endpoint runs under ``timeout(1)``, and ``xsk.py`` waits for it to exit
+before the case ends.
+
+The endpoints send UDP over IPv6 when ``LOCAL_V6`` and ``REMOTE_V6`` are
+set and over IPv4 otherwise, between the addresses of the two hosts. Each
+sends to the MAC address of its next hop to the other host, which is the
+peer interface on a shared link and the gateway otherwise. ``xsk.py``
+picks the UDP port at random for the run, so ntuple rules can steer the
+test flow. It takes the last DUT queue that has both an RX and a TX ring
+out of RSS and binds the DUT endpoint to it. For DUT RX cases it steers
+the test flow to that queue, and for DUT TX cases to queue 0 on the
+remote receiver. A TX-only zero-copy socket fills no RX buffers, so its
+queue drops what it receives, and TX cases keep that queue out of RSS as
+well. Accelerated RFS, which ntuple filters turn on in some drivers,
+could still steer the control connection to that queue, so RFS has to
+stay off on the DUT, as it is by default. As the XDP programs pass the
+control connection and all other traffic to the stack, the tested link
+does not have to be otherwise idle.
+
+``xsk.py`` sets up the queue, the ntuple rules and huge pages for the
+UNALIGNED cases once, before the cases run, and undoes them however the
+run ends. The run is skipped when either host has no ntuple support or
+rejects the ntuple rule, and the UNALIGNED cases are left out when either
+host cannot reserve the huge pages. Each endpoint detaches its XDP program
+and restores the MTU before it exits. Cases that do not need larger frames
+default to an MTU of 1500 (``ETH_DATA_LEN``), and the SKB-mode remote
+endpoint only raises its MTU when a case needs a larger one, as changing
+the MTU can reset the NIC. Before the endpoints start, ``xsk.py`` sets
+with ``ethtool -G`` the TX ring of the sending interface to 64 descriptors
+for HW_SW_MIN_RING_SIZE, and for HW_SW_MAX_RING_SIZE the TX ring of the
+sending interface and the RX ring of the receiving one to their maximum
+sizes, which can reset the NIC as well. Once both endpoints are ready,
+each waits for its link before sending, as such a reset can take the
+link down on both hosts, and ``xsk.py`` raises the traffic and link
+timeouts of the endpoints to 20 seconds with ``--timeout``. When the run
+ends, the runner resets the RSS indirection table of the DUT with
+``ethtool -X default``, writes the saved table back if it was not the
+default, and restores the ntuple setting and the huge-page count. It
+restores the ring sizes after the case however the endpoints end, and
+after an endpoint fails or is killed, it also detaches the XDP program
+and restores the MTU. A host whose ring sizes ``ethtool -g`` cannot read
+skips the two ring cases.
+The runner does not change channel counts. A DUT with fewer than two
+queues that have both rings skips all cases, as it has no queue to take
+out of RSS. So does a DUT that cannot take one out of RSS.
+
+The remote is either another host (``REMOTE_TYPE=ssh``) or the peer port
+of the same host moved to a network namespace (``REMOTE_TYPE=netns``).
+The framework runs the remote commands for either backend. Both endpoints
+run as root.
+
+Setup
+-----
+
+Build the engine on the DUT::
+
+  make -C tools/testing/selftests/net/lib
+
+A top-level selftests build with ``TARGETS=drivers/net/hw`` includes
+``net/lib`` as well.
+
+Configure the usual driver test variables in
+``tools/testing/selftests/drivers/net/hw/net.config`` or the environment::
+
+  NETIF=eth0
+  LOCAL_V4=192.0.2.1
+  REMOTE_V4=192.0.2.2
+  REMOTE_TYPE=netns
+  REMOTE_ARGS=xsk-peer
+
+Set ``LOCAL_V6`` and ``REMOTE_V6`` as well to test over IPv6, with the
+addresses added ``nodad``. ``REMOTE_ARGS`` names the namespace that holds
+the peer port. With eth0 connected back to back to eth1 of the same host,
+set it up as root::
+
+  ip netns add xsk-peer
+  ip link set eth1 netns xsk-peer
+  ip -n xsk-peer link set lo up
+  ip -n xsk-peer addr add 192.0.2.2/24 dev eth1
+  ip -n xsk-peer link set eth1 up
+  ip addr add 192.0.2.1/24 dev eth0
+  ip link set eth0 up
+
+Run as root on the DUT::
+
+  cd tools/testing/selftests/drivers/net/hw
+  sudo ./xsk.py -t test_xsk.rx_SEND_RECEIVE
+
+``xskxceiver -L`` lists the cases, and ``xsk.py -l`` the names to pass to
+``-t``. Omit ``-t`` to run all cases.
+Set the variables in ``net.config`` when using ``sudo`` so they are
+available to the test process.
+
+``test_xsk`` runs each case with the DUT endpoint driven by interrupts.
+``test_xsk_busy_poll`` runs the same cases again with the DUT endpoint
+busy polling as in the busy-poll pass of ``test_xsk.py``, e.g.
+``-t 'test_xsk_busy_poll.*'``. Each of its cases sets
+``napi_defer_hard_irqs`` and ``gro_flush_timeout`` on the DUT to the
+values ``test_xsk.py`` uses on veth and restores them when it ends. The
+remote endpoint does not busy poll.
+
+With SSH, each case starts its remote endpoint over SSH. SSH connection
+sharing for the remote host (``ControlMaster``, ``ControlPath`` and
+``ControlPersist`` in ssh_config(5)) avoids a new SSH login for each remote
+command. With ``sudo``, that is root's SSH configuration.
+
+The remote host needs AF_XDP in SKB mode, BPF and ``timeout(1)``. In a
+namespace, the remote endpoint runs the DUT's ``xskxceiver`` binary. With
+SSH, ``xsk.py`` copies that binary to the remote, so both hosts must have
+compatible architectures and libraries. The DUT needs RSS support, and
+both hosts need ntuple support. The test uses ``NetDrvEpEnv`` and the
+networking selftest Python helpers for setup and rollback.
+
+The hardware list covers baseline traffic, 2K frames, single packets,
+poll, headroom, invalid TX descriptors, socket statistics, XDP program
+cleanup, XDP drop, metadata, tail adjustment, multi-buffer, 9K,
+unaligned traffic, HW ring sizes, socket teardown, and shared UMEM.
+For ``TOO_MANY_FRAGS``, the runner reads the DUT's ``xdp-zc-max-segs``
+value and passes it to both endpoint processes so the SKB peer validates
+the same packet stream without a capabilities exchange. A DUT without
+multi-buffer zero-copy does not list the case.
tools/testing/selftests/net/lib/xsk/xskxceiver.c +2 -0
index a4a66c9ebde2..e8cd3529d169 100644
@@ -9,6 +9,8 @@
  * See test_xsk.py for detailed information on test topology
  * and prerequisite network setup.
  *
+ * See README.rst for the generic and hardware test 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.
Signature · 1 line
2.43.0
Reviewed-by on the v4 series
#35 lore raw
In reply to Maciej Fijalkowski
Quoted 19 lines · Maciej Fijalkowski

v3: https://lore.kernel.org/netdev/[email protected]/
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)

Quoted 8 lines

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

I think this serves well as a baseline for the XSK HW driver tests. I think we'll surface a lot of bugs here! ;-)

For the series: