AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/10/02 15:39 flow patch-triage
1m Args:
null

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "KMSANReasoning": "",
  "NeedsKMSAN": false,
  "Reasoning": "The patch series touches only documentation (Documentation/networking/af_xdp.rst), MAINTAINERS, and user-space selftests and tooling under tools/testing/selftests/. No kernel source code or compiled kernel image (vmlinux/modules) is modified, so there is no kernel code to fuzz.",
  "WorthFuzzing": false
}

1/1 2026/10/02 15:39 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit a05bc1140f04aabae706af64482c25331f6a6377\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Fri Oct 2 15:38:58 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/Documentation/networking/af_xdp.rst b/Documentation/networking/af_xdp.rst\nindex cc3f0d16b28fb..538e71adb7593 100644\n--- a/Documentation/networking/af_xdp.rst\n+++ b/Documentation/networking/af_xdp.rst\n@@ -211,7 +211,7 @@ Libbpf\n \n Libbpf is a helper library for eBPF and XDP that makes using these\n technologies a lot simpler. It also contains specific helper functions\n-in tools/testing/selftests/bpf/xsk.h for facilitating the use of\n+in tools/testing/selftests/net/lib/xsk/xsk.h for facilitating the use of\n AF_XDP. It contains two types of functions: those that can be used to\n make the setup of AF_XDP socket easier and ones that can be used in the\n data plane to access the rings safely and quickly.\n@@ -751,7 +751,7 @@ return values:\n      returned number signifies the max number of frags supported.\n \n For an example on how these are used through libbpf, please take a\n-look at tools/testing/selftests/bpf/xskxceiver.c.\n+look at tools/testing/selftests/net/lib/xsk/xskxceiver.c.\n \n Multi-Buffer Support for Zero-Copy Drivers\n ------------------------------------------\n@@ -785,7 +785,7 @@ can be displayed with \"-h\", as usual.\n This sample application uses libbpf to make the setup and usage of\n AF_XDP simpler. If you want to know how the raw uapi of AF_XDP is\n really used to make something more advanced, take a look at the libbpf\n-code in tools/testing/selftests/bpf/xsk.[ch].\n+code in tools/testing/selftests/net/lib/xsk/xsk.[ch].\n \n FAQ\n =======\ndiff --git a/MAINTAINERS b/MAINTAINERS\nindex 140eafcbbd782..fd89174efe24d 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -29736,7 +29736,9 @@ F:\tinclude/net/xsk_buff_pool.h\n F:\tinclude/uapi/linux/if_xdp.h\n F:\tinclude/uapi/linux/xdp_diag.h\n F:\tnet/xdp/\n-F:\ttools/testing/selftests/bpf/*xsk*\n+F:\ttools/testing/selftests/drivers/net/hw/xsk.py\n+F:\ttools/testing/selftests/net/*xsk*\n+F:\ttools/testing/selftests/net/lib/xsk/\n \n XEN BLOCK SUBSYSTEM\n M:\tRoger Pau Monné \u003croger@xenproject.org\u003e\ndiff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftests/bpf/.gitignore\nindex 986a6389186ba..3c3183ea3c837 100644\n--- a/tools/testing/selftests/bpf/.gitignore\n+++ b/tools/testing/selftests/bpf/.gitignore\n@@ -37,7 +37,6 @@ test_cpp\n /uprobe_multi\n *.ko\n *.tmp\n-xskxceiver\n xdp_redirect_multi\n xdp_synproxy\n xdp_hw_metadata\ndiff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile\nindex 93c707116fad0..a2d357781c0fd 100644\n--- a/tools/testing/selftests/bpf/Makefile\n+++ b/tools/testing/selftests/bpf/Makefile\n@@ -62,7 +62,8 @@ COMMON_CFLAGS = -g $(OPT_FLAGS) -rdynamic -std=gnu11\t\t\t\t\\\n \t  $(GENFLAGS) $(SAN_CFLAGS) $(LIBELF_CFLAGS)\t\t\t\\\n \t  -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR)\t\t\\\n \t  -I$(TOOLSINCDIR) -I$(TOOLSARCHINCDIR) -I$(APIDIR) -I$(OUTPUT)\t\\\n-\t  -I$(CURDIR)/libarena/include\n+\t  -I$(CURDIR)/libarena/include\t\t\t\t\t\\\n+\t  -I$(CURDIR)/../net/lib/xsk\n LDFLAGS += $(SAN_LDFLAGS)\n LDLIBS += $(LIBELF_LIBS) -lz -lrt -lpthread\n \n@@ -118,14 +119,13 @@ TEST_GEN_PROGS += test_progs-cpuv4\n TEST_INST_SUBDIRS += cpuv4\n endif\n \n-TEST_FILES = xsk_prereqs.sh $(wildcard progs/btf_dump_test_case_*.c)\n+TEST_FILES = $(wildcard progs/btf_dump_test_case_*.c)\n \n # Order correspond to 'make run_tests' order\n TEST_PROGS := test_kmod.sh \\\n \ttest_lirc_mode2.sh \\\n \ttest_bpftool_build.sh \\\n \ttest_doc_build.sh \\\n-\ttest_xsk.sh \\\n \ttest_xdp_features.sh\n \n TEST_PROGS_EXTENDED := \\\n@@ -144,8 +144,7 @@ TEST_GEN_PROGS_EXTENDED = \\\n \tveristat \\\n \txdp_features \\\n \txdp_hw_metadata \\\n-\txdp_synproxy \\\n-\txskxceiver\n+\txdp_synproxy\n \n TEST_GEN_FILES += $(TEST_KMODS) liburandom_read.so urandom_read sign-file uprobe_multi\n \n@@ -542,7 +541,6 @@ linked_maps.skel.h-deps := linked_maps1.bpf.o linked_maps2.bpf.o\n test_subskeleton.skel.h-deps := test_subskeleton_lib2.bpf.o test_subskeleton_lib.bpf.o test_subskeleton.bpf.o\n test_subskeleton_lib.skel.h-deps := test_subskeleton_lib2.bpf.o test_subskeleton_lib.bpf.o\n test_usdt.skel.h-deps := test_usdt.bpf.o test_usdt_multispec.bpf.o\n-xsk_xdp_progs.skel.h-deps := xsk_xdp_progs.bpf.o\n xdp_hw_metadata.skel.h-deps := xdp_hw_metadata.bpf.o\n xdp_features.skel.h-deps := xdp_features.bpf.o\n tracing_multi.skel.h-deps := tracing_multi_attach.bpf.o tracing_multi_check.bpf.o\n@@ -769,6 +767,8 @@ $(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o:\t\t\t\t\\\n \t$$(call msg,EXT-OBJ,$(TRUNNER_BINARY),$$@)\n \t$(Q)$$(CC) $$(CFLAGS) -c $$\u003c $$(LDLIBS) -o $$@\n \n+$(TRUNNER_OUTPUT)/xsk.o: ../net/lib/xsk/xsk.h\n+\n $(TRUNNER_LIB_OBJS): $(TRUNNER_OUTPUT)/%.o:$(TOOLSDIR)/lib/%.c\n \t$$(call msg,LIB-OBJ,$(TRUNNER_BINARY),$$@)\n \t$(Q)$$(CC) $$(CFLAGS) -c $$\u003c $$(LDLIBS) -o $$@\n@@ -845,6 +845,10 @@ $(LIBARENA_ASAN_SKEL): $(INCLUDE_DIR)/vmlinux.h $(BPFOBJ) $(LIBARENA_BPF_DEPS)\n \t+$(MAKE) -C libarena libarena_asan.skel.h $(LIBARENA_MAKE_ARGS)\n endif\n \n+# xsk.c lives in ../net/lib/xsk so it can be shared with selftests/net;\n+# let make find it there instead of keeping a local copy.\n+vpath %.c ../net/lib/xsk\n+\n # Define test_progs test runner.\n TRUNNER_TESTS_DIR := prog_tests\n TRUNNER_BPF_PROGS_DIR := progs\n@@ -931,18 +935,9 @@ $(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT)\n \t$(call msg,BINARY,,$@)\n \t$(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@\n \n-# Keep xskxceiver independent from test_progs object dependencies.\n-$(OUTPUT)/xskxceiver: xskxceiver.c xsk.c network_helpers.c \\\n-\t\t\t   $(TOOLSDIR)/lib/find_bit.c prog_tests/test_xsk.c \\\n-\t\t\t   xskxceiver.h xsk.h network_helpers.h \\\n-\t\t\t   prog_tests/test_xsk.h test_progs.h bpf_util.h \\\n-\t\t\t   $(OUTPUT)/xsk_xdp_progs.skel.h $(BPFOBJ) | $(OUTPUT)\n-\t$(call msg,BINARY,,$@)\n-\t$(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@\n-\n-$(OUTPUT)/xdp_hw_metadata: xdp_hw_metadata.c xsk.c network_helpers.c \\\n+$(OUTPUT)/xdp_hw_metadata: xdp_hw_metadata.c ../net/lib/xsk/xsk.c network_helpers.c \\\n \t\t\t   $(TOOLSDIR)/lib/find_bit.c xdp_metadata.h \\\n-\t\t\t   xsk.h network_helpers.h test_progs.h bpf_util.h \\\n+\t\t\t   ../net/lib/xsk/xsk.h network_helpers.h test_progs.h bpf_util.h \\\n \t\t\t   $(OUTPUT)/xdp_hw_metadata.skel.h $(BPFOBJ) | $(OUTPUT)\n \t$(call msg,BINARY,,$@)\n \t$(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@\ndiff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c\nindex cdf2d7d3ab321..d72d7022cc697 100644\n--- a/tools/testing/selftests/bpf/network_helpers.c\n+++ b/tools/testing/selftests/bpf/network_helpers.c\n@@ -622,54 +622,6 @@ int get_socket_local_port(int sock_fd)\n \treturn -1;\n }\n \n-int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)\n-{\n-\tstruct ifreq ifr = {0};\n-\tint sockfd, err;\n-\n-\tsockfd = socket(AF_INET, SOCK_DGRAM, 0);\n-\tif (sockfd \u003c 0)\n-\t\treturn -errno;\n-\n-\tmemcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));\n-\n-\tring_param-\u003ecmd = ETHTOOL_GRINGPARAM;\n-\tifr.ifr_data = (char *)ring_param;\n-\n-\tif (ioctl(sockfd, SIOCETHTOOL, \u0026ifr) \u003c 0) {\n-\t\terr = errno;\n-\t\tclose(sockfd);\n-\t\treturn -err;\n-\t}\n-\n-\tclose(sockfd);\n-\treturn 0;\n-}\n-\n-int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)\n-{\n-\tstruct ifreq ifr = {0};\n-\tint sockfd, err;\n-\n-\tsockfd = socket(AF_INET, SOCK_DGRAM, 0);\n-\tif (sockfd \u003c 0)\n-\t\treturn -errno;\n-\n-\tmemcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));\n-\n-\tring_param-\u003ecmd = ETHTOOL_SRINGPARAM;\n-\tifr.ifr_data = (char *)ring_param;\n-\n-\tif (ioctl(sockfd, SIOCETHTOOL, \u0026ifr) \u003c 0) {\n-\t\terr = errno;\n-\t\tclose(sockfd);\n-\t\treturn -err;\n-\t}\n-\n-\tclose(sockfd);\n-\treturn 0;\n-}\n-\n struct send_recv_arg {\n \tint\t\tfd;\n \tuint32_t\tbytes;\ndiff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h\nindex 75133119c04a3..e7333b769150b 100644\n--- a/tools/testing/selftests/bpf/network_helpers.h\n+++ b/tools/testing/selftests/bpf/network_helpers.h\n@@ -89,8 +89,6 @@ int make_sockaddr(int family, const char *addr_str, __u16 port,\n \t\t  struct sockaddr_storage *addr, socklen_t *len);\n char *ping_command(int family);\n int get_socket_local_port(int sock_fd);\n-int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);\n-int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);\n \n int open_tuntap(const char *dev_name, bool need_mac);\n \ndiff --git a/tools/testing/selftests/bpf/prog_tests/xsk.c b/tools/testing/selftests/bpf/prog_tests/xsk.c\ndeleted file mode 100644\nindex 6e2f63ee2a6c3..0000000000000\n--- a/tools/testing/selftests/bpf/prog_tests/xsk.c\n+++ /dev/null\n@@ -1,170 +0,0 @@\n-// SPDX-License-Identifier: GPL-2.0\n-#include \u003cnet/if.h\u003e\n-#include \u003cstdarg.h\u003e\n-\n-#include \"network_helpers.h\"\n-#include \"test_progs.h\"\n-#include \"test_xsk.h\"\n-#include \"xsk_xdp_progs.skel.h\"\n-\n-#define VETH_RX \"veth0\"\n-#define VETH_TX \"veth1\"\n-#define MTU\t1500\n-\n-int setup_veth(bool busy_poll)\n-{\n-\tSYS(fail,\n-\t\"ip link add %s numtxqueues 4 numrxqueues 4 type veth peer name %s numtxqueues 4 numrxqueues 4\",\n-\tVETH_RX, VETH_TX);\n-\tSYS(fail, \"sysctl -wq net.ipv6.conf.%s.disable_ipv6=1\", VETH_RX);\n-\tSYS(fail, \"sysctl -wq net.ipv6.conf.%s.disable_ipv6=1\", VETH_TX);\n-\n-\tif (busy_poll) {\n-\t\tSYS(fail, \"echo 2 \u003e /sys/class/net/%s/napi_defer_hard_irqs\", VETH_RX);\n-\t\tSYS(fail, \"echo 200000 \u003e /sys/class/net/%s/gro_flush_timeout\", VETH_RX);\n-\t\tSYS(fail, \"echo 2 \u003e /sys/class/net/%s/napi_defer_hard_irqs\", VETH_TX);\n-\t\tSYS(fail, \"echo 200000 \u003e /sys/class/net/%s/gro_flush_timeout\", VETH_TX);\n-\t}\n-\n-\tSYS(fail, \"ip link set %s mtu %d\", VETH_RX, MTU);\n-\tSYS(fail, \"ip link set %s mtu %d\", VETH_TX, MTU);\n-\tSYS(fail, \"ip link set %s up\", VETH_RX);\n-\tSYS(fail, \"ip link set %s up\", VETH_TX);\n-\n-\treturn 0;\n-\n-fail:\n-\treturn -1;\n-}\n-\n-void delete_veth(void)\n-{\n-\tSYS_NOFAIL(\"ip link del %s\", VETH_RX);\n-\tSYS_NOFAIL(\"ip link del %s\", VETH_TX);\n-}\n-\n-int configure_ifobj(struct ifobject *tx, struct ifobject *rx)\n-{\n-\trx-\u003eifindex = if_nametoindex(VETH_RX);\n-\tif (!ASSERT_OK_FD(rx-\u003eifindex, \"get RX ifindex\"))\n-\t\treturn -1;\n-\n-\ttx-\u003eifindex = if_nametoindex(VETH_TX);\n-\tif (!ASSERT_OK_FD(tx-\u003eifindex, \"get TX ifindex\"))\n-\t\treturn -1;\n-\n-\ttx-\u003eshared_umem = false;\n-\trx-\u003eshared_umem = false;\n-\n-\n-\treturn 0;\n-}\n-\n-static void test_xsk(const struct test_spec *test_to_run, enum test_mode mode)\n-{\n-\tu32 max_frags, umem_tailroom, cache_line_size;\n-\tstruct ifobject *ifobj_tx, *ifobj_rx;\n-\tstruct test_spec test;\n-\tint ret;\n-\n-\tifobj_tx = ifobject_create();\n-\tif (!ASSERT_OK_PTR(ifobj_tx, \"create ifobj_tx\"))\n-\t\treturn;\n-\n-\tifobj_rx = ifobject_create();\n-\tif (!ASSERT_OK_PTR(ifobj_rx, \"create ifobj_rx\"))\n-\t\tgoto delete_tx;\n-\n-\tif (!ASSERT_OK(configure_ifobj(ifobj_tx, ifobj_rx), \"conigure ifobj\"))\n-\t\tgoto delete_rx;\n-\n-\tret = get_hw_ring_size(ifobj_tx-\u003eifname, \u0026ifobj_tx-\u003ering);\n-\tif (!ret) {\n-\t\tifobj_tx-\u003ehw_ring_size_supp = true;\n-\t\tifobj_tx-\u003eset_ring.default_tx = ifobj_tx-\u003ering.tx_pending;\n-\t\tifobj_tx-\u003eset_ring.default_rx = ifobj_tx-\u003ering.rx_pending;\n-\t}\n-\n-\tcache_line_size = read_procfs_val(SMP_CACHE_BYTES_PATH);\n-\tif (!cache_line_size)\n-\t\tcache_line_size = 64;\n-\n-\tmax_frags = read_procfs_val(MAX_SKB_FRAGS_PATH);\n-\tif (!max_frags)\n-\t\tmax_frags = 17;\n-\n-\tifobj_tx-\u003emax_skb_frags = max_frags;\n-\tifobj_rx-\u003emax_skb_frags = max_frags;\n-\n-\t/* 48 bytes is a part of skb_shared_info w/o frags array;\n-\t * 16 bytes is sizeof(skb_frag_t)\n-\t */\n-\tumem_tailroom = ALIGN(48 + (max_frags * 16), cache_line_size);\n-\tifobj_tx-\u003eumem_tailroom = umem_tailroom;\n-\tifobj_rx-\u003eumem_tailroom = umem_tailroom;\n-\n-\tif (!ASSERT_OK(init_iface(ifobj_rx, worker_testapp_validate_rx), \"init RX\"))\n-\t\tgoto delete_rx;\n-\tif (!ASSERT_OK(init_iface(ifobj_tx, worker_testapp_validate_tx), \"init TX\"))\n-\t\tgoto delete_rx;\n-\n-\ttest_init(\u0026test, ifobj_tx, ifobj_rx, 0, \u0026tests[0]);\n-\n-\ttest.tx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);\n-\tif (!ASSERT_OK_PTR(test.tx_pkt_stream_default, \"TX pkt generation\"))\n-\t\tgoto delete_rx;\n-\ttest.rx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);\n-\tif (!ASSERT_OK_PTR(test.rx_pkt_stream_default, \"RX pkt generation\"))\n-\t\tgoto delete_rx;\n-\n-\n-\ttest_init(\u0026test, ifobj_tx, ifobj_rx, mode, test_to_run);\n-\tret = test.test_func(\u0026test);\n-\tif (ret != TEST_SKIP)\n-\t\tASSERT_OK(ret, \"Run test\");\n-\tpkt_stream_restore_default(\u0026test);\n-\n-\tif (ifobj_tx-\u003ehw_ring_size_supp)\n-\t\thw_ring_size_reset(ifobj_tx);\n-\n-\tpkt_stream_delete(test.tx_pkt_stream_default);\n-\tpkt_stream_delete(test.rx_pkt_stream_default);\n-\txsk_xdp_progs__destroy(ifobj_tx-\u003exdp_progs);\n-\txsk_xdp_progs__destroy(ifobj_rx-\u003exdp_progs);\n-\n-delete_rx:\n-\tifobject_delete(ifobj_rx);\n-delete_tx:\n-\tifobject_delete(ifobj_tx);\n-}\n-\n-void test_ns_xsk_skb(void)\n-{\n-\tint i;\n-\n-\tif (!ASSERT_OK(setup_veth(false), \"setup veth\"))\n-\t\treturn;\n-\n-\tfor (i = 0; i \u003c ARRAY_SIZE(tests); i++) {\n-\t\tif (test__start_subtest(tests[i].name))\n-\t\t\ttest_xsk(\u0026tests[i], TEST_MODE_SKB);\n-\t}\n-\n-\tdelete_veth();\n-}\n-\n-void test_ns_xsk_drv(void)\n-{\n-\tint i;\n-\n-\tif (!ASSERT_OK(setup_veth(false), \"setup veth\"))\n-\t\treturn;\n-\n-\tfor (i = 0; i \u003c ARRAY_SIZE(tests); i++) {\n-\t\tif (test__start_subtest(tests[i].name))\n-\t\t\ttest_xsk(\u0026tests[i], TEST_MODE_DRV);\n-\t}\n-\n-\tdelete_veth();\n-}\n-\ndiff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c\ndeleted file mode 100644\nindex 7dad8556a722e..0000000000000\n--- a/tools/testing/selftests/bpf/xskxceiver.c\n+++ /dev/null\n@@ -1,479 +0,0 @@\n-// SPDX-License-Identifier: GPL-2.0\n-/* Copyright(c) 2020 Intel Corporation. */\n-\n-/*\n- * Some functions in this program are taken from\n- * Linux kernel samples/bpf/xdpsock* and modified\n- * for use.\n- *\n- * See test_xsk.sh for detailed information on test topology\n- * and prerequisite network setup.\n- *\n- * This test program contains two threads, each thread is single socket with\n- * a unique UMEM. It validates in-order packet delivery and packet content\n- * by sending packets to each other.\n- *\n- * Tests Information:\n- * ------------------\n- * These selftests test AF_XDP SKB and Native/DRV modes using veth\n- * Virtual Ethernet interfaces.\n- *\n- * For each mode, the following tests are run:\n- *    a. nopoll - soft-irq processing in run-to-completion mode\n- *    b. poll - using poll() syscall\n- *    c. Socket Teardown\n- *       Create a Tx and a Rx socket, Tx from one socket, Rx on another. Destroy\n- *       both sockets, then repeat multiple times. Only nopoll mode is used\n- *    d. Bi-directional sockets\n- *       Configure sockets as bi-directional tx/rx sockets, sets up fill and\n- *       completion rings on each socket, tx/rx in both directions. Only nopoll\n- *       mode is used\n- *    e. Statistics\n- *       Trigger some error conditions and ensure that the appropriate statistics\n- *       are incremented. Within this test, the following statistics are tested:\n- *       i.   rx dropped\n- *            Increase the UMEM frame headroom to a value which results in\n- *            insufficient space in the rx buffer for both the packet and the headroom.\n- *       ii.  tx invalid\n- *            Set the 'len' field of tx descriptors to an invalid value (umem frame\n- *            size + 1).\n- *       iii. rx ring full\n- *            Reduce the size of the RX ring to a fraction of the fill ring size.\n- *       iv.  fill queue empty\n- *            Do not populate the fill queue and then try to receive pkts.\n- *    f. bpf_link resource persistence\n- *       Configure sockets at indexes 0 and 1, run a traffic on queue ids 0,\n- *       then remove xsk sockets from queue 0 on both veth interfaces and\n- *       finally run a traffic on queues ids 1\n- *    g. unaligned mode\n- *    h. tests for invalid and corner case Tx descriptors so that the correct ones\n- *       are discarded and let through, respectively.\n- *    i. 2K frame size tests\n- *    j. If multi-buffer is supported, send 9k packets divided into 3 frames\n- *    k. If multi-buffer and huge pages are supported, send 9k packets in a single frame\n- *       using unaligned mode\n- *    l. If multi-buffer is supported, try various nasty combinations of descriptors to\n- *       check if they pass the validation or not\n- *\n- * Flow:\n- * -----\n- * - Single process spawns two threads: Tx and Rx\n- * - Each of these two threads attach to a veth interface\n- * - Each thread creates one AF_XDP socket connected to a unique umem for each\n- *   veth interface\n- * - Tx thread Transmits a number of packets from veth\u003cxxxx\u003e to veth\u003cyyyy\u003e\n- * - Rx thread verifies if all packets were received and delivered in-order,\n- *   and have the right content\n- *\n- * Enable/disable packet dump mode:\n- * --------------------------\n- * To enable L2 - L4 headers and payload dump of each packet on STDOUT, add\n- * parameter -D to params array in test_xsk.sh, i.e. params=(\"-S\" \"-D\")\n- */\n-\n-#define _GNU_SOURCE\n-#include \u003cassert.h\u003e\n-#include \u003cfcntl.h\u003e\n-#include \u003cgetopt.h\u003e\n-#include \u003clinux/if_link.h\u003e\n-#include \u003clinux/if_ether.h\u003e\n-#include \u003clinux/mman.h\u003e\n-#include \u003clinux/netdev.h\u003e\n-#include \u003clinux/ethtool.h\u003e\n-#include \u003clinux/align.h\u003e\n-#include \u003carpa/inet.h\u003e\n-#include \u003cnet/if.h\u003e\n-#include \u003clocale.h\u003e\n-#include \u003cstdio.h\u003e\n-#include \u003cstdlib.h\u003e\n-#include \u003clibgen.h\u003e\n-#include \u003cstddef.h\u003e\n-#include \u003csys/mman.h\u003e\n-#include \u003csys/types.h\u003e\n-\n-#include \"prog_tests/test_xsk.h\"\n-#include \"xsk_xdp_progs.skel.h\"\n-#include \"xsk.h\"\n-#include \"xskxceiver.h\"\n-#include \u003cbpf/bpf.h\u003e\n-#include \u003clinux/filter.h\u003e\n-#include \"kselftest.h\"\n-#include \"xsk_xdp_common.h\"\n-\n-#include \u003cnetwork_helpers.h\u003e\n-\n-static bool opt_print_tests;\n-static enum test_mode opt_mode = TEST_MODE_ALL;\n-static u32 opt_run_test = RUN_ALL_TESTS;\n-\n-void test__fail(void) { /* for network_helpers.c */ }\n-\n-static void __exit_with_error(int error, const char *file, const char *func, int line)\n-{\n-\tksft_test_result_fail(\"[%s:%s:%i]: ERROR: %d/\\\"%s\\\"\\n\", file, func, line,\n-\t\t\t      error, strerror(error));\n-\tksft_exit_xfail();\n-}\n-\n-#define exit_with_error(error) __exit_with_error(error, __FILE__, __func__, __LINE__)\n-\n-static bool ifobj_zc_avail(struct ifobject *ifobject)\n-{\n-\tsize_t umem_sz = DEFAULT_UMEM_BUFFERS * XSK_UMEM__DEFAULT_FRAME_SIZE;\n-\tint mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE;\n-\tstruct xsk_socket_info *xsk;\n-\tstruct xsk_umem_info *umem;\n-\tbool zc_avail = false;\n-\tvoid *bufs;\n-\tint ret;\n-\n-\tbufs = mmap(NULL, umem_sz, PROT_READ | PROT_WRITE, mmap_flags, -1, 0);\n-\tif (bufs == MAP_FAILED)\n-\t\texit_with_error(errno);\n-\n-\tumem = calloc(1, sizeof(struct xsk_umem_info));\n-\tif (!umem) {\n-\t\tmunmap(bufs, umem_sz);\n-\t\texit_with_error(ENOMEM);\n-\t}\n-\tumem-\u003eframe_size = XSK_UMEM__DEFAULT_FRAME_SIZE;\n-\tret = xsk_configure_umem(ifobject, umem, bufs, umem_sz);\n-\tif (ret)\n-\t\texit_with_error(-ret);\n-\n-\txsk = calloc(1, sizeof(struct xsk_socket_info));\n-\tif (!xsk)\n-\t\tgoto out;\n-\tifobject-\u003ebind_flags = XDP_USE_NEED_WAKEUP | XDP_ZEROCOPY;\n-\tifobject-\u003erx_on = true;\n-\txsk-\u003erxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS;\n-\tret = xsk_configure_socket(xsk, umem, ifobject, false);\n-\tif (!ret)\n-\t\tzc_avail = true;\n-\n-\txsk_socket__delete(xsk-\u003exsk);\n-\tfree(xsk);\n-out:\n-\tmunmap(umem-\u003ebuffer, umem_sz);\n-\txsk_umem__delete(umem-\u003eumem);\n-\tfree(umem);\n-\treturn zc_avail;\n-}\n-\n-static struct option long_options[] = {\n-\t{\"interface\", required_argument, 0, 'i'},\n-\t{\"busy-poll\", no_argument, 0, 'b'},\n-\t{\"verbose\", no_argument, 0, 'v'},\n-\t{\"mode\", required_argument, 0, 'm'},\n-\t{\"list\", no_argument, 0, 'l'},\n-\t{\"test\", required_argument, 0, 't'},\n-\t{\"help\", no_argument, 0, 'h'},\n-\t{0, 0, 0, 0}\n-};\n-\n-static void print_usage(char **argv)\n-{\n-\tconst char *str =\n-\t\t\"  Usage: xskxceiver [OPTIONS]\\n\"\n-\t\t\"  Options:\\n\"\n-\t\t\"  -i, --interface      Use interface\\n\"\n-\t\t\"  -v, --verbose        Verbose output\\n\"\n-\t\t\"  -b, --busy-poll      Enable busy poll\\n\"\n-\t\t\"  -m, --mode           Run only mode skb, drv, or zc\\n\"\n-\t\t\"  -l, --list           List all available tests\\n\"\n-\t\t\"  -t, --test           Run a specific test. Enter number from -l option.\\n\"\n-\t\t\"  -h, --help           Display this help and exit\\n\";\n-\n-\tksft_print_msg(str, basename(argv[0]));\n-\tksft_exit_xfail();\n-}\n-\n-static bool validate_interface(struct ifobject *ifobj)\n-{\n-\tif (!strcmp(ifobj-\u003eifname, \"\"))\n-\t\treturn false;\n-\treturn true;\n-}\n-\n-static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj_rx, int argc,\n-\t\t\t       char **argv)\n-{\n-\tstruct ifobject *ifobj;\n-\tu32 interface_nb = 0;\n-\tint option_index, c;\n-\n-\topterr = 0;\n-\n-\tfor (;;) {\n-\t\tc = getopt_long(argc, argv, \"i:vbm:lt:\", long_options, \u0026option_index);\n-\t\tif (c == -1)\n-\t\t\tbreak;\n-\n-\t\tswitch (c) {\n-\t\tcase 'i':\n-\t\t\tif (interface_nb == 0)\n-\t\t\t\tifobj = ifobj_tx;\n-\t\t\telse if (interface_nb == 1)\n-\t\t\t\tifobj = ifobj_rx;\n-\t\t\telse\n-\t\t\t\tbreak;\n-\n-\t\t\tmemcpy(ifobj-\u003eifname, optarg,\n-\t\t\t       min_t(size_t, MAX_INTERFACE_NAME_CHARS, strlen(optarg)));\n-\n-\t\t\tifobj-\u003eifindex = if_nametoindex(ifobj-\u003eifname);\n-\t\t\tif (!ifobj-\u003eifindex)\n-\t\t\t\texit_with_error(errno);\n-\n-\t\t\tinterface_nb++;\n-\t\t\tbreak;\n-\t\tcase 'v':\n-\t\t\topt_verbose = true;\n-\t\t\tbreak;\n-\t\tcase 'b':\n-\t\t\tifobj_tx-\u003ebusy_poll = true;\n-\t\t\tifobj_rx-\u003ebusy_poll = true;\n-\t\t\tbreak;\n-\t\tcase 'm':\n-\t\t\tif (!strncmp(\"skb\", optarg, strlen(optarg)))\n-\t\t\t\topt_mode = TEST_MODE_SKB;\n-\t\t\telse if (!strncmp(\"drv\", optarg, strlen(optarg)))\n-\t\t\t\topt_mode = TEST_MODE_DRV;\n-\t\t\telse if (!strncmp(\"zc\", optarg, strlen(optarg)))\n-\t\t\t\topt_mode = TEST_MODE_ZC;\n-\t\t\telse\n-\t\t\t\tprint_usage(argv);\n-\t\t\tbreak;\n-\t\tcase 'l':\n-\t\t\topt_print_tests = true;\n-\t\t\tbreak;\n-\t\tcase 't':\n-\t\t\terrno = 0;\n-\t\t\topt_run_test = strtol(optarg, NULL, 0);\n-\t\t\tif (errno)\n-\t\t\t\tprint_usage(argv);\n-\t\t\tbreak;\n-\t\tcase 'h':\n-\t\tdefault:\n-\t\t\tprint_usage(argv);\n-\t\t}\n-\t}\n-}\n-\n-static void xsk_unload_xdp_programs(struct ifobject *ifobj)\n-{\n-\txsk_xdp_progs__destroy(ifobj-\u003exdp_progs);\n-}\n-\n-static void run_pkt_test(struct test_spec *test)\n-{\n-\tint ret;\n-\n-\tret = test-\u003etest_func(test);\n-\n-\tswitch (ret) {\n-\tcase TEST_PASS:\n-\t\tksft_test_result_pass(\"PASS: %s %s%s\\n\", mode_string(test), busy_poll_string(test),\n-\t\t\t\t      test-\u003ename);\n-\t\tbreak;\n-\tcase TEST_SKIP:\n-\t\tksft_test_result_skip(\"SKIP: %s %s%s\\n\", mode_string(test), busy_poll_string(test),\n-\t\t\t\t      test-\u003ename);\n-\t\tbreak;\n-\tcase TEST_FAILURE:\n-\t\tksft_test_result_fail(\"FAIL: %s %s%s\\n\", mode_string(test), busy_poll_string(test),\n-\t\t\t\t      test-\u003ename);\n-\t\tbreak;\n-\tdefault:\n-\t\tksft_test_result_fail(\"FAIL: %s %s%s -- Unexpected returned value (%d)\\n\",\n-\t\t\t\t      mode_string(test), busy_poll_string(test), test-\u003ename, ret);\n-\t}\n-\n-\tpkt_stream_restore_default(test);\n-}\n-\n-static bool is_xdp_supported(int ifindex)\n-{\n-\tint flags = XDP_FLAGS_DRV_MODE;\n-\n-\tLIBBPF_OPTS(bpf_link_create_opts, opts, .flags = flags);\n-\tstruct bpf_insn insns[2] = {\n-\t\tBPF_MOV64_IMM(BPF_REG_0, XDP_PASS),\n-\t\tBPF_EXIT_INSN()\n-\t};\n-\tint prog_fd, insn_cnt = ARRAY_SIZE(insns);\n-\tint err;\n-\n-\tprog_fd = bpf_prog_load(BPF_PROG_TYPE_XDP, NULL, \"GPL\", insns, insn_cnt, NULL);\n-\tif (prog_fd \u003c 0)\n-\t\treturn false;\n-\n-\terr = bpf_xdp_attach(ifindex, prog_fd, flags, NULL);\n-\tif (err) {\n-\t\tclose(prog_fd);\n-\t\treturn false;\n-\t}\n-\n-\tbpf_xdp_detach(ifindex, flags, NULL);\n-\tclose(prog_fd);\n-\n-\treturn true;\n-}\n-\n-static void print_tests(void)\n-{\n-\tu32 i;\n-\n-\tprintf(\"Tests:\\n\");\n-\tfor (i = 0; i \u003c ARRAY_SIZE(tests); i++)\n-\t\tprintf(\"%u: %s\\n\", i, tests[i].name);\n-\tfor (i = ARRAY_SIZE(tests); i \u003c ARRAY_SIZE(tests) + ARRAY_SIZE(ci_skip_tests); i++)\n-\t\tprintf(\"%u: %s\\n\", i, ci_skip_tests[i - ARRAY_SIZE(tests)].name);\n-}\n-\n-int main(int argc, char **argv)\n-{\n-\tconst size_t total_tests = ARRAY_SIZE(tests) + ARRAY_SIZE(ci_skip_tests);\n-\tu32 cache_line_size, max_frags, umem_tailroom;\n-\tstruct pkt_stream *rx_pkt_stream_default;\n-\tstruct pkt_stream *tx_pkt_stream_default;\n-\tstruct ifobject *ifobj_tx, *ifobj_rx;\n-\tu32 i, j, failed_tests = 0, nb_tests;\n-\tint modes = TEST_MODE_SKB + 1;\n-\tstruct test_spec test;\n-\tbool shared_netdev;\n-\tint ret;\n-\n-\t/* Use libbpf 1.0 API mode */\n-\tlibbpf_set_strict_mode(LIBBPF_STRICT_ALL);\n-\n-\tifobj_tx = ifobject_create();\n-\tif (!ifobj_tx)\n-\t\texit_with_error(ENOMEM);\n-\tifobj_rx = ifobject_create();\n-\tif (!ifobj_rx)\n-\t\texit_with_error(ENOMEM);\n-\n-\tsetlocale(LC_ALL, \"\");\n-\n-\tcache_line_size = read_procfs_val(SMP_CACHE_BYTES_PATH);\n-\tif (!cache_line_size) {\n-\t\tksft_print_msg(\"Can't get SMP_CACHE_BYTES from system, using default (64)\\n\");\n-\t\tcache_line_size = 64;\n-\t}\n-\n-\tmax_frags = read_procfs_val(MAX_SKB_FRAGS_PATH);\n-\tif (!max_frags) {\n-\t\tksft_print_msg(\"Can't get MAX_SKB_FRAGS from system, using default (17)\\n\");\n-\t\tmax_frags = 17;\n-\t}\n-\tifobj_tx-\u003emax_skb_frags = max_frags;\n-\tifobj_rx-\u003emax_skb_frags = max_frags;\n-\n-\t/* 48 bytes is a part of skb_shared_info w/o frags array;\n-\t * 16 bytes is sizeof(skb_frag_t)\n-\t */\n-\tumem_tailroom = ALIGN(48 + (max_frags * 16), cache_line_size);\n-\tifobj_tx-\u003eumem_tailroom = umem_tailroom;\n-\tifobj_rx-\u003eumem_tailroom = umem_tailroom;\n-\n-\tparse_command_line(ifobj_tx, ifobj_rx, argc, argv);\n-\n-\tif (opt_print_tests) {\n-\t\tprint_tests();\n-\t\tksft_exit_xpass();\n-\t}\n-\tif (opt_run_test != RUN_ALL_TESTS \u0026\u0026 opt_run_test \u003e= total_tests) {\n-\t\tksft_print_msg(\"Error: test %u does not exist.\\n\", opt_run_test);\n-\t\tksft_exit_xfail();\n-\t}\n-\n-\tshared_netdev = (ifobj_tx-\u003eifindex == ifobj_rx-\u003eifindex);\n-\tifobj_tx-\u003eshared_umem = shared_netdev;\n-\tifobj_rx-\u003eshared_umem = shared_netdev;\n-\n-\tif (!validate_interface(ifobj_tx) || !validate_interface(ifobj_rx))\n-\t\tprint_usage(argv);\n-\n-\tif (is_xdp_supported(ifobj_tx-\u003eifindex)) {\n-\t\tmodes++;\n-\t\tif (ifobj_zc_avail(ifobj_tx))\n-\t\t\tmodes++;\n-\t}\n-\n-\tret = get_hw_ring_size(ifobj_tx-\u003eifname, \u0026ifobj_tx-\u003ering);\n-\tif (!ret) {\n-\t\tifobj_tx-\u003ehw_ring_size_supp = true;\n-\t\tifobj_tx-\u003eset_ring.default_tx = ifobj_tx-\u003ering.tx_pending;\n-\t\tifobj_tx-\u003eset_ring.default_rx = ifobj_tx-\u003ering.rx_pending;\n-\t}\n-\n-\tif (init_iface(ifobj_rx, worker_testapp_validate_rx) ||\n-\t    init_iface(ifobj_tx, worker_testapp_validate_tx)) {\n-\t\tksft_print_msg(\"Error : can't initialize interfaces\\n\");\n-\t\tksft_exit_xfail();\n-\t}\n-\n-\ttest_init(\u0026test, ifobj_tx, ifobj_rx, 0, \u0026tests[0]);\n-\ttx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);\n-\trx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);\n-\tif (!tx_pkt_stream_default || !rx_pkt_stream_default)\n-\t\texit_with_error(ENOMEM);\n-\ttest.tx_pkt_stream_default = tx_pkt_stream_default;\n-\ttest.rx_pkt_stream_default = rx_pkt_stream_default;\n-\n-\tif (opt_run_test == RUN_ALL_TESTS)\n-\t\tnb_tests = total_tests;\n-\telse\n-\t\tnb_tests = 1;\n-\tif (opt_mode == TEST_MODE_ALL) {\n-\t\tksft_set_plan(modes * nb_tests);\n-\t} else {\n-\t\tif (opt_mode == TEST_MODE_DRV \u0026\u0026 modes \u003c= TEST_MODE_DRV) {\n-\t\t\tksft_print_msg(\"Error: XDP_DRV mode not supported.\\n\");\n-\t\t\tksft_exit_xfail();\n-\t\t}\n-\t\tif (opt_mode == TEST_MODE_ZC \u0026\u0026 modes \u003c= TEST_MODE_ZC) {\n-\t\t\tksft_print_msg(\"Error: zero-copy mode not supported.\\n\");\n-\t\t\tksft_exit_xfail();\n-\t\t}\n-\n-\t\tksft_set_plan(nb_tests);\n-\t}\n-\n-\tfor (i = 0; i \u003c modes; i++) {\n-\t\tif (opt_mode != TEST_MODE_ALL \u0026\u0026 i != opt_mode)\n-\t\t\tcontinue;\n-\n-\t\tfor (j = 0; j \u003c total_tests; j++) {\n-\t\t\tif (opt_run_test != RUN_ALL_TESTS \u0026\u0026 j != opt_run_test)\n-\t\t\t\tcontinue;\n-\n-\t\t\tif (j \u003c ARRAY_SIZE(tests))\n-\t\t\t\ttest_init(\u0026test, ifobj_tx, ifobj_rx, i, \u0026tests[j]);\n-\t\t\telse\n-\t\t\t\ttest_init(\u0026test, ifobj_tx, ifobj_rx, i,\n-\t\t\t\t\t  \u0026ci_skip_tests[j - ARRAY_SIZE(tests)]);\n-\t\t\trun_pkt_test(\u0026test);\n-\t\t\tusleep(USLEEP_MAX);\n-\n-\t\t\tif (test.fail)\n-\t\t\t\tfailed_tests++;\n-\t\t}\n-\t}\n-\n-\tif (ifobj_tx-\u003ehw_ring_size_supp)\n-\t\thw_ring_size_reset(ifobj_tx);\n-\n-\tpkt_stream_delete(tx_pkt_stream_default);\n-\tpkt_stream_delete(rx_pkt_stream_default);\n-\txsk_unload_xdp_programs(ifobj_tx);\n-\txsk_unload_xdp_programs(ifobj_rx);\n-\tifobject_delete(ifobj_tx);\n-\tifobject_delete(ifobj_rx);\n-\n-\tif (failed_tests)\n-\t\tksft_exit_fail();\n-\telse\n-\t\tksft_exit_pass();\n-}\ndiff --git a/tools/testing/selftests/drivers/net/README.rst b/tools/testing/selftests/drivers/net/README.rst\nindex c6bed9a985bc7..34a5053a9816d 100644\n--- a/tools/testing/selftests/drivers/net/README.rst\n+++ b/tools/testing/selftests/drivers/net/README.rst\n@@ -132,6 +132,13 @@ Communication channel dependent::\n   for netns - name of the \"remote\" namespace\n   for ssh - name/address of the remote host\n \n+Test specific variables\n+~~~~~~~~~~~~~~~~~~~~~~~\n+\n+Some tests read further variables from the same environment or\n+``net.config``. ``hw/xsk.py`` and its ``XSK_*`` variables are described in\n+``tools/testing/selftests/net/lib/xsk/README.rst``.\n+\n Example\n =======\n \ndiff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile\nindex 78bb0169350b2..b43bde9f309f2 100644\n--- a/tools/testing/selftests/drivers/net/hw/Makefile\n+++ b/tools/testing/selftests/drivers/net/hw/Makefile\n@@ -50,6 +50,7 @@ TEST_PROGS = \\\n \tuserns_devmem.py \\\n \tuso.py \\\n \txdp_metadata.py \\\n+\txsk.py \\\n \txsk_reconfig.py \\\n \t#\n \ndiff --git a/tools/testing/selftests/drivers/net/hw/config b/tools/testing/selftests/drivers/net/hw/config\nindex d89a9ba176558..fbf048d1d7323 100644\n--- a/tools/testing/selftests/drivers/net/hw/config\n+++ b/tools/testing/selftests/drivers/net/hw/config\n@@ -25,4 +25,5 @@ CONFIG_SYNC_FILE=y\n CONFIG_UDMABUF=y\n CONFIG_USER_NS=y\n CONFIG_VXLAN=y\n+CONFIG_XDP_SOCKETS=y\n CONFIG_XFRM_USER=y\ndiff --git a/tools/testing/selftests/drivers/net/hw/xsk.py b/tools/testing/selftests/drivers/net/hw/xsk.py\nnew file mode 100755\nindex 0000000000000..dd6bdbb1abeaf\n--- /dev/null\n+++ b/tools/testing/selftests/drivers/net/hw/xsk.py\n@@ -0,0 +1,402 @@\n+#!/usr/bin/env python3\n+# SPDX-License-Identifier: GPL-2.0\n+\n+\"\"\"AF_XDP zero-copy hardware tests with an SKB-mode XSK peer.\"\"\"\n+\n+import re\n+import shlex\n+import subprocess\n+import sys\n+import time\n+from pathlib import Path\n+\n+from lib.py import (EthtoolFamily, KsftFailEx, KsftNamedVariant, KsftSkipEx,\n+                    NetdevFamily, NetDrvEpEnv, bkg, cmd, defer, ethtool,\n+                    fd_read_timeout, ip, ksft_exit, ksft_pr, ksft_run,\n+                    ksft_variants, rand_port)\n+\n+CASE_TIMEOUT = 120\n+LISTEN_TIMEOUT = 30\n+NR_HUGEPAGES = 32\n+SKIP_CODE = 4\n+XSK_BIN = (Path(__file__).parent / \"../../../net/lib/xskxceiver\").resolve()\n+XSK_CASES = XSK_BIN.parent / \"xsk/test_xsk_case_defs.h\"\n+\n+\n+def _hardware_cases():\n+    defs = XSK_CASES.read_text()\n+    entries = re.findall(r\"(?m)^XSK_TEST_CASE\\((\\w+),\\s*\\w+,\\s*([^)]+)\\)\", defs)\n+    if not entries or len(entries) != defs.count(\"XSK_TEST_CASE(\"):\n+        raise KsftFailEx(f\"cannot parse {XSK_CASES}\")\n+    variants = []\n+    for test_id, (name, hw) in enumerate(entries):\n+        flags = {flag.strip() for flag in hw.split(\"|\")}\n+        if not flags \u003c= {\"0\", \"XSK_HW_RX\", \"XSK_HW_TX\"}:\n+            raise KsftFailEx(f\"invalid hardware directions for {name}: {hw}\")\n+        variants += [KsftNamedVariant(f\"{d}_{name.lower()}\", name, d, test_id)\n+                     for d in (\"rx\", \"tx\") if f\"XSK_HW_{d.upper()}\" in flags]\n+    return variants\n+\n+\n+def _management_addr(cfg):\n+    if cfg.env.get(\"REMOTE_TYPE\") == \"ssh\":\n+        return cfg.remote.name.rpartition(\"@\")[2]\n+    raise KsftSkipEx(\"AF_XDP hardware tests require an SSH remote\")\n+\n+\n+def _root_cmd(command, host=None, sudo=False, **kwargs):\n+    if sudo:\n+        command = \"sudo -n \" + command\n+    return cmd(command, host=host, **kwargs)\n+\n+\n+def _remote_binary(cfg, local_binary):\n+    binary = cfg.env.get(\"XSK_REMOTE_BIN\")\n+    if not binary:\n+        return cfg.remote.deploy(local_binary)\n+    if cfg.env.get(\"REMOTE_TYPE\") != \"ssh\":\n+        raise KsftSkipEx(\"XSK_REMOTE_BIN requires the SSH remote backend\")\n+    if cfg.env.get(\"XSK_REMOTE_DEPLOY\", \"1\") == \"0\":\n+        result = cmd(f\"test -x {shlex.quote(binary)}\", host=cfg.remote,\n+                     fail=False)\n+        if result.ret:\n+            raise KsftSkipEx(f\"remote xskxceiver is not executable: {binary}\")\n+        return binary\n+    upload = binary + \".upload\"\n+    cmd([\"scp\", \"-q\", str(local_binary), f\"{cfg.remote.name}:{upload}\"],\n+        shell=False)\n+    cmd(f\"mv -f {shlex.quote(upload)} {shlex.quote(binary)}\",\n+        host=cfg.remote)\n+    return binary\n+\n+\n+def _remote_sudo(cfg):\n+    return cfg.env.get(\"XSK_REMOTE_SUDO\", \"\").lower() not in (\"\", \"0\", \"false\")\n+\n+\n+def _restore_mtu(ifname, mtu, host=None, sudo=False):\n+    actual = ip(f\"link show dev {shlex.quote(ifname)}\", json=True,\n+                host=host)[0][\"mtu\"]\n+    if actual == mtu:\n+        return\n+    _root_cmd(f\"ip link set dev {shlex.quote(ifname)} mtu {mtu}\",\n+              host=host, sudo=sudo)\n+\n+\n+def _reserve_hugepages(host=None, sudo=False):\n+    have = int(cmd(\"sysctl -n vm.nr_hugepages\", host=host).stdout)\n+    if have \u003e= NR_HUGEPAGES:\n+        return\n+    _root_cmd(f\"sysctl -qw vm.nr_hugepages={NR_HUGEPAGES}\", host=host,\n+              sudo=sudo, fail=False)\n+    got = int(cmd(\"sysctl -n vm.nr_hugepages\", host=host).stdout)\n+    if got != have:\n+        defer(_root_cmd, f\"sysctl -qw vm.nr_hugepages={have}\", host=host,\n+              sudo=sudo)\n+    if got \u003c NR_HUGEPAGES:\n+        raise KsftSkipEx(f\"only {got}/{NR_HUGEPAGES} hugepages available\")\n+\n+\n+def _prefer_busy_poll(ifname):\n+    \"\"\"SO_PREFER_BUSY_POLL keeps the device IRQs masked between busy polls\n+    only while napi_defer_hard_irqs and gro_flush_timeout are set. Use the\n+    values that test_xsk.sh sets on veth.\"\"\"\n+    for knob, value in ((\"napi_defer_hard_irqs\", \"2\"),\n+                        (\"gro_flush_timeout\", \"200000\")):\n+        path = Path(\"/sys/class/net\", ifname, knob)\n+        orig = path.read_text(encoding=\"utf-8\").strip()\n+        if orig != value:\n+            path.write_text(value, encoding=\"utf-8\")\n+            defer(path.write_text, orig, encoding=\"utf-8\")\n+\n+\n+def _feature_state(ifname, feature, host=None):\n+    \"\"\"Read an ethtool -k feature. Parse the text output, as older ethtool\n+    versions can't print -k as JSON.\"\"\"\n+    output = ethtool(f\"-k {shlex.quote(ifname)}\", host=host).stdout\n+    match = re.search(rf\"^{re.escape(feature)}:\\s+(on|off)(.*)$\", output,\n+                      re.MULTILINE)\n+    if not match:\n+        raise KsftSkipEx(f\"ethtool does not report {feature} on {ifname}\")\n+    return {\"active\": match[1] == \"on\", \"fixed\": \"[fixed]\" in match[2]}\n+\n+\n+def _steer_udp(ifname, port, queue, host=None, sudo=False):\n+    dev = shlex.quote(ifname)\n+    rule = f\"ethtool -N {dev} flow-type udp4 dst-port {port} action {queue}\"\n+    # Look at ntuple-filters only once the rule is refused, as every command\n+    # on the remote costs a round trip.\n+    added = _root_cmd(rule, host=host, sudo=sudo, fail=False)\n+    if added.ret:\n+        ntuple = _feature_state(ifname, \"ntuple-filters\", host)\n+        if not ntuple[\"active\"]:\n+            if ntuple[\"fixed\"]:\n+                raise KsftSkipEx(\"NIC does not support ntuple filters\")\n+            _root_cmd(f\"ethtool -K {dev} ntuple-filters on\", host=host,\n+                      sudo=sudo)\n+            defer(_root_cmd, f\"ethtool -K {dev} ntuple-filters off\",\n+                  host=host, sudo=sudo)\n+            added = _root_cmd(rule, host=host, sudo=sudo, fail=False)\n+    if added.ret:\n+        ksft_pr(repr(added))\n+        raise KsftSkipEx(f\"cannot steer UDP flow to queue {queue} on {ifname}\")\n+    match = re.search(r\"ID (\\d+)\", added.stdout)\n+    if not match:\n+        raise KsftFailEx(f\"cannot identify new ntuple rule: {added.stdout}\")\n+    defer(_root_cmd, f\"ethtool -N {dev} delete {match[1]}\", host=host,\n+          sudo=sudo)\n+\n+\n+def _reserve_rx_queue(cfg, port):\n+    \"\"\"Move one RX queue out of default RSS and steer the test UDP flow.\"\"\"\n+    header = {\"dev-index\": cfg.ifindex}\n+    channels = cfg.ethnl.channels_get({\"header\": header})\n+    count = (channels.get(\"combined-count\") or 0) + (channels.get(\"rx-count\") or 0)\n+    if count \u003c 2:\n+        raise KsftSkipEx(\"RX queue isolation needs at least two channels\")\n+    queue = count - 1\n+\n+    try:\n+        rss = cfg.ethnl.rss_get({\"header\": header})\n+        saved = list(rss[\"indir\"])\n+    except Exception as exc:\n+        raise KsftSkipEx(f\"cannot read RSS indirection table: {exc}\") from exc\n+    if queue in saved:\n+        updated = [0 if entry == queue else entry for entry in saved]\n+        try:\n+            cfg.ethnl.rss_set({\"header\": header, \"indir\": updated})\n+        except Exception as exc:\n+            raise KsftSkipEx(f\"cannot reserve RX queue in RSS: {exc}\") from exc\n+        defer(cfg.ethnl.rss_set, {\"header\": header, \"indir\": saved})\n+        actual = cfg.ethnl.rss_get({\"header\": header}).get(\"indir\")\n+        if actual != updated:\n+            raise KsftSkipEx(\"NIC did not remove the reserved queue from RSS\")\n+\n+    _steer_udp(cfg.ifname, port, queue)\n+    return queue\n+\n+\n+def _case_args(cfg, name):\n+    if name != \"TOO_MANY_FRAGS\":\n+        return []\n+    try:\n+        info = cfg.netnl.dev_get({\"ifindex\": cfg.ifindex})\n+    except Exception as exc:\n+        raise KsftSkipEx(f\"cannot query DUT fragment limit: {exc}\") from exc\n+    max_frags = info.get(\"xdp-zc-max-segs\", 0)\n+    if max_frags \u003c= 1:\n+        raise KsftSkipEx(\"DUT does not advertise multi-buffer zero-copy\")\n+    return [\"--max-frags\", str(max_frags)]\n+\n+\n+def _idle_mtu(ifname, host=None):\n+    \"\"\"Return the MTU of a link that has no XDP program attached.\"\"\"\n+    info = ip(f\"link show dev {shlex.quote(ifname)}\", json=True, host=host)[0]\n+    if \"xdp\" in info:\n+        raise KsftSkipEx(f\"{ifname} already has an XDP program\")\n+    return info[\"mtu\"]\n+\n+\n+def _remote_idle_mtu(cfg):\n+    \"\"\"Look at the remote link once. Every case leaves its MTU as it found\n+    it and an endpoint replaces a program left behind by an earlier case,\n+    so looking again would only add a round trip to each case.\"\"\"\n+    if not hasattr(cfg, \"xsk_remote_mtu\"):\n+        cfg.xsk_remote_mtu = _idle_mtu(cfg.remote_ifname, cfg.remote)\n+    return cfg.xsk_remote_mtu\n+\n+\n+def _detach_xdp(ifname, mode, host=None, sudo=False):\n+    \"\"\"A killed endpoint leaves its XDP program behind; name the mode, as a\n+    bare \"xdp off\" only detaches driver mode on a native-XDP NIC.\"\"\"\n+    info = ip(f\"link show dev {shlex.quote(ifname)}\", json=True, host=host)[0]\n+    if \"xdp\" not in info:\n+        return\n+    _root_cmd(f\"ip link set dev {shlex.quote(ifname)} {mode} off\", host=host,\n+              sudo=sudo)\n+\n+\n+def _wait_remote_listen(remote, port):\n+    \"\"\"Read the remote endpoint's stderr up to the line it prints once it\n+    listens, as polling its sockets would cost a round trip per try. Return\n+    what was read and whether that line came.\"\"\"\n+    line = f\"Listening for XSK peer on port {port}\\n\".encode()\n+    fd = remote.proc.stderr.fileno()\n+    head = b\"\"\n+    deadline = time.monotonic() + LISTEN_TIMEOUT\n+    while line not in head:\n+        try:\n+            data = fd_read_timeout(fd, max(deadline - time.monotonic(), 0))\n+        except TimeoutError:\n+            break\n+        if not data:\n+            break\n+        head += data\n+    return head.decode(), line in head\n+\n+\n+def _require_zc(cfg):\n+    if not hasattr(cfg, \"xsk_zc\"):\n+        xdp_features = cfg.netnl.dev_get({\"ifindex\": cfg.ifindex})[\"xdp-features\"]\n+        cfg.xsk_zc = \"xsk-zerocopy\" in xdp_features\n+    if not cfg.xsk_zc:\n+        raise KsftSkipEx(\"NIC does not advertise AF_XDP zero-copy\")\n+\n+\n+def _remote_test_binary(cfg):\n+    if not hasattr(cfg, \"xsk_remote_bin\"):\n+        cfg.xsk_remote_bin = _remote_binary(cfg, XSK_BIN)\n+    return cfg.xsk_remote_bin\n+\n+\n+def _udp_port(cfg):\n+    port = int(cfg.env.get(\"XSK_UDP_PORT\", \"42567\"))\n+    if not 1 \u003c= port \u003c= 65535:\n+        raise KsftFailEx(\"XSK_UDP_PORT must be from 1 to 65535\")\n+    return port\n+\n+\n+def _setup_case(cfg, name, direction, port, busy_poll):\n+    \"\"\"Set up what this case alone needs; defer() undoes it when it ends.\n+    Return the DUT queue and the fallbacks for what the endpoints undo.\"\"\"\n+    sudo = _remote_sudo(cfg)\n+    local_mtu = _idle_mtu(cfg.ifname)\n+    remote_mtu = _remote_idle_mtu(cfg)\n+    if \"UNALIGNED\" in name:\n+        _reserve_hugepages()\n+        _reserve_hugepages(cfg.remote, sudo)\n+    if busy_poll:\n+        _prefer_busy_poll(cfg.ifname)\n+\n+    if direction == \"rx\":\n+        queue = _reserve_rx_queue(cfg, port)\n+    else:\n+        queue = 0\n+        _steer_udp(cfg.remote_ifname, port, 0, cfg.remote, sudo)\n+\n+    # Undo what a failed or killed endpoint may leave behind. Defers run in\n+    # reverse, so the XDP programs, which can cap the MTU, are detached first.\n+    fallbacks = [\n+        defer(_restore_mtu, cfg.ifname, local_mtu),\n+        defer(_restore_mtu, cfg.remote_ifname, remote_mtu, cfg.remote, sudo),\n+        defer(_detach_xdp, cfg.ifname, \"xdpdrv\"),\n+        defer(_detach_xdp, cfg.remote_ifname, \"xdpgeneric\", cfg.remote, sudo),\n+    ]\n+    return queue, fallbacks\n+\n+\n+def _udp_args(cfg, direction, port):\n+    if direction == \"rx\":\n+        src, dst = cfg.remote_addr_v[\"4\"], cfg.addr_v[\"4\"]\n+    else:\n+        src, dst = cfg.addr_v[\"4\"], cfg.remote_addr_v[\"4\"]\n+    return [\"--udp-src\", src, \"--udp-dst\", dst, \"--udp-port\", str(port)]\n+\n+\n+def _case_result(local, remote):\n+    if local and local.stdout:\n+        ksft_pr(local.stdout, line_pfx=\"dut|\")\n+    if local and local.stderr:\n+        ksft_pr(local.stderr, line_pfx=\"dut|\")\n+    if remote.stdout:\n+        ksft_pr(remote.stdout, line_pfx=\"remote|\")\n+    if remote.stderr:\n+        ksft_pr(remote.stderr, line_pfx=\"remote|\")\n+    if local is None:\n+        raise KsftFailEx(\"remote XSK endpoint did not listen on the control \"\n+                         f\"port, exit {remote.ret}\")\n+    if local.ret == SKIP_CODE or remote.ret == SKIP_CODE:\n+        raise KsftSkipEx(\"AF_XDP case unsupported by one endpoint\")\n+    if local.ret or remote.ret:\n+        raise KsftFailEx(f\"DUT exit {local.ret}, remote exit {remote.ret}\")\n+\n+\n+def _run_local(args):\n+    local = cmd(args, background=True, shell=False, fail=False)\n+    try:\n+        local.process(terminate=False, fail=False, timeout=CASE_TIMEOUT)\n+    except subprocess.TimeoutExpired as exc:\n+        local.proc.kill()\n+        local.process(terminate=False, fail=False)\n+        raise KsftFailEx(f\"DUT case timed out after {CASE_TIMEOUT}s\") from exc\n+    return local\n+\n+\n+def _run_endpoints(cfg, local_args, remote_args, control_port, fallbacks):\n+    local = None\n+    remote = bkg(shlex.join(remote_args), host=cfg.remote, exit_wait=True,\n+                 fail=False)\n+    try:\n+        head, listening = _wait_remote_listen(remote, control_port)\n+        if listening:\n+            local = _run_local(local_args)\n+            remote.process(terminate=False, fail=False, timeout=10)\n+    finally:\n+        if remote.ret is None:\n+            remote.process(terminate=True, fail=False)\n+    # _wait_remote_listen() took the start of stderr off the pipe.\n+    remote.stderr = head + remote.stderr\n+    if local and {local.ret, remote.ret} \u003c= {0, SKIP_CODE}:\n+        # Both endpoints detached XDP and restored the MTU when they exited.\n+        for fallback in fallbacks:\n+            fallback.cancel()\n+    _case_result(local, remote)\n+\n+\n+def test_xsk(cfg, name, direction, test_id, busy_poll=False):\n+    cfg.require_ipver(\"4\")\n+    sync_addr = _management_addr(cfg)\n+    udp_port = _udp_port(cfg)\n+    _require_zc(cfg)\n+    remote_bin = _remote_test_binary(cfg)\n+    case_args = _case_args(cfg, name)\n+    queue, fallbacks = _setup_case(cfg, name, direction, udp_port, busy_poll)\n+\n+    udp_args = _udp_args(cfg, direction, udp_port)\n+    control_port = rand_port()\n+    remote_args = [str(remote_bin), \"-i\", cfg.remote_ifname,\n+                   \"--hw\", \"--listen\", \"-m\", \"skb\",\n+                   \"-t\", str(test_id),\n+                   \"-e\", \"tx\" if direction == \"rx\" else \"rx\",\n+                   \"-p\", \"0.0.0.0\", \"-P\", str(control_port), *udp_args,\n+                   \"--peer-mac\", cfg.dev[\"address\"], \"--queue\", \"0\", *case_args]\n+    if _remote_sudo(cfg):\n+        remote_args = [\"sudo\", \"-n\"] + remote_args\n+    local_args = [str(XSK_BIN), \"-i\", cfg.ifname, \"--hw\", \"-m\", \"zc\",\n+                  \"-t\", str(test_id), \"-e\", direction,\n+                  \"-p\", sync_addr, \"-P\", str(control_port), *udp_args,\n+                  \"--peer-mac\", cfg.remote_dev[\"address\"],\n+                  \"--queue\", str(queue), *case_args]\n+    if busy_poll:\n+        local_args.append(\"-b\")\n+    _run_endpoints(cfg, local_args, remote_args, control_port, fallbacks)\n+\n+\n+def test_xsk_busy_poll(cfg, name, direction, test_id):\n+    \"\"\"Run a case with the DUT endpoint busy polling.\"\"\"\n+    test_xsk(cfg, name, direction, test_id, busy_poll=True)\n+\n+\n+def main():\n+    # ksft_run() rejects options it does not know, so take -b out first.\n+    busy_poll = \"-b\" in sys.argv[1:]\n+    if busy_poll:\n+        sys.argv.remove(\"-b\")\n+    test = test_xsk_busy_poll if busy_poll else test_xsk\n+    variants = ksft_variants(_hardware_cases())(test)\n+\n+    if any(arg in (\"-h\", \"-l\") for arg in sys.argv[1:]):\n+        ksft_run(cases=[variants])\n+        return\n+    if not XSK_BIN.exists():\n+        print(f\"1..0 # SKIP {XSK_BIN} was not built\")\n+        sys.exit(SKIP_CODE)\n+    with NetDrvEpEnv(__file__, nsim_test=False) as cfg:\n+        cfg.ethnl = EthtoolFamily()\n+        cfg.netnl = NetdevFamily()\n+        ksft_run(cases=[variants], args=(cfg,))\n+    ksft_exit()\n+\n+\n+if __name__ == \"__main__\":\n+    main()\ndiff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile\nindex 3ee3378f8b26e..f0e2cc1917e0e 100644\n--- a/tools/testing/selftests/net/Makefile\n+++ b/tools/testing/selftests/net/Makefile\n@@ -117,6 +117,7 @@ TEST_PROGS := \\\n \ttest_vxlan_under_vrf.sh \\\n \ttest_vxlan_vnifilter_notify.sh \\\n \ttest_vxlan_vnifiltering.sh \\\n+\ttest_xsk.sh \\\n \ttfo_passive.sh \\\n \ttraceroute.sh \\\n \ttxtimestamp.sh \\\n@@ -206,6 +207,7 @@ TEST_FILES := \\\n \tin_netns.sh \\\n \tlib.sh \\\n \tsettings \\\n+\txsk_prereqs.sh \\\n # end of TEST_FILES\n \n # YNL files, must be before \"include ..lib.mk\"\ndiff --git a/tools/testing/selftests/net/bpf.mk b/tools/testing/selftests/net/bpf.mk\nindex a4f6755dd8941..6a2f078fed9d6 100644\n--- a/tools/testing/selftests/net/bpf.mk\n+++ b/tools/testing/selftests/net/bpf.mk\n@@ -1,6 +1,7 @@\n # SPDX-License-Identifier: GPL-2.0\n # Rules to generate bpf objs\n CLANG ?= clang\n+BPFTOOL ?= bpftool\n SCRATCH_DIR := $(OUTPUT)/tools\n BUILD_DIR := $(SCRATCH_DIR)/build\n BPFDIR := $(top_srcdir)/tools/lib/bpf\n@@ -42,6 +43,10 @@ $(BPF_PROG_OBJS): $(OUTPUT)/%.o : %.c $(BPFOBJ) | $(MAKE_DIRS)\n \t$(Q)$(CLANG) -O2 -g --target=bpf $(CCINCLUDE) $(CLANG_SYS_INCLUDES) \\\n \t-c $\u003c -o $@\n \n+$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o\n+\t$(call msg,GEN-SKEL,,$@)\n+\t$(Q)$(BPFTOOL) gen skeleton $\u003c name $(notdir $*) \u003e $@\n+\n $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile)\t\t       \\\n \t   $(APIDIR)/linux/bpf.h\t\t\t\t\t       \\\n \t   | $(BUILD_DIR)/libbpf\ndiff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config\nindex 30d5fcb09a831..eddc8dcd7da63 100644\n--- a/tools/testing/selftests/net/config\n+++ b/tools/testing/selftests/net/config\n@@ -135,5 +135,6 @@ CONFIG_USER_NS=y\n CONFIG_VETH=y\n CONFIG_VLAN_8021Q=y\n CONFIG_VXLAN=m\n+CONFIG_XDP_SOCKETS=y\n CONFIG_XFRM_INTERFACE=m\n CONFIG_XFRM_USER=m\ndiff --git a/tools/testing/selftests/net/lib/.gitignore b/tools/testing/selftests/net/lib/.gitignore\nindex 6cd2b762af5d5..1106fef3041ff 100644\n--- a/tools/testing/selftests/net/lib/.gitignore\n+++ b/tools/testing/selftests/net/lib/.gitignore\n@@ -2,3 +2,5 @@\n csum\n gro\n xdp_helper\n+xsk_xdp_progs.skel.h\n+xskxceiver\ndiff --git a/tools/testing/selftests/net/lib/Makefile b/tools/testing/selftests/net/lib/Makefile\nindex ff83603397d06..0757a20612ae6 100644\n--- a/tools/testing/selftests/net/lib/Makefile\n+++ b/tools/testing/selftests/net/lib/Makefile\n@@ -18,8 +18,51 @@ TEST_GEN_FILES := \\\n \txdp_helper \\\n # end of TEST_GEN_FILES\n \n-TEST_INCLUDES := $(wildcard py/*.py sh/*.sh)\n+BPFTOOL ?= bpftool\n+HAS_BPFTOOL := $(shell command -v $(BPFTOOL) \u003e/dev/null 2\u003e\u00261 \u0026\u0026 echo y)\n+ifeq ($(HAS_BPFTOOL),y)\n+TEST_GEN_FILES += xskxceiver\n+else\n+$(warning excluding xskxceiver, bpftool not found)\n+endif\n+\n+TEST_INCLUDES := $(wildcard py/*.py sh/*.sh) xsk/test_xsk_case_defs.h\n \n include ../../lib.mk\n \n include ../bpf.mk\n+\n+# AF_XDP test engine shared by net/test_xsk.sh and drivers/net/hw/xsk.py.\n+XSK_DIR := xsk\n+XSK_BPF_OBJ := $(OUTPUT)/xsk_xdp_progs.bpf.o\n+XSK_SKEL := $(OUTPUT)/xsk_xdp_progs.skel.h\n+XSK_SOURCES := $(addprefix $(XSK_DIR)/,xskxceiver.c xsk.c test_xsk.c xsk_peer.c) \\\n+\t$(top_srcdir)/tools/lib/find_bit.c\n+XSK_HEADERS := $(wildcard $(XSK_DIR)/*.h)\n+\n+# xsk.py may copy xskxceiver to a host with an older libc.  Prefer a\n+# static binary when the required archives are installed.  XSK_STATIC=0/1\n+# can be used to override the probe.\n+PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config\n+XSK_STATIC_LIBS := $(shell $(PKG_CONFIG) libelf --static --libs 2\u003e/dev/null || \\\n+\techo -lelf -lz -lzstd) -lz\n+XSK_STATIC ?= $(shell echo 'int main(void) { return 0; }' | \\\n+\t$(CC) -x c - -static $(XSK_STATIC_LIBS) -o /dev/null 2\u003e/dev/null \u0026\u0026 echo 1)\n+ifeq ($(XSK_STATIC),1)\n+XSK_LDLIBS := -static $(XSK_STATIC_LIBS)\n+else\n+XSK_LDLIBS := $(shell $(PKG_CONFIG) libelf --libs 2\u003e/dev/null || echo -lelf) -lz\n+endif\n+\n+$(XSK_BPF_OBJ): $(XSK_DIR)/xsk_xdp_progs.bpf.c $(XSK_DIR)/xsk_xdp_common.h $(BPFOBJ)\n+\t$(call msg,BPF_PROG,,$@)\n+\t$(Q)$(CLANG) -O2 -g --target=bpf $(CCINCLUDE) $(CLANG_SYS_INCLUDES) \\\n+\t\t-Wno-compare-distinct-pointer-types -c $\u003c -o $@\n+\n+$(OUTPUT)/xskxceiver: $(XSK_SOURCES) $(XSK_HEADERS) $(XSK_SKEL) $(BPFOBJ)\n+\t$(call msg,CC,,$@)\n+\t$(Q)$(CC) $(CFLAGS) -I$(top_srcdir)/tools/include -I$(OUTPUT) \\\n+\t\t-I$(SCRATCH_DIR)/include \\\n+\t\t$(XSK_SOURCES) $(BPFOBJ) $(LDLIBS) $(XSK_LDLIBS) -o $@\n+\n+EXTRA_CLEAN += $(XSK_BPF_OBJ) $(XSK_SKEL)\ndiff --git a/tools/testing/selftests/net/lib/xsk/README.rst b/tools/testing/selftests/net/lib/xsk/README.rst\nnew file mode 100644\nindex 0000000000000..a4503e50a6c49\n--- /dev/null\n+++ b/tools/testing/selftests/net/lib/xsk/README.rst\n@@ -0,0 +1,130 @@\n+.. SPDX-License-Identifier: GPL-2.0\n+\n+==========\n+xskxceiver\n+==========\n+\n+The AF_XDP engine in ``net/lib/xsk`` is built as ``net/lib/xskxceiver``.\n+The generic ``net/test_xsk.sh`` test runs SKB and DRV modes over veth.\n+\n+Generic veth test\n+=================\n+\n+Two ``xskxceiver`` processes own the TX and RX veth interfaces. The TX\n+process listens on a TCP control port and the RX process connects. The\n+shell wrapper starts a fresh process pair for each mode and case. A small\n+control channel reports readiness, packet progress, and aborts. For example::\n+\n+  make -C tools/testing/selftests/net/lib\n+  cd tools/testing/selftests/net\n+  sudo ./test_xsk.sh\n+\n+The shell wrapper creates the veth pair. ``-m skb|drv`` selects a mode,\n+``-t`` selects a test by the name or number shown by ``xskxceiver -l``,\n+and ``-p N`` selects a fixed control port instead of the default random\n+port. The generic frame format is unchanged.\n+\n+Hardware zero-copy test\n+=======================\n+\n+``test_xsk_case_defs.h`` defines the cases for both ``xskxceiver`` and\n+``drivers/net/hw/xsk.py``, and the DUT directions in which the Python\n+runner runs each of them. The runner reads this list and owns the TAP\n+results.\n+\n+It starts one ``xskxceiver`` process on each host for each case. The DUT\n+runs in ZC mode; the remote runs in SKB mode and does not need zero-copy.\n+RX and TX cases are named separately in TAP. The hardware runner skips a\n+DUT that does not advertise AF_XDP zero-copy. The DUT endpoint binds with\n+``XDP_ZEROCOPY``, which fails instead of falling back to copy mode, so an\n+advertised device that cannot bind or run a case fails it.\n+\n+The remote XSK endpoint listens on a TCP control port and the DUT connects.\n+The listener prints a line on stderr once it listens, so ``xsk.py`` starts\n+the DUT endpoint without polling the remote for the port. The small\n+per-case channel reports readiness, packet progress, and aborts. It has no\n+capabilities or verdict handshake. ``xsk.py`` chooses the case, sets the\n+timeout, and reports the result from both process exit codes.\n+\n+Both XSK endpoints generate and validate raw IPv4/UDP frames with one fixed\n+UDP port, so ntuple rules can steer the test flow. They do not use AF_INET\n+sockets. On DUT RX cases ``xsk.py`` reserves the last RX queue outside RSS\n+and steers test traffic to it. On DUT TX cases it steers traffic to queue 0\n+on the remote receiver. The XDP programs redirect every packet, so the\n+tested link must carry no other traffic; SSH and the control channel go\n+to the ``REMOTE_ARGS`` host, which has to be reached over another link.\n+Each case sets up only what its direction needs and undoes it when the\n+case ends, so a setup failure skips only the cases that need that setup.\n+Each endpoint detaches its XDP program and restores any changed ring sizes\n+and the MTU before it exits. The SKB-mode remote endpoint only raises its\n+MTU when a case needs a larger one, as changing the MTU can reset the NIC.\n+The runner restores the RSS table, ntuple setting, and huge-page count.\n+After an endpoint fails or is killed, the runner also detaches the XDP\n+program and restores the MTU. The runner does not change channel counts.\n+A one-channel DUT skips RX cases because it has no queue to reserve\n+outside RSS.\n+\n+Setup\n+-----\n+\n+Build the engine on the DUT::\n+\n+  make -C tools/testing/selftests/net/lib\n+\n+A top-level selftests build with ``TARGETS=drivers/net/hw`` includes\n+``net/lib`` as well. The binary is linked statically when the static\n+libraries are installed; ``XSK_STATIC=0`` or ``XSK_STATIC=1`` overrides the\n+probe.\n+\n+Configure the usual driver test variables in\n+``tools/testing/selftests/drivers/net/hw/net.config`` or the environment::\n+\n+  NETIF=eth0\n+  LOCAL_V4=192.0.2.1\n+  REMOTE_V4=192.0.2.2\n+  REMOTE_TYPE=ssh\n+  REMOTE_ARGS=user@remote.example.com\n+  XSK_REMOTE_BIN=/path/to/remote/xskxceiver\n+  XSK_REMOTE_SUDO=1\n+\n+Run as root on the DUT::\n+\n+  cd tools/testing/selftests/drivers/net/hw\n+  sudo ./xsk.py -t test_xsk.rx_send_receive\n+\n+``./xsk.py -l`` lists the case names. Omit ``-t`` to run the full hardware\n+matrix. Set the variables in ``net.config`` when using ``sudo`` so they are\n+available to the test process.\n+\n+``./xsk.py -b`` runs the same cases as ``test_xsk_busy_poll`` instead, with\n+the DUT endpoint busy polling as in the busy-poll pass of ``test_xsk.sh``.\n+Each case then sets ``napi_defer_hard_irqs`` and ``gro_flush_timeout`` on\n+the DUT to the values ``test_xsk.sh`` uses on veth and restores them when\n+it ends. The remote endpoint does not busy poll.\n+\n+Each case starts its remote endpoint over SSH, and a DUT TX case also adds\n+and removes a flow steering rule on the remote. SSH connection sharing for\n+the remote host (``ControlMaster``, ``ControlPath`` and ``ControlPersist``\n+in ssh_config(5)) avoids a new SSH login for each remote command. With\n+``sudo``, that is root's SSH configuration.\n+\n+The remote host needs AF_XDP in SKB mode and BPF. ``xsk.py`` copies the\n+DUT's ``xskxceiver`` binary to the remote, so both hosts must have\n+compatible architectures. ``XSK_REMOTE_BIN`` chooses a fixed destination\n+path for that copy. Set ``XSK_REMOTE_DEPLOY=0`` to use a binary built on\n+the remote from the same test case definitions instead. ``XSK_REMOTE_SUDO=1``\n+runs the remote endpoint and setup commands through passwordless ``sudo -n``;\n+omit it when SSH logs in as root. The DUT needs ntuple and RSS support for\n+RX cases, while the remote needs ntuple support for DUT TX cases. The test\n+uses ``NetDrvEpEnv`` and the networking selftest Python helpers for setup\n+and rollback.\n+\n+The DUT uses the SSH host name to connect to the remote control listener.\n+``XSK_UDP_PORT`` changes the fixed test UDP port (default 42567). The remote\n+listens on all addresses for control.\n+\n+The hardware list covers baseline traffic, 2K frames, poll, headroom,\n+invalid TX descriptors, TX invalid-descriptor statistics, metadata, 9K,\n+and unaligned traffic. For ``TOO_MANY_FRAGS``, the runner reads the DUT's\n+``xdp-zc-max-segs`` value and passes it to both endpoint processes so the\n+SKB peer validates the same packet stream without a capabilities exchange.\ndiff --git a/tools/testing/selftests/bpf/prog_tests/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c\nsimilarity index 86%\nrename from tools/testing/selftests/bpf/prog_tests/test_xsk.c\nrename to tools/testing/selftests/net/lib/xsk/test_xsk.c\nindex 4549358cc8c21..3e2ca21bdb99f 100644\n--- a/tools/testing/selftests/bpf/prog_tests/test_xsk.c\n+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c\n@@ -1,20 +1,22 @@\n // SPDX-License-Identifier: GPL-2.0\n+#include \u003carpa/inet.h\u003e\n #include \u003cbpf/bpf.h\u003e\n #include \u003cerrno.h\u003e\n #include \u003clinux/bitmap.h\u003e\n #include \u003clinux/if_link.h\u003e\n #include \u003clinux/mman.h\u003e\n #include \u003clinux/netdev.h\u003e\n+#include \u003clinux/ip.h\u003e\n+#include \u003clinux/udp.h\u003e\n #include \u003cpoll.h\u003e\n-#include \u003cpthread.h\u003e\n #include \u003cstring.h\u003e\n #include \u003csys/mman.h\u003e\n #include \u003csys/socket.h\u003e\n #include \u003csys/time.h\u003e\n #include \u003cunistd.h\u003e\n \n-#include \"network_helpers.h\"\n #include \"test_xsk.h\"\n+#include \"xsk_peer.h\"\n #include \"xsk_xdp_common.h\"\n #include \"xsk_xdp_progs.skel.h\"\n \n@@ -27,8 +29,11 @@\n #define PKT_DUMP_NB_TO_PRINT\t\t16\n /* Just to align the data in the packet */\n #define PKT_HDR_SIZE\t\t\t(sizeof(struct ethhdr) + 2)\n+#define UDP_PKT_HDR_SIZE\t\t(sizeof(struct ethhdr) + sizeof(struct iphdr) + \\\n+\t\t\t\t sizeof(struct udphdr) + 2)\n #define POLL_TMOUT\t\t\t1000\n #define THREAD_TMOUT\t\t\t3\n+#define HW_THREAD_TMOUT\t\t20\n #define UMEM_HEADROOM_TEST_SIZE\t\t128\n #define XSK_DESC__INVALID_OPTION\t(0xffff)\n #define XSK_UMEM__INVALID_FRAME_SIZE\t(MAX_ETH_JUMBO_SIZE + 1)\n@@ -36,12 +41,47 @@\n #define XSK_UMEM__MAX_FRAME_SIZE\t(4 * 1024)\n \n static const u8 g_mac[ETH_ALEN] = {0x55, 0x44, 0x33, 0x22, 0x11, 0x00};\n+static bool udp_packets;\n+static struct in_addr udp_src_ip;\n+static struct in_addr udp_dst_ip;\n+static u16 udp_port;\n+static u32 pkt_hdr_size = PKT_HDR_SIZE;\n+static u32 max_frags_override;\n \n bool opt_verbose;\n-pthread_barrier_t barr;\n-pthread_mutex_t pacing_mutex = PTHREAD_MUTEX_INITIALIZER;\n \n int pkts_in_flight;\n+static struct xsk_peer *ctrl_peer;\n+static bool hw_test;\n+\n+void xsk_set_endpoint(struct xsk_peer *peer, bool hardware)\n+{\n+\tctrl_peer = peer;\n+\thw_test = hardware;\n+}\n+\n+static int pacing_rx_progress(u32 pkts)\n+{\n+\tint err = xsk_peer_rx_progress(ctrl_peer, pkts);\n+\n+\tif (err)\n+\t\tksft_print_msg(\"RX control channel failed: %d (%s)\\n\", err,\n+\t\t\t       strerror(-err));\n+\treturn err;\n+}\n+\n+static int pacing_tx_sync(void)\n+{\n+\tint acked = xsk_peer_tx_sync(ctrl_peer);\n+\n+\tif (acked \u003c 0) {\n+\t\tksft_print_msg(\"TX control channel failed: %d (%s)\\n\", acked,\n+\t\t\t       strerror(-acked));\n+\t\treturn acked;\n+\t}\n+\tpkts_in_flight -= acked;\n+\treturn 0;\n+}\n \n /* The payload is a word consisting of a packet sequence number in the upper\n  * 16-bits and a intra packet data sequence number in the lower 16 bits. So the 3rd packet's\n@@ -57,11 +97,70 @@ static void write_payload(void *dest, u32 pkt_nb, u32 start, u32 size)\n \t\tptr[i] = htonl(pkt_nb \u003c\u003c 16 | (i + start));\n }\n \n-static void gen_eth_hdr(struct xsk_socket_info *xsk, struct ethhdr *eth_hdr)\n+int xsk_set_udp_packet_format(const char *src_ip, const char *dst_ip, u16 port)\n+{\n+\tif (inet_pton(AF_INET, src_ip, \u0026udp_src_ip) != 1 ||\n+\t    inet_pton(AF_INET, dst_ip, \u0026udp_dst_ip) != 1 || !port)\n+\t\treturn -EINVAL;\n+\tudp_packets = true;\n+\tudp_port = port;\n+\tpkt_hdr_size = UDP_PKT_HDR_SIZE;\n+\treturn 0;\n+}\n+\n+void xsk_set_max_frags(u32 max_frags)\n {\n+\tmax_frags_override = max_frags;\n+}\n+\n+static u16 ip_checksum(const void *buf, size_t len)\n+{\n+\tconst u16 *word = buf;\n+\tu32 sum = 0;\n+\n+\twhile (len \u003e 1) {\n+\t\tsum += *word++;\n+\t\tlen -= sizeof(*word);\n+\t}\n+\twhile (sum \u003e\u003e 16)\n+\t\tsum = (sum \u0026 0xffff) + (sum \u003e\u003e 16);\n+\treturn ~sum;\n+}\n+\n+static void gen_pkt_hdr(struct xsk_socket_info *xsk, void *data, u32 total_len)\n+{\n+\tstruct ethhdr *eth_hdr = data;\n+\tstruct udphdr udp = {\n+\t\t.source = htons(udp_port),\n+\t\t.dest = htons(udp_port),\n+\t\t.len = htons(total_len - sizeof(*eth_hdr) -\n+\t\t\t     sizeof(struct iphdr)),\n+\t};\n+\tstruct iphdr ip = {\n+\t\t.version = 4,\n+\t\t.ihl = 5,\n+\t\t.ttl = 64,\n+\t\t.protocol = IPPROTO_UDP,\n+\t\t.tot_len = htons(total_len - sizeof(*eth_hdr)),\n+\t\t.saddr = udp_src_ip.s_addr,\n+\t\t.daddr = udp_dst_ip.s_addr,\n+\t};\n+\tu8 *ptr = data;\n+\n \tmemcpy(eth_hdr-\u003eh_dest, xsk-\u003edst_mac, ETH_ALEN);\n \tmemcpy(eth_hdr-\u003eh_source, xsk-\u003esrc_mac, ETH_ALEN);\n-\teth_hdr-\u003eh_proto = htons(ETH_P_LOOPBACK);\n+\tif (!udp_packets) {\n+\t\teth_hdr-\u003eh_proto = htons(ETH_P_LOOPBACK);\n+\t\treturn;\n+\t}\n+\n+\teth_hdr-\u003eh_proto = htons(ETH_P_IP);\n+\tip.check = ip_checksum(\u0026ip, sizeof(ip));\n+\tptr += sizeof(*eth_hdr);\n+\tmemcpy(ptr, \u0026ip, sizeof(ip));\n+\tptr += sizeof(ip);\n+\tmemcpy(ptr, \u0026udp, sizeof(udp));\n+\tmemset(ptr + sizeof(udp), 0, 2);\n }\n \n static u32 mode_to_xdp_flags(enum test_mode mode)\n@@ -101,10 +200,6 @@ int xsk_configure_umem(struct ifobject *ifobj, struct xsk_umem_info *umem, void\n \t\treturn ret;\n \n \tumem-\u003ebuffer = buffer;\n-\tif (ifobj-\u003eshared_umem \u0026\u0026 ifobj-\u003erx_on) {\n-\t\tumem-\u003ebase_addr = umem_size(umem);\n-\t\tumem-\u003enext_buffer = umem_size(umem);\n-\t}\n \n \treturn 0;\n }\n@@ -115,8 +210,8 @@ static u64 umem_alloc_buffer(struct xsk_umem_info *umem)\n \n \taddr = umem-\u003enext_buffer;\n \tumem-\u003enext_buffer += umem-\u003eframe_size;\n-\tif (umem-\u003enext_buffer \u003e= umem-\u003ebase_addr + umem_size(umem))\n-\t\tumem-\u003enext_buffer = umem-\u003ebase_addr;\n+\tif (umem-\u003enext_buffer \u003e= umem_size(umem))\n+\t\tumem-\u003enext_buffer = 0;\n \n \treturn addr;\n }\n@@ -170,7 +265,8 @@ int xsk_configure_socket(struct xsk_socket_info *xsk, struct xsk_umem_info *umem\n \n \ttxr = ifobject-\u003etx_on ? \u0026xsk-\u003etx : NULL;\n \trxr = ifobject-\u003erx_on ? \u0026xsk-\u003erx : NULL;\n-\treturn xsk_socket__create(\u0026xsk-\u003exsk, ifobject-\u003eifindex, 0, umem-\u003eumem, rxr, txr, \u0026cfg);\n+\treturn xsk_socket__create(\u0026xsk-\u003exsk, ifobject-\u003eifindex, ifobject-\u003equeue_id,\n+\t\t\t\t  umem-\u003eumem, rxr, txr, \u0026cfg);\n }\n \n static int set_ring_size(struct ifobject *ifobj)\n@@ -195,6 +291,10 @@ static int set_ring_size(struct ifobject *ifobj)\n \n int hw_ring_size_reset(struct ifobject *ifobj)\n {\n+\tif (ifobj-\u003ering.tx_pending == ifobj-\u003eset_ring.default_tx \u0026\u0026\n+\t    ifobj-\u003ering.rx_pending == ifobj-\u003eset_ring.default_rx)\n+\t\treturn 0;\n+\n \tifobj-\u003ering.tx_pending = ifobj-\u003eset_ring.default_tx;\n \tifobj-\u003ering.rx_pending = ifobj-\u003eset_ring.default_rx;\n \treturn set_ring_size(ifobj);\n@@ -207,7 +307,8 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,\n \n \tfor (i = 0; i \u003c MAX_INTERFACES; i++) {\n \t\tstruct ifobject *ifobj = i ? ifobj_rx : ifobj_tx;\n-\t\tstruct xsk_umem_info *umem_real;\n+\t\tstruct ifobject *peer = i ? ifobj_tx : ifobj_rx;\n+\t\tstruct xsk_umem_info *umem;\n \n \t\tifobj-\u003exsk = \u0026ifobj-\u003exsk_arr[0];\n \t\tifobj-\u003euse_poll = false;\n@@ -224,33 +325,37 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,\n \t\t\tifobj-\u003etx_on = false;\n \t\t}\n \n-\t\tumem_real = ifobj-\u003exsk_arr[0].umem_real;\n-\t\tmemset(umem_real, 0, sizeof(*umem_real));\n+\t\tumem = ifobj-\u003exsk_arr[0].umem;\n+\t\tmemset(umem, 0, sizeof(*umem));\n \t\tfor (j = 0; j \u003c MAX_SOCKETS; j++) {\n \t\t\tstruct xsk_socket_info *xsk = \u0026ifobj-\u003exsk_arr[j];\n \n \t\t\tmemset(xsk, 0, sizeof(*xsk));\n \t\t\txsk-\u003erxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS;\n-\t\t\tif (j == 0)\n-\t\t\t\txsk-\u003eumem_real = umem_real;\n-\t\t\txsk-\u003eumem = umem_real;\n+\t\t\txsk-\u003eumem = umem;\n \t\t\txsk-\u003ebatch_size = DEFAULT_BATCH_SIZE;\n \t\t\tif (i == 0)\n \t\t\t\txsk-\u003epkt_stream = test-\u003etx_pkt_stream_default;\n \t\t\telse\n \t\t\t\txsk-\u003epkt_stream = test-\u003erx_pkt_stream_default;\n \n-\t\t\tmemcpy(xsk-\u003esrc_mac, g_mac, ETH_ALEN);\n-\t\t\tmemcpy(xsk-\u003edst_mac, g_mac, ETH_ALEN);\n-\t\t\txsk-\u003esrc_mac[5] += ((j * 2) + 0);\n-\t\t\txsk-\u003edst_mac[5] += ((j * 2) + 1);\n+\t\t\tif (hw_test) {\n+\t\t\t\tmemcpy(xsk-\u003esrc_mac, ifobj-\u003ecaps.mac, ETH_ALEN);\n+\t\t\t\tmemcpy(xsk-\u003edst_mac, peer-\u003ecaps.mac, ETH_ALEN);\n+\t\t\t} else {\n+\t\t\t\tmemcpy(xsk-\u003esrc_mac, g_mac, ETH_ALEN);\n+\t\t\t\tmemcpy(xsk-\u003edst_mac, g_mac, ETH_ALEN);\n+\t\t\t\txsk-\u003esrc_mac[5] += ((j * 2) + 0);\n+\t\t\t\txsk-\u003edst_mac[5] += ((j * 2) + 1);\n+\t\t\t}\n \t\t}\n \n \t\tifobj-\u003exsk-\u003eumem-\u003enum_frames = DEFAULT_UMEM_BUFFERS;\n \t\tifobj-\u003exsk-\u003eumem-\u003eframe_size = XSK_UMEM__DEFAULT_FRAME_SIZE;\n \t}\n \n-\tif (ifobj_tx-\u003ehw_ring_size_supp)\n+\tif (ifobj_has_cap(ifobj_tx, XSK_CAP_HW_RING) \u0026\u0026\n+\t    ifobj_is_local(ifobj_tx))\n \t\thw_ring_size_reset(ifobj_tx);\n \n \ttest-\u003eifobj_tx = ifobj_tx;\n@@ -258,7 +363,6 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,\n \ttest-\u003ecurrent_step = 0;\n \ttest-\u003etotal_steps = 1;\n \ttest-\u003enb_sockets = 1;\n-\ttest-\u003efail = false;\n \ttest-\u003eset_ring = false;\n \ttest-\u003eadjust_tail = false;\n \ttest-\u003eadjust_tail_support = false;\n@@ -326,26 +430,42 @@ static void test_spec_set_xdp_prog(struct test_spec *test, struct bpf_program *x\n \ttest-\u003exskmap_tx = xskmap_tx;\n }\n \n-static int test_spec_set_mtu(struct test_spec *test, int mtu)\n+/* An MTU change can reset a NIC. A hardware SKB-mode endpoint runs a case at\n+ * any larger MTU, as generic XDP does not limit it, so only raise its MTU.\n+ */\n+static bool mtu_change_needed(struct ifobject *ifobj, enum test_mode mode, int mtu)\n+{\n+\tif (hw_test \u0026\u0026 mode == TEST_MODE_SKB)\n+\t\treturn ifobj-\u003edev_mtu \u003c mtu;\n+\treturn ifobj-\u003edev_mtu != mtu;\n+}\n+\n+static int test_spec_set_mtu_ifobj(struct ifobject *ifobj, enum test_mode mode, int mtu)\n {\n \tint err;\n \n-\tif (test-\u003eifobj_rx-\u003emtu != mtu) {\n-\t\terr = xsk_set_mtu(test-\u003eifobj_rx-\u003eifindex, mtu);\n-\t\tif (err)\n-\t\t\treturn err;\n-\t\ttest-\u003eifobj_rx-\u003emtu = mtu;\n-\t}\n-\tif (test-\u003eifobj_tx-\u003emtu != mtu) {\n-\t\terr = xsk_set_mtu(test-\u003eifobj_tx-\u003eifindex, mtu);\n+\tif (ifobj_is_local(ifobj) \u0026\u0026 mtu_change_needed(ifobj, mode, mtu)) {\n+\t\terr = xsk_set_mtu(ifobj-\u003eifindex, mtu);\n \t\tif (err)\n \t\t\treturn err;\n-\t\ttest-\u003eifobj_tx-\u003emtu = mtu;\n+\t\tifobj-\u003edev_mtu = mtu;\n \t}\n \n+\tifobj-\u003emtu = mtu;\n \treturn 0;\n }\n \n+static int test_spec_set_mtu(struct test_spec *test, int mtu)\n+{\n+\tint err;\n+\n+\terr = test_spec_set_mtu_ifobj(test-\u003eifobj_rx, test-\u003emode, mtu);\n+\tif (err)\n+\t\treturn err;\n+\n+\treturn test_spec_set_mtu_ifobj(test-\u003eifobj_tx, test-\u003emode, mtu);\n+}\n+\n void pkt_stream_reset(struct pkt_stream *pkt_stream)\n {\n \tif (pkt_stream) {\n@@ -375,6 +495,9 @@ static struct pkt *pkt_stream_get_next_rx_pkt(struct pkt_stream *pkt_stream, u32\n \n void pkt_stream_delete(struct pkt_stream *pkt_stream)\n {\n+\tif (!pkt_stream)\n+\t\treturn;\n+\n \tfree(pkt_stream-\u003epkts);\n \tfree(pkt_stream);\n }\n@@ -625,7 +748,7 @@ static void pkt_stream_cancel(struct pkt_stream *pkt_stream)\n }\n \n static void pkt_generate(struct xsk_socket_info *xsk, struct xsk_umem_info *umem, u64 addr, u32 len,\n-\t\t\t u32 pkt_nb, u32 bytes_written)\n+\t\t\t u32 total_len, u32 pkt_nb, u32 bytes_written)\n {\n \tvoid *data = xsk_umem__get_data(umem-\u003ebuffer, addr);\n \n@@ -633,12 +756,12 @@ static void pkt_generate(struct xsk_socket_info *xsk, struct xsk_umem_info *umem\n \t\treturn;\n \n \tif (!bytes_written) {\n-\t\tgen_eth_hdr(xsk, data);\n+\t\tgen_pkt_hdr(xsk, data, total_len);\n \n-\t\tlen -= PKT_HDR_SIZE;\n-\t\tdata += PKT_HDR_SIZE;\n+\t\tlen -= pkt_hdr_size;\n+\t\tdata += pkt_hdr_size;\n \t} else {\n-\t\tbytes_written -= PKT_HDR_SIZE;\n+\t\tbytes_written -= pkt_hdr_size;\n \t}\n \n \twrite_payload(data, pkt_nb, bytes_written, len);\n@@ -741,7 +864,7 @@ static void pkt_dump(void *pkt, u32 len, bool eth_header)\n \t\tfor (i = 0; i \u003c ETH_ALEN; i++)\n \t\t\tksft_print_msg(\"%02X\", ethhdr-\u003eh_source[i]);\n \n-\t\tdata = pkt + PKT_HDR_SIZE;\n+\t\tdata = pkt + pkt_hdr_size;\n \t} else {\n \t\tdata = pkt;\n \t}\n@@ -825,8 +948,6 @@ static bool is_frag_valid(struct xsk_umem_info *umem, u64 addr, u32 len, u32 exp\n \tvoid *data = xsk_umem__get_data(umem-\u003ebuffer, addr);\n \tu64 umem_sz = umem_size(umem);\n \n-\taddr -= umem-\u003ebase_addr;\n-\n \tif (addr \u003e= umem_sz || addr + len \u003e umem_sz) {\n \t\tksft_print_msg(\"Frag invalid addr: %llx len: %u\\n\",\n \t\t\t       (unsigned long long)addr, len);\n@@ -840,11 +961,15 @@ static bool is_frag_valid(struct xsk_umem_info *umem, u64 addr, u32 len, u32 exp\n \n \tpkt_data = data;\n \tif (!bytes_processed) {\n-\t\tpkt_data += PKT_HDR_SIZE / sizeof(*pkt_data);\n-\t\tlen -= PKT_HDR_SIZE;\n+\t\tif (len \u003c pkt_hdr_size + sizeof(*pkt_data))\n+\t\t\treturn false;\n+\t\tpkt_data += pkt_hdr_size / sizeof(*pkt_data);\n+\t\tlen -= pkt_hdr_size;\n \t} else {\n-\t\tbytes_processed -= PKT_HDR_SIZE;\n+\t\tbytes_processed -= pkt_hdr_size;\n \t}\n+\tif (len \u003c sizeof(*pkt_data))\n+\t\treturn false;\n \n \texpected_seqnum = bytes_processed / sizeof(*pkt_data);\n \tseqnum = ntohl(*pkt_data) \u0026 0xffff;\n@@ -994,6 +1119,9 @@ static int __receive_pkts(struct test_spec *test, struct xsk_socket_info *xsk)\n \tfds.fd = xsk_socket__fd(xsk-\u003exsk);\n \tfds.events = POLLIN;\n \n+\tif (pacing_rx_progress(0))\n+\t\treturn TEST_FAILURE;\n+\n \tret = kick_rx(xsk);\n \tif (ret)\n \t\treturn TEST_FAILURE;\n@@ -1093,9 +1221,8 @@ static int __receive_pkts(struct test_spec *test, struct xsk_socket_info *xsk)\n \tif (ifobj-\u003erelease_rx)\n \t\txsk_ring_cons__release(\u0026xsk-\u003erx, frags_processed);\n \n-\tpthread_mutex_lock(\u0026pacing_mutex);\n-\tpkts_in_flight -= pkts_sent;\n-\tpthread_mutex_unlock(\u0026pacing_mutex);\n+\tif (pacing_rx_progress(pkts_sent))\n+\t\treturn TEST_FAILURE;\n \tpkts_sent = 0;\n \n \treturn TEST_CONTINUE;\n@@ -1122,7 +1249,7 @@ bool all_packets_received(struct test_spec *test, struct xsk_socket_info *xsk, u\n \n static int receive_pkts(struct test_spec *test)\n {\n-\tstruct timeval tv_end, tv_now, tv_timeout = {THREAD_TMOUT, 0};\n+\tstruct timeval tv_end, tv_now, tv_timeout = {hw_test ? HW_THREAD_TMOUT : THREAD_TMOUT, 0};\n \tDECLARE_BITMAP(bitmap, test-\u003enb_sockets);\n \tstruct xsk_socket_info *xsk;\n \tu32 sock_num = 0;\n@@ -1164,13 +1291,16 @@ static int __send_pkts(struct ifobject *ifobject, struct xsk_socket_info *xsk,\n \t\t       bool test_timeout)\n {\n \tu32 i, idx = 0, valid_pkts = 0, valid_frags = 0, buffer_len;\n-\tstruct xsk_umem_info *umem = ifobject-\u003exsk_arr[0].umem_real;\n+\tstruct xsk_umem_info *umem = ifobject-\u003exsk_arr[0].umem;\n \tstruct pkt_stream *pkt_stream = xsk-\u003epkt_stream;\n \tbool use_poll = ifobject-\u003euse_poll;\n \tstruct pollfd fds = { };\n \tint ret;\n \n \tbuffer_len = pkt_get_buffer_len(umem, pkt_stream-\u003emax_pkt_len);\n+\tif (pacing_tx_sync())\n+\t\treturn TEST_FAILURE;\n+\n \t/* pkts_in_flight might be negative if many invalid packets are sent */\n \tif (pkts_in_flight \u003e= (int)((umem_size(umem) - xsk-\u003ebatch_size * buffer_len) /\n \t    buffer_len) \u0026\u0026 !test_timeout) {\n@@ -1236,8 +1366,8 @@ static int __send_pkts(struct ifobject *ifobject, struct xsk_socket_info *xsk,\n \t\t\t\ttx_desc-\u003eoptions = 0;\n \t\t\t}\n \t\t\tif (pkt-\u003evalid)\n-\t\t\t\tpkt_generate(xsk, umem, tx_desc-\u003eaddr, tx_desc-\u003elen, pkt-\u003epkt_nb,\n-\t\t\t\t\t     bytes_written);\n+\t\t\t\tpkt_generate(xsk, umem, tx_desc-\u003eaddr, tx_desc-\u003elen, pkt-\u003elen,\n+\t\t\t\t\t     pkt-\u003epkt_nb, bytes_written);\n \t\t\tbytes_written += tx_desc-\u003elen;\n \n \t\t\tprint_verbose(\"Tx addr: %llx len: %u options: %u pkt_nb: %u\\n\",\n@@ -1255,9 +1385,7 @@ static int __send_pkts(struct ifobject *ifobject, struct xsk_socket_info *xsk,\n \t\tvalid_frags += nb_frags;\n \t}\n \n-\tpthread_mutex_lock(\u0026pacing_mutex);\n \tpkts_in_flight += valid_pkts;\n-\tpthread_mutex_unlock(\u0026pacing_mutex);\n \n \txsk_ring_prod__submit(\u0026xsk-\u003etx, i);\n \txsk-\u003eoutstanding_tx += valid_frags;\n@@ -1286,7 +1414,7 @@ static int __send_pkts(struct ifobject *ifobject, struct xsk_socket_info *xsk,\n \n static int wait_for_tx_completion(struct xsk_socket_info *xsk)\n {\n-\tstruct timeval tv_end, tv_now, tv_timeout = {THREAD_TMOUT, 0};\n+\tstruct timeval tv_end, tv_now, tv_timeout = {hw_test ? HW_THREAD_TMOUT : THREAD_TMOUT, 0};\n \tint ret;\n \n \tret = gettimeofday(\u0026tv_now, NULL);\n@@ -1334,9 +1462,6 @@ static int send_pkts(struct test_spec *test, struct ifobject *ifobject)\n \t\t\tif (ret != TEST_CONTINUE)\n \t\t\t\treturn ret;\n \n-\t\t\tif (test-\u003efail)\n-\t\t\t\treturn TEST_FAILURE;\n-\n \t\t\tif (!test-\u003epoll_tmout) {\n \t\t\t\tret = wait_for_tx_completion(\u0026ifobject-\u003exsk_arr[i]);\n \t\t\t\tif (ret)\n@@ -1468,12 +1593,12 @@ static int validate_tx_invalid_descs(struct ifobject *ifobject)\n }\n \n static int xsk_configure(struct test_spec *test, struct ifobject *ifobject,\n-\t\t\t  struct xsk_umem_info *umem, bool tx)\n+\t\t\t  struct xsk_umem_info *umem)\n {\n \tint i, ret;\n \n \tfor (i = 0; i \u003c test-\u003enb_sockets; i++) {\n-\t\tbool shared = (ifobject-\u003eshared_umem \u0026\u0026 tx) ? true : !!i;\n+\t\tbool shared = !!i;\n \t\tu32 ctr = 0;\n \n \t\twhile (ctr++ \u003c SOCK_RECONF_CTR) {\n@@ -1497,31 +1622,6 @@ static int xsk_configure(struct test_spec *test, struct ifobject *ifobject,\n \treturn 0;\n }\n \n-static int thread_common_ops_tx(struct test_spec *test, struct ifobject *ifobject)\n-{\n-\tstruct xsk_umem_info *umem_rx, *umem_tx;\n-\tint ret;\n-\n-\tif (!test-\u003eifobj_rx || !test-\u003eifobj_rx-\u003exsk_arr[0].umem-\u003eumem) {\n-\t\tksft_print_msg(\"Error: RX UMEM is not initialized before shared-UMEM TX setup\\n\");\n-\t\treturn -EINVAL;\n-\t}\n-\n-\tumem_rx = test-\u003eifobj_rx-\u003exsk_arr[0].umem;\n-\tumem_tx = ifobject-\u003exsk_arr[0].umem_real;\n-\tmemcpy(umem_tx, umem_rx, sizeof(*umem_tx));\n-\tumem_tx-\u003ebase_addr = 0;\n-\tumem_tx-\u003enext_buffer = 0;\n-\n-\tret = xsk_configure(test, ifobject, umem_rx, true);\n-\tif (ret)\n-\t\treturn ret;\n-\tifobject-\u003exsk = \u0026ifobject-\u003exsk_arr[0];\n-\tifobject-\u003exskmap = test-\u003eifobj_rx-\u003exskmap;\n-\n-\treturn 0;\n-}\n-\n static int xsk_populate_fill_ring(struct xsk_umem_info *umem, struct pkt_stream *pkt_stream,\n \t\t\t\t   bool fill_up)\n {\n@@ -1547,7 +1647,7 @@ static int xsk_populate_fill_ring(struct xsk_umem_info *umem, struct pkt_stream\n \t\t\tif (!pkt) {\n \t\t\t\tif (!fill_up)\n \t\t\t\t\tbreak;\n-\t\t\t\taddr = filled * umem-\u003eframe_size + umem-\u003ebase_addr;\n+\t\t\t\taddr = filled * umem-\u003eframe_size;\n \t\t\t} else if (pkt-\u003eoffset \u003e= 0) {\n \t\t\t\taddr = pkt-\u003eoffset % umem-\u003eframe_size + umem_alloc_buffer(umem);\n \t\t\t} else {\n@@ -1584,9 +1684,6 @@ static int thread_common_ops(struct test_spec *test, struct ifobject *ifobject)\n \tif (umem-\u003eunaligned_mode)\n \t\tmmap_flags |= MAP_HUGETLB | MAP_HUGE_2MB;\n \n-\tif (ifobject-\u003eshared_umem)\n-\t\tumem_sz *= 2;\n-\n \tmmap_sz = umem-\u003eunaligned_mode ?\n \t\tceil_u64(umem_sz, HUGEPAGE_SIZE) * HUGEPAGE_SIZE : umem_sz;\n \n@@ -1600,7 +1697,7 @@ static int thread_common_ops(struct test_spec *test, struct ifobject *ifobject)\n \tif (ret)\n \t\treturn ret;\n \n-\tret = xsk_configure(test, ifobject, umem, false);\n+\tret = xsk_configure(test, ifobject, umem);\n \tif (ret)\n \t\treturn ret;\n \n@@ -1623,40 +1720,28 @@ static int thread_common_ops(struct test_spec *test, struct ifobject *ifobject)\n \treturn 0;\n }\n \n-void *worker_testapp_validate_tx(void *arg)\n+static int testapp_validate_tx_endpoint(struct test_spec *test,\n+\t\t\t\t\tstruct ifobject *ifobject)\n {\n-\tstruct test_spec *test = (struct test_spec *)arg;\n-\tstruct ifobject *ifobject = test-\u003eifobj_tx;\n \tint err;\n \n \tif (test-\u003ecurrent_step == 1) {\n-\t\tif (!ifobject-\u003eshared_umem) {\n-\t\t\tif (thread_common_ops(test, ifobject)) {\n-\t\t\t\ttest-\u003efail = true;\n-\t\t\t\tpthread_exit(NULL);\n-\t\t\t}\n-\t\t} else {\n-\t\t\tif (thread_common_ops_tx(test, ifobject)) {\n-\t\t\t\ttest-\u003efail = true;\n-\t\t\t\tpthread_exit(NULL);\n-\t\t\t}\n-\t\t}\n+\t\terr = thread_common_ops(test, ifobject);\n+\t\tif (err)\n+\t\t\treturn err;\n \t}\n \n \terr = send_pkts(test, ifobject);\n \n \tif (!err \u0026\u0026 ifobject-\u003evalidation_func)\n \t\terr = ifobject-\u003evalidation_func(ifobject);\n-\tif (err)\n-\t\ttest-\u003efail = true;\n \n-\tpthread_exit(NULL);\n+\treturn err;\n }\n \n-void *worker_testapp_validate_rx(void *arg)\n+static int testapp_prepare_rx_endpoint(struct test_spec *test,\n+\t\t\t\t       struct ifobject *ifobject)\n {\n-\tstruct test_spec *test = (struct test_spec *)arg;\n-\tstruct ifobject *ifobject = test-\u003eifobj_rx;\n \tint err;\n \n \tif (test-\u003ecurrent_step == 1) {\n@@ -1669,36 +1754,86 @@ void *worker_testapp_validate_rx(void *arg)\n \t\t\t\t       strerror(-err));\n \t}\n \n-\tif (test-\u003euse_barrier)\n-\t\tpthread_barrier_wait(\u0026barr);\n+\treturn err;\n+}\n \n-\t/* We leave only now in case of error to avoid getting stuck in the barrier */\n-\tif (err) {\n-\t\ttest-\u003efail = true;\n-\t\tpthread_exit(NULL);\n-\t}\n+static int testapp_validate_rx_endpoint(struct test_spec *test,\n+\t\t\t\t\tstruct ifobject *ifobject)\n+{\n+\tbool supported;\n+\tint err;\n \n \terr = receive_pkts(test);\n \n \tif (!err \u0026\u0026 ifobject-\u003evalidation_func)\n \t\terr = ifobject-\u003evalidation_func(ifobject);\n+\tif (!err)\n+\t\treturn TEST_PASS;\n+\n+\tif (!test-\u003eadjust_tail)\n+\t\treturn err;\n+\n+\tif (is_adjust_tail_supported(ifobject-\u003exdp_progs, \u0026supported))\n+\t\treturn TEST_FAILURE;\n+\tif (!supported) {\n+\t\ttest-\u003eadjust_tail_support = false;\n+\t\treturn TEST_PASS;\n+\t}\n+\n+\treturn err;\n+}\n+\n+static int sync_endpoints(struct test_spec *test)\n+{\n+\tint err = xsk_peer_ready(ctrl_peer);\n+\n+\tif (err)\n+\t\tksft_print_msg(\"Endpoint synchronization failed at step %u: %d (%s)\\n\",\n+\t\t\t       test-\u003ecurrent_step, err, strerror(-err));\n+\treturn err;\n+}\n+\n+int worker_testapp_validate_tx(struct test_spec *test)\n+{\n+\tint err;\n+\n+\terr = sync_endpoints(test);\n+\tif (err)\n+\t\treturn err;\n \n+\terr = testapp_validate_tx_endpoint(test, test-\u003eifobj_tx);\n \tif (err) {\n-\t\tif (!test-\u003eadjust_tail) {\n-\t\t\ttest-\u003efail = true;\n-\t\t} else {\n-\t\t\tbool supported;\n+\t\tksft_print_msg(\"TX endpoint traffic failed at step %u: %d\\n\",\n+\t\t\t       test-\u003ecurrent_step, err);\n+\t\txsk_peer_abort(ctrl_peer);\n+\t}\n+\treturn err;\n+}\n \n-\t\t\tif (is_adjust_tail_supported(ifobject-\u003exdp_progs, \u0026supported))\n-\t\t\t\ttest-\u003efail = true;\n-\t\t\telse if (!supported)\n-\t\t\t\ttest-\u003eadjust_tail_support = false;\n-\t\t\telse\n-\t\t\t\ttest-\u003efail = true;\n-\t\t}\n+int worker_testapp_validate_rx(struct test_spec *test)\n+{\n+\tstruct ifobject *ifobject = test-\u003eifobj_rx;\n+\tint err;\n+\n+\terr = testapp_prepare_rx_endpoint(test, ifobject);\n+\tif (err) {\n+\t\tksft_print_msg(\"RX endpoint setup failed at step %u: %d\\n\",\n+\t\t\t       test-\u003ecurrent_step, err);\n+\t\txsk_peer_abort(ctrl_peer);\n+\t\treturn err;\n \t}\n \n-\tpthread_exit(NULL);\n+\terr = sync_endpoints(test);\n+\tif (err)\n+\t\treturn err;\n+\n+\terr = testapp_validate_rx_endpoint(test, ifobject);\n+\tif (err) {\n+\t\tksft_print_msg(\"RX endpoint traffic failed at step %u: %d\\n\",\n+\t\t\t       test-\u003ecurrent_step, err);\n+\t\txsk_peer_abort(ctrl_peer);\n+\t}\n+\treturn err;\n }\n \n static void testapp_clean_xsk_umem(struct ifobject *ifobj)\n@@ -1753,13 +1888,17 @@ static int xsk_attach_xdp_progs(struct test_spec *test, struct ifobject *ifobj_r\n {\n \tint err = 0;\n \n-\tif (xdp_prog_changed_rx(test)) {\n+\tif (ifobj_is_local(ifobj_rx) \u0026\u0026 xdp_prog_changed_rx(test)) {\n \t\terr = xsk_reattach_xdp(ifobj_rx, test-\u003exdp_prog_rx, test-\u003exskmap_rx, test-\u003emode);\n \t\tif (err)\n \t\t\treturn err;\n \t}\n \n-\tif (!ifobj_tx || ifobj_tx-\u003eshared_umem)\n+\tif (!ifobj_tx || !ifobj_is_local(ifobj_tx))\n+\t\treturn 0;\n+\n+\t/* A ZC driver can require XDP to be enabled for TX wakeups. */\n+\tif (hw_test \u0026\u0026 !ifobj_tx-\u003erx_on \u0026\u0026 test-\u003emode != TEST_MODE_ZC)\n \t\treturn 0;\n \n \tif (xdp_prog_changed_tx(test))\n@@ -1772,7 +1911,7 @@ static void clean_sockets(struct test_spec *test, struct ifobject *ifobj)\n {\n \tu32 i;\n \n-\tif (!ifobj || !test)\n+\tif (!ifobj || !test || !ifobj_is_local(ifobj))\n \t\treturn;\n \n \tfor (i = 0; i \u003c test-\u003enb_sockets; i++)\n@@ -1784,29 +1923,32 @@ static void clean_umem(struct test_spec *test, struct ifobject *ifobj1, struct i\n \tif (!ifobj1)\n \t\treturn;\n \n-\ttestapp_clean_xsk_umem(ifobj1);\n-\tif (ifobj2 \u0026\u0026 !ifobj2-\u003eshared_umem)\n+\tif (ifobj_is_local(ifobj1))\n+\t\ttestapp_clean_xsk_umem(ifobj1);\n+\tif (ifobj2 \u0026\u0026 ifobj_is_local(ifobj2))\n \t\ttestapp_clean_xsk_umem(ifobj2);\n }\n \n static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *ifobj1,\n \t\t\t\t      struct ifobject *ifobj2)\n {\n-\tpthread_t t0, t1;\n+\tu32 mbuf_cap;\n \tint err;\n \n-\tif (test-\u003emtu \u003e MAX_ETH_PKT_SIZE) {\n-\t\tif (test-\u003emode == TEST_MODE_ZC \u0026\u0026 (!ifobj1-\u003emulti_buff_zc_supp ||\n-\t\t\t\t\t\t   (ifobj2 \u0026\u0026 !ifobj2-\u003emulti_buff_zc_supp))) {\n-\t\t\tksft_print_msg(\"Multi buffer for zero-copy not supported.\\n\");\n-\t\t\treturn TEST_SKIP;\n-\t\t}\n-\t\tif (test-\u003emode != TEST_MODE_ZC \u0026\u0026 (!ifobj1-\u003emulti_buff_supp ||\n-\t\t\t\t\t\t   (ifobj2 \u0026\u0026 !ifobj2-\u003emulti_buff_supp))) {\n-\t\t\tksft_print_msg(\"Multi buffer not supported.\\n\");\n-\t\t\treturn TEST_SKIP;\n-\t\t}\n+\tif (test-\u003emtu \u003c= MAX_ETH_PKT_SIZE)\n+\t\tgoto skip_mbuf_check;\n+\n+\tmbuf_cap = test-\u003emode == TEST_MODE_ZC ? XSK_CAP_MBUF_ZC :\n+\t\t\t\t\t\tXSK_CAP_MBUF;\n+\n+\tif (!ifobj_has_cap(ifobj1, mbuf_cap) ||\n+\t    (ifobj2 \u0026\u0026 !ifobj_has_cap(ifobj2, mbuf_cap))) {\n+\t\tksft_print_msg(\"Multi buffer%s not supported.\\n\",\n+\t\t\t\tmbuf_cap == XSK_CAP_MBUF_ZC ? \" for zero-copy\" : \"\");\n+\t\treturn TEST_SKIP;\n \t}\n+\n+skip_mbuf_check:\n \terr = test_spec_set_mtu(test, test-\u003emtu);\n \tif (err) {\n \t\tksft_print_msg(\"Error, could not set mtu.\\n\");\n@@ -1819,51 +1961,27 @@ static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *i\n \t\t\t       err, strerror(-err));\n \t\treturn TEST_FAILURE;\n \t}\n-\ttest-\u003euse_barrier = !!ifobj2;\n-\n-\tif (test-\u003euse_barrier) {\n-\t\tif (pthread_barrier_init(\u0026barr, NULL, 2))\n-\t\t\treturn TEST_FAILURE;\n \n+\tif (ifobj2)\n \t\tpkt_stream_reset(ifobj2-\u003exsk-\u003epkt_stream);\n-\t}\n-\n \ttest-\u003ecurrent_step++;\n \tpkt_stream_reset(ifobj1-\u003exsk-\u003epkt_stream);\n \tpkts_in_flight = 0;\n \n-\t/*Spawn RX thread */\n-\tpthread_create(\u0026t0, NULL, ifobj1-\u003efunc_ptr, test);\n-\n-\tif (test-\u003euse_barrier) {\n-\t\tpthread_barrier_wait(\u0026barr);\n-\t\tif (pthread_barrier_destroy(\u0026barr)) {\n-\t\t\ttest-\u003euse_barrier = false;\n-\t\t\tpthread_join(t0, NULL);\n-\t\t\tclean_sockets(test, ifobj1);\n-\t\t\tclean_umem(test, ifobj1, NULL);\n-\t\t\treturn TEST_FAILURE;\n-\t\t}\n-\t}\n-\n-\tif (ifobj2) {\n-\t\t/*Spawn TX thread */\n-\t\tpthread_create(\u0026t1, NULL, ifobj2-\u003efunc_ptr, test);\n-\t\tpthread_join(t1, NULL);\n-\t}\n-\n-\tpthread_join(t0, NULL);\n-\n-\tif (test-\u003etotal_steps == test-\u003ecurrent_step || test-\u003efail) {\n+\t/* In a one-sided step, the idle endpoint only keeps in step. */\n+\tif (ifobj_is_local(ifobj1))\n+\t\terr = ifobj1-\u003efunc_ptr(test);\n+\telse if (ifobj2 \u0026\u0026 ifobj_is_local(ifobj2))\n+\t\terr = ifobj2-\u003efunc_ptr(test);\n+\telse\n+\t\terr = sync_endpoints(test);\n+\tif (test-\u003etotal_steps == test-\u003ecurrent_step || err) {\n \t\tclean_sockets(test, ifobj1);\n \t\tclean_sockets(test, ifobj2);\n \t\tclean_umem(test, ifobj1, ifobj2);\n \t}\n \n-\tif (test-\u003efail)\n-\t\treturn TEST_FAILURE;\n-\n-\treturn TEST_PASS;\n+\treturn err ? TEST_FAILURE : TEST_PASS;\n }\n \n static int testapp_validate_traffic(struct test_spec *test)\n@@ -1871,15 +1989,16 @@ static int testapp_validate_traffic(struct test_spec *test)\n \tstruct ifobject *ifobj_rx = test-\u003eifobj_rx;\n \tstruct ifobject *ifobj_tx = test-\u003eifobj_tx;\n \n-\tif ((ifobj_rx-\u003exsk-\u003eumem-\u003eunaligned_mode \u0026\u0026 !ifobj_rx-\u003eunaligned_supp) ||\n-\t    (ifobj_tx-\u003exsk-\u003eumem-\u003eunaligned_mode \u0026\u0026 !ifobj_tx-\u003eunaligned_supp)) {\n+\tif (ifobj_rx-\u003exsk-\u003eumem-\u003eunaligned_mode \u0026\u0026\n+\t    !ifobj_has_cap(ifobj_rx, XSK_CAP_UNALIGNED)) {\n \t\tksft_print_msg(\"No huge pages present.\\n\");\n \t\treturn TEST_SKIP;\n \t}\n \n \tif (test-\u003eset_ring) {\n-\t\tif (ifobj_tx-\u003ehw_ring_size_supp) {\n-\t\t\tif (set_ring_size(ifobj_tx)) {\n+\t\tif (ifobj_has_cap(ifobj_tx, XSK_CAP_HW_RING)) {\n+\t\t\tif (ifobj_is_local(ifobj_tx) \u0026\u0026\n+\t\t\t    set_ring_size(ifobj_tx)) {\n \t\t\t\tksft_print_msg(\"Failed to change HW ring size.\\n\");\n \t\t\t\treturn TEST_FAILURE;\n \t\t\t}\n@@ -1912,7 +2031,7 @@ int testapp_teardown(struct test_spec *test)\n \n static void swap_directions(struct ifobject **ifobj1, struct ifobject **ifobj2)\n {\n-\tthread_func_t tmp_func_ptr = (*ifobj1)-\u003efunc_ptr;\n+\ttest_func_t tmp_func_ptr = (*ifobj1)-\u003efunc_ptr;\n \tstruct ifobject *tmp_ifobj = (*ifobj1);\n \n \t(*ifobj1)-\u003efunc_ptr = (*ifobj2)-\u003efunc_ptr;\n@@ -1951,6 +2070,9 @@ static int swap_xsk_resources(struct test_spec *test)\n \ttest-\u003eifobj_tx-\u003exsk = \u0026test-\u003eifobj_tx-\u003exsk_arr[1];\n \ttest-\u003eifobj_rx-\u003exsk = \u0026test-\u003eifobj_rx-\u003exsk_arr[1];\n \n+\tif (!ifobj_is_local(test-\u003eifobj_rx))\n+\t\treturn TEST_PASS;\n+\n \tret = xsk_update_xskmap(test-\u003eifobj_rx-\u003exskmap, test-\u003eifobj_rx-\u003exsk-\u003exsk, 0);\n \tif (ret)\n \t\treturn TEST_FAILURE;\n@@ -1984,7 +2106,7 @@ int testapp_headroom(struct test_spec *test)\n int testapp_stats_rx_dropped(struct test_spec *test)\n {\n \tstruct xsk_umem_info *umem = test-\u003eifobj_rx-\u003exsk-\u003eumem;\n-\tu32 umem_tr = test-\u003eifobj_tx-\u003eumem_tailroom;\n+\tu32 umem_tr = xsk_get_cap(test, umem_tailroom);\n \n \tif (test-\u003emode == TEST_MODE_ZC) {\n \t\tksft_print_msg(\"Can not run RX_DROPPED test for ZC mode\\n\");\n@@ -2164,12 +2286,6 @@ int testapp_invalid_desc(struct test_spec *test)\n \t\tpkts[8].valid = false;\n \t}\n \n-\tif (test-\u003eifobj_tx-\u003eshared_umem) {\n-\t\tpkts[4].offset += umem_sz;\n-\t\tpkts[5].offset += umem_sz;\n-\t\tpkts[6].offset += umem_sz;\n-\t}\n-\n \tif (pkt_stream_generate_custom(test, pkts, ARRAY_SIZE(pkts)))\n \t\treturn TEST_FAILURE;\n \treturn testapp_validate_traffic(test);\n@@ -2209,6 +2325,10 @@ int testapp_xdp_shared_umem(struct test_spec *test)\n \tstruct xsk_xdp_progs *skel_tx = test-\u003eifobj_tx-\u003exdp_progs;\n \tint ret;\n \n+\t/* The XDP program picks the socket from the synthetic destination MAC. */\n+\tif (hw_test)\n+\t\treturn TEST_SKIP;\n+\n \ttest-\u003etotal_steps = 1;\n \ttest-\u003enb_sockets = 2;\n \n@@ -2228,28 +2348,14 @@ int testapp_xdp_shared_umem(struct test_spec *test)\n \n int testapp_poll_txq_tmout(struct test_spec *test)\n {\n-\tbool shared_umem = test-\u003eifobj_tx-\u003eshared_umem;\n-\tint ret;\n-\n \ttest-\u003epoll_tmout = true;\n-\t/*\n-\t * POLL_TXQ_FULL exercises TX timeout setup in isolation.\n-\t * Keep TX out of shared-UMEM mode here so TX setup does not require\n-\t * RX UMEM to be initialized first.\n-\t */\n-\ttest-\u003eifobj_tx-\u003eshared_umem = false;\n \ttest-\u003eifobj_tx-\u003euse_poll = true;\n \t/* create invalid frame by set umem frame_size and pkt length equal to 2048 */\n \ttest-\u003eifobj_tx-\u003exsk-\u003eumem-\u003eframe_size = 2048;\n-\tif (pkt_stream_replace(test, 2 * DEFAULT_PKT_CNT, 2048)) {\n-\t\ttest-\u003eifobj_tx-\u003eshared_umem = shared_umem;\n+\tif (pkt_stream_replace(test, 2 * DEFAULT_PKT_CNT, 2048))\n \t\treturn TEST_FAILURE;\n-\t}\n-\n-\tret = testapp_validate_traffic_single_thread(test, test-\u003eifobj_tx);\n-\ttest-\u003eifobj_tx-\u003eshared_umem = shared_umem;\n \n-\treturn ret;\n+\treturn testapp_validate_traffic_single_thread(test, test-\u003eifobj_tx);\n }\n \n int testapp_poll_rxq_tmout(struct test_spec *test)\n@@ -2265,10 +2371,12 @@ int testapp_too_many_frags(struct test_spec *test)\n \tu32 max_frags, i;\n \tint ret = TEST_FAILURE;\n \n-\tif (test-\u003emode == TEST_MODE_ZC) {\n-\t\tmax_frags = test-\u003eifobj_tx-\u003exdp_zc_max_segs;\n+\tif (max_frags_override) {\n+\t\tmax_frags = max_frags_override;\n+\t} else if (test-\u003emode == TEST_MODE_ZC) {\n+\t\tmax_frags = xsk_get_cap(test, xdp_zc_max_segs);\n \t} else {\n-\t\tmax_frags = test-\u003eifobj_tx-\u003emax_skb_frags;\n+\t\tmax_frags = xsk_get_cap(test, max_skb_frags);\n \t\tmax_frags += 1;\n \t}\n \n@@ -2319,7 +2427,7 @@ int testapp_too_many_frags(struct test_spec *test)\n \treturn ret;\n }\n \n-static int xsk_load_xdp_programs(struct ifobject *ifobj)\n+int xsk_load_xdp_programs(struct ifobject *ifobj)\n {\n \tifobj-\u003exdp_progs = xsk_xdp_progs__open_and_load();\n \tif (libbpf_get_error(ifobj-\u003exdp_progs))\n@@ -2328,7 +2436,6 @@ static int xsk_load_xdp_programs(struct ifobject *ifobj)\n \treturn 0;\n }\n \n-/* Simple test */\n static bool hugepages_present(void)\n {\n \tsize_t mmap_sz = 2 * DEFAULT_UMEM_BUFFERS * XSK_UMEM__DEFAULT_FRAME_SIZE;\n@@ -2344,21 +2451,13 @@ static bool hugepages_present(void)\n \treturn true;\n }\n \n-int init_iface(struct ifobject *ifobj, thread_func_t func_ptr)\n+static int detect_ifobj_caps(struct ifobject *ifobj)\n {\n \tLIBBPF_OPTS(bpf_xdp_query_opts, query_opts);\n \tint err;\n \n-\tifobj-\u003efunc_ptr = func_ptr;\n-\n-\terr = xsk_load_xdp_programs(ifobj);\n-\tif (err) {\n-\t\tksft_print_msg(\"Error loading XDP program\\n\");\n-\t\treturn err;\n-\t}\n-\n \tif (hugepages_present())\n-\t\tifobj-\u003eunaligned_supp = true;\n+\t\tifobj_set_cap(ifobj, XSK_CAP_UNALIGNED);\n \n \terr = bpf_xdp_query(ifobj-\u003eifindex, XDP_FLAGS_DRV_MODE, \u0026query_opts);\n \tif (err) {\n@@ -2366,19 +2465,46 @@ int init_iface(struct ifobject *ifobj, thread_func_t func_ptr)\n \t\treturn err;\n \t}\n \tif (query_opts.feature_flags \u0026 NETDEV_XDP_ACT_RX_SG)\n-\t\tifobj-\u003emulti_buff_supp = true;\n+\t\tifobj_set_cap(ifobj, XSK_CAP_MBUF);\n \tif (query_opts.feature_flags \u0026 NETDEV_XDP_ACT_XSK_ZEROCOPY) {\n+\t\tifobj_set_cap(ifobj, XSK_CAP_ZC_ADVERTISED);\n \t\tif (query_opts.xdp_zc_max_segs \u003e 1) {\n-\t\t\tifobj-\u003emulti_buff_zc_supp = true;\n-\t\t\tifobj-\u003exdp_zc_max_segs = query_opts.xdp_zc_max_segs;\n+\t\t\tifobj_set_cap(ifobj, XSK_CAP_MBUF_ZC);\n+\t\t\tifobj-\u003ecaps.xdp_zc_max_segs = query_opts.xdp_zc_max_segs;\n \t\t} else {\n-\t\t\tifobj-\u003exdp_zc_max_segs = 0;\n+\t\t\tifobj-\u003ecaps.xdp_zc_max_segs = 0;\n \t\t}\n \t}\n \n+\tif (!get_hw_ring_size(ifobj-\u003eifname, \u0026ifobj-\u003ering)) {\n+\t\tifobj_set_cap(ifobj, XSK_CAP_HW_RING);\n+\t\tifobj-\u003ecaps.tx_max_pending = ifobj-\u003ering.tx_max_pending;\n+\t\tifobj-\u003eset_ring.default_tx = ifobj-\u003ering.tx_pending;\n+\t\tifobj-\u003eset_ring.default_rx = ifobj-\u003ering.rx_pending;\n+\t}\n+\n \treturn 0;\n }\n \n+int init_iface(struct ifobject *ifobj)\n+{\n+\tint err;\n+\n+\terr = xsk_load_xdp_programs(ifobj);\n+\tif (err) {\n+\t\tksft_print_msg(\"Error loading XDP program\\n\");\n+\t\treturn err;\n+\t}\n+\n+\terr = xsk_get_mac(ifobj-\u003eifname, ifobj-\u003ecaps.mac);\n+\tif (err) {\n+\t\tksft_print_msg(\"Error reading interface MAC address\\n\");\n+\t\treturn err;\n+\t}\n+\n+\treturn detect_ifobj_caps(ifobj);\n+}\n+\n int testapp_send_receive(struct test_spec *test)\n {\n \treturn testapp_validate_traffic(test);\n@@ -2488,7 +2614,7 @@ int testapp_hw_sw_max_ring_size(struct test_spec *test)\n \n \ttest-\u003eset_ring = true;\n \ttest-\u003etotal_steps = 2;\n-\ttest-\u003eifobj_tx-\u003ering.tx_pending = test-\u003eifobj_tx-\u003ering.tx_max_pending;\n+\ttest-\u003eifobj_tx-\u003ering.tx_pending = xsk_get_cap(test, tx_max_pending);\n \ttest-\u003eifobj_tx-\u003ering.rx_pending  = test-\u003eifobj_tx-\u003ering.rx_max_pending;\n \ttest-\u003eifobj_rx-\u003exsk-\u003eumem-\u003enum_frames = max_descs;\n \ttest-\u003eifobj_rx-\u003exsk-\u003eumem-\u003efill_size = max_descs;\n@@ -2503,8 +2629,8 @@ int testapp_hw_sw_max_ring_size(struct test_spec *test)\n \t/* Set batch_size to 8152 for testing, as the ice HW ignores the 3 lowest bits when\n \t * updating the Rx HW tail register.\n \t */\n-\ttest-\u003eifobj_tx-\u003exsk-\u003ebatch_size = test-\u003eifobj_tx-\u003ering.tx_max_pending - 8;\n-\ttest-\u003eifobj_rx-\u003exsk-\u003ebatch_size = test-\u003eifobj_tx-\u003ering.tx_max_pending - 8;\n+\ttest-\u003eifobj_tx-\u003exsk-\u003ebatch_size = xsk_get_cap(test, tx_max_pending) - 8;\n+\ttest-\u003eifobj_rx-\u003exsk-\u003ebatch_size = xsk_get_cap(test, tx_max_pending) - 8;\n \tif (pkt_stream_replace(test, max_descs, MIN_PKT_SIZE)) {\n \t\tclean_sockets(test, test-\u003eifobj_tx);\n \t\tclean_sockets(test, test-\u003eifobj_rx);\n@@ -2597,7 +2723,7 @@ int testapp_adjust_tail_grow_mb(struct test_spec *test)\n \tgrow_size = XSK_UMEM__MAX_FRAME_SIZE -\n \t\t    XSK_UMEM__LARGE_FRAME_SIZE -\n \t\t    XDP_PACKET_HEADROOM -\n-\t\t    test-\u003eifobj_tx-\u003eumem_tailroom;\n+\t\t    xsk_get_cap(test, umem_tailroom);\n \ttest-\u003emtu = MAX_ETH_JUMBO_SIZE;\n \n \treturn testapp_adjust_tail(test, grow_size, XSK_UMEM__LARGE_FRAME_SIZE * 2);\n@@ -2633,8 +2759,8 @@ struct ifobject *ifobject_create(void)\n \tif (!ifobj-\u003exsk_arr)\n \t\tgoto out_xsk_arr;\n \n-\tifobj-\u003exsk_arr[0].umem_real = calloc(1, sizeof(struct xsk_umem_info));\n-\tif (!ifobj-\u003exsk_arr[0].umem_real)\n+\tifobj-\u003exsk_arr[0].umem = calloc(1, sizeof(struct xsk_umem_info));\n+\tif (!ifobj-\u003exsk_arr[0].umem)\n \t\tgoto out_umem;\n \n \treturn ifobj;\n@@ -2649,7 +2775,7 @@ struct ifobject *ifobject_create(void)\n void ifobject_delete(struct ifobject *ifobj)\n {\n \tif (ifobj-\u003exsk_arr)\n-\t\tfree(ifobj-\u003exsk_arr[0].umem_real);\n+\t\tfree(ifobj-\u003exsk_arr[0].umem);\n \n \tfree(ifobj-\u003exsk_arr);\n \tfree(ifobj);\ndiff --git a/tools/testing/selftests/bpf/prog_tests/test_xsk.h b/tools/testing/selftests/net/lib/xsk/test_xsk.h\nsimilarity index 67%\nrename from tools/testing/selftests/bpf/prog_tests/test_xsk.h\nrename to tools/testing/selftests/net/lib/xsk/test_xsk.h\nindex 03753ddc5dcda..e1ffd054c8f70 100644\n--- a/tools/testing/selftests/bpf/prog_tests/test_xsk.h\n+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.h\n@@ -5,7 +5,7 @@\n #include \u003clinux/ethtool.h\u003e\n #include \u003clinux/if_xdp.h\u003e\n \n-#include \"../kselftest.h\"\n+#include \"kselftest.h\"\n #include \"xsk.h\"\n \n #ifndef SO_PREFER_BUSY_POLL\n@@ -77,13 +77,18 @@ enum test_mode {\n struct ifobject;\n struct test_spec;\n typedef int (*validation_func_t)(struct ifobject *ifobj);\n-typedef void *(*thread_func_t)(void *arg);\n typedef int (*test_func_t)(struct test_spec *test);\n \n+struct xsk_peer;\n+\n+/* The control channel to the other endpoint. */\n+void xsk_set_endpoint(struct xsk_peer *peer, bool hw_test);\n+int xsk_set_udp_packet_format(const char *src_ip, const char *dst_ip, u16 port);\n+void xsk_set_max_frags(u32 max_frags);\n+\n struct xsk_socket_info {\n \tstruct xsk_ring_cons rx;\n \tstruct xsk_ring_prod tx;\n-\tstruct xsk_umem_info *umem_real;\n \tstruct xsk_umem_info *umem;\n \tstruct xsk_socket *xsk;\n \tstruct pkt_stream *pkt_stream;\n@@ -108,7 +113,6 @@ struct xsk_umem_info {\n \tu32 frame_headroom;\n \tvoid *buffer;\n \tu32 frame_size;\n-\tu32 base_addr;\n \tu32 fill_size;\n \tu32 comp_size;\n \tbool unaligned_mode;\n@@ -121,11 +125,29 @@ struct set_hw_ring {\n \n int hw_ring_size_reset(struct ifobject *ifobj);\n \n+#define XSK_CAP_UNALIGNED        (1U \u003c\u003c 0)\n+#define XSK_CAP_MBUF             (1U \u003c\u003c 1)\n+#define XSK_CAP_MBUF_ZC          (1U \u003c\u003c 2)\n+#define XSK_CAP_HW_RING          (1U \u003c\u003c 3)\n+#define XSK_CAP_DRV              (1U \u003c\u003c 4)\n+#define XSK_CAP_ZC               (1U \u003c\u003c 5)\n+#define XSK_CAP_ZC_ADVERTISED    (1U \u003c\u003c 6)\n+\n+struct xsk_caps {\n+\tu32 flags;\n+\tu32 xdp_zc_max_segs;\n+\tu32 max_skb_frags;\n+\tu32 umem_tailroom;\n+\tu32 tx_max_pending;\n+\tu8 mac[ETH_ALEN];\n+};\n+\n struct ifobject {\n \tchar ifname[MAX_INTERFACE_NAME_CHARS];\n+\tstruct xsk_caps caps;\n \tstruct xsk_socket_info *xsk;\n \tstruct xsk_socket_info *xsk_arr;\n-\tthread_func_t func_ptr;\n+\ttest_func_t func_ptr;\n \tvalidation_func_t validation_func;\n \tstruct xsk_xdp_progs *xdp_progs;\n \tstruct bpf_map *xskmap;\n@@ -134,27 +156,43 @@ struct ifobject {\n \tstruct set_hw_ring set_ring;\n \tenum test_mode mode;\n \tint ifindex;\n+\tu32 queue_id;\n \tint mtu;\n+\t/* Above mtu when a hardware SKB-mode endpoint keeps a larger MTU. */\n+\tint dev_mtu;\n+\tint orig_mtu;\n \tu32 bind_flags;\n-\tu32 xdp_zc_max_segs;\n-\tu32 umem_tailroom;\n-\tu32 max_skb_frags;\n \tbool tx_on;\n \tbool rx_on;\n \tbool use_poll;\n \tbool busy_poll;\n \tbool use_fill_ring;\n \tbool release_rx;\n-\tbool shared_umem;\n \tbool use_metadata;\n-\tbool unaligned_supp;\n-\tbool multi_buff_supp;\n-\tbool multi_buff_zc_supp;\n-\tbool hw_ring_size_supp;\n };\n+\n+static inline bool ifobj_has_cap(const struct ifobject *ifobj, u32 cap)\n+{\n+\treturn ifobj \u0026\u0026 (ifobj-\u003ecaps.flags \u0026 cap);\n+}\n+\n+static inline void ifobj_set_cap(struct ifobject *ifobj, u32 cap)\n+{\n+\tifobj-\u003ecaps.flags |= cap;\n+}\n+\n+/* The shadow of the peer's ifobject is never bound to an interface. */\n+static inline bool ifobj_is_local(const struct ifobject *ifobj)\n+{\n+\treturn ifobj-\u003eifindex;\n+}\n+\n+#define xsk_get_cap(test, cap) ((test)-\u003eifobj_tx-\u003ecaps.cap)\n+\n struct ifobject *ifobject_create(void);\n void ifobject_delete(struct ifobject *ifobj);\n-int init_iface(struct ifobject *ifobj, thread_func_t func_ptr);\n+int init_iface(struct ifobject *ifobj);\n+int xsk_load_xdp_programs(struct ifobject *ifobj);\n \n int xsk_configure_umem(struct ifobject *ifobj, struct xsk_umem_info *umem, void *buffer, u64 size);\n int xsk_configure_socket(struct xsk_socket_info *xsk, struct xsk_umem_info *umem,\n@@ -203,12 +241,10 @@ struct test_spec {\n \tu16 total_steps;\n \tu16 current_step;\n \tu16 nb_sockets;\n-\tbool fail;\n \tbool set_ring;\n \tbool adjust_tail;\n \tbool adjust_tail_support;\n \tbool poll_tmout;\n-\tbool use_barrier;\n \tenum test_mode mode;\n \tchar name[MAX_TEST_NAME_SIZE];\n };\n@@ -269,55 +305,14 @@ int testapp_xdp_metadata_mb(struct test_spec *test);\n int testapp_xdp_prog_cleanup(struct test_spec *test);\n int testapp_xdp_shared_umem(struct test_spec *test);\n \n-void *worker_testapp_validate_rx(void *arg);\n-void *worker_testapp_validate_tx(void *arg);\n+int worker_testapp_validate_rx(struct test_spec *test);\n+int worker_testapp_validate_tx(struct test_spec *test);\n \n static const struct test_spec tests[] = {\n-\t{.name = \"SEND_RECEIVE\", .test_func = testapp_send_receive},\n-\t{.name = \"SEND_RECEIVE_2K_FRAME\", .test_func = testapp_send_receive_2k_frame},\n-\t{.name = \"SEND_RECEIVE_SINGLE_PKT\", .test_func = testapp_single_pkt},\n-\t{.name = \"POLL_RX\", .test_func = testapp_poll_rx},\n-\t{.name = \"POLL_TX\", .test_func = testapp_poll_tx},\n-\t{.name = \"POLL_RXQ_FULL\", .test_func = testapp_poll_rxq_tmout},\n-\t{.name = \"POLL_TXQ_FULL\", .test_func = testapp_poll_txq_tmout},\n-\t{.name = \"ALIGNED_INV_DESC\", .test_func = testapp_aligned_inv_desc},\n-\t{.name = \"ALIGNED_INV_DESC_2K_FRAME_SIZE\", .test_func = testapp_aligned_inv_desc_2k_frame},\n-\t{.name = \"UMEM_HEADROOM\", .test_func = testapp_headroom},\n-\t{.name = \"BIDIRECTIONAL\", .test_func = testapp_bidirectional},\n-\t{.name = \"STAT_RX_DROPPED\", .test_func = testapp_stats_rx_dropped},\n-\t{.name = \"STAT_TX_INVALID\", .test_func = testapp_stats_tx_invalid_descs},\n-\t{.name = \"STAT_RX_FULL\", .test_func = testapp_stats_rx_full},\n-\t{.name = \"STAT_FILL_EMPTY\", .test_func = testapp_stats_fill_empty},\n-\t{.name = \"XDP_PROG_CLEANUP\", .test_func = testapp_xdp_prog_cleanup},\n-\t{.name = \"XDP_DROP_HALF\", .test_func = testapp_xdp_drop},\n-\t{.name = \"XDP_SHARED_UMEM\", .test_func = testapp_xdp_shared_umem},\n-\t{.name = \"XDP_METADATA_COPY\", .test_func = testapp_xdp_metadata},\n-\t{.name = \"XDP_METADATA_COPY_MULTI_BUFF\", .test_func = testapp_xdp_metadata_mb},\n-\t{.name = \"ALIGNED_INV_DESC_MULTI_BUFF\", .test_func = testapp_aligned_inv_desc_mb},\n-\t{.name = \"TOO_MANY_FRAGS\", .test_func = testapp_too_many_frags},\n-\t{.name = \"XDP_ADJUST_TAIL_SHRINK\", .test_func = testapp_adjust_tail_shrink},\n-\t{.name = \"TX_QUEUE_CONSUMER\", .test_func = testapp_tx_queue_consumer},\n-\t};\n-\n-static const struct test_spec ci_skip_tests[] = {\n-\t/* Flaky tests */\n-\t{.name = \"XDP_ADJUST_TAIL_SHRINK_MULTI_BUFF\", .test_func = testapp_adjust_tail_shrink_mb},\n-\t{.name = \"XDP_ADJUST_TAIL_GROW\", .test_func = testapp_adjust_tail_grow},\n-\t{.name = \"XDP_ADJUST_TAIL_GROW_MULTI_BUFF\", .test_func = testapp_adjust_tail_grow_mb},\n-\t{.name = \"SEND_RECEIVE_9K_PACKETS\", .test_func = testapp_send_receive_mb},\n-\t/* Tests with huge page dependency */\n-\t{.name = \"SEND_RECEIVE_UNALIGNED\", .test_func = testapp_send_receive_unaligned},\n-\t{.name = \"UNALIGNED_INV_DESC\", .test_func = testapp_unaligned_inv_desc},\n-\t{.name = \"UNALIGNED_INV_DESC_4001_FRAME_SIZE\",\n-\t .test_func = testapp_unaligned_inv_desc_4001_frame},\n-\t{.name = \"SEND_RECEIVE_UNALIGNED_9K_PACKETS\",\n-\t .test_func = testapp_send_receive_unaligned_mb},\n-\t{.name = \"UNALIGNED_INV_DESC_MULTI_BUFF\", .test_func = testapp_unaligned_inv_desc_mb},\n-\t/* Test with HW ring size dependency */\n-\t{.name = \"HW_SW_MIN_RING_SIZE\", .test_func = testapp_hw_sw_min_ring_size},\n-\t{.name = \"HW_SW_MAX_RING_SIZE\", .test_func = testapp_hw_sw_max_ring_size},\n-\t/* Too long test */\n-\t{.name = \"TEARDOWN\", .test_func = testapp_teardown},\n+#define XSK_TEST_CASE(_name, _func, ...) \\\n+\t{ .name = #_name, .test_func = _func },\n+#include \"test_xsk_case_defs.h\"\n+#undef XSK_TEST_CASE\n };\n \n \ndiff --git a/tools/testing/selftests/net/lib/xsk/test_xsk_case_defs.h b/tools/testing/selftests/net/lib/xsk/test_xsk_case_defs.h\nnew file mode 100644\nindex 0000000000000..873e89c9d4d5a\n--- /dev/null\n+++ b/tools/testing/selftests/net/lib/xsk/test_xsk_case_defs.h\n@@ -0,0 +1,57 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+/*\n+ * Each XSK_TEST_CASE entry has a name, function, and hardware directions.\n+ * Only xsk.py reads the directions, the DUT roles in which it runs a case.\n+ *\n+ * Keep this list in test ID order. It is shared by xskxceiver and xsk.py.\n+ */\n+XSK_TEST_CASE(SEND_RECEIVE, testapp_send_receive, XSK_HW_RX | XSK_HW_TX)\n+XSK_TEST_CASE(SEND_RECEIVE_2K_FRAME, testapp_send_receive_2k_frame,\n+\t      XSK_HW_RX | XSK_HW_TX)\n+XSK_TEST_CASE(SEND_RECEIVE_SINGLE_PKT, testapp_single_pkt,\n+\t      XSK_HW_RX | XSK_HW_TX)\n+XSK_TEST_CASE(POLL_RX, testapp_poll_rx, XSK_HW_RX)\n+XSK_TEST_CASE(POLL_TX, testapp_poll_tx, XSK_HW_TX)\n+XSK_TEST_CASE(POLL_RXQ_FULL, testapp_poll_rxq_tmout, XSK_HW_RX)\n+XSK_TEST_CASE(POLL_TXQ_FULL, testapp_poll_txq_tmout, XSK_HW_TX)\n+XSK_TEST_CASE(ALIGNED_INV_DESC, testapp_aligned_inv_desc, XSK_HW_TX)\n+XSK_TEST_CASE(ALIGNED_INV_DESC_2K_FRAME_SIZE,\n+\t      testapp_aligned_inv_desc_2k_frame, XSK_HW_TX)\n+XSK_TEST_CASE(UMEM_HEADROOM, testapp_headroom, XSK_HW_RX)\n+XSK_TEST_CASE(BIDIRECTIONAL, testapp_bidirectional, 0)\n+XSK_TEST_CASE(STAT_RX_DROPPED, testapp_stats_rx_dropped, 0)\n+XSK_TEST_CASE(STAT_TX_INVALID, testapp_stats_tx_invalid_descs, XSK_HW_TX)\n+XSK_TEST_CASE(STAT_RX_FULL, testapp_stats_rx_full, 0)\n+XSK_TEST_CASE(STAT_FILL_EMPTY, testapp_stats_fill_empty, 0)\n+XSK_TEST_CASE(XDP_PROG_CLEANUP, testapp_xdp_prog_cleanup, XSK_HW_RX)\n+XSK_TEST_CASE(XDP_DROP_HALF, testapp_xdp_drop, 0)\n+XSK_TEST_CASE(XDP_SHARED_UMEM, testapp_xdp_shared_umem, 0)\n+XSK_TEST_CASE(XDP_METADATA_COPY, testapp_xdp_metadata, XSK_HW_RX)\n+XSK_TEST_CASE(XDP_METADATA_COPY_MULTI_BUFF, testapp_xdp_metadata_mb, 0)\n+XSK_TEST_CASE(ALIGNED_INV_DESC_MULTI_BUFF, testapp_aligned_inv_desc_mb,\n+\t      XSK_HW_TX)\n+XSK_TEST_CASE(TOO_MANY_FRAGS, testapp_too_many_frags, XSK_HW_TX)\n+XSK_TEST_CASE(XDP_ADJUST_TAIL_SHRINK, testapp_adjust_tail_shrink, 0)\n+XSK_TEST_CASE(TX_QUEUE_CONSUMER, testapp_tx_queue_consumer, 0)\n+/* Flaky tests */\n+XSK_TEST_CASE(XDP_ADJUST_TAIL_SHRINK_MULTI_BUFF,\n+\t      testapp_adjust_tail_shrink_mb, 0)\n+XSK_TEST_CASE(XDP_ADJUST_TAIL_GROW, testapp_adjust_tail_grow, 0)\n+XSK_TEST_CASE(XDP_ADJUST_TAIL_GROW_MULTI_BUFF, testapp_adjust_tail_grow_mb, 0)\n+XSK_TEST_CASE(SEND_RECEIVE_9K_PACKETS, testapp_send_receive_mb,\n+\t      XSK_HW_RX | XSK_HW_TX)\n+/* Tests with huge page dependency */\n+XSK_TEST_CASE(SEND_RECEIVE_UNALIGNED, testapp_send_receive_unaligned,\n+\t      XSK_HW_RX | XSK_HW_TX)\n+XSK_TEST_CASE(UNALIGNED_INV_DESC, testapp_unaligned_inv_desc, XSK_HW_TX)\n+XSK_TEST_CASE(UNALIGNED_INV_DESC_4001_FRAME_SIZE,\n+\t      testapp_unaligned_inv_desc_4001_frame, XSK_HW_TX)\n+XSK_TEST_CASE(SEND_RECEIVE_UNALIGNED_9K_PACKETS,\n+\t      testapp_send_receive_unaligned_mb, XSK_HW_RX | XSK_HW_TX)\n+XSK_TEST_CASE(UNALIGNED_INV_DESC_MULTI_BUFF, testapp_unaligned_inv_desc_mb,\n+\t      XSK_HW_TX)\n+/* Tests with HW ring size dependency */\n+XSK_TEST_CASE(HW_SW_MIN_RING_SIZE, testapp_hw_sw_min_ring_size, 0)\n+XSK_TEST_CASE(HW_SW_MAX_RING_SIZE, testapp_hw_sw_max_ring_size, 0)\n+/* Too long test */\n+XSK_TEST_CASE(TEARDOWN, testapp_teardown, 0)\ndiff --git a/tools/testing/selftests/bpf/xsk.c b/tools/testing/selftests/net/lib/xsk/xsk.c\nsimilarity index 91%\nrename from tools/testing/selftests/bpf/xsk.c\nrename to tools/testing/selftests/net/lib/xsk/xsk.c\nindex 25d568abf0f20..bd2ef3ee91248 100644\n--- a/tools/testing/selftests/bpf/xsk.c\n+++ b/tools/testing/selftests/net/lib/xsk/xsk.c\n@@ -35,7 +35,6 @@\n #include \u003cbpf/bpf.h\u003e\n #include \u003cbpf/libbpf.h\u003e\n #include \"xsk.h\"\n-#include \"bpf_util.h\"\n \n #ifndef SOL_XDP\n  #define SOL_XDP 283\n@@ -779,3 +778,88 @@ void xsk_socket__delete(struct xsk_socket *xsk)\n \t\tclose(xsk-\u003efd);\n \tfree(xsk);\n }\n+\n+int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)\n+{\n+\tstruct ifreq ifr = {0};\n+\tint sockfd, err;\n+\n+\tsockfd = socket(AF_INET, SOCK_DGRAM, 0);\n+\tif (sockfd \u003c 0)\n+\t\treturn -errno;\n+\n+\tmemcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));\n+\n+\tring_param-\u003ecmd = ETHTOOL_GRINGPARAM;\n+\tifr.ifr_data = (char *)ring_param;\n+\n+\tif (ioctl(sockfd, SIOCETHTOOL, \u0026ifr) \u003c 0) {\n+\t\terr = errno;\n+\t\tclose(sockfd);\n+\t\treturn -err;\n+\t}\n+\n+\tclose(sockfd);\n+\treturn 0;\n+}\n+\n+int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)\n+{\n+\tstruct ifreq ifr = {0};\n+\tint sockfd, err;\n+\n+\tsockfd = socket(AF_INET, SOCK_DGRAM, 0);\n+\tif (sockfd \u003c 0)\n+\t\treturn -errno;\n+\n+\tmemcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));\n+\n+\tring_param-\u003ecmd = ETHTOOL_SRINGPARAM;\n+\tifr.ifr_data = (char *)ring_param;\n+\n+\tif (ioctl(sockfd, SIOCETHTOOL, \u0026ifr) \u003c 0) {\n+\t\terr = errno;\n+\t\tclose(sockfd);\n+\t\treturn -err;\n+\t}\n+\n+\tclose(sockfd);\n+\treturn 0;\n+}\n+\n+static int xsk_ifreq_ioctl(const char *ifname, unsigned long req, struct ifreq *ifr)\n+{\n+\tint fd, err = 0;\n+\n+\tfd = socket(AF_INET, SOCK_DGRAM, 0);\n+\tif (fd \u003c 0)\n+\t\treturn -errno;\n+\n+\tstrncpy(ifr-\u003eifr_name, ifname, sizeof(ifr-\u003eifr_name) - 1);\n+\tif (ioctl(fd, req, ifr) \u003c 0)\n+\t\terr = -errno;\n+\tclose(fd);\n+\treturn err;\n+}\n+\n+int xsk_get_mac(const char *ifname, u8 mac[ETH_ALEN])\n+{\n+\tstruct ifreq ifr = {};\n+\tint err;\n+\n+\terr = xsk_ifreq_ioctl(ifname, SIOCGIFHWADDR, \u0026ifr);\n+\tif (!err)\n+\t\tmemcpy(mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN);\n+\treturn err;\n+}\n+\n+int xsk_get_mtu(const char *ifname, int *mtu)\n+{\n+\tstruct ifreq ifr = {};\n+\tint err;\n+\n+\terr = xsk_ifreq_ioctl(ifname, SIOCGIFMTU, \u0026ifr);\n+\tif (!err)\n+\t\t*mtu = ifr.ifr_mtu;\n+\treturn err;\n+}\ndiff --git a/tools/testing/selftests/bpf/xsk.h b/tools/testing/selftests/net/lib/xsk/xsk.h\nsimilarity index 95%\nrename from tools/testing/selftests/bpf/xsk.h\nrename to tools/testing/selftests/net/lib/xsk/xsk.h\nindex 48729da142c24..c09ddbc38db9b 100644\n--- a/tools/testing/selftests/bpf/xsk.h\n+++ b/tools/testing/selftests/net/lib/xsk/xsk.h\n@@ -15,6 +15,7 @@\n #include \u003cstdio.h\u003e\n #include \u003cstdint.h\u003e\n #include \u003cstdbool.h\u003e\n+#include \u003clinux/ethtool.h\u003e\n #include \u003clinux/if_xdp.h\u003e\n \n #include \u003cbpf/libbpf.h\u003e\n@@ -242,6 +243,11 @@ void xsk_socket__delete(struct xsk_socket *xsk);\n \n int xsk_set_mtu(int ifindex, int mtu);\n \n+int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);\n+int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);\n+int xsk_get_mac(const char *ifname, u8 mac[ETH_ALEN]);\n+int xsk_get_mtu(const char *ifname, int *mtu);\n+\n #ifdef __cplusplus\n } /* extern \"C\" */\n #endif\ndiff --git a/tools/testing/selftests/net/lib/xsk/xsk_peer.c b/tools/testing/selftests/net/lib/xsk/xsk_peer.c\nnew file mode 100644\nindex 0000000000000..1228dc01f85ce\n--- /dev/null\n+++ b/tools/testing/selftests/net/lib/xsk/xsk_peer.c\n@@ -0,0 +1,272 @@\n+// SPDX-License-Identifier: GPL-2.0\n+#include \u003carpa/inet.h\u003e\n+#include \u003cerrno.h\u003e\n+#include \u003cnetdb.h\u003e\n+#include \u003cnetinet/tcp.h\u003e\n+#include \u003cpoll.h\u003e\n+#include \u003cstdio.h\u003e\n+#include \u003cstdlib.h\u003e\n+#include \u003csys/socket.h\u003e\n+#include \u003cunistd.h\u003e\n+\n+#include \"xsk_peer.h\"\n+\n+#define XSK_PEER_MAGIC\t\t\t0x58534b50\n+#define XSK_PEER_ACCEPT_TMOUT_MS\t30000\n+\n+/* One case per connection; the launcher owns the verdict. */\n+enum xsk_peer_msg_type {\n+\tXSK_PEER_READY = 1,\n+\tXSK_PEER_PROGRESS,\n+\tXSK_PEER_ABORT,\n+};\n+\n+struct xsk_peer_msg {\n+\tu32 magic;\n+\tu32 type;\n+\tu32 pkts;\n+};\n+\n+struct xsk_peer {\n+\tint fd;\n+\tu32 acked;\n+\tbool ready_seen;\n+\tbool closed;\n+};\n+\n+static int io_full(int fd, void *buf, size_t len, bool write_op)\n+{\n+\tsize_t done = 0;\n+\tssize_t ret;\n+\n+\twhile (done \u003c len) {\n+\t\tif (write_op)\n+\t\t\tret = send(fd, (char *)buf + done, len - done, MSG_NOSIGNAL);\n+\t\telse\n+\t\t\tret = read(fd, (char *)buf + done, len - done);\n+\t\tif (ret \u003c 0 \u0026\u0026 errno == EINTR)\n+\t\t\tcontinue;\n+\t\tif (ret \u003c 0)\n+\t\t\treturn -errno;\n+\t\tif (!ret)\n+\t\t\treturn -EPIPE;\n+\t\tdone += ret;\n+\t}\n+\treturn 0;\n+}\n+\n+/*\n+ * Past its last barrier the peer may exit at any time, and it resets the\n+ * connection if our progress reports are still unread.\n+ */\n+static bool peer_gone(int err)\n+{\n+\treturn err == -EPIPE || err == -ECONNRESET;\n+}\n+\n+static int peer_send(struct xsk_peer *peer, u32 type, u32 pkts)\n+{\n+\tstruct xsk_peer_msg msg = {\n+\t\t.magic = htonl(XSK_PEER_MAGIC),\n+\t\t.type = htonl(type),\n+\t\t.pkts = htonl(pkts),\n+\t};\n+\n+\treturn io_full(peer-\u003efd, \u0026msg, sizeof(msg), true);\n+}\n+\n+static int peer_recv_one(struct xsk_peer *peer)\n+{\n+\tstruct xsk_peer_msg msg;\n+\tint err;\n+\n+\terr = io_full(peer-\u003efd, \u0026msg, sizeof(msg), false);\n+\tif (peer_gone(err))\n+\t\tpeer-\u003eclosed = true;\n+\tif (err)\n+\t\treturn err;\n+\tif (ntohl(msg.magic) != XSK_PEER_MAGIC)\n+\t\treturn -EPROTO;\n+\n+\tswitch (ntohl(msg.type)) {\n+\tcase XSK_PEER_READY:\n+\t\t/* The peer waits for our READY, so it is at most one step ahead. */\n+\t\tif (peer-\u003eready_seen)\n+\t\t\treturn -EPROTO;\n+\t\tpeer-\u003eready_seen = true;\n+\t\treturn 0;\n+\tcase XSK_PEER_PROGRESS:\n+\t\tpeer-\u003eacked += ntohl(msg.pkts);\n+\t\treturn 0;\n+\tcase XSK_PEER_ABORT:\n+\t\treturn -ECANCELED;\n+\tdefault:\n+\t\treturn -EPROTO;\n+\t}\n+}\n+\n+/* Consume what the peer has sent so far without blocking. */\n+static int peer_drain(struct xsk_peer *peer)\n+{\n+\tstruct pollfd pfd = { .fd = peer-\u003efd, .events = POLLIN };\n+\tint ret;\n+\n+\twhile (!peer-\u003eclosed) {\n+\t\tret = poll(\u0026pfd, 1, 0);\n+\t\tif (ret \u003c 0 \u0026\u0026 errno == EINTR)\n+\t\t\tcontinue;\n+\t\tif (ret \u003c 0)\n+\t\t\treturn -errno;\n+\t\tif (!ret)\n+\t\t\tbreak;\n+\t\tret = peer_recv_one(peer);\n+\t\tif (ret \u0026\u0026 !peer-\u003eclosed)\n+\t\t\treturn ret;\n+\t}\n+\treturn 0;\n+}\n+\n+/* Return once both endpoints are set up for the next step. */\n+int xsk_peer_ready(struct xsk_peer *peer)\n+{\n+\tint err;\n+\n+\terr = peer_send(peer, XSK_PEER_READY, 0);\n+\twhile (!err \u0026\u0026 !peer-\u003eready_seen)\n+\t\terr = peer_recv_one(peer);\n+\tif (err)\n+\t\treturn err;\n+\n+\t/* TCP ordering puts all progress of the previous step before READY. */\n+\tpeer-\u003eready_seen = false;\n+\tpeer-\u003eacked = 0;\n+\treturn 0;\n+}\n+\n+void xsk_peer_abort(struct xsk_peer *peer)\n+{\n+\tif (peer \u0026\u0026 !peer-\u003eclosed)\n+\t\tpeer_send(peer, XSK_PEER_ABORT, 0);\n+}\n+\n+int xsk_peer_rx_progress(struct xsk_peer *peer, u32 pkts)\n+{\n+\tint err;\n+\n+\tif (pkts \u0026\u0026 !peer-\u003eclosed) {\n+\t\terr = peer_send(peer, XSK_PEER_PROGRESS, pkts);\n+\t\tif (peer_gone(err))\n+\t\t\tpeer-\u003eclosed = true;\n+\t\telse if (err)\n+\t\t\treturn err;\n+\t}\n+\treturn peer_drain(peer);\n+}\n+\n+/* Return the packets RX reported consumed since the last call, or -errno. */\n+int xsk_peer_tx_sync(struct xsk_peer *peer)\n+{\n+\tint err = peer_drain(peer);\n+\tu32 acked = peer-\u003eacked;\n+\n+\tif (err)\n+\t\treturn err;\n+\tpeer-\u003eacked = 0;\n+\treturn acked;\n+}\n+\n+static int accept_tmout(int lfd)\n+{\n+\tstruct pollfd pfd = { .fd = lfd, .events = POLLIN };\n+\tint ret;\n+\n+\tdo {\n+\t\tret = poll(\u0026pfd, 1, XSK_PEER_ACCEPT_TMOUT_MS);\n+\t} while (ret \u003c 0 \u0026\u0026 errno == EINTR);\n+\tif (!ret)\n+\t\terrno = ETIMEDOUT;\n+\treturn ret \u003e 0 ? accept(lfd, NULL, NULL) : -1;\n+}\n+\n+/*\n+ * The launcher starts the listener and waits for its port before starting\n+ * the connector, so connect() needs no retry. accept() is bounded in case\n+ * the connector exits before it gets that far.\n+ *\n+ * The listener also says on stderr when it listens, so that a launcher can\n+ * wait for that line instead of polling for the port over SSH.\n+ */\n+static int peer_open_tcp(const char *host, const char *port, bool listen_side)\n+{\n+\tstruct addrinfo hints = { .ai_family = AF_UNSPEC, .ai_socktype = SOCK_STREAM };\n+\tint fd = -1, lfd, saved = ECONNREFUSED, one = 1, err;\n+\tstruct addrinfo *res, *ai;\n+\n+\terr = getaddrinfo(host, port, \u0026hints, \u0026res);\n+\tif (err)\n+\t\treturn -EINVAL;\n+\n+\tif (!listen_side)\n+\t\tgoto conn;\n+\n+\tfor (ai = res; ai; ai = ai-\u003eai_next) {\n+\t\tlfd = socket(ai-\u003eai_family, ai-\u003eai_socktype, ai-\u003eai_protocol);\n+\t\tif (lfd \u003c 0)\n+\t\t\tcontinue;\n+\t\tsetsockopt(lfd, SOL_SOCKET, SO_REUSEADDR, \u0026one, sizeof(one));\n+\t\tif (!bind(lfd, ai-\u003eai_addr, ai-\u003eai_addrlen) \u0026\u0026 !listen(lfd, 1)) {\n+\t\t\tfprintf(stderr, \"Listening for XSK peer on port %s\\n\", port);\n+\t\t\tfd = accept_tmout(lfd);\n+\t\t\tsaved = errno;\n+\t\t\tclose(lfd);\n+\t\t\tbreak;\n+\t\t}\n+\t\tsaved = errno;\n+\t\tclose(lfd);\n+\t}\n+\tfreeaddrinfo(res);\n+\treturn fd \u003e= 0 ? fd : -saved;\n+\n+conn:\n+\tfor (ai = res; ai; ai = ai-\u003eai_next) {\n+\t\tfd = socket(ai-\u003eai_family, ai-\u003eai_socktype, ai-\u003eai_protocol);\n+\t\tif (fd \u003c 0)\n+\t\t\tcontinue;\n+\t\tif (!connect(fd, ai-\u003eai_addr, ai-\u003eai_addrlen))\n+\t\t\tbreak;\n+\t\tsaved = errno;\n+\t\tclose(fd);\n+\t\tfd = -1;\n+\t}\n+\tfreeaddrinfo(res);\n+\treturn fd \u003e= 0 ? fd : -saved;\n+}\n+\n+struct xsk_peer *xsk_peer_open(const char *host, const char *port,\n+\t\t\t       bool listen_side)\n+{\n+\tint fd = peer_open_tcp(host, port, listen_side);\n+\tstruct xsk_peer *peer;\n+\tint one = 1;\n+\n+\tif (fd \u003c 0) {\n+\t\terrno = -fd;\n+\t\treturn NULL;\n+\t}\n+\tpeer = calloc(1, sizeof(*peer));\n+\tif (!peer) {\n+\t\tclose(fd);\n+\t\treturn NULL;\n+\t}\n+\tpeer-\u003efd = fd;\n+\tsetsockopt(fd, IPPROTO_TCP, TCP_NODELAY, \u0026one, sizeof(one));\n+\treturn peer;\n+}\n+\n+void xsk_peer_close(struct xsk_peer *peer)\n+{\n+\tif (peer) {\n+\t\tclose(peer-\u003efd);\n+\t\tfree(peer);\n+\t}\n+}\ndiff --git a/tools/testing/selftests/net/lib/xsk/xsk_peer.h b/tools/testing/selftests/net/lib/xsk/xsk_peer.h\nnew file mode 100644\nindex 0000000000000..1e61078baea23\n--- /dev/null\n+++ b/tools/testing/selftests/net/lib/xsk/xsk_peer.h\n@@ -0,0 +1,18 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+#ifndef XSK_PEER_H_\n+#define XSK_PEER_H_\n+\n+#include \u003clinux/types.h\u003e\n+\n+struct xsk_peer;\n+\n+struct xsk_peer *xsk_peer_open(const char *host, const char *port,\n+\t\t\t       bool listen_side);\n+void xsk_peer_close(struct xsk_peer *peer);\n+\n+int xsk_peer_ready(struct xsk_peer *peer);\n+void xsk_peer_abort(struct xsk_peer *peer);\n+int xsk_peer_rx_progress(struct xsk_peer *peer, u32 pkts);\n+int xsk_peer_tx_sync(struct xsk_peer *peer);\n+\n+#endif /* XSK_PEER_H_ */\ndiff --git a/tools/testing/selftests/bpf/xsk_xdp_common.h b/tools/testing/selftests/net/lib/xsk/xsk_xdp_common.h\nsimilarity index 100%\nrename from tools/testing/selftests/bpf/xsk_xdp_common.h\nrename to tools/testing/selftests/net/lib/xsk/xsk_xdp_common.h\ndiff --git a/tools/testing/selftests/bpf/progs/xsk_xdp_progs.c b/tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c\nsimilarity index 100%\nrename from tools/testing/selftests/bpf/progs/xsk_xdp_progs.c\nrename to tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c\ndiff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.c b/tools/testing/selftests/net/lib/xsk/xskxceiver.c\nnew file mode 100644\nindex 0000000000000..510cb8e4e0540\n--- /dev/null\n+++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.c\n@@ -0,0 +1,654 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/* Copyright(c) 2020 Intel Corporation. */\n+\n+/*\n+ * Some functions in this program are taken from\n+ * Linux kernel samples/bpf/xdpsock* and modified\n+ * for use.\n+ *\n+ * See test_xsk.sh for detailed information on test topology\n+ * and prerequisite network setup.\n+ *\n+ * See README.rst for the generic and hardware test setup.\n+ *\n+ * Each instance of this test program runs one endpoint, Tx or Rx, with a\n+ * single socket and a unique UMEM. Two instances validate in-order packet\n+ * delivery and packet content by sending packets to each other.\n+ *\n+ * Tests Information:\n+ * ------------------\n+ * These selftests test AF_XDP SKB and Native/DRV modes using veth\n+ * Virtual Ethernet interfaces.\n+ *\n+ * For each mode, the following tests are run:\n+ *    a. nopoll - soft-irq processing in run-to-completion mode\n+ *    b. poll - using poll() syscall\n+ *    c. Socket Teardown\n+ *       Create a Tx and a Rx socket, Tx from one socket, Rx on another. Destroy\n+ *       both sockets, then repeat multiple times. Only nopoll mode is used\n+ *    d. Bi-directional sockets\n+ *       Configure sockets as bi-directional tx/rx sockets, sets up fill and\n+ *       completion rings on each socket, tx/rx in both directions. Only nopoll\n+ *       mode is used\n+ *    e. Statistics\n+ *       Trigger some error conditions and ensure that the appropriate statistics\n+ *       are incremented. Within this test, the following statistics are tested:\n+ *       i.   rx dropped\n+ *            Increase the UMEM frame headroom to a value which results in\n+ *            insufficient space in the rx buffer for both the packet and the headroom.\n+ *       ii.  tx invalid\n+ *            Set the 'len' field of tx descriptors to an invalid value (umem frame\n+ *            size + 1).\n+ *       iii. rx ring full\n+ *            Reduce the size of the RX ring to a fraction of the fill ring size.\n+ *       iv.  fill queue empty\n+ *            Do not populate the fill queue and then try to receive pkts.\n+ *    f. bpf_link resource persistence\n+ *       Configure sockets at indexes 0 and 1, run a traffic on queue ids 0,\n+ *       then remove xsk sockets from queue 0 on both veth interfaces and\n+ *       finally run a traffic on queues ids 1\n+ *    g. unaligned mode\n+ *    h. tests for invalid and corner case Tx descriptors so that the correct ones\n+ *       are discarded and let through, respectively.\n+ *    i. 2K frame size tests\n+ *    j. If multi-buffer is supported, send 9k packets divided into 3 frames\n+ *    k. If multi-buffer and huge pages are supported, send 9k packets in a single frame\n+ *       using unaligned mode\n+ *    l. If multi-buffer is supported, try various nasty combinations of descriptors to\n+ *       check if they pass the validation or not\n+ *\n+ * drivers/net/hw/xsk.py runs the hardware cases on a physical device in\n+ * zero-copy mode, with an SKB-mode peer on a remote host.\n+ *\n+ * Flow:\n+ * -----\n+ * - test_xsk.sh starts two processes: Tx and Rx\n+ * - Each of these two processes attach to a veth interface\n+ * - Each process creates one AF_XDP socket connected to a unique umem for each\n+ *   veth interface\n+ * - Tx process listens on a TCP control port, Rx process connects to it and\n+ *   the two synchronize each test step over that connection\n+ * - Tx process Transmits a number of packets from veth\u003cxxxx\u003e to veth\u003cyyyy\u003e\n+ * - Rx process verifies if all packets were received and delivered in-order,\n+ *   and have the right content\n+ *\n+ * Enable/disable packet dump mode:\n+ * --------------------------\n+ * To enable L2 - L4 headers and payload dump of each packet on STDOUT, add\n+ * parameter -D to params array in test_xsk.sh, i.e. params=(\"-S\" \"-D\")\n+ */\n+\n+#define _GNU_SOURCE\n+#include \u003cassert.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003cgetopt.h\u003e\n+#include \u003clinux/if_link.h\u003e\n+#include \u003clinux/if_ether.h\u003e\n+#include \u003clinux/mman.h\u003e\n+#include \u003clinux/netdev.h\u003e\n+#include \u003clinux/ethtool.h\u003e\n+#include \u003clinux/align.h\u003e\n+#include \u003carpa/inet.h\u003e\n+#include \u003cnet/if.h\u003e\n+#include \u003cnetinet/ether.h\u003e\n+#include \u003clocale.h\u003e\n+#include \u003cstdio.h\u003e\n+#include \u003cstdlib.h\u003e\n+#include \u003clibgen.h\u003e\n+#include \u003cstddef.h\u003e\n+#include \u003csys/mman.h\u003e\n+#include \u003csys/types.h\u003e\n+\n+#include \"test_xsk.h\"\n+#include \"xsk_peer.h\"\n+#include \"xsk_xdp_progs.skel.h\"\n+#include \"xsk.h\"\n+#include \"xskxceiver.h\"\n+#include \u003cbpf/bpf.h\u003e\n+#include \u003clinux/filter.h\u003e\n+#include \"kselftest.h\"\n+#include \"xsk_xdp_common.h\"\n+\n+enum xsk_endpoint_role {\n+\tXSK_ENDPOINT_NONE,\n+\tXSK_ENDPOINT_RX,\n+\tXSK_ENDPOINT_TX,\n+};\n+\n+static enum test_mode opt_mode = TEST_MODE_ALL;\n+static u32 opt_run_test = RUN_ALL_TESTS;\n+static enum xsk_endpoint_role opt_endpoint_role = XSK_ENDPOINT_NONE;\n+static bool opt_hw;\n+static bool opt_listen;\n+static const char *opt_peer_host;\n+static const char *opt_peer_port;\n+static const char *opt_ifname;\n+static const char *opt_udp_src;\n+static const char *opt_udp_dst;\n+static const struct ether_addr *opt_peer_mac;\n+static struct ether_addr peer_mac;\n+static u16 opt_udp_port;\n+static u32 opt_queue;\n+static u32 opt_max_frags;\n+\n+enum {\n+\tOPT_HW = 256,\n+\tOPT_LISTEN,\n+\tOPT_UDP_SRC,\n+\tOPT_UDP_DST,\n+\tOPT_UDP_PORT,\n+\tOPT_PEER_MAC,\n+\tOPT_QUEUE,\n+\tOPT_MAX_FRAGS,\n+};\n+\n+static void __exit_with_error(int error, const char *file, const char *func, int line)\n+{\n+\tksft_test_result_fail(\"[%s:%s:%i]: ERROR: %d/\\\"%s\\\"\\n\", file, func, line,\n+\t\t\t      error, strerror(error));\n+\tksft_exit_xfail();\n+}\n+\n+#define exit_with_error(error) __exit_with_error(error, __FILE__, __func__, __LINE__)\n+\n+static bool ifobj_zc_avail(struct ifobject *ifobject)\n+{\n+\tsize_t umem_sz = DEFAULT_UMEM_BUFFERS * XSK_UMEM__DEFAULT_FRAME_SIZE;\n+\tint mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE;\n+\tstruct xsk_socket_info *xsk;\n+\tstruct xsk_umem_info *umem;\n+\tbool zc_avail = false;\n+\tvoid *bufs;\n+\tint ret;\n+\n+\tbufs = mmap(NULL, umem_sz, PROT_READ | PROT_WRITE, mmap_flags, -1, 0);\n+\tif (bufs == MAP_FAILED)\n+\t\texit_with_error(errno);\n+\n+\tumem = calloc(1, sizeof(struct xsk_umem_info));\n+\tif (!umem) {\n+\t\tmunmap(bufs, umem_sz);\n+\t\texit_with_error(ENOMEM);\n+\t}\n+\tumem-\u003eframe_size = XSK_UMEM__DEFAULT_FRAME_SIZE;\n+\tret = xsk_configure_umem(ifobject, umem, bufs, umem_sz);\n+\tif (ret)\n+\t\texit_with_error(-ret);\n+\n+\txsk = calloc(1, sizeof(struct xsk_socket_info));\n+\tif (!xsk)\n+\t\tgoto out;\n+\tifobject-\u003ebind_flags = XDP_USE_NEED_WAKEUP | XDP_ZEROCOPY;\n+\tifobject-\u003erx_on = true;\n+\txsk-\u003erxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS;\n+\tret = xsk_configure_socket(xsk, umem, ifobject, false);\n+\tif (!ret)\n+\t\tzc_avail = true;\n+\n+\txsk_socket__delete(xsk-\u003exsk);\n+\tfree(xsk);\n+out:\n+\tmunmap(umem-\u003ebuffer, umem_sz);\n+\txsk_umem__delete(umem-\u003eumem);\n+\tfree(umem);\n+\treturn zc_avail;\n+}\n+\n+static struct option long_options[] = {\n+\t{\"interface\", required_argument, 0, 'i'},\n+\t{\"busy-poll\", no_argument, 0, 'b'},\n+\t{\"verbose\", no_argument, 0, 'v'},\n+\t{\"mode\", required_argument, 0, 'm'},\n+\t{\"list\", no_argument, 0, 'l'},\n+\t{\"test\", required_argument, 0, 't'},\n+\t{\"endpoint\", required_argument, 0, 'e'},\n+\t{\"peer\", required_argument, 0, 'p'},\n+\t{\"peer-port\", required_argument, 0, 'P'},\n+\t{\"hw\", no_argument, 0, OPT_HW},\n+\t{\"listen\", no_argument, 0, OPT_LISTEN},\n+\t{\"udp-src\", required_argument, 0, OPT_UDP_SRC},\n+\t{\"udp-dst\", required_argument, 0, OPT_UDP_DST},\n+\t{\"udp-port\", required_argument, 0, OPT_UDP_PORT},\n+\t{\"peer-mac\", required_argument, 0, OPT_PEER_MAC},\n+\t{\"queue\", required_argument, 0, OPT_QUEUE},\n+\t{\"max-frags\", required_argument, 0, OPT_MAX_FRAGS},\n+\t{\"help\", no_argument, 0, 'h'},\n+\t{0, 0, 0, 0}\n+};\n+\n+static void print_usage(char **argv)\n+{\n+\tconst char *str =\n+\t\t\"  Usage: xskxceiver -i IFACE -e rx|tx -m MODE -t TEST -p HOST -P PORT [OPTIONS]\\n\"\n+\t\t\"  Options:\\n\"\n+\t\t\"  -i, --interface      Use interface\\n\"\n+\t\t\"  -v, --verbose        Verbose output\\n\"\n+\t\t\"  -b, --busy-poll      Enable busy poll\\n\"\n+\t\t\"  -m, --mode           Run only mode skb, drv, or zc\\n\"\n+\t\t\"  -l, --list           List all available tests\\n\"\n+\t\t\"  -t, --test           Run a specific test. Enter number from -l option.\\n\"\n+\t\t\"  -e, --endpoint       Role of this endpoint: rx or tx\\n\"\n+\t\t\"  -p, --peer           Control host: IPv4/IPv6 address or hostname\\n\"\n+\t\t\"  -P, --peer-port      Control TCP port (1-65535)\\n\"\n+\t\t\"      --listen         Listen instead of connecting (hardware peer)\\n\"\n+\t\t\"      --hw             One physical-link case, controlled by xsk.py\\n\"\n+\t\t\"      --udp-src IP     IPv4 source address for test packets\\n\"\n+\t\t\"      --udp-dst IP     IPv4 destination address for test packets\\n\"\n+\t\t\"      --udp-port PORT  UDP source and destination port\\n\"\n+\t\t\"      --peer-mac MAC   Remote interface MAC address\\n\"\n+\t\t\"      --queue N        AF_XDP queue to bind (default 0)\\n\"\n+\t\t\"      --max-frags N    Fragment limit selected by the hardware runner\\n\"\n+\t\t\"  -h, --help           Display this help and exit\\n\";\n+\n+\tksft_print_msg(str, basename(argv[0]));\n+\tksft_exit_xfail();\n+}\n+\n+static void bind_iface(struct ifobject *ifobj, const char *ifname, char **argv)\n+{\n+\tsize_t len = strlen(ifname);\n+\n+\tif (!len || len \u003e= sizeof(ifobj-\u003eifname))\n+\t\tprint_usage(argv);\n+\n+\tmemcpy(ifobj-\u003eifname, ifname, len + 1);\n+\tifobj-\u003eifindex = if_nametoindex(ifobj-\u003eifname);\n+\tif (!ifobj-\u003eifindex) {\n+\t\tksft_print_msg(\"Error: cannot resolve interface %s\\n\", ifobj-\u003eifname);\n+\t\tksft_exit_fail();\n+\t}\n+\n+\tif (init_iface(ifobj)) {\n+\t\tksft_print_msg(\"Error: cannot initialize interface %s\\n\", ifobj-\u003eifname);\n+\t\tksft_exit_fail();\n+\t}\n+\tif (xsk_get_mtu(ifobj-\u003eifname, \u0026ifobj-\u003emtu)) {\n+\t\tksft_print_msg(\"Error: cannot read MTU of interface %s\\n\", ifobj-\u003eifname);\n+\t\tksft_exit_fail();\n+\t}\n+\tifobj-\u003edev_mtu = ifobj-\u003emtu;\n+\tifobj-\u003eorig_mtu = ifobj-\u003emtu;\n+}\n+\n+static void print_tests(void)\n+{\n+\tu32 i;\n+\n+\tprintf(\"Tests:\\n\");\n+\tfor (i = 0; i \u003c ARRAY_SIZE(tests); i++)\n+\t\tprintf(\"%u: %s\\n\", i, tests[i].name);\n+}\n+\n+static u32 parse_u32(const char *arg, u32 min, u32 max, char **argv)\n+{\n+\tunsigned long val;\n+\tchar *end;\n+\n+\terrno = 0;\n+\tval = strtoul(arg, \u0026end, 10);\n+\tif (arg[0] \u003c '0' || arg[0] \u003e '9' || errno || *end || val \u003c min || val \u003e max)\n+\t\tprint_usage(argv);\n+\treturn val;\n+}\n+\n+static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj_rx, int argc,\n+\t\t\t       char **argv)\n+{\n+\tint option_index, c;\n+\n+\topterr = 0;\n+\n+\tfor (;;) {\n+\t\tc = getopt_long(argc, argv, \"i:vbm:lt:e:p:P:\", long_options, \u0026option_index);\n+\t\tif (c == -1)\n+\t\t\tbreak;\n+\n+\t\tswitch (c) {\n+\t\tcase 'i':\n+\t\t\topt_ifname = optarg;\n+\t\t\tbreak;\n+\t\tcase 'v':\n+\t\t\topt_verbose = true;\n+\t\t\tbreak;\n+\t\tcase 'b':\n+\t\t\tifobj_tx-\u003ebusy_poll = true;\n+\t\t\tifobj_rx-\u003ebusy_poll = true;\n+\t\t\tbreak;\n+\t\tcase 'm':\n+\t\t\tif (!strncmp(\"skb\", optarg, strlen(optarg)))\n+\t\t\t\topt_mode = TEST_MODE_SKB;\n+\t\t\telse if (!strncmp(\"drv\", optarg, strlen(optarg)))\n+\t\t\t\topt_mode = TEST_MODE_DRV;\n+\t\t\telse if (!strncmp(\"zc\", optarg, strlen(optarg)))\n+\t\t\t\topt_mode = TEST_MODE_ZC;\n+\t\t\telse\n+\t\t\t\tprint_usage(argv);\n+\t\t\tbreak;\n+\t\tcase 'l':\n+\t\t\tprint_tests();\n+\t\t\tksft_exit_pass();\n+\t\t\tbreak;\n+\t\tcase 't':\n+\t\t\terrno = 0;\n+\t\t\topt_run_test = strtol(optarg, NULL, 0);\n+\t\t\tif (errno)\n+\t\t\t\tprint_usage(argv);\n+\t\t\tbreak;\n+\t\tcase 'e':\n+\t\t\tif (!strcmp(optarg, \"rx\"))\n+\t\t\t\topt_endpoint_role = XSK_ENDPOINT_RX;\n+\t\t\telse if (!strcmp(optarg, \"tx\"))\n+\t\t\t\topt_endpoint_role = XSK_ENDPOINT_TX;\n+\t\t\telse\n+\t\t\t\tprint_usage(argv);\n+\t\t\tbreak;\n+\t\tcase 'p':\n+\t\t\topt_peer_host = optarg;\n+\t\t\tbreak;\n+\t\tcase 'P':\n+\t\t\topt_peer_port = optarg;\n+\t\t\tbreak;\n+\t\tcase OPT_HW:\n+\t\t\topt_hw = true;\n+\t\t\tbreak;\n+\t\tcase OPT_LISTEN:\n+\t\t\topt_listen = true;\n+\t\t\tbreak;\n+\t\tcase OPT_UDP_SRC:\n+\t\t\topt_udp_src = optarg;\n+\t\t\tbreak;\n+\t\tcase OPT_UDP_DST:\n+\t\t\topt_udp_dst = optarg;\n+\t\t\tbreak;\n+\t\tcase OPT_UDP_PORT:\n+\t\t\topt_udp_port = parse_u32(optarg, 1, UINT16_MAX, argv);\n+\t\t\tbreak;\n+\t\tcase OPT_PEER_MAC:\n+\t\t\topt_peer_mac = ether_aton_r(optarg, \u0026peer_mac);\n+\t\t\tif (!opt_peer_mac)\n+\t\t\t\tprint_usage(argv);\n+\t\t\tbreak;\n+\t\tcase OPT_QUEUE:\n+\t\t\topt_queue = parse_u32(optarg, 0, UINT32_MAX, argv);\n+\t\t\tbreak;\n+\t\tcase OPT_MAX_FRAGS:\n+\t\t\topt_max_frags = parse_u32(optarg, 1, UINT16_MAX, argv);\n+\t\t\tbreak;\n+\t\tcase 'h':\n+\t\tdefault:\n+\t\t\tprint_usage(argv);\n+\t\t}\n+\t}\n+\n+\tif (!opt_ifname || opt_endpoint_role == XSK_ENDPOINT_NONE || !opt_peer_host ||\n+\t    !*opt_peer_host || !opt_peer_port || opt_run_test == RUN_ALL_TESTS ||\n+\t    opt_mode == TEST_MODE_ALL)\n+\t\tprint_usage(argv);\n+\tif (opt_hw \u0026\u0026 (!opt_udp_src || !opt_udp_dst || !opt_udp_port || !opt_peer_mac))\n+\t\tprint_usage(argv);\n+\tif ((opt_listen || opt_max_frags) \u0026\u0026 !opt_hw)\n+\t\tprint_usage(argv);\n+}\n+\n+static void xsk_unload_xdp_programs(struct ifobject *ifobj)\n+{\n+\txsk_xdp_progs__destroy(ifobj-\u003exdp_progs);\n+}\n+\n+static void report_pkt_test(struct test_spec *test, int ret)\n+{\n+\tswitch (ret) {\n+\tcase TEST_PASS:\n+\t\tksft_test_result_pass(\"PASS: %s %s%s\\n\", mode_string(test), busy_poll_string(test),\n+\t\t\t\t      test-\u003ename);\n+\t\tbreak;\n+\tcase TEST_SKIP:\n+\t\tksft_test_result_skip(\"SKIP: %s %s%s\\n\", mode_string(test), busy_poll_string(test),\n+\t\t\t\t      test-\u003ename);\n+\t\tbreak;\n+\tcase TEST_FAILURE:\n+\t\tksft_test_result_fail(\"FAIL: %s %s%s\\n\", mode_string(test), busy_poll_string(test),\n+\t\t\t\t      test-\u003ename);\n+\t\tbreak;\n+\tdefault:\n+\t\tksft_test_result_fail(\"FAIL: %s %s%s -- Unexpected returned value (%d)\\n\",\n+\t\t\t\t      mode_string(test), busy_poll_string(test), test-\u003ename, ret);\n+\t}\n+}\n+\n+static int run_pkt_test(struct test_spec *test)\n+{\n+\tint ret;\n+\n+\tret = test-\u003etest_func(test);\n+\tif (!opt_hw)\n+\t\treport_pkt_test(test, ret);\n+\tpkt_stream_restore_default(test);\n+\treturn ret;\n+}\n+\n+static bool is_xdp_supported(int ifindex)\n+{\n+\tint flags = XDP_FLAGS_DRV_MODE;\n+\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts, .flags = flags);\n+\tstruct bpf_insn insns[2] = {\n+\t\tBPF_MOV64_IMM(BPF_REG_0, XDP_PASS),\n+\t\tBPF_EXIT_INSN()\n+\t};\n+\tint prog_fd, insn_cnt = ARRAY_SIZE(insns);\n+\tint err;\n+\n+\tprog_fd = bpf_prog_load(BPF_PROG_TYPE_XDP, NULL, \"GPL\", insns, insn_cnt, NULL);\n+\tif (prog_fd \u003c 0)\n+\t\treturn false;\n+\n+\terr = bpf_xdp_attach(ifindex, prog_fd, flags, NULL);\n+\tif (err) {\n+\t\tclose(prog_fd);\n+\t\treturn false;\n+\t}\n+\n+\tbpf_xdp_detach(ifindex, flags, NULL);\n+\tclose(prog_fd);\n+\n+\treturn true;\n+}\n+\n+static u32 detect_mode_caps(struct ifobject *ifobj)\n+{\n+\tif (opt_hw \u0026\u0026 opt_mode == TEST_MODE_ZC \u0026\u0026\n+\t    ifobj_has_cap(ifobj, XSK_CAP_ZC_ADVERTISED)) {\n+\t\t/* Trust the advertised flag; an XDP_ZEROCOPY bind never falls back to copy. */\n+\t\tifobj_set_cap(ifobj, XSK_CAP_DRV | XSK_CAP_ZC);\n+\t} else if (!opt_hw \u0026\u0026 is_xdp_supported(ifobj-\u003eifindex)) {\n+\t\tifobj_set_cap(ifobj, XSK_CAP_DRV);\n+\t\tif (ifobj_zc_avail(ifobj))\n+\t\t\tifobj_set_cap(ifobj, XSK_CAP_ZC);\n+\t}\n+\n+\treturn ifobj-\u003ecaps.flags;\n+}\n+\n+static bool mode_supported(enum test_mode mode, u32 caps)\n+{\n+\tif (mode == TEST_MODE_SKB)\n+\t\treturn true;\n+\tif (mode == TEST_MODE_DRV)\n+\t\treturn caps \u0026 XSK_CAP_DRV;\n+\treturn caps \u0026 XSK_CAP_ZC;\n+}\n+\n+static int cleanup_iface(struct ifobject *ifobj)\n+{\n+\tint err = 0;\n+\n+\t/* A peer shadow has a skeleton but no bound interface. */\n+\tif (!ifobj_is_local(ifobj))\n+\t\tgoto unload;\n+\n+\tif (ifobj_has_cap(ifobj, XSK_CAP_HW_RING))\n+\t\thw_ring_size_reset(ifobj);\n+\tif (ifobj-\u003exdp_prog)\n+\t\txsk_detach_xdp_program(ifobj-\u003eifindex,\n+\t\t\t\t       ifobj-\u003emode == TEST_MODE_SKB ?\n+\t\t\t\t       XDP_FLAGS_SKB_MODE : XDP_FLAGS_DRV_MODE);\n+\t/* After the detach, as an attached program can cap the MTU. */\n+\tif (ifobj-\u003edev_mtu != ifobj-\u003eorig_mtu) {\n+\t\terr = xsk_set_mtu(ifobj-\u003eifindex, ifobj-\u003eorig_mtu);\n+\t\tif (err)\n+\t\t\tksft_print_msg(\"Failed to restore MTU %d on %s\\n\",\n+\t\t\t\t       ifobj-\u003eorig_mtu, ifobj-\u003eifname);\n+\t}\n+unload:\n+\txsk_unload_xdp_programs(ifobj);\n+\treturn err;\n+}\n+\n+/* Connect the two endpoints without negotiating the remote NIC's capabilities. */\n+static int setup_peer(struct ifobject *local, struct ifobject *shadow,\n+\t\t      struct xsk_peer **peer)\n+{\n+\t/* Unattached skeleton copy; the engine only attaches the local side. */\n+\tif (xsk_load_xdp_programs(shadow))\n+\t\treturn TEST_FAILURE;\n+\n+\t/* Generic TX listens; Python chooses the listener for hardware cases. */\n+\t*peer = xsk_peer_open(opt_peer_host, opt_peer_port,\n+\t\t\t      opt_hw ? opt_listen :\n+\t\t\t      opt_endpoint_role == XSK_ENDPOINT_TX);\n+\tif (!*peer) {\n+\t\tksft_print_msg(\"Failed to connect XSK peer: %s\\n\", strerror(errno));\n+\t\treturn TEST_FAILURE;\n+\t}\n+\n+\tshadow-\u003ecaps = local-\u003ecaps;\n+\tif (opt_hw)\n+\t\tmemcpy(shadow-\u003ecaps.mac, opt_peer_mac-\u003eether_addr_octet, ETH_ALEN);\n+\n+\txsk_set_endpoint(*peer, opt_hw);\n+\treturn TEST_PASS;\n+}\n+\n+int main(int argc, char **argv)\n+{\n+\tu32 cache_line_size, max_frags, umem_tailroom;\n+\tconst size_t total_tests = ARRAY_SIZE(tests);\n+\tstruct ifobject *ifobj_tx, *ifobj_rx;\n+\tstruct ifobject *shadow_ifobj;\n+\tstruct ifobject *local_ifobj;\n+\tstruct xsk_peer *peer = NULL;\n+\tstruct test_spec test = {};\n+\tint ret = TEST_FAILURE;\n+\tu32 caps;\n+\tint err;\n+\n+\t/* Use libbpf 1.0 API mode */\n+\tlibbpf_set_strict_mode(LIBBPF_STRICT_ALL);\n+\n+\tifobj_tx = ifobject_create();\n+\tif (!ifobj_tx)\n+\t\texit_with_error(ENOMEM);\n+\tifobj_rx = ifobject_create();\n+\tif (!ifobj_rx)\n+\t\texit_with_error(ENOMEM);\n+\n+\tsetlocale(LC_ALL, \"\");\n+\n+\tcache_line_size = read_procfs_val(SMP_CACHE_BYTES_PATH);\n+\tif (!cache_line_size) {\n+\t\tksft_print_msg(\"Can't get SMP_CACHE_BYTES from system, using default (64)\\n\");\n+\t\tcache_line_size = 64;\n+\t}\n+\n+\tmax_frags = read_procfs_val(MAX_SKB_FRAGS_PATH);\n+\tif (!max_frags) {\n+\t\tksft_print_msg(\"Can't get MAX_SKB_FRAGS from system, using default (17)\\n\");\n+\t\tmax_frags = 17;\n+\t}\n+\tifobj_tx-\u003ecaps.max_skb_frags = max_frags;\n+\tifobj_rx-\u003ecaps.max_skb_frags = max_frags;\n+\n+\t/* 48 bytes is a part of skb_shared_info w/o frags array;\n+\t * 16 bytes is sizeof(skb_frag_t)\n+\t */\n+\tumem_tailroom = ALIGN(48 + (max_frags * 16), cache_line_size);\n+\tifobj_tx-\u003ecaps.umem_tailroom = umem_tailroom;\n+\tifobj_rx-\u003ecaps.umem_tailroom = umem_tailroom;\n+\n+\tparse_command_line(ifobj_tx, ifobj_rx, argc, argv);\n+\n+\tif (opt_run_test != RUN_ALL_TESTS \u0026\u0026 opt_run_test \u003e= total_tests) {\n+\t\tksft_print_msg(\"Error: test %u does not exist.\\n\", opt_run_test);\n+\t\tksft_exit_xfail();\n+\t}\n+\n+\txsk_set_max_frags(opt_max_frags);\n+\tif (opt_hw \u0026\u0026 xsk_set_udp_packet_format(opt_udp_src, opt_udp_dst,\n+\t\t\t\t\t\topt_udp_port))\n+\t\tprint_usage(argv);\n+\n+\t/* swap_directions() swaps the workers, so the shadow needs one too. */\n+\tifobj_tx-\u003efunc_ptr = worker_testapp_validate_tx;\n+\tifobj_rx-\u003efunc_ptr = worker_testapp_validate_rx;\n+\tif (opt_endpoint_role == XSK_ENDPOINT_TX) {\n+\t\tlocal_ifobj = ifobj_tx;\n+\t\tshadow_ifobj = ifobj_rx;\n+\t} else {\n+\t\tlocal_ifobj = ifobj_rx;\n+\t\tshadow_ifobj = ifobj_tx;\n+\t}\n+\tbind_iface(local_ifobj, opt_ifname, argv);\n+\tlocal_ifobj-\u003equeue_id = opt_queue;\n+\t/* The zero-copy probe binds to queue_id, so set it first. */\n+\tcaps = detect_mode_caps(local_ifobj);\n+\n+\ttest.tx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);\n+\ttest.rx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);\n+\tif (!test.tx_pkt_stream_default || !test.rx_pkt_stream_default)\n+\t\tgoto out;\n+\n+\tif (setup_peer(local_ifobj, shadow_ifobj, \u0026peer))\n+\t\tgoto out;\n+\n+\tif (!mode_supported(opt_mode, caps)) {\n+\t\tif (opt_mode == TEST_MODE_DRV)\n+\t\t\tksft_print_msg(\"XDP_DRV mode not supported.\\n\");\n+\t\telse\n+\t\t\tksft_print_msg(\"zero-copy mode not supported.\\n\");\n+\t\tret = TEST_SKIP;\n+\t\tgoto out;\n+\t}\n+\n+\t/* Line-buffer stdout so verdicts reach a capturing launcher live. */\n+\tif (!opt_hw) {\n+\t\tksft_print_header();\n+\t\tksft_set_plan(1);\n+\t}\n+\ttest_init(\u0026test, ifobj_tx, ifobj_rx, opt_mode, \u0026tests[opt_run_test]);\n+\tret = run_pkt_test(\u0026test);\n+\n+out:\n+\txsk_set_endpoint(NULL, false);\n+\terr = cleanup_iface(ifobj_tx);\n+\terr |= cleanup_iface(ifobj_rx);\n+\t/* xsk.py trusts a passed or skipped endpoint to have undone the MTU. */\n+\tif (err)\n+\t\tret = TEST_FAILURE;\n+\txsk_peer_close(peer);\n+\tpkt_stream_delete(test.tx_pkt_stream_default);\n+\tpkt_stream_delete(test.rx_pkt_stream_default);\n+\tifobject_delete(ifobj_tx);\n+\tifobject_delete(ifobj_rx);\n+\n+\tif (ret == TEST_SKIP \u0026\u0026 !opt_hw \u0026\u0026 ksft_test_num()) {\n+\t\tksft_print_cnts();\n+\t\treturn KSFT_SKIP;\n+\t}\n+\tif (ret == TEST_SKIP)\n+\t\tksft_exit_skip(\"mode or test not supported\\n\");\n+\tif (ret)\n+\t\tksft_exit_fail();\n+\telse\n+\t\tksft_exit_pass();\n+}\ndiff --git a/tools/testing/selftests/bpf/xskxceiver.h b/tools/testing/selftests/net/lib/xsk/xskxceiver.h\nsimilarity index 100%\nrename from tools/testing/selftests/bpf/xskxceiver.h\nrename to tools/testing/selftests/net/lib/xsk/xskxceiver.h\ndiff --git a/tools/testing/selftests/bpf/test_xsk.sh b/tools/testing/selftests/net/test_xsk.sh\nsimilarity index 57%\nrename from tools/testing/selftests/bpf/test_xsk.sh\nrename to tools/testing/selftests/net/test_xsk.sh\nindex 62db060298a4a..2ef9ce7e1b27d 100755\n--- a/tools/testing/selftests/bpf/test_xsk.sh\n+++ b/tools/testing/selftests/net/test_xsk.sh\n@@ -8,22 +8,20 @@\n #\n # Topology:\n # ---------\n-#                 -----------\n-#               _ | Process | _\n-#              /  -----------  \\\n-#             /        |        \\\n-#            /         |         \\\n-#      -----------     |     -----------\n-#      | Thread1 |     |     | Thread2 |\n-#      -----------     |     -----------\n-#           |          |          |\n-#      -----------     |     -----------\n-#      |  xskX   |     |     |  xskY   |\n-#      -----------     |     -----------\n-#           |          |          |\n-#      -----------     |     ----------\n-#      |  vethX  | --------- |  vethY |\n-#      -----------   peer    ----------\n+#      -----------   control    -----------\n+#      | TX proc | ------------ | RX proc |\n+#      -----------  (TCP, lo)   -----------\n+#           |                        |\n+#      -----------              -----------\n+#      |  xskX   |              |  xskY   |\n+#      -----------              -----------\n+#           |                        |\n+#      -----------              ----------\n+#      |  vethX  | ------------ |  vethY |\n+#      -----------     peer     ----------\n+#\n+# The two xskxceiver processes each drive one veth and synchronize over a\n+# TCP control connection on 127.0.0.1.\n #\n # AF_XDP is an address family optimized for high performance packet processing,\n # it is XDP’s user-space interface.\n@@ -71,10 +69,10 @@\n # Set up veth interfaces and leave them up so xskxceiver can be launched in a debugger:\n #   sudo ./test_xsk.sh -d\n #\n-# Run test suite for physical device in loopback mode\n-#   sudo ./test_xsk.sh -i IFACE\n+# Use a specific TCP port for the control connection (random by default)\n+#   sudo ./test_xsk.sh -p PORT\n #\n-# Run test suite in a specific mode only [skb,drv,zc]\n+# Run test suite in a specific mode only [skb,drv]\n #   sudo ./test_xsk.sh -m MODE\n #\n # List available tests\n@@ -88,14 +86,20 @@\n \n . xsk_prereqs.sh\n \n-ETH=\"\"\n+if [ ! -x \"./${XSKOBJ}\" ]; then\n+\techo \"xskxceiver was not built; skipping\"\n+\texit $ksft_skip\n+fi\n+\n+PEER_HOST=127.0.0.1\n+PEER_PORT=\n \n-while getopts \"vi:dm:lt:h\" flag\n+while getopts \"vdm:lt:p:h\" flag\n do\n \tcase \"${flag}\" in\n \t\tv) verbose=1;;\n \t\td) debug=1;;\n-\t\ti) ETH=${OPTARG};;\n+\t\tp) PEER_PORT=${OPTARG};;\n \t\tm) MODE=${OPTARG};;\n \t\tl) list=1;;\n \t\tt) TEST=${OPTARG};;\n@@ -157,34 +161,53 @@ if [[ $help -eq 1 ]]; then\n         exit\n fi\n \n-if [ ! -z $ETH ]; then\n-\tVETH0=${ETH}\n-\tVETH1=${ETH}\n+if [ -n \"$MODE\" ]; then\n+\tcase \"$MODE\" in\n+\t\tskb|drv) MODES=(\"$MODE\");;\n+\t\t*) echo \"Unsupported veth mode: $MODE (expected skb or drv)\" \u003e\u00262\n+\t\t   exit 1;;\n+\tesac\n else\n-\tvalidate_root_exec\n-\tvalidate_veth_support ${VETH0}\n-\tvalidate_ip_utility\n-\tsetup_vethPairs\n-\n-\tretval=$?\n-\tif [ $retval -ne 0 ]; then\n-\t\ttest_status $retval \"${TEST_NAME}\"\n-\t\tcleanup_exit ${VETH0} ${VETH1}\n-\t\texit $retval\n-\tfi\n+\tMODES=(skb drv)\n fi\n \n+if [ -n \"$TEST\" ]; then\n+\tif [[ \"$TEST\" =~ ^[0-9]+$ ]]; then\n+\t\tCASES=(\"$TEST\")\n+\telse\n+\t\tmapfile -t CASES \u003c \u003c(./${XSKOBJ} -l |\n+\t\t\tawk -F ': ' -v name=\"$TEST\" '$2 == name {print $1}')\n+\tfi\n+else\n+\tmapfile -t CASES \u003c \u003c(./${XSKOBJ} -l | awk -F ': ' '/^[0-9]+: / {print $1}')\n+fi\n+if [ ${#CASES[@]} -eq 0 ]; then\n+\techo \"Unknown AF_XDP test: $TEST\" \u003e\u00262\n+\texit 1\n+fi\n \n-if [[ $verbose -eq 1 ]]; then\n-\tARGS+=\"-v \"\n+if [ -z \"$PEER_PORT\" ]; then\n+\tPEER_PORT=$(random_port) || {\n+\t\techo \"Could not find an unused TCP port\" \u003e\u00262\n+\t\texit 1\n+\t}\n fi\n \n-if [ -n \"$MODE\" ]; then\n-\tARGS+=\"-m ${MODE} \"\n+validate_root_exec\n+validate_veth_support ${VETH0}\n+validate_ip_utility\n+setup_vethPairs\n+\n+retval=$?\n+if [ $retval -ne 0 ]; then\n+\ttest_status $retval \"${TEST_NAME}\"\n+\tcleanup_exit ${VETH0} ${VETH1}\n+\texit $retval\n fi\n \n-if [ -n \"$TEST\" ]; then\n-\tARGS+=\"-t ${TEST} \"\n+\n+if [[ $verbose -eq 1 ]]; then\n+\tARGS+=\"-v \"\n fi\n \n retval=$?\n@@ -193,54 +216,81 @@ test_status $retval \"${TEST_NAME}\"\n ## START TESTS\n \n statusList=()\n+nameList=()\n+\n+run_matrix()\n+{\n+\tlocal mode case_id\n+\n+\tfor mode in \"${MODES[@]}\"; do\n+\t\tfor case_id in \"${CASES[@]}\"; do\n+\t\t\tARGS=\"${BASE_ARGS} -m ${mode} -t ${case_id}\"\n+\t\t\tTEST_NAME=\"XSK_${mode}_${case_id}_${RUN_VARIANT}_${VETH0}\"\n+\t\t\texec_xskxceiver\n+\t\tdone\n+\tdone\n+}\n+\n+BASE_ARGS=\"${ARGS}\"\n \n-TEST_NAME=\"XSK_SELFTESTS_${VETH0}_SOFTIRQ\"\n+RUN_VARIANT=SOFTIRQ\n \n if [[ $debug -eq 1 ]]; then\n-    echo \"-i\" ${VETH0} \"-i\" ${VETH1}\n+    ARGS=\"${BASE_ARGS} -m ${MODES[0]} -t ${CASES[0]}\"\n+    echo \"./${XSKOBJ} -i ${VETH0} -e tx -p ${PEER_HOST} -P ${PEER_PORT} ${ARGS}\"\n+    echo \"./${XSKOBJ} -i ${VETH1} -e rx -p ${PEER_HOST} -P ${PEER_PORT} ${ARGS}\"\n     exit\n fi\n \n-exec_xskxceiver\n+run_matrix\n \n-if [ -z $ETH ]; then\n-\tcleanup_exit ${VETH0} ${VETH1}\n-else\n-\tcleanup_iface ${ETH} ${MTU}\n-fi\n+cleanup_exit ${VETH0} ${VETH1}\n \n if [[ $list -eq 1 ]]; then\n     exit\n fi\n \n-TEST_NAME=\"XSK_SELFTESTS_${VETH0}_BUSY_POLL\"\n+RUN_VARIANT=BUSY_POLL\n busy_poll=1\n \n-if [ -z $ETH ]; then\n-\tsetup_vethPairs\n-fi\n-exec_xskxceiver\n+setup_vethPairs\n+run_matrix\n \n ## END TESTS\n \n-if [ -z $ETH ]; then\n-\tcleanup_exit ${VETH0} ${VETH1}\n-else\n-\tcleanup_iface ${ETH} ${MTU}\n-fi\n+cleanup_exit ${VETH0} ${VETH1}\n \n+passes=0\n+skips=0\n failures=0\n-echo -e \"\\nSummary:\"\n+failed_tests=()\n for i in \"${!statusList[@]}\"\n do\n-\tif [ ${statusList[$i]} -ne 0 ]; then\n-\t        test_status ${statusList[$i]} ${nameList[$i]}\n-\t\tfailures=1\n-\tfi\n+\tcase ${statusList[$i]} in\n+\t\t$ksft_pass)\n+\t\t\tpasses=$((passes + 1))\n+\t\t\t;;\n+\t\t$ksft_skip)\n+\t\t\tskips=$((skips + 1))\n+\t\t\t;;\n+\t\t*)\n+\t\t\tfailures=$((failures + 1))\n+\t\t\tfailed_tests+=(\"${nameList[$i]}\")\n+\t\t\t;;\n+\tesac\n done\n \n-if [ $failures -eq 0 ]; then\n-        echo \"All tests successful!\"\n-else\n+echo\n+echo \"Summary:\"\n+printf \"  Tests:   %d\\n\" \"${#statusList[@]}\"\n+printf \"  Passed:  %d\\n\" \"$passes\"\n+printf \"  Skipped: %d\\n\" \"$skips\"\n+printf \"  Failed:  %d\\n\" \"$failures\"\n+\n+if [ $failures -ne 0 ]; then\n+\techo \"Failed tests:\"\n+\tfor TEST_NAME in \"${failed_tests[@]}\"; do\n+\t\techo \"  $TEST_NAME\"\n+\tdone\n \texit 1\n fi\ndiff --git a/tools/testing/selftests/bpf/xsk_prereqs.sh b/tools/testing/selftests/net/xsk_prereqs.sh\nsimilarity index 53%\nrename from tools/testing/selftests/bpf/xsk_prereqs.sh\nrename to tools/testing/selftests/net/xsk_prereqs.sh\nindex 47c7b8064f38b..82cd7839d77d9 100755\n--- a/tools/testing/selftests/bpf/xsk_prereqs.sh\n+++ b/tools/testing/selftests/net/xsk_prereqs.sh\n@@ -8,7 +8,7 @@ ksft_xfail=2\n ksft_xpass=3\n ksft_skip=4\n \n-XSKOBJ=xskxceiver\n+XSKOBJ=lib/xskxceiver\n \n validate_root_exec()\n {\n@@ -53,13 +53,6 @@ test_exit()\n \texit 1\n }\n \n-cleanup_iface()\n-{\n-\tip link set $1 mtu $2\n-\tip link set $1 xdp off\n-\tip link set $1 xdpgeneric off\n-}\n-\n clear_configs()\n {\n \t[ $(ip link show $1 \u0026\u003e/dev/null; echo $?;) == 0 ] \u0026\u0026\n@@ -76,14 +69,63 @@ validate_ip_utility()\n \t[ ! $(type -P ip) ] \u0026\u0026 { echo \"'ip' not found. Skipping tests.\"; test_exit $ksft_skip; }\n }\n \n+wait_port_listen()\n+{\n+\tlocal i\n+\n+\tfor i in $(seq 50); do\n+\t\tif [ -n \"$(ss -Hltn \"sport = :$1\" 2\u003e/dev/null)\" ]; then\n+\t\t\treturn 0\n+\t\tfi\n+\t\tkill -0 $2 2\u003e/dev/null || return 1\n+\t\tsleep 0.1\n+\tdone\n+\treturn 1\n+}\n+\n+random_port()\n+{\n+\tlocal i port\n+\n+\tfor i in $(seq 50); do\n+\t\tport=$((32768 + RANDOM))\n+\t\tif [ -z \"$(ss -Hltn \"sport = :$port\" 2\u003e/dev/null)\" ]; then\n+\t\t\techo \"$port\"\n+\t\t\treturn 0\n+\t\tfi\n+\tdone\n+\treturn 1\n+}\n+\n+# The TX endpoint listens on the control port and runs in the background,\n+# the RX endpoint connects to it and reports; both print the same verdicts.\n exec_xskxceiver()\n {\n+\tlocal tx_log tx_pid tx_ret run_args=\"${ARGS}\"\n+\n         if [[ $busy_poll -eq 1 ]]; then\n-\t        ARGS+=\"-b \"\n+\t\trun_args+=\" -b\"\n+\tfi\n+\n+\ttx_log=$(mktemp)\n+\t./${XSKOBJ} -i ${VETH0} -e tx -p ${PEER_HOST} -P ${PEER_PORT} ${run_args} \u003e ${tx_log} 2\u003e\u00261 \u0026\n+\ttx_pid=$!\n+\n+\tif wait_port_listen ${PEER_PORT} ${tx_pid}; then\n+\t\t./${XSKOBJ} -i ${VETH1} -e rx -p ${PEER_HOST} -P ${PEER_PORT} ${run_args}\n+\t\tretval=$?\n+\telse\n+\t\techo \"TX endpoint did not listen on ${PEER_HOST}:${PEER_PORT}\"\n+\t\tretval=1\n \tfi\n \n-\t./${XSKOBJ} -i ${VETH0} -i ${VETH1} ${ARGS}\n-\tretval=$?\n+\twait ${tx_pid}\n+\ttx_ret=$?\n+\tif [[ $tx_ret -ne 0 || $verbose -eq 1 ]]; then\n+\t\tsed 's/^/tx| /' ${tx_log}\n+\tfi\n+\trm -f ${tx_log}\n+\t[[ $retval -eq 0 ]] \u0026\u0026 retval=$tx_ret\n \n \tif [[ $list -ne 1 ]]; then\n \t    test_status $retval \"${TEST_NAME}\"\n"
}

2/1 2026/10/02 15:39 agent patch-evaluator
1m Model:
core

Args:
null

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "Reasoning": "The patch series touches only documentation (Documentation/networking/af_xdp.rst), MAINTAINERS, and user-space selftests and tooling under tools/testing/selftests/. No kernel source code or compiled kernel image (vmlinux/modules) is modified, so there is no kernel code to fuzz.",
  "WorthFuzzing": false
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit a05bc1140f04aabae706af64482c25331f6a6377
Author: syz-cluster <triage@syzkaller.com>
Date:   Fri Oct 2 15:38:58 2026 +0000

    syz-cluster: applied patch under review

diff --git a/Documentation/networking/af_xdp.rst b/Documentation/networking/af_xdp.rst
index cc3f0d16b28fb..538e71adb7593 100644
--- a/Documentation/networking/af_xdp.rst
+++ b/Documentation/networking/af_xdp.rst
@@ -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
 =======
diff --git a/MAINTAINERS b/MAINTAINERS
index 140eafcbbd782..fd89174efe24d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -29736,7 +29736,9 @@ 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/drivers/net/hw/xsk.py
+F:	tools/testing/selftests/net/*xsk*
+F:	tools/testing/selftests/net/lib/xsk/
 
 XEN BLOCK SUBSYSTEM
 M:	Roger Pau Monné <roger@xenproject.org>
diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftests/bpf/.gitignore
index 986a6389186ba..3c3183ea3c837 100644
--- a/tools/testing/selftests/bpf/.gitignore
+++ b/tools/testing/selftests/bpf/.gitignore
@@ -37,7 +37,6 @@ test_cpp
 /uprobe_multi
 *.ko
 *.tmp
-xskxceiver
 xdp_redirect_multi
 xdp_synproxy
 xdp_hw_metadata
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 93c707116fad0..a2d357781c0fd 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -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 $@
diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index cdf2d7d3ab321..d72d7022cc697 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -622,54 +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;
-}
-
-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;
diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h
index 75133119c04a3..e7333b769150b 100644
--- a/tools/testing/selftests/bpf/network_helpers.h
+++ b/tools/testing/selftests/bpf/network_helpers.h
@@ -89,8 +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 set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
 
 int open_tuntap(const char *dev_name, bool need_mac);
 
diff --git a/tools/testing/selftests/bpf/prog_tests/xsk.c b/tools/testing/selftests/bpf/prog_tests/xsk.c
deleted file mode 100644
index 6e2f63ee2a6c3..0000000000000
--- a/tools/testing/selftests/bpf/prog_tests/xsk.c
+++ /dev/null
@@ -1,170 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <net/if.h>
-#include <stdarg.h>
-
-#include "network_helpers.h"
-#include "test_progs.h"
-#include "test_xsk.h"
-#include "xsk_xdp_progs.skel.h"
-
-#define VETH_RX "veth0"
-#define VETH_TX "veth1"
-#define MTU	1500
-
-int setup_veth(bool busy_poll)
-{
-	SYS(fail,
-	"ip link add %s numtxqueues 4 numrxqueues 4 type veth peer name %s numtxqueues 4 numrxqueues 4",
-	VETH_RX, VETH_TX);
-	SYS(fail, "sysctl -wq net.ipv6.conf.%s.disable_ipv6=1", VETH_RX);
-	SYS(fail, "sysctl -wq net.ipv6.conf.%s.disable_ipv6=1", VETH_TX);
-
-	if (busy_poll) {
-		SYS(fail, "echo 2 > /sys/class/net/%s/napi_defer_hard_irqs", VETH_RX);
-		SYS(fail, "echo 200000 > /sys/class/net/%s/gro_flush_timeout", VETH_RX);
-		SYS(fail, "echo 2 > /sys/class/net/%s/napi_defer_hard_irqs", VETH_TX);
-		SYS(fail, "echo 200000 > /sys/class/net/%s/gro_flush_timeout", VETH_TX);
-	}
-
-	SYS(fail, "ip link set %s mtu %d", VETH_RX, MTU);
-	SYS(fail, "ip link set %s mtu %d", VETH_TX, MTU);
-	SYS(fail, "ip link set %s up", VETH_RX);
-	SYS(fail, "ip link set %s up", VETH_TX);
-
-	return 0;
-
-fail:
-	return -1;
-}
-
-void delete_veth(void)
-{
-	SYS_NOFAIL("ip link del %s", VETH_RX);
-	SYS_NOFAIL("ip link del %s", VETH_TX);
-}
-
-int configure_ifobj(struct ifobject *tx, struct ifobject *rx)
-{
-	rx->ifindex = if_nametoindex(VETH_RX);
-	if (!ASSERT_OK_FD(rx->ifindex, "get RX ifindex"))
-		return -1;
-
-	tx->ifindex = if_nametoindex(VETH_TX);
-	if (!ASSERT_OK_FD(tx->ifindex, "get TX ifindex"))
-		return -1;
-
-	tx->shared_umem = false;
-	rx->shared_umem = false;
-
-
-	return 0;
-}
-
-static void test_xsk(const struct test_spec *test_to_run, enum test_mode mode)
-{
-	u32 max_frags, umem_tailroom, cache_line_size;
-	struct ifobject *ifobj_tx, *ifobj_rx;
-	struct test_spec test;
-	int ret;
-
-	ifobj_tx = ifobject_create();
-	if (!ASSERT_OK_PTR(ifobj_tx, "create ifobj_tx"))
-		return;
-
-	ifobj_rx = ifobject_create();
-	if (!ASSERT_OK_PTR(ifobj_rx, "create ifobj_rx"))
-		goto delete_tx;
-
-	if (!ASSERT_OK(configure_ifobj(ifobj_tx, ifobj_rx), "conigure ifobj"))
-		goto delete_rx;
-
-	ret = get_hw_ring_size(ifobj_tx->ifname, &ifobj_tx->ring);
-	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)
-		cache_line_size = 64;
-
-	max_frags = read_procfs_val(MAX_SKB_FRAGS_PATH);
-	if (!max_frags)
-		max_frags = 17;
-
-	ifobj_tx->max_skb_frags = max_frags;
-	ifobj_rx->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;
-
-	if (!ASSERT_OK(init_iface(ifobj_rx, worker_testapp_validate_rx), "init RX"))
-		goto delete_rx;
-	if (!ASSERT_OK(init_iface(ifobj_tx, worker_testapp_validate_tx), "init TX"))
-		goto delete_rx;
-
-	test_init(&test, ifobj_tx, ifobj_rx, 0, &tests[0]);
-
-	test.tx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);
-	if (!ASSERT_OK_PTR(test.tx_pkt_stream_default, "TX pkt generation"))
-		goto delete_rx;
-	test.rx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);
-	if (!ASSERT_OK_PTR(test.rx_pkt_stream_default, "RX pkt generation"))
-		goto delete_rx;
-
-
-	test_init(&test, ifobj_tx, ifobj_rx, mode, test_to_run);
-	ret = test.test_func(&test);
-	if (ret != TEST_SKIP)
-		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);
-	xsk_xdp_progs__destroy(ifobj_rx->xdp_progs);
-
-delete_rx:
-	ifobject_delete(ifobj_rx);
-delete_tx:
-	ifobject_delete(ifobj_tx);
-}
-
-void test_ns_xsk_skb(void)
-{
-	int i;
-
-	if (!ASSERT_OK(setup_veth(false), "setup veth"))
-		return;
-
-	for (i = 0; i < ARRAY_SIZE(tests); i++) {
-		if (test__start_subtest(tests[i].name))
-			test_xsk(&tests[i], TEST_MODE_SKB);
-	}
-
-	delete_veth();
-}
-
-void test_ns_xsk_drv(void)
-{
-	int i;
-
-	if (!ASSERT_OK(setup_veth(false), "setup veth"))
-		return;
-
-	for (i = 0; i < ARRAY_SIZE(tests); i++) {
-		if (test__start_subtest(tests[i].name))
-			test_xsk(&tests[i], TEST_MODE_DRV);
-	}
-
-	delete_veth();
-}
-
diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
deleted file mode 100644
index 7dad8556a722e..0000000000000
--- a/tools/testing/selftests/bpf/xskxceiver.c
+++ /dev/null
@@ -1,479 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/* Copyright(c) 2020 Intel Corporation. */
-
-/*
- * Some functions in this program are taken from
- * Linux kernel samples/bpf/xdpsock* and modified
- * for use.
- *
- * See test_xsk.sh for detailed information on test topology
- * and prerequisite network setup.
- *
- * This test program contains two threads, each thread is single socket with
- * a unique UMEM. It validates in-order packet delivery and packet content
- * by sending packets to each other.
- *
- * Tests Information:
- * ------------------
- * These selftests test AF_XDP SKB and Native/DRV modes using veth
- * Virtual Ethernet interfaces.
- *
- * For each mode, the following tests are run:
- *    a. nopoll - soft-irq processing in run-to-completion mode
- *    b. poll - using poll() syscall
- *    c. Socket Teardown
- *       Create a Tx and a Rx socket, Tx from one socket, Rx on another. Destroy
- *       both sockets, then repeat multiple times. Only nopoll mode is used
- *    d. Bi-directional sockets
- *       Configure sockets as bi-directional tx/rx sockets, sets up fill and
- *       completion rings on each socket, tx/rx in both directions. Only nopoll
- *       mode is used
- *    e. Statistics
- *       Trigger some error conditions and ensure that the appropriate statistics
- *       are incremented. Within this test, the following statistics are tested:
- *       i.   rx dropped
- *            Increase the UMEM frame headroom to a value which results in
- *            insufficient space in the rx buffer for both the packet and the headroom.
- *       ii.  tx invalid
- *            Set the 'len' field of tx descriptors to an invalid value (umem frame
- *            size + 1).
- *       iii. rx ring full
- *            Reduce the size of the RX ring to a fraction of the fill ring size.
- *       iv.  fill queue empty
- *            Do not populate the fill queue and then try to receive pkts.
- *    f. bpf_link resource persistence
- *       Configure sockets at indexes 0 and 1, run a traffic on queue ids 0,
- *       then remove xsk sockets from queue 0 on both veth interfaces and
- *       finally run a traffic on queues ids 1
- *    g. unaligned mode
- *    h. tests for invalid and corner case Tx descriptors so that the correct ones
- *       are discarded and let through, respectively.
- *    i. 2K frame size tests
- *    j. If multi-buffer is supported, send 9k packets divided into 3 frames
- *    k. If multi-buffer and huge pages are supported, send 9k packets in a single frame
- *       using unaligned mode
- *    l. If multi-buffer is supported, try various nasty combinations of descriptors to
- *       check if they pass the validation or not
- *
- * Flow:
- * -----
- * - Single process spawns two threads: Tx and Rx
- * - Each of these two threads attach to a veth interface
- * - Each thread creates one AF_XDP socket connected to a unique umem for each
- *   veth interface
- * - Tx thread Transmits a number of packets from veth<xxxx> to veth<yyyy>
- * - Rx thread verifies if all packets were received and delivered in-order,
- *   and have the right content
- *
- * Enable/disable packet dump mode:
- * --------------------------
- * To enable L2 - L4 headers and payload dump of each packet on STDOUT, add
- * parameter -D to params array in test_xsk.sh, i.e. params=("-S" "-D")
- */
-
-#define _GNU_SOURCE
-#include <assert.h>
-#include <fcntl.h>
-#include <getopt.h>
-#include <linux/if_link.h>
-#include <linux/if_ether.h>
-#include <linux/mman.h>
-#include <linux/netdev.h>
-#include <linux/ethtool.h>
-#include <linux/align.h>
-#include <arpa/inet.h>
-#include <net/if.h>
-#include <locale.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <libgen.h>
-#include <stddef.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-
-#include "prog_tests/test_xsk.h"
-#include "xsk_xdp_progs.skel.h"
-#include "xsk.h"
-#include "xskxceiver.h"
-#include <bpf/bpf.h>
-#include <linux/filter.h>
-#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,
-			      error, strerror(error));
-	ksft_exit_xfail();
-}
-
-#define exit_with_error(error) __exit_with_error(error, __FILE__, __func__, __LINE__)
-
-static bool ifobj_zc_avail(struct ifobject *ifobject)
-{
-	size_t umem_sz = DEFAULT_UMEM_BUFFERS * XSK_UMEM__DEFAULT_FRAME_SIZE;
-	int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE;
-	struct xsk_socket_info *xsk;
-	struct xsk_umem_info *umem;
-	bool zc_avail = false;
-	void *bufs;
-	int ret;
-
-	bufs = mmap(NULL, umem_sz, PROT_READ | PROT_WRITE, mmap_flags, -1, 0);
-	if (bufs == MAP_FAILED)
-		exit_with_error(errno);
-
-	umem = calloc(1, sizeof(struct xsk_umem_info));
-	if (!umem) {
-		munmap(bufs, umem_sz);
-		exit_with_error(ENOMEM);
-	}
-	umem->frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE;
-	ret = xsk_configure_umem(ifobject, umem, bufs, umem_sz);
-	if (ret)
-		exit_with_error(-ret);
-
-	xsk = calloc(1, sizeof(struct xsk_socket_info));
-	if (!xsk)
-		goto out;
-	ifobject->bind_flags = XDP_USE_NEED_WAKEUP | XDP_ZEROCOPY;
-	ifobject->rx_on = true;
-	xsk->rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS;
-	ret = xsk_configure_socket(xsk, umem, ifobject, false);
-	if (!ret)
-		zc_avail = true;
-
-	xsk_socket__delete(xsk->xsk);
-	free(xsk);
-out:
-	munmap(umem->buffer, umem_sz);
-	xsk_umem__delete(umem->umem);
-	free(umem);
-	return zc_avail;
-}
-
-static struct option long_options[] = {
-	{"interface", required_argument, 0, 'i'},
-	{"busy-poll", no_argument, 0, 'b'},
-	{"verbose", no_argument, 0, 'v'},
-	{"mode", required_argument, 0, 'm'},
-	{"list", no_argument, 0, 'l'},
-	{"test", required_argument, 0, 't'},
-	{"help", no_argument, 0, 'h'},
-	{0, 0, 0, 0}
-};
-
-static void print_usage(char **argv)
-{
-	const char *str =
-		"  Usage: xskxceiver [OPTIONS]\n"
-		"  Options:\n"
-		"  -i, --interface      Use interface\n"
-		"  -v, --verbose        Verbose output\n"
-		"  -b, --busy-poll      Enable busy poll\n"
-		"  -m, --mode           Run only mode skb, drv, or zc\n"
-		"  -l, --list           List all available tests\n"
-		"  -t, --test           Run a specific test. Enter number from -l option.\n"
-		"  -h, --help           Display this help and exit\n";
-
-	ksft_print_msg(str, basename(argv[0]));
-	ksft_exit_xfail();
-}
-
-static bool validate_interface(struct ifobject *ifobj)
-{
-	if (!strcmp(ifobj->ifname, ""))
-		return false;
-	return true;
-}
-
-static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj_rx, int argc,
-			       char **argv)
-{
-	struct ifobject *ifobj;
-	u32 interface_nb = 0;
-	int option_index, c;
-
-	opterr = 0;
-
-	for (;;) {
-		c = getopt_long(argc, argv, "i:vbm:lt:", long_options, &option_index);
-		if (c == -1)
-			break;
-
-		switch (c) {
-		case 'i':
-			if (interface_nb == 0)
-				ifobj = ifobj_tx;
-			else if (interface_nb == 1)
-				ifobj = ifobj_rx;
-			else
-				break;
-
-			memcpy(ifobj->ifname, optarg,
-			       min_t(size_t, MAX_INTERFACE_NAME_CHARS, strlen(optarg)));
-
-			ifobj->ifindex = if_nametoindex(ifobj->ifname);
-			if (!ifobj->ifindex)
-				exit_with_error(errno);
-
-			interface_nb++;
-			break;
-		case 'v':
-			opt_verbose = true;
-			break;
-		case 'b':
-			ifobj_tx->busy_poll = true;
-			ifobj_rx->busy_poll = true;
-			break;
-		case 'm':
-			if (!strncmp("skb", optarg, strlen(optarg)))
-				opt_mode = TEST_MODE_SKB;
-			else if (!strncmp("drv", optarg, strlen(optarg)))
-				opt_mode = TEST_MODE_DRV;
-			else if (!strncmp("zc", optarg, strlen(optarg)))
-				opt_mode = TEST_MODE_ZC;
-			else
-				print_usage(argv);
-			break;
-		case 'l':
-			opt_print_tests = true;
-			break;
-		case 't':
-			errno = 0;
-			opt_run_test = strtol(optarg, NULL, 0);
-			if (errno)
-				print_usage(argv);
-			break;
-		case 'h':
-		default:
-			print_usage(argv);
-		}
-	}
-}
-
-static void xsk_unload_xdp_programs(struct ifobject *ifobj)
-{
-	xsk_xdp_progs__destroy(ifobj->xdp_progs);
-}
-
-static void run_pkt_test(struct test_spec *test)
-{
-	int ret;
-
-	ret = test->test_func(test);
-
-	switch (ret) {
-	case TEST_PASS:
-		ksft_test_result_pass("PASS: %s %s%s\n", mode_string(test), busy_poll_string(test),
-				      test->name);
-		break;
-	case TEST_SKIP:
-		ksft_test_result_skip("SKIP: %s %s%s\n", mode_string(test), busy_poll_string(test),
-				      test->name);
-		break;
-	case TEST_FAILURE:
-		ksft_test_result_fail("FAIL: %s %s%s\n", mode_string(test), busy_poll_string(test),
-				      test->name);
-		break;
-	default:
-		ksft_test_result_fail("FAIL: %s %s%s -- Unexpected returned value (%d)\n",
-				      mode_string(test), busy_poll_string(test), test->name, ret);
-	}
-
-	pkt_stream_restore_default(test);
-}
-
-static bool is_xdp_supported(int ifindex)
-{
-	int flags = XDP_FLAGS_DRV_MODE;
-
-	LIBBPF_OPTS(bpf_link_create_opts, opts, .flags = flags);
-	struct bpf_insn insns[2] = {
-		BPF_MOV64_IMM(BPF_REG_0, XDP_PASS),
-		BPF_EXIT_INSN()
-	};
-	int prog_fd, insn_cnt = ARRAY_SIZE(insns);
-	int err;
-
-	prog_fd = bpf_prog_load(BPF_PROG_TYPE_XDP, NULL, "GPL", insns, insn_cnt, NULL);
-	if (prog_fd < 0)
-		return false;
-
-	err = bpf_xdp_attach(ifindex, prog_fd, flags, NULL);
-	if (err) {
-		close(prog_fd);
-		return false;
-	}
-
-	bpf_xdp_detach(ifindex, flags, NULL);
-	close(prog_fd);
-
-	return true;
-}
-
-static void print_tests(void)
-{
-	u32 i;
-
-	printf("Tests:\n");
-	for (i = 0; i < ARRAY_SIZE(tests); i++)
-		printf("%u: %s\n", i, tests[i].name);
-	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;
-	struct pkt_stream *rx_pkt_stream_default;
-	struct pkt_stream *tx_pkt_stream_default;
-	struct ifobject *ifobj_tx, *ifobj_rx;
-	u32 i, j, failed_tests = 0, nb_tests;
-	int modes = TEST_MODE_SKB + 1;
-	struct test_spec test;
-	bool shared_netdev;
-	int ret;
-
-	/* Use libbpf 1.0 API mode */
-	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
-
-	ifobj_tx = ifobject_create();
-	if (!ifobj_tx)
-		exit_with_error(ENOMEM);
-	ifobj_rx = ifobject_create();
-	if (!ifobj_rx)
-		exit_with_error(ENOMEM);
-
-	setlocale(LC_ALL, "");
-
-	cache_line_size = read_procfs_val(SMP_CACHE_BYTES_PATH);
-	if (!cache_line_size) {
-		ksft_print_msg("Can't get SMP_CACHE_BYTES from system, using default (64)\n");
-		cache_line_size = 64;
-	}
-
-	max_frags = read_procfs_val(MAX_SKB_FRAGS_PATH);
-	if (!max_frags) {
-		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;
-
-	/* 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;
-
-	parse_command_line(ifobj_tx, ifobj_rx, argc, argv);
-
-	if (opt_print_tests) {
-		print_tests();
-		ksft_exit_xpass();
-	}
-	if (opt_run_test != RUN_ALL_TESTS && opt_run_test >= total_tests) {
-		ksft_print_msg("Error: test %u does not exist.\n", opt_run_test);
-		ksft_exit_xfail();
-	}
-
-	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);
-
-	if (is_xdp_supported(ifobj_tx->ifindex)) {
-		modes++;
-		if (ifobj_zc_avail(ifobj_tx))
-			modes++;
-	}
-
-	ret = get_hw_ring_size(ifobj_tx->ifname, &ifobj_tx->ring);
-	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)) {
-		ksft_print_msg("Error : can't initialize interfaces\n");
-		ksft_exit_xfail();
-	}
-
-	test_init(&test, ifobj_tx, ifobj_rx, 0, &tests[0]);
-	tx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);
-	rx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);
-	if (!tx_pkt_stream_default || !rx_pkt_stream_default)
-		exit_with_error(ENOMEM);
-	test.tx_pkt_stream_default = tx_pkt_stream_default;
-	test.rx_pkt_stream_default = rx_pkt_stream_default;
-
-	if (opt_run_test == RUN_ALL_TESTS)
-		nb_tests = total_tests;
-	else
-		nb_tests = 1;
-	if (opt_mode == TEST_MODE_ALL) {
-		ksft_set_plan(modes * nb_tests);
-	} else {
-		if (opt_mode == TEST_MODE_DRV && modes <= TEST_MODE_DRV) {
-			ksft_print_msg("Error: XDP_DRV mode not supported.\n");
-			ksft_exit_xfail();
-		}
-		if (opt_mode == TEST_MODE_ZC && modes <= TEST_MODE_ZC) {
-			ksft_print_msg("Error: zero-copy mode not supported.\n");
-			ksft_exit_xfail();
-		}
-
-		ksft_set_plan(nb_tests);
-	}
-
-	for (i = 0; i < modes; i++) {
-		if (opt_mode != TEST_MODE_ALL && i != opt_mode)
-			continue;
-
-		for (j = 0; j < total_tests; j++) {
-			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)]);
-			run_pkt_test(&test);
-			usleep(USLEEP_MAX);
-
-			if (test.fail)
-				failed_tests++;
-		}
-	}
-
-	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);
-	xsk_unload_xdp_programs(ifobj_rx);
-	ifobject_delete(ifobj_tx);
-	ifobject_delete(ifobj_rx);
-
-	if (failed_tests)
-		ksft_exit_fail();
-	else
-		ksft_exit_pass();
-}
diff --git a/tools/testing/selftests/drivers/net/README.rst b/tools/testing/selftests/drivers/net/README.rst
index c6bed9a985bc7..34a5053a9816d 100644
--- a/tools/testing/selftests/drivers/net/README.rst
+++ b/tools/testing/selftests/drivers/net/README.rst
@@ -132,6 +132,13 @@ Communication channel dependent::
   for netns - name of the "remote" namespace
   for ssh - name/address of the remote host
 
+Test specific variables
+~~~~~~~~~~~~~~~~~~~~~~~
+
+Some tests read further variables from the same environment or
+``net.config``. ``hw/xsk.py`` and its ``XSK_*`` variables are described in
+``tools/testing/selftests/net/lib/xsk/README.rst``.
+
 Example
 =======
 
diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile
index 78bb0169350b2..b43bde9f309f2 100644
--- a/tools/testing/selftests/drivers/net/hw/Makefile
+++ b/tools/testing/selftests/drivers/net/hw/Makefile
@@ -50,6 +50,7 @@ TEST_PROGS = \
 	userns_devmem.py \
 	uso.py \
 	xdp_metadata.py \
+	xsk.py \
 	xsk_reconfig.py \
 	#
 
diff --git a/tools/testing/selftests/drivers/net/hw/config b/tools/testing/selftests/drivers/net/hw/config
index d89a9ba176558..fbf048d1d7323 100644
--- a/tools/testing/selftests/drivers/net/hw/config
+++ b/tools/testing/selftests/drivers/net/hw/config
@@ -25,4 +25,5 @@ CONFIG_SYNC_FILE=y
 CONFIG_UDMABUF=y
 CONFIG_USER_NS=y
 CONFIG_VXLAN=y
+CONFIG_XDP_SOCKETS=y
 CONFIG_XFRM_USER=y
diff --git a/tools/testing/selftests/drivers/net/hw/xsk.py b/tools/testing/selftests/drivers/net/hw/xsk.py
new file mode 100755
index 0000000000000..dd6bdbb1abeaf
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/hw/xsk.py
@@ -0,0 +1,402 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+"""AF_XDP zero-copy hardware tests with an SKB-mode XSK peer."""
+
+import re
+import shlex
+import subprocess
+import sys
+import time
+from pathlib import Path
+
+from lib.py import (EthtoolFamily, KsftFailEx, KsftNamedVariant, KsftSkipEx,
+                    NetdevFamily, NetDrvEpEnv, bkg, cmd, defer, ethtool,
+                    fd_read_timeout, ip, ksft_exit, ksft_pr, ksft_run,
+                    ksft_variants, rand_port)
+
+CASE_TIMEOUT = 120
+LISTEN_TIMEOUT = 30
+NR_HUGEPAGES = 32
+SKIP_CODE = 4
+XSK_BIN = (Path(__file__).parent / "../../../net/lib/xskxceiver").resolve()
+XSK_CASES = XSK_BIN.parent / "xsk/test_xsk_case_defs.h"
+
+
+def _hardware_cases():
+    defs = XSK_CASES.read_text()
+    entries = re.findall(r"(?m)^XSK_TEST_CASE\((\w+),\s*\w+,\s*([^)]+)\)", defs)
+    if not entries or len(entries) != defs.count("XSK_TEST_CASE("):
+        raise KsftFailEx(f"cannot parse {XSK_CASES}")
+    variants = []
+    for test_id, (name, hw) in enumerate(entries):
+        flags = {flag.strip() for flag in hw.split("|")}
+        if not flags <= {"0", "XSK_HW_RX", "XSK_HW_TX"}:
+            raise KsftFailEx(f"invalid hardware directions for {name}: {hw}")
+        variants += [KsftNamedVariant(f"{d}_{name.lower()}", name, d, test_id)
+                     for d in ("rx", "tx") if f"XSK_HW_{d.upper()}" in flags]
+    return variants
+
+
+def _management_addr(cfg):
+    if cfg.env.get("REMOTE_TYPE") == "ssh":
+        return cfg.remote.name.rpartition("@")[2]
+    raise KsftSkipEx("AF_XDP hardware tests require an SSH remote")
+
+
+def _root_cmd(command, host=None, sudo=False, **kwargs):
+    if sudo:
+        command = "sudo -n " + command
+    return cmd(command, host=host, **kwargs)
+
+
+def _remote_binary(cfg, local_binary):
+    binary = cfg.env.get("XSK_REMOTE_BIN")
+    if not binary:
+        return cfg.remote.deploy(local_binary)
+    if cfg.env.get("REMOTE_TYPE") != "ssh":
+        raise KsftSkipEx("XSK_REMOTE_BIN requires the SSH remote backend")
+    if cfg.env.get("XSK_REMOTE_DEPLOY", "1") == "0":
+        result = cmd(f"test -x {shlex.quote(binary)}", host=cfg.remote,
+                     fail=False)
+        if result.ret:
+            raise KsftSkipEx(f"remote xskxceiver is not executable: {binary}")
+        return binary
+    upload = binary + ".upload"
+    cmd(["scp", "-q", str(local_binary), f"{cfg.remote.name}:{upload}"],
+        shell=False)
+    cmd(f"mv -f {shlex.quote(upload)} {shlex.quote(binary)}",
+        host=cfg.remote)
+    return binary
+
+
+def _remote_sudo(cfg):
+    return cfg.env.get("XSK_REMOTE_SUDO", "").lower() not in ("", "0", "false")
+
+
+def _restore_mtu(ifname, mtu, host=None, sudo=False):
+    actual = ip(f"link show dev {shlex.quote(ifname)}", json=True,
+                host=host)[0]["mtu"]
+    if actual == mtu:
+        return
+    _root_cmd(f"ip link set dev {shlex.quote(ifname)} mtu {mtu}",
+              host=host, sudo=sudo)
+
+
+def _reserve_hugepages(host=None, sudo=False):
+    have = int(cmd("sysctl -n vm.nr_hugepages", host=host).stdout)
+    if have >= NR_HUGEPAGES:
+        return
+    _root_cmd(f"sysctl -qw vm.nr_hugepages={NR_HUGEPAGES}", host=host,
+              sudo=sudo, fail=False)
+    got = int(cmd("sysctl -n vm.nr_hugepages", host=host).stdout)
+    if got != have:
+        defer(_root_cmd, f"sysctl -qw vm.nr_hugepages={have}", host=host,
+              sudo=sudo)
+    if got < NR_HUGEPAGES:
+        raise KsftSkipEx(f"only {got}/{NR_HUGEPAGES} hugepages available")
+
+
+def _prefer_busy_poll(ifname):
+    """SO_PREFER_BUSY_POLL keeps the device IRQs masked between busy polls
+    only while napi_defer_hard_irqs and gro_flush_timeout are set. Use the
+    values that test_xsk.sh sets on veth."""
+    for knob, value in (("napi_defer_hard_irqs", "2"),
+                        ("gro_flush_timeout", "200000")):
+        path = Path("/sys/class/net", ifname, knob)
+        orig = path.read_text(encoding="utf-8").strip()
+        if orig != value:
+            path.write_text(value, encoding="utf-8")
+            defer(path.write_text, orig, encoding="utf-8")
+
+
+def _feature_state(ifname, feature, host=None):
+    """Read an ethtool -k feature. Parse the text output, as older ethtool
+    versions can't print -k as JSON."""
+    output = ethtool(f"-k {shlex.quote(ifname)}", host=host).stdout
+    match = re.search(rf"^{re.escape(feature)}:\s+(on|off)(.*)$", output,
+                      re.MULTILINE)
+    if not match:
+        raise KsftSkipEx(f"ethtool does not report {feature} on {ifname}")
+    return {"active": match[1] == "on", "fixed": "[fixed]" in match[2]}
+
+
+def _steer_udp(ifname, port, queue, host=None, sudo=False):
+    dev = shlex.quote(ifname)
+    rule = f"ethtool -N {dev} flow-type udp4 dst-port {port} action {queue}"
+    # Look at ntuple-filters only once the rule is refused, as every command
+    # on the remote costs a round trip.
+    added = _root_cmd(rule, host=host, sudo=sudo, fail=False)
+    if added.ret:
+        ntuple = _feature_state(ifname, "ntuple-filters", host)
+        if not ntuple["active"]:
+            if ntuple["fixed"]:
+                raise KsftSkipEx("NIC does not support ntuple filters")
+            _root_cmd(f"ethtool -K {dev} ntuple-filters on", host=host,
+                      sudo=sudo)
+            defer(_root_cmd, f"ethtool -K {dev} ntuple-filters off",
+                  host=host, sudo=sudo)
+            added = _root_cmd(rule, host=host, sudo=sudo, fail=False)
+    if added.ret:
+        ksft_pr(repr(added))
+        raise KsftSkipEx(f"cannot steer UDP flow to queue {queue} on {ifname}")
+    match = re.search(r"ID (\d+)", added.stdout)
+    if not match:
+        raise KsftFailEx(f"cannot identify new ntuple rule: {added.stdout}")
+    defer(_root_cmd, f"ethtool -N {dev} delete {match[1]}", host=host,
+          sudo=sudo)
+
+
+def _reserve_rx_queue(cfg, port):
+    """Move one RX queue out of default RSS and steer the test UDP flow."""
+    header = {"dev-index": cfg.ifindex}
+    channels = cfg.ethnl.channels_get({"header": header})
+    count = (channels.get("combined-count") or 0) + (channels.get("rx-count") or 0)
+    if count < 2:
+        raise KsftSkipEx("RX queue isolation needs at least two channels")
+    queue = count - 1
+
+    try:
+        rss = cfg.ethnl.rss_get({"header": header})
+        saved = list(rss["indir"])
+    except Exception as exc:
+        raise KsftSkipEx(f"cannot read RSS indirection table: {exc}") from exc
+    if queue in saved:
+        updated = [0 if entry == queue else entry for entry in saved]
+        try:
+            cfg.ethnl.rss_set({"header": header, "indir": updated})
+        except Exception as exc:
+            raise KsftSkipEx(f"cannot reserve RX queue in RSS: {exc}") from exc
+        defer(cfg.ethnl.rss_set, {"header": header, "indir": saved})
+        actual = cfg.ethnl.rss_get({"header": header}).get("indir")
+        if actual != updated:
+            raise KsftSkipEx("NIC did not remove the reserved queue from RSS")
+
+    _steer_udp(cfg.ifname, port, queue)
+    return queue
+
+
+def _case_args(cfg, name):
+    if name != "TOO_MANY_FRAGS":
+        return []
+    try:
+        info = cfg.netnl.dev_get({"ifindex": cfg.ifindex})
+    except Exception as exc:
+        raise KsftSkipEx(f"cannot query DUT fragment limit: {exc}") from exc
+    max_frags = info.get("xdp-zc-max-segs", 0)
+    if max_frags <= 1:
+        raise KsftSkipEx("DUT does not advertise multi-buffer zero-copy")
+    return ["--max-frags", str(max_frags)]
+
+
+def _idle_mtu(ifname, host=None):
+    """Return the MTU of a link that has no XDP program attached."""
+    info = ip(f"link show dev {shlex.quote(ifname)}", json=True, host=host)[0]
+    if "xdp" in info:
+        raise KsftSkipEx(f"{ifname} already has an XDP program")
+    return info["mtu"]
+
+
+def _remote_idle_mtu(cfg):
+    """Look at the remote link once. Every case leaves its MTU as it found
+    it and an endpoint replaces a program left behind by an earlier case,
+    so looking again would only add a round trip to each case."""
+    if not hasattr(cfg, "xsk_remote_mtu"):
+        cfg.xsk_remote_mtu = _idle_mtu(cfg.remote_ifname, cfg.remote)
+    return cfg.xsk_remote_mtu
+
+
+def _detach_xdp(ifname, mode, host=None, sudo=False):
+    """A killed endpoint leaves its XDP program behind; name the mode, as a
+    bare "xdp off" only detaches driver mode on a native-XDP NIC."""
+    info = ip(f"link show dev {shlex.quote(ifname)}", json=True, host=host)[0]
+    if "xdp" not in info:
+        return
+    _root_cmd(f"ip link set dev {shlex.quote(ifname)} {mode} off", host=host,
+              sudo=sudo)
+
+
+def _wait_remote_listen(remote, port):
+    """Read the remote endpoint's stderr up to the line it prints once it
+    listens, as polling its sockets would cost a round trip per try. Return
+    what was read and whether that line came."""
+    line = f"Listening for XSK peer on port {port}\n".encode()
+    fd = remote.proc.stderr.fileno()
+    head = b""
+    deadline = time.monotonic() + LISTEN_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 _require_zc(cfg):
+    if not hasattr(cfg, "xsk_zc"):
+        xdp_features = cfg.netnl.dev_get({"ifindex": cfg.ifindex})["xdp-features"]
+        cfg.xsk_zc = "xsk-zerocopy" in xdp_features
+    if not cfg.xsk_zc:
+        raise KsftSkipEx("NIC does not advertise AF_XDP zero-copy")
+
+
+def _remote_test_binary(cfg):
+    if not hasattr(cfg, "xsk_remote_bin"):
+        cfg.xsk_remote_bin = _remote_binary(cfg, XSK_BIN)
+    return cfg.xsk_remote_bin
+
+
+def _udp_port(cfg):
+    port = int(cfg.env.get("XSK_UDP_PORT", "42567"))
+    if not 1 <= port <= 65535:
+        raise KsftFailEx("XSK_UDP_PORT must be from 1 to 65535")
+    return port
+
+
+def _setup_case(cfg, name, direction, port, busy_poll):
+    """Set up what this case alone needs; defer() undoes it when it ends.
+    Return the DUT queue and the fallbacks for what the endpoints undo."""
+    sudo = _remote_sudo(cfg)
+    local_mtu = _idle_mtu(cfg.ifname)
+    remote_mtu = _remote_idle_mtu(cfg)
+    if "UNALIGNED" in name:
+        _reserve_hugepages()
+        _reserve_hugepages(cfg.remote, sudo)
+    if busy_poll:
+        _prefer_busy_poll(cfg.ifname)
+
+    if direction == "rx":
+        queue = _reserve_rx_queue(cfg, port)
+    else:
+        queue = 0
+        _steer_udp(cfg.remote_ifname, port, 0, cfg.remote, sudo)
+
+    # Undo what a failed or killed endpoint may leave behind. Defers run in
+    # reverse, so the XDP programs, which can cap the MTU, are detached first.
+    fallbacks = [
+        defer(_restore_mtu, cfg.ifname, local_mtu),
+        defer(_restore_mtu, cfg.remote_ifname, remote_mtu, cfg.remote, sudo),
+        defer(_detach_xdp, cfg.ifname, "xdpdrv"),
+        defer(_detach_xdp, cfg.remote_ifname, "xdpgeneric", cfg.remote, sudo),
+    ]
+    return queue, fallbacks
+
+
+def _udp_args(cfg, direction, port):
+    if direction == "rx":
+        src, dst = cfg.remote_addr_v["4"], cfg.addr_v["4"]
+    else:
+        src, dst = cfg.addr_v["4"], cfg.remote_addr_v["4"]
+    return ["--udp-src", src, "--udp-dst", dst, "--udp-port", str(port)]
+
+
+def _case_result(local, remote):
+    if local and local.stdout:
+        ksft_pr(local.stdout, line_pfx="dut|")
+    if local and local.stderr:
+        ksft_pr(local.stderr, line_pfx="dut|")
+    if remote.stdout:
+        ksft_pr(remote.stdout, line_pfx="remote|")
+    if remote.stderr:
+        ksft_pr(remote.stderr, line_pfx="remote|")
+    if local is None:
+        raise KsftFailEx("remote XSK endpoint did not listen on the control "
+                         f"port, exit {remote.ret}")
+    if local.ret == SKIP_CODE or remote.ret == SKIP_CODE:
+        raise KsftSkipEx("AF_XDP case unsupported by one endpoint")
+    if local.ret or remote.ret:
+        raise KsftFailEx(f"DUT exit {local.ret}, remote exit {remote.ret}")
+
+
+def _run_local(args):
+    local = cmd(args, background=True, shell=False, fail=False)
+    try:
+        local.process(terminate=False, fail=False, timeout=CASE_TIMEOUT)
+    except subprocess.TimeoutExpired as exc:
+        local.proc.kill()
+        local.process(terminate=False, fail=False)
+        raise KsftFailEx(f"DUT case timed out after {CASE_TIMEOUT}s") from exc
+    return local
+
+
+def _run_endpoints(cfg, local_args, remote_args, control_port, fallbacks):
+    local = None
+    remote = bkg(shlex.join(remote_args), host=cfg.remote, exit_wait=True,
+                 fail=False)
+    try:
+        head, listening = _wait_remote_listen(remote, control_port)
+        if listening:
+            local = _run_local(local_args)
+            remote.process(terminate=False, fail=False, timeout=10)
+    finally:
+        if remote.ret is None:
+            remote.process(terminate=True, fail=False)
+    # _wait_remote_listen() took the start of stderr off the pipe.
+    remote.stderr = head + remote.stderr
+    if local and {local.ret, remote.ret} <= {0, SKIP_CODE}:
+        # Both endpoints detached XDP and restored the MTU when they exited.
+        for fallback in fallbacks:
+            fallback.cancel()
+    _case_result(local, remote)
+
+
+def test_xsk(cfg, name, direction, test_id, busy_poll=False):
+    cfg.require_ipver("4")
+    sync_addr = _management_addr(cfg)
+    udp_port = _udp_port(cfg)
+    _require_zc(cfg)
+    remote_bin = _remote_test_binary(cfg)
+    case_args = _case_args(cfg, name)
+    queue, fallbacks = _setup_case(cfg, name, direction, udp_port, busy_poll)
+
+    udp_args = _udp_args(cfg, direction, udp_port)
+    control_port = rand_port()
+    remote_args = [str(remote_bin), "-i", cfg.remote_ifname,
+                   "--hw", "--listen", "-m", "skb",
+                   "-t", str(test_id),
+                   "-e", "tx" if direction == "rx" else "rx",
+                   "-p", "0.0.0.0", "-P", str(control_port), *udp_args,
+                   "--peer-mac", cfg.dev["address"], "--queue", "0", *case_args]
+    if _remote_sudo(cfg):
+        remote_args = ["sudo", "-n"] + remote_args
+    local_args = [str(XSK_BIN), "-i", cfg.ifname, "--hw", "-m", "zc",
+                  "-t", str(test_id), "-e", direction,
+                  "-p", sync_addr, "-P", str(control_port), *udp_args,
+                  "--peer-mac", cfg.remote_dev["address"],
+                  "--queue", str(queue), *case_args]
+    if busy_poll:
+        local_args.append("-b")
+    _run_endpoints(cfg, local_args, remote_args, control_port, fallbacks)
+
+
+def test_xsk_busy_poll(cfg, name, direction, test_id):
+    """Run a case with the DUT endpoint busy polling."""
+    test_xsk(cfg, name, direction, test_id, busy_poll=True)
+
+
+def main():
+    # ksft_run() rejects options it does not know, so take -b out first.
+    busy_poll = "-b" in sys.argv[1:]
+    if busy_poll:
+        sys.argv.remove("-b")
+    test = test_xsk_busy_poll if busy_poll else test_xsk
+    variants = ksft_variants(_hardware_cases())(test)
+
+    if any(arg in ("-h", "-l") for arg in sys.argv[1:]):
+        ksft_run(cases=[variants])
+        return
+    if not XSK_BIN.exists():
+        print(f"1..0 # SKIP {XSK_BIN} was not built")
+        sys.exit(SKIP_CODE)
+    with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+        cfg.ethnl = EthtoolFamily()
+        cfg.netnl = NetdevFamily()
+        ksft_run(cases=[variants], args=(cfg,))
+    ksft_exit()
+
+
+if __name__ == "__main__":
+    main()
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 3ee3378f8b26e..f0e2cc1917e0e 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -117,6 +117,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 \
@@ -206,6 +207,7 @@ TEST_FILES := \
 	in_netns.sh \
 	lib.sh \
 	settings \
+	xsk_prereqs.sh \
 # end of TEST_FILES
 
 # YNL files, must be before "include ..lib.mk"
diff --git a/tools/testing/selftests/net/bpf.mk b/tools/testing/selftests/net/bpf.mk
index a4f6755dd8941..6a2f078fed9d6 100644
--- a/tools/testing/selftests/net/bpf.mk
+++ b/tools/testing/selftests/net/bpf.mk
@@ -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,10 @@ $(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 $*) > $@
+
 $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile)		       \
 	   $(APIDIR)/linux/bpf.h					       \
 	   | $(BUILD_DIR)/libbpf
diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config
index 30d5fcb09a831..eddc8dcd7da63 100644
--- a/tools/testing/selftests/net/config
+++ b/tools/testing/selftests/net/config
@@ -135,5 +135,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
diff --git a/tools/testing/selftests/net/lib/.gitignore b/tools/testing/selftests/net/lib/.gitignore
index 6cd2b762af5d5..1106fef3041ff 100644
--- a/tools/testing/selftests/net/lib/.gitignore
+++ b/tools/testing/selftests/net/lib/.gitignore
@@ -2,3 +2,5 @@
 csum
 gro
 xdp_helper
+xsk_xdp_progs.skel.h
+xskxceiver
diff --git a/tools/testing/selftests/net/lib/Makefile b/tools/testing/selftests/net/lib/Makefile
index ff83603397d06..0757a20612ae6 100644
--- a/tools/testing/selftests/net/lib/Makefile
+++ b/tools/testing/selftests/net/lib/Makefile
@@ -18,8 +18,51 @@ TEST_GEN_FILES := \
 	xdp_helper \
 # end of TEST_GEN_FILES
 
-TEST_INCLUDES := $(wildcard py/*.py sh/*.sh)
+BPFTOOL ?= bpftool
+HAS_BPFTOOL := $(shell command -v $(BPFTOOL) >/dev/null 2>&1 && echo y)
+ifeq ($(HAS_BPFTOOL),y)
+TEST_GEN_FILES += xskxceiver
+else
+$(warning excluding xskxceiver, bpftool not found)
+endif
+
+TEST_INCLUDES := $(wildcard py/*.py sh/*.sh) xsk/test_xsk_case_defs.h
 
 include ../../lib.mk
 
 include ../bpf.mk
+
+# AF_XDP test engine shared by net/test_xsk.sh 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
+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)
+
+# xsk.py may copy xskxceiver to a host with an older libc.  Prefer a
+# static binary when the required archives are installed.  XSK_STATIC=0/1
+# can be used to override the probe.
+PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
+XSK_STATIC_LIBS := $(shell $(PKG_CONFIG) libelf --static --libs 2>/dev/null || \
+	echo -lelf -lz -lzstd) -lz
+XSK_STATIC ?= $(shell echo 'int main(void) { return 0; }' | \
+	$(CC) -x c - -static $(XSK_STATIC_LIBS) -o /dev/null 2>/dev/null && echo 1)
+ifeq ($(XSK_STATIC),1)
+XSK_LDLIBS := -static $(XSK_STATIC_LIBS)
+else
+XSK_LDLIBS := $(shell $(PKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) -lz
+endif
+
+$(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) $(CFLAGS) -I$(top_srcdir)/tools/include -I$(OUTPUT) \
+		-I$(SCRATCH_DIR)/include \
+		$(XSK_SOURCES) $(BPFOBJ) $(LDLIBS) $(XSK_LDLIBS) -o $@
+
+EXTRA_CLEAN += $(XSK_BPF_OBJ) $(XSK_SKEL)
diff --git a/tools/testing/selftests/net/lib/xsk/README.rst b/tools/testing/selftests/net/lib/xsk/README.rst
new file mode 100644
index 0000000000000..a4503e50a6c49
--- /dev/null
+++ b/tools/testing/selftests/net/lib/xsk/README.rst
@@ -0,0 +1,130 @@
+.. 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.sh`` test runs SKB and DRV modes over veth.
+
+Generic veth test
+=================
+
+Two ``xskxceiver`` processes own the TX and RX veth interfaces. The TX
+process listens on a TCP control port and the RX process connects. The
+shell wrapper starts a fresh process pair for each mode and case. A small
+control channel reports readiness, packet progress, and aborts. For example::
+
+  make -C tools/testing/selftests/net/lib
+  cd tools/testing/selftests/net
+  sudo ./test_xsk.sh
+
+The shell wrapper creates the veth pair. ``-m skb|drv`` selects a mode,
+``-t`` selects a test by the name or number shown by ``xskxceiver -l``,
+and ``-p N`` selects a fixed control port instead of the default random
+port. The generic frame format is unchanged.
+
+Hardware zero-copy test
+=======================
+
+``test_xsk_case_defs.h`` defines the cases for both ``xskxceiver`` and
+``drivers/net/hw/xsk.py``, and the DUT directions in which the Python
+runner runs each of them. The runner reads this list and owns the TAP
+results.
+
+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. 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.
+
+The remote XSK endpoint listens on a TCP control port and the DUT connects.
+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 small
+per-case channel reports readiness, packet progress, and aborts. It has no
+capabilities or verdict handshake. ``xsk.py`` chooses the case, sets the
+timeout, and reports the result from both process exit codes.
+
+Both XSK endpoints generate and validate raw IPv4/UDP frames with one fixed
+UDP port, so ntuple rules can steer the test flow. They do not use AF_INET
+sockets. On DUT RX cases ``xsk.py`` reserves the last RX queue outside RSS
+and steers test traffic to it. On DUT TX cases it steers traffic to queue 0
+on the remote receiver. The XDP programs redirect every packet, so the
+tested link must carry no other traffic; SSH and the control channel go
+to the ``REMOTE_ARGS`` host, which has to be reached over another link.
+Each case sets up only what its direction needs and undoes it when the
+case ends, so a setup failure skips only the cases that need that setup.
+Each endpoint detaches its XDP program and restores any changed ring sizes
+and the MTU before it exits. The SKB-mode remote endpoint only raises its
+MTU when a case needs a larger one, as changing the MTU can reset the NIC.
+The runner restores the RSS table, ntuple setting, and huge-page count.
+After an endpoint fails or is killed, the runner also detaches the XDP
+program and restores the MTU. The runner does not change channel counts.
+A one-channel DUT skips RX cases because it has no queue to reserve
+outside RSS.
+
+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. The binary is linked statically when the static
+libraries are installed; ``XSK_STATIC=0`` or ``XSK_STATIC=1`` overrides the
+probe.
+
+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=ssh
+  REMOTE_ARGS=user@remote.example.com
+  XSK_REMOTE_BIN=/path/to/remote/xskxceiver
+  XSK_REMOTE_SUDO=1
+
+Run as root on the DUT::
+
+  cd tools/testing/selftests/drivers/net/hw
+  sudo ./xsk.py -t test_xsk.rx_send_receive
+
+``./xsk.py -l`` lists the case names. Omit ``-t`` to run the full hardware
+matrix. Set the variables in ``net.config`` when using ``sudo`` so they are
+available to the test process.
+
+``./xsk.py -b`` runs the same cases as ``test_xsk_busy_poll`` instead, with
+the DUT endpoint busy polling as in the busy-poll pass of ``test_xsk.sh``.
+Each case then sets ``napi_defer_hard_irqs`` and ``gro_flush_timeout`` on
+the DUT to the values ``test_xsk.sh`` uses on veth and restores them when
+it ends. The remote endpoint does not busy poll.
+
+Each case starts its remote endpoint over SSH, and a DUT TX case also adds
+and removes a flow steering rule on the remote. 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 and BPF. ``xsk.py`` copies the
+DUT's ``xskxceiver`` binary to the remote, so both hosts must have
+compatible architectures. ``XSK_REMOTE_BIN`` chooses a fixed destination
+path for that copy. Set ``XSK_REMOTE_DEPLOY=0`` to use a binary built on
+the remote from the same test case definitions instead. ``XSK_REMOTE_SUDO=1``
+runs the remote endpoint and setup commands through passwordless ``sudo -n``;
+omit it when SSH logs in as root. The DUT needs ntuple and RSS support for
+RX cases, while the remote needs ntuple support for DUT TX cases. The test
+uses ``NetDrvEpEnv`` and the networking selftest Python helpers for setup
+and rollback.
+
+The DUT uses the SSH host name to connect to the remote control listener.
+``XSK_UDP_PORT`` changes the fixed test UDP port (default 42567). The remote
+listens on all addresses for control.
+
+The hardware list covers baseline traffic, 2K frames, poll, headroom,
+invalid TX descriptors, TX invalid-descriptor statistics, metadata, 9K,
+and unaligned traffic. 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.
diff --git a/tools/testing/selftests/bpf/prog_tests/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c
similarity index 86%
rename from tools/testing/selftests/bpf/prog_tests/test_xsk.c
rename to tools/testing/selftests/net/lib/xsk/test_xsk.c
index 4549358cc8c21..3e2ca21bdb99f 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c
@@ -1,20 +1,22 @@
 // SPDX-License-Identifier: GPL-2.0
+#include <arpa/inet.h>
 #include <bpf/bpf.h>
 #include <errno.h>
 #include <linux/bitmap.h>
 #include <linux/if_link.h>
 #include <linux/mman.h>
 #include <linux/netdev.h>
+#include <linux/ip.h>
+#include <linux/udp.h>
 #include <poll.h>
-#include <pthread.h>
 #include <string.h>
 #include <sys/mman.h>
 #include <sys/socket.h>
 #include <sys/time.h>
 #include <unistd.h>
 
-#include "network_helpers.h"
 #include "test_xsk.h"
+#include "xsk_peer.h"
 #include "xsk_xdp_common.h"
 #include "xsk_xdp_progs.skel.h"
 
@@ -27,8 +29,11 @@
 #define PKT_DUMP_NB_TO_PRINT		16
 /* Just to align the data in the packet */
 #define PKT_HDR_SIZE			(sizeof(struct ethhdr) + 2)
+#define UDP_PKT_HDR_SIZE		(sizeof(struct ethhdr) + sizeof(struct iphdr) + \
+				 sizeof(struct udphdr) + 2)
 #define POLL_TMOUT			1000
 #define THREAD_TMOUT			3
+#define HW_THREAD_TMOUT		20
 #define UMEM_HEADROOM_TEST_SIZE		128
 #define XSK_DESC__INVALID_OPTION	(0xffff)
 #define XSK_UMEM__INVALID_FRAME_SIZE	(MAX_ETH_JUMBO_SIZE + 1)
@@ -36,12 +41,47 @@
 #define XSK_UMEM__MAX_FRAME_SIZE	(4 * 1024)
 
 static const u8 g_mac[ETH_ALEN] = {0x55, 0x44, 0x33, 0x22, 0x11, 0x00};
+static bool udp_packets;
+static struct in_addr udp_src_ip;
+static struct in_addr udp_dst_ip;
+static u16 udp_port;
+static u32 pkt_hdr_size = PKT_HDR_SIZE;
+static u32 max_frags_override;
 
 bool opt_verbose;
-pthread_barrier_t barr;
-pthread_mutex_t pacing_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 int pkts_in_flight;
+static struct xsk_peer *ctrl_peer;
+static bool hw_test;
+
+void xsk_set_endpoint(struct xsk_peer *peer, bool hardware)
+{
+	ctrl_peer = peer;
+	hw_test = hardware;
+}
+
+static int pacing_rx_progress(u32 pkts)
+{
+	int err = xsk_peer_rx_progress(ctrl_peer, pkts);
+
+	if (err)
+		ksft_print_msg("RX control channel failed: %d (%s)\n", err,
+			       strerror(-err));
+	return err;
+}
+
+static int pacing_tx_sync(void)
+{
+	int acked = xsk_peer_tx_sync(ctrl_peer);
+
+	if (acked < 0) {
+		ksft_print_msg("TX control channel failed: %d (%s)\n", acked,
+			       strerror(-acked));
+		return acked;
+	}
+	pkts_in_flight -= acked;
+	return 0;
+}
 
 /* The payload is a word consisting of a packet sequence number in the upper
  * 16-bits and a intra packet data sequence number in the lower 16 bits. So the 3rd packet's
@@ -57,11 +97,70 @@ static void write_payload(void *dest, u32 pkt_nb, u32 start, u32 size)
 		ptr[i] = htonl(pkt_nb << 16 | (i + start));
 }
 
-static void gen_eth_hdr(struct xsk_socket_info *xsk, struct ethhdr *eth_hdr)
+int xsk_set_udp_packet_format(const char *src_ip, const char *dst_ip, u16 port)
+{
+	if (inet_pton(AF_INET, src_ip, &udp_src_ip) != 1 ||
+	    inet_pton(AF_INET, dst_ip, &udp_dst_ip) != 1 || !port)
+		return -EINVAL;
+	udp_packets = true;
+	udp_port = port;
+	pkt_hdr_size = UDP_PKT_HDR_SIZE;
+	return 0;
+}
+
+void xsk_set_max_frags(u32 max_frags)
 {
+	max_frags_override = max_frags;
+}
+
+static u16 ip_checksum(const void *buf, size_t len)
+{
+	const u16 *word = buf;
+	u32 sum = 0;
+
+	while (len > 1) {
+		sum += *word++;
+		len -= sizeof(*word);
+	}
+	while (sum >> 16)
+		sum = (sum & 0xffff) + (sum >> 16);
+	return ~sum;
+}
+
+static void gen_pkt_hdr(struct xsk_socket_info *xsk, void *data, u32 total_len)
+{
+	struct ethhdr *eth_hdr = data;
+	struct udphdr udp = {
+		.source = htons(udp_port),
+		.dest = htons(udp_port),
+		.len = htons(total_len - sizeof(*eth_hdr) -
+			     sizeof(struct iphdr)),
+	};
+	struct iphdr ip = {
+		.version = 4,
+		.ihl = 5,
+		.ttl = 64,
+		.protocol = IPPROTO_UDP,
+		.tot_len = htons(total_len - sizeof(*eth_hdr)),
+		.saddr = udp_src_ip.s_addr,
+		.daddr = udp_dst_ip.s_addr,
+	};
+	u8 *ptr = data;
+
 	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 (!udp_packets) {
+		eth_hdr->h_proto = htons(ETH_P_LOOPBACK);
+		return;
+	}
+
+	eth_hdr->h_proto = htons(ETH_P_IP);
+	ip.check = ip_checksum(&ip, sizeof(ip));
+	ptr += sizeof(*eth_hdr);
+	memcpy(ptr, &ip, sizeof(ip));
+	ptr += sizeof(ip);
+	memcpy(ptr, &udp, sizeof(udp));
+	memset(ptr + sizeof(udp), 0, 2);
 }
 
 static u32 mode_to_xdp_flags(enum test_mode mode)
@@ -101,10 +200,6 @@ int xsk_configure_umem(struct ifobject *ifobj, struct xsk_umem_info *umem, void
 		return ret;
 
 	umem->buffer = buffer;
-	if (ifobj->shared_umem && ifobj->rx_on) {
-		umem->base_addr = umem_size(umem);
-		umem->next_buffer = umem_size(umem);
-	}
 
 	return 0;
 }
@@ -115,8 +210,8 @@ static u64 umem_alloc_buffer(struct xsk_umem_info *umem)
 
 	addr = umem->next_buffer;
 	umem->next_buffer += umem->frame_size;
-	if (umem->next_buffer >= umem->base_addr + umem_size(umem))
-		umem->next_buffer = umem->base_addr;
+	if (umem->next_buffer >= umem_size(umem))
+		umem->next_buffer = 0;
 
 	return addr;
 }
@@ -170,7 +265,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 int set_ring_size(struct ifobject *ifobj)
@@ -195,6 +291,10 @@ static int set_ring_size(struct ifobject *ifobj)
 
 int hw_ring_size_reset(struct ifobject *ifobj)
 {
+	if (ifobj->ring.tx_pending == ifobj->set_ring.default_tx &&
+	    ifobj->ring.rx_pending == ifobj->set_ring.default_rx)
+		return 0;
+
 	ifobj->ring.tx_pending = ifobj->set_ring.default_tx;
 	ifobj->ring.rx_pending = ifobj->set_ring.default_rx;
 	return set_ring_size(ifobj);
@@ -207,7 +307,8 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
 
 	for (i = 0; i < MAX_INTERFACES; i++) {
 		struct ifobject *ifobj = i ? ifobj_rx : ifobj_tx;
-		struct xsk_umem_info *umem_real;
+		struct ifobject *peer = i ? ifobj_tx : ifobj_rx;
+		struct xsk_umem_info *umem;
 
 		ifobj->xsk = &ifobj->xsk_arr[0];
 		ifobj->use_poll = false;
@@ -224,33 +325,37 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
 			ifobj->tx_on = false;
 		}
 
-		umem_real = ifobj->xsk_arr[0].umem_real;
-		memset(umem_real, 0, sizeof(*umem_real));
+		umem = ifobj->xsk_arr[0].umem;
+		memset(umem, 0, sizeof(*umem));
 		for (j = 0; j < MAX_SOCKETS; j++) {
 			struct xsk_socket_info *xsk = &ifobj->xsk_arr[j];
 
 			memset(xsk, 0, sizeof(*xsk));
 			xsk->rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS;
-			if (j == 0)
-				xsk->umem_real = umem_real;
-			xsk->umem = umem_real;
+			xsk->umem = umem;
 			xsk->batch_size = DEFAULT_BATCH_SIZE;
 			if (i == 0)
 				xsk->pkt_stream = test->tx_pkt_stream_default;
 			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);
+			if (hw_test) {
+				memcpy(xsk->src_mac, ifobj->caps.mac, ETH_ALEN);
+				memcpy(xsk->dst_mac, peer->caps.mac, ETH_ALEN);
+			} else {
+				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);
+			}
 		}
 
 		ifobj->xsk->umem->num_frames = DEFAULT_UMEM_BUFFERS;
 		ifobj->xsk->umem->frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE;
 	}
 
-	if (ifobj_tx->hw_ring_size_supp)
+	if (ifobj_has_cap(ifobj_tx, XSK_CAP_HW_RING) &&
+	    ifobj_is_local(ifobj_tx))
 		hw_ring_size_reset(ifobj_tx);
 
 	test->ifobj_tx = ifobj_tx;
@@ -258,7 +363,6 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
 	test->current_step = 0;
 	test->total_steps = 1;
 	test->nb_sockets = 1;
-	test->fail = false;
 	test->set_ring = false;
 	test->adjust_tail = false;
 	test->adjust_tail_support = false;
@@ -326,26 +430,42 @@ static void test_spec_set_xdp_prog(struct test_spec *test, struct bpf_program *x
 	test->xskmap_tx = xskmap_tx;
 }
 
-static int test_spec_set_mtu(struct test_spec *test, int mtu)
+/* An MTU change can reset a NIC. A hardware 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 (hw_test && 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 (test->ifobj_rx->mtu != mtu) {
-		err = xsk_set_mtu(test->ifobj_rx->ifindex, mtu);
-		if (err)
-			return err;
-		test->ifobj_rx->mtu = mtu;
-	}
-	if (test->ifobj_tx->mtu != mtu) {
-		err = xsk_set_mtu(test->ifobj_tx->ifindex, mtu);
+	if (ifobj_is_local(ifobj) && mtu_change_needed(ifobj, mode, mtu)) {
+		err = xsk_set_mtu(ifobj->ifindex, mtu);
 		if (err)
 			return err;
-		test->ifobj_tx->mtu = mtu;
+		ifobj->dev_mtu = mtu;
 	}
 
+	ifobj->mtu = mtu;
 	return 0;
 }
 
+static int test_spec_set_mtu(struct test_spec *test, int mtu)
+{
+	int err;
+
+	err = test_spec_set_mtu_ifobj(test->ifobj_rx, test->mode, mtu);
+	if (err)
+		return err;
+
+	return test_spec_set_mtu_ifobj(test->ifobj_tx, test->mode, mtu);
+}
+
 void pkt_stream_reset(struct pkt_stream *pkt_stream)
 {
 	if (pkt_stream) {
@@ -375,6 +495,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);
 }
@@ -625,7 +748,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);
 
@@ -633,12 +756,12 @@ 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, total_len);
 
-		len -= PKT_HDR_SIZE;
-		data += PKT_HDR_SIZE;
+		len -= pkt_hdr_size;
+		data += pkt_hdr_size;
 	} else {
-		bytes_written -= PKT_HDR_SIZE;
+		bytes_written -= pkt_hdr_size;
 	}
 
 	write_payload(data, pkt_nb, bytes_written, len);
@@ -741,7 +864,7 @@ static void pkt_dump(void *pkt, u32 len, bool eth_header)
 		for (i = 0; i < ETH_ALEN; i++)
 			ksft_print_msg("%02X", ethhdr->h_source[i]);
 
-		data = pkt + PKT_HDR_SIZE;
+		data = pkt + pkt_hdr_size;
 	} else {
 		data = pkt;
 	}
@@ -825,8 +948,6 @@ static bool is_frag_valid(struct xsk_umem_info *umem, u64 addr, u32 len, u32 exp
 	void *data = xsk_umem__get_data(umem->buffer, addr);
 	u64 umem_sz = umem_size(umem);
 
-	addr -= umem->base_addr;
-
 	if (addr >= umem_sz || addr + len > umem_sz) {
 		ksft_print_msg("Frag invalid addr: %llx len: %u\n",
 			       (unsigned long long)addr, len);
@@ -840,11 +961,15 @@ static bool is_frag_valid(struct xsk_umem_info *umem, u64 addr, u32 len, u32 exp
 
 	pkt_data = data;
 	if (!bytes_processed) {
-		pkt_data += PKT_HDR_SIZE / sizeof(*pkt_data);
-		len -= PKT_HDR_SIZE;
+		if (len < pkt_hdr_size + sizeof(*pkt_data))
+			return false;
+		pkt_data += pkt_hdr_size / sizeof(*pkt_data);
+		len -= pkt_hdr_size;
 	} else {
-		bytes_processed -= PKT_HDR_SIZE;
+		bytes_processed -= pkt_hdr_size;
 	}
+	if (len < sizeof(*pkt_data))
+		return false;
 
 	expected_seqnum = bytes_processed / sizeof(*pkt_data);
 	seqnum = ntohl(*pkt_data) & 0xffff;
@@ -994,6 +1119,9 @@ static int __receive_pkts(struct test_spec *test, struct xsk_socket_info *xsk)
 	fds.fd = xsk_socket__fd(xsk->xsk);
 	fds.events = POLLIN;
 
+	if (pacing_rx_progress(0))
+		return TEST_FAILURE;
+
 	ret = kick_rx(xsk);
 	if (ret)
 		return TEST_FAILURE;
@@ -1093,9 +1221,8 @@ static int __receive_pkts(struct test_spec *test, struct xsk_socket_info *xsk)
 	if (ifobj->release_rx)
 		xsk_ring_cons__release(&xsk->rx, frags_processed);
 
-	pthread_mutex_lock(&pacing_mutex);
-	pkts_in_flight -= pkts_sent;
-	pthread_mutex_unlock(&pacing_mutex);
+	if (pacing_rx_progress(pkts_sent))
+		return TEST_FAILURE;
 	pkts_sent = 0;
 
 	return TEST_CONTINUE;
@@ -1122,7 +1249,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 = {hw_test ? HW_THREAD_TMOUT : THREAD_TMOUT, 0};
 	DECLARE_BITMAP(bitmap, test->nb_sockets);
 	struct xsk_socket_info *xsk;
 	u32 sock_num = 0;
@@ -1164,13 +1291,16 @@ static int __send_pkts(struct ifobject *ifobject, struct xsk_socket_info *xsk,
 		       bool test_timeout)
 {
 	u32 i, idx = 0, valid_pkts = 0, valid_frags = 0, buffer_len;
-	struct xsk_umem_info *umem = ifobject->xsk_arr[0].umem_real;
+	struct xsk_umem_info *umem = ifobject->xsk_arr[0].umem;
 	struct pkt_stream *pkt_stream = xsk->pkt_stream;
 	bool use_poll = ifobject->use_poll;
 	struct pollfd fds = { };
 	int ret;
 
 	buffer_len = pkt_get_buffer_len(umem, pkt_stream->max_pkt_len);
+	if (pacing_tx_sync())
+		return TEST_FAILURE;
+
 	/* pkts_in_flight might be negative if many invalid packets are sent */
 	if (pkts_in_flight >= (int)((umem_size(umem) - xsk->batch_size * buffer_len) /
 	    buffer_len) && !test_timeout) {
@@ -1236,8 +1366,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, pkt->len,
+					     pkt->pkt_nb, bytes_written);
 			bytes_written += tx_desc->len;
 
 			print_verbose("Tx addr: %llx len: %u options: %u pkt_nb: %u\n",
@@ -1255,9 +1385,7 @@ static int __send_pkts(struct ifobject *ifobject, struct xsk_socket_info *xsk,
 		valid_frags += nb_frags;
 	}
 
-	pthread_mutex_lock(&pacing_mutex);
 	pkts_in_flight += valid_pkts;
-	pthread_mutex_unlock(&pacing_mutex);
 
 	xsk_ring_prod__submit(&xsk->tx, i);
 	xsk->outstanding_tx += valid_frags;
@@ -1286,7 +1414,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 = {hw_test ? HW_THREAD_TMOUT : THREAD_TMOUT, 0};
 	int ret;
 
 	ret = gettimeofday(&tv_now, NULL);
@@ -1334,9 +1462,6 @@ static int send_pkts(struct test_spec *test, struct ifobject *ifobject)
 			if (ret != TEST_CONTINUE)
 				return ret;
 
-			if (test->fail)
-				return TEST_FAILURE;
-
 			if (!test->poll_tmout) {
 				ret = wait_for_tx_completion(&ifobject->xsk_arr[i]);
 				if (ret)
@@ -1468,12 +1593,12 @@ static int validate_tx_invalid_descs(struct ifobject *ifobject)
 }
 
 static int xsk_configure(struct test_spec *test, struct ifobject *ifobject,
-			  struct xsk_umem_info *umem, bool tx)
+			  struct xsk_umem_info *umem)
 {
 	int i, ret;
 
 	for (i = 0; i < test->nb_sockets; i++) {
-		bool shared = (ifobject->shared_umem && tx) ? true : !!i;
+		bool shared = !!i;
 		u32 ctr = 0;
 
 		while (ctr++ < SOCK_RECONF_CTR) {
@@ -1497,31 +1622,6 @@ static int xsk_configure(struct test_spec *test, struct ifobject *ifobject,
 	return 0;
 }
 
-static int thread_common_ops_tx(struct test_spec *test, struct ifobject *ifobject)
-{
-	struct xsk_umem_info *umem_rx, *umem_tx;
-	int ret;
-
-	if (!test->ifobj_rx || !test->ifobj_rx->xsk_arr[0].umem->umem) {
-		ksft_print_msg("Error: RX UMEM is not initialized before shared-UMEM TX setup\n");
-		return -EINVAL;
-	}
-
-	umem_rx = test->ifobj_rx->xsk_arr[0].umem;
-	umem_tx = ifobject->xsk_arr[0].umem_real;
-	memcpy(umem_tx, umem_rx, sizeof(*umem_tx));
-	umem_tx->base_addr = 0;
-	umem_tx->next_buffer = 0;
-
-	ret = xsk_configure(test, ifobject, umem_rx, true);
-	if (ret)
-		return ret;
-	ifobject->xsk = &ifobject->xsk_arr[0];
-	ifobject->xskmap = test->ifobj_rx->xskmap;
-
-	return 0;
-}
-
 static int xsk_populate_fill_ring(struct xsk_umem_info *umem, struct pkt_stream *pkt_stream,
 				   bool fill_up)
 {
@@ -1547,7 +1647,7 @@ static int xsk_populate_fill_ring(struct xsk_umem_info *umem, struct pkt_stream
 			if (!pkt) {
 				if (!fill_up)
 					break;
-				addr = filled * umem->frame_size + umem->base_addr;
+				addr = filled * umem->frame_size;
 			} else if (pkt->offset >= 0) {
 				addr = pkt->offset % umem->frame_size + umem_alloc_buffer(umem);
 			} else {
@@ -1584,9 +1684,6 @@ static int thread_common_ops(struct test_spec *test, struct ifobject *ifobject)
 	if (umem->unaligned_mode)
 		mmap_flags |= MAP_HUGETLB | MAP_HUGE_2MB;
 
-	if (ifobject->shared_umem)
-		umem_sz *= 2;
-
 	mmap_sz = umem->unaligned_mode ?
 		ceil_u64(umem_sz, HUGEPAGE_SIZE) * HUGEPAGE_SIZE : umem_sz;
 
@@ -1600,7 +1697,7 @@ static int thread_common_ops(struct test_spec *test, struct ifobject *ifobject)
 	if (ret)
 		return ret;
 
-	ret = xsk_configure(test, ifobject, umem, false);
+	ret = xsk_configure(test, ifobject, umem);
 	if (ret)
 		return ret;
 
@@ -1623,40 +1720,28 @@ 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);
-			}
-		}
+		err = thread_common_ops(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,36 +1754,86 @@ 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 (!test->adjust_tail)
+		return err;
+
+	if (is_adjust_tail_supported(ifobject->xdp_progs, &supported))
+		return TEST_FAILURE;
+	if (!supported) {
+		test->adjust_tail_support = false;
+		return TEST_PASS;
+	}
+
+	return err;
+}
+
+static int sync_endpoints(struct test_spec *test)
+{
+	int err = xsk_peer_ready(ctrl_peer);
+
+	if (err)
+		ksft_print_msg("Endpoint synchronization failed at step %u: %d (%s)\n",
+			       test->current_step, err, strerror(-err));
+	return err;
+}
+
+int worker_testapp_validate_tx(struct test_spec *test)
+{
+	int err;
+
+	err = sync_endpoints(test);
+	if (err)
+		return err;
 
+	err = testapp_validate_tx_endpoint(test, test->ifobj_tx);
 	if (err) {
-		if (!test->adjust_tail) {
-			test->fail = true;
-		} else {
-			bool supported;
+		ksft_print_msg("TX endpoint traffic failed at step %u: %d\n",
+			       test->current_step, err);
+		xsk_peer_abort(ctrl_peer);
+	}
+	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;
-		}
+int worker_testapp_validate_rx(struct test_spec *test)
+{
+	struct ifobject *ifobject = test->ifobj_rx;
+	int err;
+
+	err = testapp_prepare_rx_endpoint(test, ifobject);
+	if (err) {
+		ksft_print_msg("RX endpoint setup failed at step %u: %d\n",
+			       test->current_step, err);
+		xsk_peer_abort(ctrl_peer);
+		return err;
 	}
 
-	pthread_exit(NULL);
+	err = sync_endpoints(test);
+	if (err)
+		return err;
+
+	err = testapp_validate_rx_endpoint(test, ifobject);
+	if (err) {
+		ksft_print_msg("RX endpoint traffic failed at step %u: %d\n",
+			       test->current_step, err);
+		xsk_peer_abort(ctrl_peer);
+	}
+	return err;
 }
 
 static void testapp_clean_xsk_umem(struct ifobject *ifobj)
@@ -1753,13 +1888,17 @@ static int xsk_attach_xdp_progs(struct test_spec *test, struct ifobject *ifobj_r
 {
 	int err = 0;
 
-	if (xdp_prog_changed_rx(test)) {
+	if (ifobj_is_local(ifobj_rx) && xdp_prog_changed_rx(test)) {
 		err = xsk_reattach_xdp(ifobj_rx, test->xdp_prog_rx, test->xskmap_rx, test->mode);
 		if (err)
 			return err;
 	}
 
-	if (!ifobj_tx || ifobj_tx->shared_umem)
+	if (!ifobj_tx || !ifobj_is_local(ifobj_tx))
+		return 0;
+
+	/* A ZC driver can require XDP to be enabled for TX wakeups. */
+	if (hw_test && !ifobj_tx->rx_on && test->mode != TEST_MODE_ZC)
 		return 0;
 
 	if (xdp_prog_changed_tx(test))
@@ -1772,7 +1911,7 @@ static void clean_sockets(struct test_spec *test, struct ifobject *ifobj)
 {
 	u32 i;
 
-	if (!ifobj || !test)
+	if (!ifobj || !test || !ifobj_is_local(ifobj))
 		return;
 
 	for (i = 0; i < test->nb_sockets; i++)
@@ -1784,29 +1923,32 @@ static void clean_umem(struct test_spec *test, struct ifobject *ifobj1, struct i
 	if (!ifobj1)
 		return;
 
-	testapp_clean_xsk_umem(ifobj1);
-	if (ifobj2 && !ifobj2->shared_umem)
+	if (ifobj_is_local(ifobj1))
+		testapp_clean_xsk_umem(ifobj1);
+	if (ifobj2 && ifobj_is_local(ifobj2))
 		testapp_clean_xsk_umem(ifobj2);
 }
 
 static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *ifobj1,
 				      struct ifobject *ifobj2)
 {
-	pthread_t t0, t1;
+	u32 mbuf_cap;
 	int err;
 
-	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");
@@ -1819,51 +1961,27 @@ static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *i
 			       err, strerror(-err));
 		return TEST_FAILURE;
 	}
-	test->use_barrier = !!ifobj2;
-
-	if (test->use_barrier) {
-		if (pthread_barrier_init(&barr, NULL, 2))
-			return TEST_FAILURE;
 
+	if (ifobj2)
 		pkt_stream_reset(ifobj2->xsk->pkt_stream);
-	}
-
 	test->current_step++;
 	pkt_stream_reset(ifobj1->xsk->pkt_stream);
 	pkts_in_flight = 0;
 
-	/*Spawn RX thread */
-	pthread_create(&t0, NULL, ifobj1->func_ptr, test);
-
-	if (test->use_barrier) {
-		pthread_barrier_wait(&barr);
-		if (pthread_barrier_destroy(&barr)) {
-			test->use_barrier = false;
-			pthread_join(t0, NULL);
-			clean_sockets(test, ifobj1);
-			clean_umem(test, ifobj1, NULL);
-			return TEST_FAILURE;
-		}
-	}
-
-	if (ifobj2) {
-		/*Spawn TX thread */
-		pthread_create(&t1, NULL, ifobj2->func_ptr, test);
-		pthread_join(t1, NULL);
-	}
-
-	pthread_join(t0, NULL);
-
-	if (test->total_steps == test->current_step || test->fail) {
+	/* In a one-sided step, the idle endpoint only keeps in step. */
+	if (ifobj_is_local(ifobj1))
+		err = ifobj1->func_ptr(test);
+	else if (ifobj2 && ifobj_is_local(ifobj2))
+		err = ifobj2->func_ptr(test);
+	else
+		err = sync_endpoints(test);
+	if (test->total_steps == test->current_step || err) {
 		clean_sockets(test, ifobj1);
 		clean_sockets(test, ifobj2);
 		clean_umem(test, ifobj1, ifobj2);
 	}
 
-	if (test->fail)
-		return TEST_FAILURE;
-
-	return TEST_PASS;
+	return err ? TEST_FAILURE : TEST_PASS;
 }
 
 static int testapp_validate_traffic(struct test_spec *test)
@@ -1871,15 +1989,16 @@ 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)) {
 		ksft_print_msg("No huge pages present.\n");
 		return TEST_SKIP;
 	}
 
 	if (test->set_ring) {
-		if (ifobj_tx->hw_ring_size_supp) {
-			if (set_ring_size(ifobj_tx)) {
+		if (ifobj_has_cap(ifobj_tx, XSK_CAP_HW_RING)) {
+			if (ifobj_is_local(ifobj_tx) &&
+			    set_ring_size(ifobj_tx)) {
 				ksft_print_msg("Failed to change HW ring size.\n");
 				return TEST_FAILURE;
 			}
@@ -1912,7 +2031,7 @@ int testapp_teardown(struct test_spec *test)
 
 static void swap_directions(struct ifobject **ifobj1, struct ifobject **ifobj2)
 {
-	thread_func_t tmp_func_ptr = (*ifobj1)->func_ptr;
+	test_func_t tmp_func_ptr = (*ifobj1)->func_ptr;
 	struct ifobject *tmp_ifobj = (*ifobj1);
 
 	(*ifobj1)->func_ptr = (*ifobj2)->func_ptr;
@@ -1951,6 +2070,9 @@ static int swap_xsk_resources(struct test_spec *test)
 	test->ifobj_tx->xsk = &test->ifobj_tx->xsk_arr[1];
 	test->ifobj_rx->xsk = &test->ifobj_rx->xsk_arr[1];
 
+	if (!ifobj_is_local(test->ifobj_rx))
+		return TEST_PASS;
+
 	ret = xsk_update_xskmap(test->ifobj_rx->xskmap, test->ifobj_rx->xsk->xsk, 0);
 	if (ret)
 		return TEST_FAILURE;
@@ -1984,7 +2106,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");
@@ -2164,12 +2286,6 @@ int testapp_invalid_desc(struct test_spec *test)
 		pkts[8].valid = false;
 	}
 
-	if (test->ifobj_tx->shared_umem) {
-		pkts[4].offset += umem_sz;
-		pkts[5].offset += umem_sz;
-		pkts[6].offset += umem_sz;
-	}
-
 	if (pkt_stream_generate_custom(test, pkts, ARRAY_SIZE(pkts)))
 		return TEST_FAILURE;
 	return testapp_validate_traffic(test);
@@ -2209,6 +2325,10 @@ int testapp_xdp_shared_umem(struct test_spec *test)
 	struct xsk_xdp_progs *skel_tx = test->ifobj_tx->xdp_progs;
 	int ret;
 
+	/* The XDP program picks the socket from the synthetic destination MAC. */
+	if (hw_test)
+		return TEST_SKIP;
+
 	test->total_steps = 1;
 	test->nb_sockets = 2;
 
@@ -2228,28 +2348,14 @@ int testapp_xdp_shared_umem(struct test_spec *test)
 
 int testapp_poll_txq_tmout(struct test_spec *test)
 {
-	bool shared_umem = test->ifobj_tx->shared_umem;
-	int ret;
-
 	test->poll_tmout = true;
-	/*
-	 * POLL_TXQ_FULL exercises TX timeout setup in isolation.
-	 * Keep TX out of shared-UMEM mode here so TX setup does not require
-	 * RX UMEM to be initialized first.
-	 */
-	test->ifobj_tx->shared_umem = false;
 	test->ifobj_tx->use_poll = true;
 	/* create invalid frame by set umem frame_size and pkt length equal to 2048 */
 	test->ifobj_tx->xsk->umem->frame_size = 2048;
-	if (pkt_stream_replace(test, 2 * DEFAULT_PKT_CNT, 2048)) {
-		test->ifobj_tx->shared_umem = shared_umem;
+	if (pkt_stream_replace(test, 2 * DEFAULT_PKT_CNT, 2048))
 		return TEST_FAILURE;
-	}
-
-	ret = testapp_validate_traffic_single_thread(test, test->ifobj_tx);
-	test->ifobj_tx->shared_umem = shared_umem;
 
-	return ret;
+	return testapp_validate_traffic_single_thread(test, test->ifobj_tx);
 }
 
 int testapp_poll_rxq_tmout(struct test_spec *test)
@@ -2265,10 +2371,12 @@ int testapp_too_many_frags(struct test_spec *test)
 	u32 max_frags, i;
 	int ret = TEST_FAILURE;
 
-	if (test->mode == TEST_MODE_ZC) {
-		max_frags = test->ifobj_tx->xdp_zc_max_segs;
+	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 = test->ifobj_tx->max_skb_frags;
+		max_frags = xsk_get_cap(test, max_skb_frags);
 		max_frags += 1;
 	}
 
@@ -2319,7 +2427,7 @@ int testapp_too_many_frags(struct test_spec *test)
 	return ret;
 }
 
-static int xsk_load_xdp_programs(struct ifobject *ifobj)
+int xsk_load_xdp_programs(struct ifobject *ifobj)
 {
 	ifobj->xdp_progs = xsk_xdp_progs__open_and_load();
 	if (libbpf_get_error(ifobj->xdp_progs))
@@ -2328,7 +2436,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;
@@ -2344,21 +2451,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) {
@@ -2366,19 +2465,46 @@ 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) {
+		ifobj_set_cap(ifobj, XSK_CAP_ZC_ADVERTISED);
 		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;
 		}
 	}
 
+	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;
+		ifobj->set_ring.default_tx = ifobj->ring.tx_pending;
+		ifobj->set_ring.default_rx = ifobj->ring.rx_pending;
+	}
+
 	return 0;
 }
 
+int init_iface(struct ifobject *ifobj)
+{
+	int err;
+
+	err = xsk_load_xdp_programs(ifobj);
+	if (err) {
+		ksft_print_msg("Error loading XDP program\n");
+		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);
+}
+
 int testapp_send_receive(struct test_spec *test)
 {
 	return testapp_validate_traffic(test);
@@ -2488,7 +2614,7 @@ int testapp_hw_sw_max_ring_size(struct test_spec *test)
 
 	test->set_ring = true;
 	test->total_steps = 2;
-	test->ifobj_tx->ring.tx_pending = test->ifobj_tx->ring.tx_max_pending;
+	test->ifobj_tx->ring.tx_pending = xsk_get_cap(test, tx_max_pending);
 	test->ifobj_tx->ring.rx_pending  = test->ifobj_tx->ring.rx_max_pending;
 	test->ifobj_rx->xsk->umem->num_frames = max_descs;
 	test->ifobj_rx->xsk->umem->fill_size = max_descs;
@@ -2503,8 +2629,8 @@ int testapp_hw_sw_max_ring_size(struct test_spec *test)
 	/* Set batch_size to 8152 for testing, as the ice HW ignores the 3 lowest bits when
 	 * updating the Rx HW tail register.
 	 */
-	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;
+	test->ifobj_tx->xsk->batch_size = xsk_get_cap(test, tx_max_pending) - 8;
+	test->ifobj_rx->xsk->batch_size = xsk_get_cap(test, tx_max_pending) - 8;
 	if (pkt_stream_replace(test, max_descs, MIN_PKT_SIZE)) {
 		clean_sockets(test, test->ifobj_tx);
 		clean_sockets(test, test->ifobj_rx);
@@ -2597,7 +2723,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);
@@ -2633,8 +2759,8 @@ struct ifobject *ifobject_create(void)
 	if (!ifobj->xsk_arr)
 		goto out_xsk_arr;
 
-	ifobj->xsk_arr[0].umem_real = calloc(1, sizeof(struct xsk_umem_info));
-	if (!ifobj->xsk_arr[0].umem_real)
+	ifobj->xsk_arr[0].umem = calloc(1, sizeof(struct xsk_umem_info));
+	if (!ifobj->xsk_arr[0].umem)
 		goto out_umem;
 
 	return ifobj;
@@ -2649,7 +2775,7 @@ struct ifobject *ifobject_create(void)
 void ifobject_delete(struct ifobject *ifobj)
 {
 	if (ifobj->xsk_arr)
-		free(ifobj->xsk_arr[0].umem_real);
+		free(ifobj->xsk_arr[0].umem);
 
 	free(ifobj->xsk_arr);
 	free(ifobj);
diff --git a/tools/testing/selftests/bpf/prog_tests/test_xsk.h b/tools/testing/selftests/net/lib/xsk/test_xsk.h
similarity index 67%
rename from tools/testing/selftests/bpf/prog_tests/test_xsk.h
rename to tools/testing/selftests/net/lib/xsk/test_xsk.h
index 03753ddc5dcda..e1ffd054c8f70 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_xsk.h
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.h
@@ -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
@@ -77,13 +77,18 @@ 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, bool hw_test);
+int xsk_set_udp_packet_format(const char *src_ip, const char *dst_ip, u16 port);
+void xsk_set_max_frags(u32 max_frags);
+
 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,7 +113,6 @@ struct xsk_umem_info {
 	u32 frame_headroom;
 	void *buffer;
 	u32 frame_size;
-	u32 base_addr;
 	u32 fill_size;
 	u32 comp_size;
 	bool unaligned_mode;
@@ -121,11 +125,29 @@ struct set_hw_ring {
 
 int hw_ring_size_reset(struct ifobject *ifobj);
 
+#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)
+#define XSK_CAP_DRV              (1U << 4)
+#define XSK_CAP_ZC               (1U << 5)
+#define XSK_CAP_ZC_ADVERTISED    (1U << 6)
+
+struct xsk_caps {
+	u32 flags;
+	u32 xdp_zc_max_segs;
+	u32 max_skb_frags;
+	u32 umem_tailroom;
+	u32 tx_max_pending;
+	u8 mac[ETH_ALEN];
+};
+
 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;
+	test_func_t func_ptr;
 	validation_func_t validation_func;
 	struct xsk_xdp_progs *xdp_progs;
 	struct bpf_map *xskmap;
@@ -134,27 +156,43 @@ struct ifobject {
 	struct set_hw_ring set_ring;
 	enum test_mode mode;
 	int ifindex;
+	u32 queue_id;
 	int mtu;
+	/* Above mtu when a hardware SKB-mode endpoint keeps a larger MTU. */
+	int dev_mtu;
+	int orig_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;
 	bool busy_poll;
 	bool use_fill_ring;
 	bool release_rx;
-	bool shared_umem;
 	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;
+}
+
+/* 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);
 
 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,
@@ -203,12 +241,10 @@ struct test_spec {
 	u16 total_steps;
 	u16 current_step;
 	u16 nb_sockets;
-	bool fail;
 	bool set_ring;
 	bool adjust_tail;
 	bool adjust_tail_support;
 	bool poll_tmout;
-	bool use_barrier;
 	enum test_mode mode;
 	char name[MAX_TEST_NAME_SIZE];
 };
@@ -269,55 +305,14 @@ 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},
-	{.name = "SEND_RECEIVE_2K_FRAME", .test_func = testapp_send_receive_2k_frame},
-	{.name = "SEND_RECEIVE_SINGLE_PKT", .test_func = testapp_single_pkt},
-	{.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},
-	};
-
-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},
-	{.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},
-	{.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},
+#define XSK_TEST_CASE(_name, _func, ...) \
+	{ .name = #_name, .test_func = _func },
+#include "test_xsk_case_defs.h"
+#undef XSK_TEST_CASE
 };
 
 
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk_case_defs.h b/tools/testing/selftests/net/lib/xsk/test_xsk_case_defs.h
new file mode 100644
index 0000000000000..873e89c9d4d5a
--- /dev/null
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk_case_defs.h
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Each XSK_TEST_CASE entry has a name, function, and hardware directions.
+ * Only xsk.py reads the directions, the DUT roles in which it runs a case.
+ *
+ * Keep this list in test ID order. It is shared by xskxceiver and xsk.py.
+ */
+XSK_TEST_CASE(SEND_RECEIVE, testapp_send_receive, XSK_HW_RX | XSK_HW_TX)
+XSK_TEST_CASE(SEND_RECEIVE_2K_FRAME, testapp_send_receive_2k_frame,
+	      XSK_HW_RX | XSK_HW_TX)
+XSK_TEST_CASE(SEND_RECEIVE_SINGLE_PKT, testapp_single_pkt,
+	      XSK_HW_RX | XSK_HW_TX)
+XSK_TEST_CASE(POLL_RX, testapp_poll_rx, XSK_HW_RX)
+XSK_TEST_CASE(POLL_TX, testapp_poll_tx, XSK_HW_TX)
+XSK_TEST_CASE(POLL_RXQ_FULL, testapp_poll_rxq_tmout, XSK_HW_RX)
+XSK_TEST_CASE(POLL_TXQ_FULL, testapp_poll_txq_tmout, XSK_HW_TX)
+XSK_TEST_CASE(ALIGNED_INV_DESC, testapp_aligned_inv_desc, XSK_HW_TX)
+XSK_TEST_CASE(ALIGNED_INV_DESC_2K_FRAME_SIZE,
+	      testapp_aligned_inv_desc_2k_frame, XSK_HW_TX)
+XSK_TEST_CASE(UMEM_HEADROOM, testapp_headroom, XSK_HW_RX)
+XSK_TEST_CASE(BIDIRECTIONAL, testapp_bidirectional, 0)
+XSK_TEST_CASE(STAT_RX_DROPPED, testapp_stats_rx_dropped, 0)
+XSK_TEST_CASE(STAT_TX_INVALID, testapp_stats_tx_invalid_descs, XSK_HW_TX)
+XSK_TEST_CASE(STAT_RX_FULL, testapp_stats_rx_full, 0)
+XSK_TEST_CASE(STAT_FILL_EMPTY, testapp_stats_fill_empty, 0)
+XSK_TEST_CASE(XDP_PROG_CLEANUP, testapp_xdp_prog_cleanup, XSK_HW_RX)
+XSK_TEST_CASE(XDP_DROP_HALF, testapp_xdp_drop, 0)
+XSK_TEST_CASE(XDP_SHARED_UMEM, testapp_xdp_shared_umem, 0)
+XSK_TEST_CASE(XDP_METADATA_COPY, testapp_xdp_metadata, XSK_HW_RX)
+XSK_TEST_CASE(XDP_METADATA_COPY_MULTI_BUFF, testapp_xdp_metadata_mb, 0)
+XSK_TEST_CASE(ALIGNED_INV_DESC_MULTI_BUFF, testapp_aligned_inv_desc_mb,
+	      XSK_HW_TX)
+XSK_TEST_CASE(TOO_MANY_FRAGS, testapp_too_many_frags, XSK_HW_TX)
+XSK_TEST_CASE(XDP_ADJUST_TAIL_SHRINK, testapp_adjust_tail_shrink, 0)
+XSK_TEST_CASE(TX_QUEUE_CONSUMER, testapp_tx_queue_consumer, 0)
+/* Flaky tests */
+XSK_TEST_CASE(XDP_ADJUST_TAIL_SHRINK_MULTI_BUFF,
+	      testapp_adjust_tail_shrink_mb, 0)
+XSK_TEST_CASE(XDP_ADJUST_TAIL_GROW, testapp_adjust_tail_grow, 0)
+XSK_TEST_CASE(XDP_ADJUST_TAIL_GROW_MULTI_BUFF, testapp_adjust_tail_grow_mb, 0)
+XSK_TEST_CASE(SEND_RECEIVE_9K_PACKETS, testapp_send_receive_mb,
+	      XSK_HW_RX | XSK_HW_TX)
+/* Tests with huge page dependency */
+XSK_TEST_CASE(SEND_RECEIVE_UNALIGNED, testapp_send_receive_unaligned,
+	      XSK_HW_RX | XSK_HW_TX)
+XSK_TEST_CASE(UNALIGNED_INV_DESC, testapp_unaligned_inv_desc, XSK_HW_TX)
+XSK_TEST_CASE(UNALIGNED_INV_DESC_4001_FRAME_SIZE,
+	      testapp_unaligned_inv_desc_4001_frame, XSK_HW_TX)
+XSK_TEST_CASE(SEND_RECEIVE_UNALIGNED_9K_PACKETS,
+	      testapp_send_receive_unaligned_mb, XSK_HW_RX | XSK_HW_TX)
+XSK_TEST_CASE(UNALIGNED_INV_DESC_MULTI_BUFF, testapp_unaligned_inv_desc_mb,
+	      XSK_HW_TX)
+/* Tests with HW ring size dependency */
+XSK_TEST_CASE(HW_SW_MIN_RING_SIZE, testapp_hw_sw_min_ring_size, 0)
+XSK_TEST_CASE(HW_SW_MAX_RING_SIZE, testapp_hw_sw_max_ring_size, 0)
+/* Too long test */
+XSK_TEST_CASE(TEARDOWN, testapp_teardown, 0)
diff --git a/tools/testing/selftests/bpf/xsk.c b/tools/testing/selftests/net/lib/xsk/xsk.c
similarity index 91%
rename from tools/testing/selftests/bpf/xsk.c
rename to tools/testing/selftests/net/lib/xsk/xsk.c
index 25d568abf0f20..bd2ef3ee91248 100644
--- a/tools/testing/selftests/bpf/xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/xsk.c
@@ -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,88 @@ 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;
+}
+
+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;
+}
+
+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;
+}
+
+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;
+}
diff --git a/tools/testing/selftests/bpf/xsk.h b/tools/testing/selftests/net/lib/xsk/xsk.h
similarity index 95%
rename from tools/testing/selftests/bpf/xsk.h
rename to tools/testing/selftests/net/lib/xsk/xsk.h
index 48729da142c24..c09ddbc38db9b 100644
--- a/tools/testing/selftests/bpf/xsk.h
+++ b/tools/testing/selftests/net/lib/xsk/xsk.h
@@ -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,11 @@ void xsk_socket__delete(struct xsk_socket *xsk);
 
 int xsk_set_mtu(int ifindex, int mtu);
 
+int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
+int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
+int xsk_get_mac(const char *ifname, u8 mac[ETH_ALEN]);
+int xsk_get_mtu(const char *ifname, int *mtu);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
diff --git a/tools/testing/selftests/net/lib/xsk/xsk_peer.c b/tools/testing/selftests/net/lib/xsk/xsk_peer.c
new file mode 100644
index 0000000000000..1228dc01f85ce
--- /dev/null
+++ b/tools/testing/selftests/net/lib/xsk/xsk_peer.c
@@ -0,0 +1,272 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <arpa/inet.h>
+#include <errno.h>
+#include <netdb.h>
+#include <netinet/tcp.h>
+#include <poll.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+#include "xsk_peer.h"
+
+#define XSK_PEER_MAGIC			0x58534b50
+#define XSK_PEER_ACCEPT_TMOUT_MS	30000
+
+/* One case per connection; the launcher owns the verdict. */
+enum xsk_peer_msg_type {
+	XSK_PEER_READY = 1,
+	XSK_PEER_PROGRESS,
+	XSK_PEER_ABORT,
+};
+
+struct xsk_peer_msg {
+	u32 magic;
+	u32 type;
+	u32 pkts;
+};
+
+struct xsk_peer {
+	int fd;
+	u32 acked;
+	bool ready_seen;
+	bool closed;
+};
+
+static int io_full(int fd, void *buf, size_t len, bool write_op)
+{
+	size_t done = 0;
+	ssize_t ret;
+
+	while (done < len) {
+		if (write_op)
+			ret = send(fd, (char *)buf + done, len - done, MSG_NOSIGNAL);
+		else
+			ret = read(fd, (char *)buf + done, len - done);
+		if (ret < 0 && errno == EINTR)
+			continue;
+		if (ret < 0)
+			return -errno;
+		if (!ret)
+			return -EPIPE;
+		done += ret;
+	}
+	return 0;
+}
+
+/*
+ * Past its last barrier the peer may exit at any time, and it resets the
+ * connection if our progress reports are still unread.
+ */
+static bool peer_gone(int err)
+{
+	return err == -EPIPE || err == -ECONNRESET;
+}
+
+static int peer_send(struct xsk_peer *peer, u32 type, u32 pkts)
+{
+	struct xsk_peer_msg msg = {
+		.magic = htonl(XSK_PEER_MAGIC),
+		.type = htonl(type),
+		.pkts = htonl(pkts),
+	};
+
+	return io_full(peer->fd, &msg, sizeof(msg), true);
+}
+
+static int peer_recv_one(struct xsk_peer *peer)
+{
+	struct xsk_peer_msg msg;
+	int err;
+
+	err = io_full(peer->fd, &msg, sizeof(msg), false);
+	if (peer_gone(err))
+		peer->closed = true;
+	if (err)
+		return err;
+	if (ntohl(msg.magic) != XSK_PEER_MAGIC)
+		return -EPROTO;
+
+	switch (ntohl(msg.type)) {
+	case XSK_PEER_READY:
+		/* The peer waits for our READY, so it is at most one step ahead. */
+		if (peer->ready_seen)
+			return -EPROTO;
+		peer->ready_seen = true;
+		return 0;
+	case XSK_PEER_PROGRESS:
+		peer->acked += ntohl(msg.pkts);
+		return 0;
+	case XSK_PEER_ABORT:
+		return -ECANCELED;
+	default:
+		return -EPROTO;
+	}
+}
+
+/* Consume what the peer has sent so far without blocking. */
+static int peer_drain(struct xsk_peer *peer)
+{
+	struct pollfd pfd = { .fd = peer->fd, .events = POLLIN };
+	int ret;
+
+	while (!peer->closed) {
+		ret = poll(&pfd, 1, 0);
+		if (ret < 0 && errno == EINTR)
+			continue;
+		if (ret < 0)
+			return -errno;
+		if (!ret)
+			break;
+		ret = peer_recv_one(peer);
+		if (ret && !peer->closed)
+			return ret;
+	}
+	return 0;
+}
+
+/* Return once both endpoints are set up for the next step. */
+int xsk_peer_ready(struct xsk_peer *peer)
+{
+	int err;
+
+	err = peer_send(peer, XSK_PEER_READY, 0);
+	while (!err && !peer->ready_seen)
+		err = peer_recv_one(peer);
+	if (err)
+		return err;
+
+	/* TCP ordering puts all progress of the previous step before READY. */
+	peer->ready_seen = false;
+	peer->acked = 0;
+	return 0;
+}
+
+void xsk_peer_abort(struct xsk_peer *peer)
+{
+	if (peer && !peer->closed)
+		peer_send(peer, XSK_PEER_ABORT, 0);
+}
+
+int xsk_peer_rx_progress(struct xsk_peer *peer, u32 pkts)
+{
+	int err;
+
+	if (pkts && !peer->closed) {
+		err = peer_send(peer, XSK_PEER_PROGRESS, pkts);
+		if (peer_gone(err))
+			peer->closed = true;
+		else if (err)
+			return err;
+	}
+	return peer_drain(peer);
+}
+
+/* Return the packets RX reported consumed since the last call, or -errno. */
+int xsk_peer_tx_sync(struct xsk_peer *peer)
+{
+	int err = peer_drain(peer);
+	u32 acked = peer->acked;
+
+	if (err)
+		return err;
+	peer->acked = 0;
+	return acked;
+}
+
+static int accept_tmout(int lfd)
+{
+	struct pollfd pfd = { .fd = lfd, .events = POLLIN };
+	int ret;
+
+	do {
+		ret = poll(&pfd, 1, XSK_PEER_ACCEPT_TMOUT_MS);
+	} while (ret < 0 && errno == EINTR);
+	if (!ret)
+		errno = ETIMEDOUT;
+	return ret > 0 ? accept(lfd, NULL, NULL) : -1;
+}
+
+/*
+ * The launcher starts the listener and waits for its port before starting
+ * the connector, so connect() needs no retry. accept() is bounded in case
+ * the connector exits before it gets that far.
+ *
+ * The listener also says on stderr when it listens, so that a launcher can
+ * wait for that line instead of polling for the port over SSH.
+ */
+static int peer_open_tcp(const char *host, const char *port, bool listen_side)
+{
+	struct addrinfo hints = { .ai_family = AF_UNSPEC, .ai_socktype = SOCK_STREAM };
+	int fd = -1, lfd, saved = ECONNREFUSED, one = 1, err;
+	struct addrinfo *res, *ai;
+
+	err = getaddrinfo(host, port, &hints, &res);
+	if (err)
+		return -EINVAL;
+
+	if (!listen_side)
+		goto conn;
+
+	for (ai = res; ai; ai = ai->ai_next) {
+		lfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
+		if (lfd < 0)
+			continue;
+		setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
+		if (!bind(lfd, ai->ai_addr, ai->ai_addrlen) && !listen(lfd, 1)) {
+			fprintf(stderr, "Listening for XSK peer on port %s\n", port);
+			fd = accept_tmout(lfd);
+			saved = errno;
+			close(lfd);
+			break;
+		}
+		saved = errno;
+		close(lfd);
+	}
+	freeaddrinfo(res);
+	return fd >= 0 ? fd : -saved;
+
+conn:
+	for (ai = res; ai; ai = ai->ai_next) {
+		fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
+		if (fd < 0)
+			continue;
+		if (!connect(fd, ai->ai_addr, ai->ai_addrlen))
+			break;
+		saved = errno;
+		close(fd);
+		fd = -1;
+	}
+	freeaddrinfo(res);
+	return fd >= 0 ? fd : -saved;
+}
+
+struct xsk_peer *xsk_peer_open(const char *host, const char *port,
+			       bool listen_side)
+{
+	int fd = peer_open_tcp(host, port, listen_side);
+	struct xsk_peer *peer;
+	int one = 1;
+
+	if (fd < 0) {
+		errno = -fd;
+		return NULL;
+	}
+	peer = calloc(1, sizeof(*peer));
+	if (!peer) {
+		close(fd);
+		return NULL;
+	}
+	peer->fd = fd;
+	setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
+	return peer;
+}
+
+void xsk_peer_close(struct xsk_peer *peer)
+{
+	if (peer) {
+		close(peer->fd);
+		free(peer);
+	}
+}
diff --git a/tools/testing/selftests/net/lib/xsk/xsk_peer.h b/tools/testing/selftests/net/lib/xsk/xsk_peer.h
new file mode 100644
index 0000000000000..1e61078baea23
--- /dev/null
+++ b/tools/testing/selftests/net/lib/xsk/xsk_peer.h
@@ -0,0 +1,18 @@
+/* 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);
+
+#endif /* XSK_PEER_H_ */
diff --git a/tools/testing/selftests/bpf/xsk_xdp_common.h b/tools/testing/selftests/net/lib/xsk/xsk_xdp_common.h
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
diff --git a/tools/testing/selftests/bpf/progs/xsk_xdp_progs.c b/tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c
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
diff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.c b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
new file mode 100644
index 0000000000000..510cb8e4e0540
--- /dev/null
+++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.c
@@ -0,0 +1,654 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2020 Intel Corporation. */
+
+/*
+ * Some functions in this program are taken from
+ * Linux kernel samples/bpf/xdpsock* and modified
+ * for use.
+ *
+ * See test_xsk.sh 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.
+ *
+ * Tests Information:
+ * ------------------
+ * These selftests test AF_XDP SKB and Native/DRV modes using veth
+ * Virtual Ethernet interfaces.
+ *
+ * For each mode, the following tests are run:
+ *    a. nopoll - soft-irq processing in run-to-completion mode
+ *    b. poll - using poll() syscall
+ *    c. Socket Teardown
+ *       Create a Tx and a Rx socket, Tx from one socket, Rx on another. Destroy
+ *       both sockets, then repeat multiple times. Only nopoll mode is used
+ *    d. Bi-directional sockets
+ *       Configure sockets as bi-directional tx/rx sockets, sets up fill and
+ *       completion rings on each socket, tx/rx in both directions. Only nopoll
+ *       mode is used
+ *    e. Statistics
+ *       Trigger some error conditions and ensure that the appropriate statistics
+ *       are incremented. Within this test, the following statistics are tested:
+ *       i.   rx dropped
+ *            Increase the UMEM frame headroom to a value which results in
+ *            insufficient space in the rx buffer for both the packet and the headroom.
+ *       ii.  tx invalid
+ *            Set the 'len' field of tx descriptors to an invalid value (umem frame
+ *            size + 1).
+ *       iii. rx ring full
+ *            Reduce the size of the RX ring to a fraction of the fill ring size.
+ *       iv.  fill queue empty
+ *            Do not populate the fill queue and then try to receive pkts.
+ *    f. bpf_link resource persistence
+ *       Configure sockets at indexes 0 and 1, run a traffic on queue ids 0,
+ *       then remove xsk sockets from queue 0 on both veth interfaces and
+ *       finally run a traffic on queues ids 1
+ *    g. unaligned mode
+ *    h. tests for invalid and corner case Tx descriptors so that the correct ones
+ *       are discarded and let through, respectively.
+ *    i. 2K frame size tests
+ *    j. If multi-buffer is supported, send 9k packets divided into 3 frames
+ *    k. If multi-buffer and huge pages are supported, send 9k packets in a single frame
+ *       using unaligned mode
+ *    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.sh starts two processes: Tx and Rx
+ * - Each of these two processes attach to a veth interface
+ * - Each process creates one AF_XDP socket connected to a unique umem for each
+ *   veth interface
+ * - Tx process listens on a TCP control port, Rx process connects to it and
+ *   the two synchronize each test step over that connection
+ * - Tx process Transmits a number of packets from veth<xxxx> to veth<yyyy>
+ * - Rx process verifies if all packets were received and delivered in-order,
+ *   and have the right content
+ *
+ * Enable/disable packet dump mode:
+ * --------------------------
+ * To enable L2 - L4 headers and payload dump of each packet on STDOUT, add
+ * parameter -D to params array in test_xsk.sh, i.e. params=("-S" "-D")
+ */
+
+#define _GNU_SOURCE
+#include <assert.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <linux/if_link.h>
+#include <linux/if_ether.h>
+#include <linux/mman.h>
+#include <linux/netdev.h>
+#include <linux/ethtool.h>
+#include <linux/align.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+#include <netinet/ether.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <libgen.h>
+#include <stddef.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+
+#include "test_xsk.h"
+#include "xsk_peer.h"
+#include "xsk_xdp_progs.skel.h"
+#include "xsk.h"
+#include "xskxceiver.h"
+#include <bpf/bpf.h>
+#include <linux/filter.h>
+#include "kselftest.h"
+#include "xsk_xdp_common.h"
+
+enum xsk_endpoint_role {
+	XSK_ENDPOINT_NONE,
+	XSK_ENDPOINT_RX,
+	XSK_ENDPOINT_TX,
+};
+
+static enum test_mode opt_mode = TEST_MODE_ALL;
+static u32 opt_run_test = RUN_ALL_TESTS;
+static enum xsk_endpoint_role opt_endpoint_role = XSK_ENDPOINT_NONE;
+static bool opt_hw;
+static bool opt_listen;
+static const char *opt_peer_host;
+static const char *opt_peer_port;
+static const char *opt_ifname;
+static const char *opt_udp_src;
+static const char *opt_udp_dst;
+static const struct ether_addr *opt_peer_mac;
+static struct ether_addr peer_mac;
+static u16 opt_udp_port;
+static u32 opt_queue;
+static u32 opt_max_frags;
+
+enum {
+	OPT_HW = 256,
+	OPT_LISTEN,
+	OPT_UDP_SRC,
+	OPT_UDP_DST,
+	OPT_UDP_PORT,
+	OPT_PEER_MAC,
+	OPT_QUEUE,
+	OPT_MAX_FRAGS,
+};
+
+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,
+			      error, strerror(error));
+	ksft_exit_xfail();
+}
+
+#define exit_with_error(error) __exit_with_error(error, __FILE__, __func__, __LINE__)
+
+static bool ifobj_zc_avail(struct ifobject *ifobject)
+{
+	size_t umem_sz = DEFAULT_UMEM_BUFFERS * XSK_UMEM__DEFAULT_FRAME_SIZE;
+	int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE;
+	struct xsk_socket_info *xsk;
+	struct xsk_umem_info *umem;
+	bool zc_avail = false;
+	void *bufs;
+	int ret;
+
+	bufs = mmap(NULL, umem_sz, PROT_READ | PROT_WRITE, mmap_flags, -1, 0);
+	if (bufs == MAP_FAILED)
+		exit_with_error(errno);
+
+	umem = calloc(1, sizeof(struct xsk_umem_info));
+	if (!umem) {
+		munmap(bufs, umem_sz);
+		exit_with_error(ENOMEM);
+	}
+	umem->frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE;
+	ret = xsk_configure_umem(ifobject, umem, bufs, umem_sz);
+	if (ret)
+		exit_with_error(-ret);
+
+	xsk = calloc(1, sizeof(struct xsk_socket_info));
+	if (!xsk)
+		goto out;
+	ifobject->bind_flags = XDP_USE_NEED_WAKEUP | XDP_ZEROCOPY;
+	ifobject->rx_on = true;
+	xsk->rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS;
+	ret = xsk_configure_socket(xsk, umem, ifobject, false);
+	if (!ret)
+		zc_avail = true;
+
+	xsk_socket__delete(xsk->xsk);
+	free(xsk);
+out:
+	munmap(umem->buffer, umem_sz);
+	xsk_umem__delete(umem->umem);
+	free(umem);
+	return zc_avail;
+}
+
+static struct option long_options[] = {
+	{"interface", required_argument, 0, 'i'},
+	{"busy-poll", no_argument, 0, 'b'},
+	{"verbose", no_argument, 0, 'v'},
+	{"mode", required_argument, 0, 'm'},
+	{"list", no_argument, 0, 'l'},
+	{"test", required_argument, 0, 't'},
+	{"endpoint", required_argument, 0, 'e'},
+	{"peer", required_argument, 0, 'p'},
+	{"peer-port", required_argument, 0, 'P'},
+	{"hw", no_argument, 0, OPT_HW},
+	{"listen", no_argument, 0, OPT_LISTEN},
+	{"udp-src", required_argument, 0, OPT_UDP_SRC},
+	{"udp-dst", required_argument, 0, OPT_UDP_DST},
+	{"udp-port", required_argument, 0, OPT_UDP_PORT},
+	{"peer-mac", required_argument, 0, OPT_PEER_MAC},
+	{"queue", required_argument, 0, OPT_QUEUE},
+	{"max-frags", required_argument, 0, OPT_MAX_FRAGS},
+	{"help", no_argument, 0, 'h'},
+	{0, 0, 0, 0}
+};
+
+static void print_usage(char **argv)
+{
+	const char *str =
+		"  Usage: xskxceiver -i IFACE -e rx|tx -m MODE -t TEST -p HOST -P PORT [OPTIONS]\n"
+		"  Options:\n"
+		"  -i, --interface      Use interface\n"
+		"  -v, --verbose        Verbose output\n"
+		"  -b, --busy-poll      Enable busy poll\n"
+		"  -m, --mode           Run only mode skb, drv, or zc\n"
+		"  -l, --list           List all available tests\n"
+		"  -t, --test           Run a specific test. Enter number from -l option.\n"
+		"  -e, --endpoint       Role of this endpoint: rx or tx\n"
+		"  -p, --peer           Control host: IPv4/IPv6 address or hostname\n"
+		"  -P, --peer-port      Control TCP port (1-65535)\n"
+		"      --listen         Listen instead of connecting (hardware peer)\n"
+		"      --hw             One physical-link case, controlled by xsk.py\n"
+		"      --udp-src IP     IPv4 source address for test packets\n"
+		"      --udp-dst IP     IPv4 destination address for test packets\n"
+		"      --udp-port PORT  UDP source and destination port\n"
+		"      --peer-mac MAC   Remote interface MAC address\n"
+		"      --queue N        AF_XDP queue to bind (default 0)\n"
+		"      --max-frags N    Fragment limit selected by the hardware runner\n"
+		"  -h, --help           Display this help and exit\n";
+
+	ksft_print_msg(str, basename(argv[0]));
+	ksft_exit_xfail();
+}
+
+static void bind_iface(struct ifobject *ifobj, const char *ifname, char **argv)
+{
+	size_t len = strlen(ifname);
+
+	if (!len || len >= sizeof(ifobj->ifname))
+		print_usage(argv);
+
+	memcpy(ifobj->ifname, ifname, len + 1);
+	ifobj->ifindex = if_nametoindex(ifobj->ifname);
+	if (!ifobj->ifindex) {
+		ksft_print_msg("Error: cannot resolve interface %s\n", ifobj->ifname);
+		ksft_exit_fail();
+	}
+
+	if (init_iface(ifobj)) {
+		ksft_print_msg("Error: cannot initialize interface %s\n", ifobj->ifname);
+		ksft_exit_fail();
+	}
+	if (xsk_get_mtu(ifobj->ifname, &ifobj->mtu)) {
+		ksft_print_msg("Error: cannot read MTU of interface %s\n", ifobj->ifname);
+		ksft_exit_fail();
+	}
+	ifobj->dev_mtu = ifobj->mtu;
+	ifobj->orig_mtu = ifobj->mtu;
+}
+
+static void print_tests(void)
+{
+	u32 i;
+
+	printf("Tests:\n");
+	for (i = 0; i < ARRAY_SIZE(tests); i++)
+		printf("%u: %s\n", i, tests[i].name);
+}
+
+static u32 parse_u32(const char *arg, u32 min, u32 max, char **argv)
+{
+	unsigned long val;
+	char *end;
+
+	errno = 0;
+	val = strtoul(arg, &end, 10);
+	if (arg[0] < '0' || arg[0] > '9' || errno || *end || val < min || val > max)
+		print_usage(argv);
+	return val;
+}
+
+static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj_rx, int argc,
+			       char **argv)
+{
+	int option_index, c;
+
+	opterr = 0;
+
+	for (;;) {
+		c = getopt_long(argc, argv, "i:vbm:lt:e:p:P:", long_options, &option_index);
+		if (c == -1)
+			break;
+
+		switch (c) {
+		case 'i':
+			opt_ifname = optarg;
+			break;
+		case 'v':
+			opt_verbose = true;
+			break;
+		case 'b':
+			ifobj_tx->busy_poll = true;
+			ifobj_rx->busy_poll = true;
+			break;
+		case 'm':
+			if (!strncmp("skb", optarg, strlen(optarg)))
+				opt_mode = TEST_MODE_SKB;
+			else if (!strncmp("drv", optarg, strlen(optarg)))
+				opt_mode = TEST_MODE_DRV;
+			else if (!strncmp("zc", optarg, strlen(optarg)))
+				opt_mode = TEST_MODE_ZC;
+			else
+				print_usage(argv);
+			break;
+		case 'l':
+			print_tests();
+			ksft_exit_pass();
+			break;
+		case 't':
+			errno = 0;
+			opt_run_test = strtol(optarg, NULL, 0);
+			if (errno)
+				print_usage(argv);
+			break;
+		case 'e':
+			if (!strcmp(optarg, "rx"))
+				opt_endpoint_role = XSK_ENDPOINT_RX;
+			else if (!strcmp(optarg, "tx"))
+				opt_endpoint_role = XSK_ENDPOINT_TX;
+			else
+				print_usage(argv);
+			break;
+		case 'p':
+			opt_peer_host = optarg;
+			break;
+		case 'P':
+			opt_peer_port = optarg;
+			break;
+		case OPT_HW:
+			opt_hw = true;
+			break;
+		case OPT_LISTEN:
+			opt_listen = true;
+			break;
+		case OPT_UDP_SRC:
+			opt_udp_src = optarg;
+			break;
+		case OPT_UDP_DST:
+			opt_udp_dst = optarg;
+			break;
+		case OPT_UDP_PORT:
+			opt_udp_port = parse_u32(optarg, 1, UINT16_MAX, argv);
+			break;
+		case OPT_PEER_MAC:
+			opt_peer_mac = ether_aton_r(optarg, &peer_mac);
+			if (!opt_peer_mac)
+				print_usage(argv);
+			break;
+		case OPT_QUEUE:
+			opt_queue = parse_u32(optarg, 0, UINT32_MAX, argv);
+			break;
+		case OPT_MAX_FRAGS:
+			opt_max_frags = parse_u32(optarg, 1, UINT16_MAX, argv);
+			break;
+		case 'h':
+		default:
+			print_usage(argv);
+		}
+	}
+
+	if (!opt_ifname || opt_endpoint_role == XSK_ENDPOINT_NONE || !opt_peer_host ||
+	    !*opt_peer_host || !opt_peer_port || opt_run_test == RUN_ALL_TESTS ||
+	    opt_mode == TEST_MODE_ALL)
+		print_usage(argv);
+	if (opt_hw && (!opt_udp_src || !opt_udp_dst || !opt_udp_port || !opt_peer_mac))
+		print_usage(argv);
+	if ((opt_listen || opt_max_frags) && !opt_hw)
+		print_usage(argv);
+}
+
+static void xsk_unload_xdp_programs(struct ifobject *ifobj)
+{
+	xsk_xdp_progs__destroy(ifobj->xdp_progs);
+}
+
+static void report_pkt_test(struct test_spec *test, int ret)
+{
+	switch (ret) {
+	case TEST_PASS:
+		ksft_test_result_pass("PASS: %s %s%s\n", mode_string(test), busy_poll_string(test),
+				      test->name);
+		break;
+	case TEST_SKIP:
+		ksft_test_result_skip("SKIP: %s %s%s\n", mode_string(test), busy_poll_string(test),
+				      test->name);
+		break;
+	case TEST_FAILURE:
+		ksft_test_result_fail("FAIL: %s %s%s\n", mode_string(test), busy_poll_string(test),
+				      test->name);
+		break;
+	default:
+		ksft_test_result_fail("FAIL: %s %s%s -- Unexpected returned value (%d)\n",
+				      mode_string(test), busy_poll_string(test), test->name, ret);
+	}
+}
+
+static int run_pkt_test(struct test_spec *test)
+{
+	int ret;
+
+	ret = test->test_func(test);
+	if (!opt_hw)
+		report_pkt_test(test, ret);
+	pkt_stream_restore_default(test);
+	return ret;
+}
+
+static bool is_xdp_supported(int ifindex)
+{
+	int flags = XDP_FLAGS_DRV_MODE;
+
+	LIBBPF_OPTS(bpf_link_create_opts, opts, .flags = flags);
+	struct bpf_insn insns[2] = {
+		BPF_MOV64_IMM(BPF_REG_0, XDP_PASS),
+		BPF_EXIT_INSN()
+	};
+	int prog_fd, insn_cnt = ARRAY_SIZE(insns);
+	int err;
+
+	prog_fd = bpf_prog_load(BPF_PROG_TYPE_XDP, NULL, "GPL", insns, insn_cnt, NULL);
+	if (prog_fd < 0)
+		return false;
+
+	err = bpf_xdp_attach(ifindex, prog_fd, flags, NULL);
+	if (err) {
+		close(prog_fd);
+		return false;
+	}
+
+	bpf_xdp_detach(ifindex, flags, NULL);
+	close(prog_fd);
+
+	return true;
+}
+
+static u32 detect_mode_caps(struct ifobject *ifobj)
+{
+	if (opt_hw && opt_mode == TEST_MODE_ZC &&
+	    ifobj_has_cap(ifobj, XSK_CAP_ZC_ADVERTISED)) {
+		/* Trust the advertised flag; an XDP_ZEROCOPY bind never falls back to copy. */
+		ifobj_set_cap(ifobj, XSK_CAP_DRV | XSK_CAP_ZC);
+	} else if (!opt_hw && is_xdp_supported(ifobj->ifindex)) {
+		ifobj_set_cap(ifobj, XSK_CAP_DRV);
+		if (ifobj_zc_avail(ifobj))
+			ifobj_set_cap(ifobj, XSK_CAP_ZC);
+	}
+
+	return ifobj->caps.flags;
+}
+
+static bool mode_supported(enum test_mode mode, u32 caps)
+{
+	if (mode == TEST_MODE_SKB)
+		return true;
+	if (mode == TEST_MODE_DRV)
+		return caps & XSK_CAP_DRV;
+	return caps & XSK_CAP_ZC;
+}
+
+static int cleanup_iface(struct ifobject *ifobj)
+{
+	int err = 0;
+
+	/* A peer shadow has a skeleton but no bound interface. */
+	if (!ifobj_is_local(ifobj))
+		goto unload;
+
+	if (ifobj_has_cap(ifobj, XSK_CAP_HW_RING))
+		hw_ring_size_reset(ifobj);
+	if (ifobj->xdp_prog)
+		xsk_detach_xdp_program(ifobj->ifindex,
+				       ifobj->mode == TEST_MODE_SKB ?
+				       XDP_FLAGS_SKB_MODE : XDP_FLAGS_DRV_MODE);
+	/* After the detach, as an attached program can cap the MTU. */
+	if (ifobj->dev_mtu != ifobj->orig_mtu) {
+		err = xsk_set_mtu(ifobj->ifindex, ifobj->orig_mtu);
+		if (err)
+			ksft_print_msg("Failed to restore MTU %d on %s\n",
+				       ifobj->orig_mtu, ifobj->ifname);
+	}
+unload:
+	xsk_unload_xdp_programs(ifobj);
+	return err;
+}
+
+/* Connect the two endpoints without negotiating the remote NIC's capabilities. */
+static int setup_peer(struct ifobject *local, struct ifobject *shadow,
+		      struct xsk_peer **peer)
+{
+	/* Unattached skeleton copy; the engine only attaches the local side. */
+	if (xsk_load_xdp_programs(shadow))
+		return TEST_FAILURE;
+
+	/* Generic TX listens; Python chooses the listener for hardware cases. */
+	*peer = xsk_peer_open(opt_peer_host, opt_peer_port,
+			      opt_hw ? opt_listen :
+			      opt_endpoint_role == XSK_ENDPOINT_TX);
+	if (!*peer) {
+		ksft_print_msg("Failed to connect XSK peer: %s\n", strerror(errno));
+		return TEST_FAILURE;
+	}
+
+	shadow->caps = local->caps;
+	if (opt_hw)
+		memcpy(shadow->caps.mac, opt_peer_mac->ether_addr_octet, ETH_ALEN);
+
+	xsk_set_endpoint(*peer, opt_hw);
+	return TEST_PASS;
+}
+
+int main(int argc, char **argv)
+{
+	u32 cache_line_size, max_frags, umem_tailroom;
+	const size_t total_tests = ARRAY_SIZE(tests);
+	struct ifobject *ifobj_tx, *ifobj_rx;
+	struct ifobject *shadow_ifobj;
+	struct ifobject *local_ifobj;
+	struct xsk_peer *peer = NULL;
+	struct test_spec test = {};
+	int ret = TEST_FAILURE;
+	u32 caps;
+	int err;
+
+	/* Use libbpf 1.0 API mode */
+	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
+
+	ifobj_tx = ifobject_create();
+	if (!ifobj_tx)
+		exit_with_error(ENOMEM);
+	ifobj_rx = ifobject_create();
+	if (!ifobj_rx)
+		exit_with_error(ENOMEM);
+
+	setlocale(LC_ALL, "");
+
+	cache_line_size = read_procfs_val(SMP_CACHE_BYTES_PATH);
+	if (!cache_line_size) {
+		ksft_print_msg("Can't get SMP_CACHE_BYTES from system, using default (64)\n");
+		cache_line_size = 64;
+	}
+
+	max_frags = read_procfs_val(MAX_SKB_FRAGS_PATH);
+	if (!max_frags) {
+		ksft_print_msg("Can't get MAX_SKB_FRAGS from system, using default (17)\n");
+		max_frags = 17;
+	}
+	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->caps.umem_tailroom = umem_tailroom;
+	ifobj_rx->caps.umem_tailroom = umem_tailroom;
+
+	parse_command_line(ifobj_tx, ifobj_rx, argc, argv);
+
+	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();
+	}
+
+	xsk_set_max_frags(opt_max_frags);
+	if (opt_hw && xsk_set_udp_packet_format(opt_udp_src, opt_udp_dst,
+						opt_udp_port))
+		print_usage(argv);
+
+	/* swap_directions() swaps the workers, so the shadow needs one too. */
+	ifobj_tx->func_ptr = worker_testapp_validate_tx;
+	ifobj_rx->func_ptr = worker_testapp_validate_rx;
+	if (opt_endpoint_role == XSK_ENDPOINT_TX) {
+		local_ifobj = ifobj_tx;
+		shadow_ifobj = ifobj_rx;
+	} else {
+		local_ifobj = ifobj_rx;
+		shadow_ifobj = ifobj_tx;
+	}
+	bind_iface(local_ifobj, opt_ifname, argv);
+	local_ifobj->queue_id = opt_queue;
+	/* The zero-copy probe binds to queue_id, so set it first. */
+	caps = detect_mode_caps(local_ifobj);
+
+	test.tx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);
+	test.rx_pkt_stream_default = pkt_stream_generate(DEFAULT_PKT_CNT, MIN_PKT_SIZE);
+	if (!test.tx_pkt_stream_default || !test.rx_pkt_stream_default)
+		goto out;
+
+	if (setup_peer(local_ifobj, shadow_ifobj, &peer))
+		goto out;
+
+	if (!mode_supported(opt_mode, caps)) {
+		if (opt_mode == TEST_MODE_DRV)
+			ksft_print_msg("XDP_DRV mode not supported.\n");
+		else
+			ksft_print_msg("zero-copy mode not supported.\n");
+		ret = TEST_SKIP;
+		goto out;
+	}
+
+	/* Line-buffer stdout so verdicts reach a capturing launcher live. */
+	if (!opt_hw) {
+		ksft_print_header();
+		ksft_set_plan(1);
+	}
+	test_init(&test, ifobj_tx, ifobj_rx, opt_mode, &tests[opt_run_test]);
+	ret = run_pkt_test(&test);
+
+out:
+	xsk_set_endpoint(NULL, false);
+	err = cleanup_iface(ifobj_tx);
+	err |= cleanup_iface(ifobj_rx);
+	/* xsk.py trusts a passed or skipped endpoint to have undone the MTU. */
+	if (err)
+		ret = TEST_FAILURE;
+	xsk_peer_close(peer);
+	pkt_stream_delete(test.tx_pkt_stream_default);
+	pkt_stream_delete(test.rx_pkt_stream_default);
+	ifobject_delete(ifobj_tx);
+	ifobject_delete(ifobj_rx);
+
+	if (ret == TEST_SKIP && !opt_hw && ksft_test_num()) {
+		ksft_print_cnts();
+		return KSFT_SKIP;
+	}
+	if (ret == TEST_SKIP)
+		ksft_exit_skip("mode or test not supported\n");
+	if (ret)
+		ksft_exit_fail();
+	else
+		ksft_exit_pass();
+}
diff --git a/tools/testing/selftests/bpf/xskxceiver.h b/tools/testing/selftests/net/lib/xsk/xskxceiver.h
similarity index 100%
rename from tools/testing/selftests/bpf/xskxceiver.h
rename to tools/testing/selftests/net/lib/xsk/xskxceiver.h
diff --git a/tools/testing/selftests/bpf/test_xsk.sh b/tools/testing/selftests/net/test_xsk.sh
similarity index 57%
rename from tools/testing/selftests/bpf/test_xsk.sh
rename to tools/testing/selftests/net/test_xsk.sh
index 62db060298a4a..2ef9ce7e1b27d 100755
--- a/tools/testing/selftests/bpf/test_xsk.sh
+++ b/tools/testing/selftests/net/test_xsk.sh
@@ -8,22 +8,20 @@
 #
 # Topology:
 # ---------
-#                 -----------
-#               _ | Process | _
-#              /  -----------  \
-#             /        |        \
-#            /         |         \
-#      -----------     |     -----------
-#      | Thread1 |     |     | Thread2 |
-#      -----------     |     -----------
-#           |          |          |
-#      -----------     |     -----------
-#      |  xskX   |     |     |  xskY   |
-#      -----------     |     -----------
-#           |          |          |
-#      -----------     |     ----------
-#      |  vethX  | --------- |  vethY |
-#      -----------   peer    ----------
+#      -----------   control    -----------
+#      | TX proc | ------------ | RX proc |
+#      -----------  (TCP, lo)   -----------
+#           |                        |
+#      -----------              -----------
+#      |  xskX   |              |  xskY   |
+#      -----------              -----------
+#           |                        |
+#      -----------              ----------
+#      |  vethX  | ------------ |  vethY |
+#      -----------     peer     ----------
+#
+# The two xskxceiver processes each drive one veth and synchronize over a
+# TCP control connection on 127.0.0.1.
 #
 # AF_XDP is an address family optimized for high performance packet processing,
 # it is XDP’s user-space interface.
@@ -71,10 +69,10 @@
 # Set up veth interfaces and leave them up so xskxceiver can be launched in a debugger:
 #   sudo ./test_xsk.sh -d
 #
-# Run test suite for physical device in loopback mode
-#   sudo ./test_xsk.sh -i IFACE
+# Use a specific TCP port for the control connection (random by default)
+#   sudo ./test_xsk.sh -p PORT
 #
-# Run test suite in a specific mode only [skb,drv,zc]
+# Run test suite in a specific mode only [skb,drv]
 #   sudo ./test_xsk.sh -m MODE
 #
 # List available tests
@@ -88,14 +86,20 @@
 
 . xsk_prereqs.sh
 
-ETH=""
+if [ ! -x "./${XSKOBJ}" ]; then
+	echo "xskxceiver was not built; skipping"
+	exit $ksft_skip
+fi
+
+PEER_HOST=127.0.0.1
+PEER_PORT=
 
-while getopts "vi:dm:lt:h" flag
+while getopts "vdm:lt:p:h" flag
 do
 	case "${flag}" in
 		v) verbose=1;;
 		d) debug=1;;
-		i) ETH=${OPTARG};;
+		p) PEER_PORT=${OPTARG};;
 		m) MODE=${OPTARG};;
 		l) list=1;;
 		t) TEST=${OPTARG};;
@@ -157,34 +161,53 @@ if [[ $help -eq 1 ]]; then
         exit
 fi
 
-if [ ! -z $ETH ]; then
-	VETH0=${ETH}
-	VETH1=${ETH}
+if [ -n "$MODE" ]; then
+	case "$MODE" in
+		skb|drv) MODES=("$MODE");;
+		*) echo "Unsupported veth mode: $MODE (expected skb or drv)" >&2
+		   exit 1;;
+	esac
 else
-	validate_root_exec
-	validate_veth_support ${VETH0}
-	validate_ip_utility
-	setup_vethPairs
-
-	retval=$?
-	if [ $retval -ne 0 ]; then
-		test_status $retval "${TEST_NAME}"
-		cleanup_exit ${VETH0} ${VETH1}
-		exit $retval
-	fi
+	MODES=(skb drv)
 fi
 
+if [ -n "$TEST" ]; then
+	if [[ "$TEST" =~ ^[0-9]+$ ]]; then
+		CASES=("$TEST")
+	else
+		mapfile -t CASES < <(./${XSKOBJ} -l |
+			awk -F ': ' -v name="$TEST" '$2 == name {print $1}')
+	fi
+else
+	mapfile -t CASES < <(./${XSKOBJ} -l | awk -F ': ' '/^[0-9]+: / {print $1}')
+fi
+if [ ${#CASES[@]} -eq 0 ]; then
+	echo "Unknown AF_XDP test: $TEST" >&2
+	exit 1
+fi
 
-if [[ $verbose -eq 1 ]]; then
-	ARGS+="-v "
+if [ -z "$PEER_PORT" ]; then
+	PEER_PORT=$(random_port) || {
+		echo "Could not find an unused TCP port" >&2
+		exit 1
+	}
 fi
 
-if [ -n "$MODE" ]; then
-	ARGS+="-m ${MODE} "
+validate_root_exec
+validate_veth_support ${VETH0}
+validate_ip_utility
+setup_vethPairs
+
+retval=$?
+if [ $retval -ne 0 ]; then
+	test_status $retval "${TEST_NAME}"
+	cleanup_exit ${VETH0} ${VETH1}
+	exit $retval
 fi
 
-if [ -n "$TEST" ]; then
-	ARGS+="-t ${TEST} "
+
+if [[ $verbose -eq 1 ]]; then
+	ARGS+="-v "
 fi
 
 retval=$?
@@ -193,54 +216,81 @@ test_status $retval "${TEST_NAME}"
 ## START TESTS
 
 statusList=()
+nameList=()
+
+run_matrix()
+{
+	local mode case_id
+
+	for mode in "${MODES[@]}"; do
+		for case_id in "${CASES[@]}"; do
+			ARGS="${BASE_ARGS} -m ${mode} -t ${case_id}"
+			TEST_NAME="XSK_${mode}_${case_id}_${RUN_VARIANT}_${VETH0}"
+			exec_xskxceiver
+		done
+	done
+}
+
+BASE_ARGS="${ARGS}"
 
-TEST_NAME="XSK_SELFTESTS_${VETH0}_SOFTIRQ"
+RUN_VARIANT=SOFTIRQ
 
 if [[ $debug -eq 1 ]]; then
-    echo "-i" ${VETH0} "-i" ${VETH1}
+    ARGS="${BASE_ARGS} -m ${MODES[0]} -t ${CASES[0]}"
+    echo "./${XSKOBJ} -i ${VETH0} -e tx -p ${PEER_HOST} -P ${PEER_PORT} ${ARGS}"
+    echo "./${XSKOBJ} -i ${VETH1} -e rx -p ${PEER_HOST} -P ${PEER_PORT} ${ARGS}"
     exit
 fi
 
-exec_xskxceiver
+run_matrix
 
-if [ -z $ETH ]; then
-	cleanup_exit ${VETH0} ${VETH1}
-else
-	cleanup_iface ${ETH} ${MTU}
-fi
+cleanup_exit ${VETH0} ${VETH1}
 
 if [[ $list -eq 1 ]]; then
     exit
 fi
 
-TEST_NAME="XSK_SELFTESTS_${VETH0}_BUSY_POLL"
+RUN_VARIANT=BUSY_POLL
 busy_poll=1
 
-if [ -z $ETH ]; then
-	setup_vethPairs
-fi
-exec_xskxceiver
+setup_vethPairs
+run_matrix
 
 ## END TESTS
 
-if [ -z $ETH ]; then
-	cleanup_exit ${VETH0} ${VETH1}
-else
-	cleanup_iface ${ETH} ${MTU}
-fi
+cleanup_exit ${VETH0} ${VETH1}
 
+passes=0
+skips=0
 failures=0
-echo -e "\nSummary:"
+failed_tests=()
 for i in "${!statusList[@]}"
 do
-	if [ ${statusList[$i]} -ne 0 ]; then
-	        test_status ${statusList[$i]} ${nameList[$i]}
-		failures=1
-	fi
+	case ${statusList[$i]} in
+		$ksft_pass)
+			passes=$((passes + 1))
+			;;
+		$ksft_skip)
+			skips=$((skips + 1))
+			;;
+		*)
+			failures=$((failures + 1))
+			failed_tests+=("${nameList[$i]}")
+			;;
+	esac
 done
 
-if [ $failures -eq 0 ]; then
-        echo "All tests successful!"
-else
+echo
+echo "Summary:"
+printf "  Tests:   %d\n" "${#statusList[@]}"
+printf "  Passed:  %d\n" "$passes"
+printf "  Skipped: %d\n" "$skips"
+printf "  Failed:  %d\n" "$failures"
+
+if [ $failures -ne 0 ]; then
+	echo "Failed tests:"
+	for TEST_NAME in "${failed_tests[@]}"; do
+		echo "  $TEST_NAME"
+	done
 	exit 1
 fi
diff --git a/tools/testing/selftests/bpf/xsk_prereqs.sh b/tools/testing/selftests/net/xsk_prereqs.sh
similarity index 53%
rename from tools/testing/selftests/bpf/xsk_prereqs.sh
rename to tools/testing/selftests/net/xsk_prereqs.sh
index 47c7b8064f38b..82cd7839d77d9 100755
--- a/tools/testing/selftests/bpf/xsk_prereqs.sh
+++ b/tools/testing/selftests/net/xsk_prereqs.sh
@@ -8,7 +8,7 @@ ksft_xfail=2
 ksft_xpass=3
 ksft_skip=4
 
-XSKOBJ=xskxceiver
+XSKOBJ=lib/xskxceiver
 
 validate_root_exec()
 {
@@ -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 ] &&
@@ -76,14 +69,63 @@ validate_ip_utility()
 	[ ! $(type -P ip) ] && { echo "'ip' not found. Skipping tests."; test_exit $ksft_skip; }
 }
 
+wait_port_listen()
+{
+	local i
+
+	for i in $(seq 50); do
+		if [ -n "$(ss -Hltn "sport = :$1" 2>/dev/null)" ]; then
+			return 0
+		fi
+		kill -0 $2 2>/dev/null || return 1
+		sleep 0.1
+	done
+	return 1
+}
+
+random_port()
+{
+	local i port
+
+	for i in $(seq 50); do
+		port=$((32768 + RANDOM))
+		if [ -z "$(ss -Hltn "sport = :$port" 2>/dev/null)" ]; then
+			echo "$port"
+			return 0
+		fi
+	done
+	return 1
+}
+
+# The TX endpoint listens on the control port and runs in the background,
+# the RX endpoint connects to it and reports; both print the same verdicts.
 exec_xskxceiver()
 {
+	local tx_log tx_pid tx_ret run_args="${ARGS}"
+
         if [[ $busy_poll -eq 1 ]]; then
-	        ARGS+="-b "
+		run_args+=" -b"
+	fi
+
+	tx_log=$(mktemp)
+	./${XSKOBJ} -i ${VETH0} -e tx -p ${PEER_HOST} -P ${PEER_PORT} ${run_args} > ${tx_log} 2>&1 &
+	tx_pid=$!
+
+	if wait_port_listen ${PEER_PORT} ${tx_pid}; then
+		./${XSKOBJ} -i ${VETH1} -e rx -p ${PEER_HOST} -P ${PEER_PORT} ${run_args}
+		retval=$?
+	else
+		echo "TX endpoint did not listen on ${PEER_HOST}:${PEER_PORT}"
+		retval=1
 	fi
 
-	./${XSKOBJ} -i ${VETH0} -i ${VETH1} ${ARGS}
-	retval=$?
+	wait ${tx_pid}
+	tx_ret=$?
+	if [[ $tx_ret -ne 0 || $verbose -eq 1 ]]; then
+		sed 's/^/tx| /' ${tx_log}
+	fi
+	rm -f ${tx_log}
+	[[ $retval -eq 0 ]] && retval=$tx_ret
 
 	if [[ $list -ne 1 ]]; then
 	    test_status $retval "${TEST_NAME}"

3/2 2026/10/02 15:39 llm patch-evaluator
1m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 60640
							output: 98
							thoughts: 1711
						

Thoughts:
**Fuzzing Evaluation: WorthFuzzing = False**

Okay, let's break this down. The request is to determine if this git patch is suitable for fuzzing with syzkaller. My initial instinct, based on the file paths, is leaning towards "no," but let's be thorough.

First, I need to look at the modified files. Right away, I'm noticing a concentration of changes within `tools/testing/selftests/`, and some within `Documentation/` and `MAINTAINERS`. I know from experience that selftests are generally user-space code.

I've got a comprehensive list of all changed files, as expected. Now, I need to rigorously apply my mental checklist to each file. Are there *any* modifications outside these expected areas? Nope. I see `Documentation/networking/af_xdp.rst`, `MAINTAINERS`, and a flurry of activity in `tools/testing/selftests/bpf`, `tools/testing/selftests/drivers/net/hw`, and `tools/testing/selftests/net/lib/xsk`. Looks like a lot of test infrastructure shuffling and renaming, even.

Crucially, are these changes affecting the *compiled kernel image* or kernel modules? Absolutely not. This entire patch appears to be focused on improving documentation, maintaining the project, and, importantly, the testing infrastructure, which is all user-space code.

Given the criteria: the patch's changes are strictly limited to documentation, `MAINTAINERS`, and user-space selftests, I'm confident in saying that the value for `WorthFuzzing` is `false`.

Now, I'll structure the `set-results` call:

*   `WorthFuzzing`: `false`
*   `Reasoning`: "The patch series exclusively modifies documentation, `MAINTAINERS`, and user-space selftests within `tools/testing/selftests/`. It does not introduce any changes to the kernel source code or affect the compiled kernel image (`vmlinux/modules`)."
*   `FocusSymbols`: `[]`
*   `EnableConfigs`: `[]`

Ready to call `set-results`.



4/2 2026/10/02 15:40 tool set-results
0m Args:
{
  "EnableConfigs": [],
  "FocusSymbols": [],
  "Reasoning": "The patch series touches only documentation (Documentation/networking/af_xdp.rst), MAINTAINERS, and user-space selftests and tooling under tools/testing/selftests/. No kernel source code or compiled kernel image (vmlinux/modules) is modified, so there is no kernel code to fuzz.",
  "WorthFuzzing": false
}

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "Reasoning": "The patch series touches only documentation (Documentation/networking/af_xdp.rst), MAINTAINERS, and user-space selftests and tooling under tools/testing/selftests/. No kernel source code or compiled kernel image (vmlinux/modules) is modified, so there is no kernel code to fuzz.",
  "WorthFuzzing": false
}

5/1 2026/10/02 15:40 action If
0m Args:
{
  "WorthFuzzing": false
}

Results:
null

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)