From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: netdev@vger.kernel.org
Cc: bpf@vger.kernel.org, magnus.karlsson@intel.com,
stfomichev@gmail.com, kuba@kernel.org, pabeni@redhat.com,
tushar.vyavahare@intel.com, kerneljasonxing@gmail.com,
bjorn@kernel.org,
Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Subject: [PATCH v2 net-next 11/14] selftests: xsk: pass non-test traffic to the stack in hardware mode
Date: Thu, 8 Oct 2026 13:49:06 +0200 [thread overview]
Message-ID: <20261008114909.734364-12-maciej.fijalkowski@intel.com> (raw)
In-Reply-To: <20261008114909.734364-1-maciej.fijalkowski@intel.com>
The XDP programs of xskxceiver redirect every packet to the XSKMAP and
drop what no socket takes, so a hardware run needs a link that carries
nothing but the test flow. While a program is attached, neighbour
discovery, LLDP or SSH on the tested link are dropped, and on the
remote receiver, whose socket shares queue 0 with RSS, such a packet
reaches the socket and fails the case.
In hardware mode, redirect only the UDP/IPv4 packets sent to the test
port (--udp-port) and pass everything else to the stack. The veth mode
keeps redirecting every packet, as its frames carry no IP header.
I think that xdpsock used to do matching based on rx queue index, but
here it would not be enough: to need no more than ntuple support from
the remote, the runner leaves its RSS table alone, so the remote's
socket shares queue 0 with whatever RSS hashes there. The port also
keeps the drop, tail-adjust and metadata programs from acting on
unrelated frames.
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
.../testing/selftests/net/lib/xsk/test_xsk.c | 2 +
.../selftests/net/lib/xsk/xsk_xdp_progs.bpf.c | 39 +++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c
index 542c0579062a..1033a5430697 100644
--- a/tools/testing/selftests/net/lib/xsk/test_xsk.c
+++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c
@@ -2454,6 +2454,8 @@ int xsk_load_xdp_programs(struct ifobject *ifobj)
if (libbpf_get_error(ifobj->xdp_progs))
return libbpf_get_error(ifobj->xdp_progs);
+ /* The shadow's copy too, swapped directions attach its programs. */
+ ifobj->xdp_progs->bss->hw_port = udp_port;
return 0;
}
diff --git a/tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c b/tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c
index 023d8befd4ca..716360d023a7 100644
--- a/tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c
+++ b/tools/testing/selftests/net/lib/xsk/xsk_xdp_progs.bpf.c
@@ -5,7 +5,11 @@
#include <bpf/bpf_helpers.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
+#include <linux/udp.h>
+#include <linux/in.h>
#include <linux/errno.h>
+#include <bpf/bpf_endian.h>
+#include <stdbool.h>
#include "xsk_xdp_common.h"
struct {
@@ -18,9 +22,34 @@ struct {
static unsigned int idx;
int adjust_value = 0;
int count = 0;
+/* UDP port of the hardware test flow, 0 redirects every packet */
+__u16 hw_port;
+
+static __always_inline bool is_test_packet(struct xdp_md *xdp)
+{
+ void *data_end = (void *)(long)xdp->data_end;
+ void *data = (void *)(long)xdp->data;
+ struct ethhdr *eth = data;
+ struct udphdr *udp;
+ struct iphdr *ip;
+
+ if (!hw_port)
+ return true;
+ if ((void *)(eth + 1) > data_end ||
+ eth->h_proto != bpf_htons(ETH_P_IP))
+ return false;
+ ip = (void *)(eth + 1);
+ if ((void *)(ip + 1) > data_end || ip->ihl != 5 ||
+ ip->protocol != IPPROTO_UDP)
+ return false;
+ udp = (void *)(ip + 1);
+ return (void *)(udp + 1) <= data_end && udp->dest == bpf_htons(hw_port);
+}
SEC("xdp.frags") int xsk_def_prog(struct xdp_md *xdp)
{
+ if (!is_test_packet(xdp))
+ return XDP_PASS;
return bpf_redirect_map(&xsk, 0, XDP_DROP);
}
@@ -28,6 +57,8 @@ SEC("xdp.frags") int xsk_xdp_drop(struct xdp_md *xdp)
{
static unsigned int drop_idx;
+ if (!is_test_packet(xdp))
+ return XDP_PASS;
/* Drop every other packet */
if (drop_idx++ % 2)
return XDP_DROP;
@@ -41,6 +72,9 @@ SEC("xdp.frags") int xsk_xdp_populate_metadata(struct xdp_md *xdp)
struct xdp_info *meta;
int err;
+ if (!is_test_packet(xdp))
+ return XDP_PASS;
+
/* Reserve enough for all custom metadata. */
err = bpf_xdp_adjust_meta(xdp, -(int)sizeof(struct xdp_info));
if (err)
@@ -64,6 +98,8 @@ SEC("xdp") int xsk_xdp_shared_umem(struct xdp_md *xdp)
void *data_end = (void *)(long)xdp->data_end;
struct ethhdr *eth = data;
+ if (!is_test_packet(xdp))
+ return XDP_PASS;
if (eth + 1 > data_end)
return XDP_DROP;
@@ -80,6 +116,9 @@ SEC("xdp.frags") int xsk_xdp_adjust_tail(struct xdp_md *xdp)
__u32 buff_len, curr_buff_len;
int ret;
+ if (!is_test_packet(xdp))
+ return XDP_PASS;
+
buff_len = bpf_xdp_get_buff_len(xdp);
if (buff_len == 0)
return XDP_DROP;
--
2.43.0
next prev parent reply other threads:[~2026-10-08 11:49 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 11:48 [PATCH v2 net-next 00/14] selftests: net: migrate AF_XDP test suite over to net Maciej Fijalkowski
2026-10-08 11:48 ` [PATCH v2 net-next 01/14] selftests: xsk: factor endpoint work out of pthread wrappers Maciej Fijalkowski
2026-10-08 11:48 ` [PATCH v2 net-next 02/14] selftests: xsk: drop the single-interface loopback mode Maciej Fijalkowski
2026-10-09 9:46 ` Björn Töpel
2026-10-09 12:43 ` Maciej Fijalkowski
2026-10-08 11:48 ` [PATCH v2 net-next 03/14] selftests/bpf: drop the test_progs AF_XDP wrapper Maciej Fijalkowski
2026-10-08 11:48 ` [PATCH v2 net-next 04/14] selftests: net: add a generic rule for BPF skeletons Maciej Fijalkowski
2026-10-08 11:49 ` [PATCH v2 net-next 05/14] selftests: xsk: move the AF_XDP test suite to selftests/net Maciej Fijalkowski
2026-10-09 11:18 ` Björn Töpel
2026-10-09 12:46 ` Maciej Fijalkowski
2026-10-08 11:49 ` [PATCH v2 net-next 06/14] selftests: xsk: collect interface capabilities in struct xsk_caps Maciej Fijalkowski
2026-10-08 11:49 ` [PATCH v2 net-next 07/14] selftests: xsk: split xskxceiver main() into setup, run and cleanup Maciej Fijalkowski
2026-10-08 11:49 ` [PATCH v2 net-next 08/14] selftests: xsk: run one test case per xskxceiver invocation Maciej Fijalkowski
2026-10-09 11:25 ` Björn Töpel
2026-10-08 11:49 ` [PATCH v2 net-next 09/14] selftests: xsk: run the RX and TX endpoints in separate processes Maciej Fijalkowski
2026-10-08 11:49 ` [PATCH v2 net-next 10/14] selftests: xsk: add a hardware mode to xskxceiver Maciej Fijalkowski
2026-10-08 11:49 ` Maciej Fijalkowski [this message]
2026-10-08 11:49 ` [PATCH v2 net-next 12/14] selftests: xsk: share test case definitions with hardware runner Maciej Fijalkowski
2026-10-09 12:12 ` Björn Töpel
2026-10-09 12:52 ` Maciej Fijalkowski
2026-10-08 11:49 ` [PATCH v2 net-next 13/14] selftests: drv-net: test AF_XDP zero-copy with an SKB peer Maciej Fijalkowski
2026-10-08 21:37 ` Jakub Kicinski
2026-10-09 13:13 ` Maciej Fijalkowski
2026-10-08 11:49 ` [PATCH v2 net-next 14/14] selftests: xsk: document generic and hardware endpoint runs Maciej Fijalkowski
2026-10-08 21:41 ` Jakub Kicinski
2026-10-08 21:30 ` [PATCH v2 net-next 00/14] selftests: net: migrate AF_XDP test suite over to net Jakub Kicinski
2026-10-09 12:02 ` Björn Töpel
2026-10-09 13:15 ` Maciej Fijalkowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261008114909.734364-12-maciej.fijalkowski@intel.com \
--to=maciej.fijalkowski@intel.com \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kerneljasonxing@gmail.com \
--cc=kuba@kernel.org \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stfomichev@gmail.com \
--cc=tushar.vyavahare@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox