Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Björn Töpel" <bjorn@kernel.org>, bpf@vger.kernel.org
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH net-next 14/15] selftests: net: xsk: Test the device's RX buffer layout
Date: Wed, 25 Nov 2026 13:00:18 +0000	[thread overview]
Message-ID: <sashiko-outbox-233424@kernel.org> (raw)
In-Reply-To: <20261124125654.183091-14-bjorn@kernel.org>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] selftests: net: xsk: XDP_UMEM_DRV_LAYOUT set on TX-only and
  ZC-probe UMEMs
- [Medium] selftests: net: xsk: is_frag_valid_drv() skips zeroed last
  word seqnum check
- [Medium] selftests: net: xsk: __receive_pkts() infinite spin reserving
  rcvd FILL slots
- [Medium] selftests: net: xsk: testapp_stats_fill_empty() fails in drv
  layout mode
- [Low] selftests: net: xsk: livelock in __receive_pkts() when
  batch_size is 1
--

commit 505282853476bb5b9e8a5968f2d816c8a8b08570
Author: Björn Töpel <bjorn@kernel.org>

selftests: net: xsk: Test the device's RX buffer layout

This commit adds the -D (--drv-layout) option to xskxceiver to test
AF_XDP UMEMs registered with XDP_UMEM_DRV_LAYOUT in driver mode.

> diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c
> index ca161511f1e5f..bae503432eeb3 100644
> --- a/tools/testing/selftests/net/lib/xsk/test_xsk.c
> +++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c
[ ... ]
> @@ -94,6 +99,8 @@ int xsk_configure_umem(struct ifobject *ifobj, struct xsk_umem_info *umem, void
>  
>  	if (umem->unaligned_mode)
>  		cfg.flags |= XDP_UMEM_UNALIGNED_CHUNK_FLAG;
> +	if (opt_drv_layout)
> +		cfg.flags |= XDP_UMEM_DRV_LAYOUT;
>  
>  	ret = xsk_umem__create(&umem->umem, buffer, size,
>  			       &umem->fq, &umem->cq, &cfg);

[Severity: Medium]
Should XDP_UMEM_DRV_LAYOUT (and the corresponding bind flags in
xsk_configure_socket() and test_init()) only be set when ifobj->rx_on is
true?

When xskxceiver is run with two distinct interfaces (-i tx_if -i rx_if
-D), ifobj_tx does not share a UMEM with ifobj_rx and has rx_on set to
false.  Setting XDP_UMEM_DRV_LAYOUT on ifobj_tx's TX-only UMEM causes
xp_assign_dev() to call xsk_sink_bind() on ifobj_tx RX queue 0 with an
unpopulated FILL ring, and when clean_sockets() closes that TX-only
socket, xsk_sink_release() defers unbinding to xp_release_deferred()
because sink->xs is NULL, which races with xsk_reattach_xdp() in later
tests and fails with -EBUSY.

In addition, at startup main() calls ifobj_zc_avail() ->
xsk_configure_umem() while rx_on is still false and frame_size is
hardcoded to 4096, so on kernels with PAGE_SIZE != 4096 xdp_umem_reg()
returns -EINVAL and ifobj_zc_avail() aborts the binary via
exit_with_error() before drv_layout_umem_ok() can skip the tests.

> @@ -161,7 +168,8 @@ int xsk_configure_socket(struct xsk_socket_info *xsk, struct xsk_umem_info *umem
>  	cfg.bind_flags = ifobject->bind_flags;
>  	if (shared)
>  		cfg.bind_flags |= XDP_SHARED_UMEM;
> -	if (ifobject->mtu > MAX_ETH_PKT_SIZE)
> +	/* The device may split any frame, see XDP_UMEM_DRV_LAYOUT */
> +	if (ifobject->mtu > MAX_ETH_PKT_SIZE || opt_drv_layout)
>  		cfg.bind_flags |= XDP_USE_SG;
>  	if (umem->comp_size)
>  		cfg.tx_size = umem->comp_size;

[Severity: Low]
Can testapp_hw_sw_min_ring_size() livelock in __receive_pkts() when a
device splits a frame across two or more RX descriptors in
opt_drv_layout mode?

testapp_hw_sw_min_ring_size() sets test->ifobj_rx->xsk->batch_size to 1.
When a received frame is split across multiple RX descriptors (for
example, header-data split), xsk_ring_cons__peek(&xsk->rx,
xsk->batch_size, &idx_rx) in __receive_pkts() peeks only the first
descriptor (with XDP_PKT_CONTD set), and the if (nb_frags) rollback
block cancels that descriptor on every call until receive_pkts() times
out.

[ ... ]

> @@ -878,6 +887,77 @@ static bool is_frag_valid(struct xsk_umem_info *umem, u64 addr, u32 len, u32 exp
>  	return false;
>  }
>  
> +/* Driver layout: a buffer may start and end anywhere in the packet, and
> + * anywhere in its chunk. Check its bytes against the generated pattern by
> + * packet offset. XDP_ADJUST_TAIL_GROW zeroes the last @grow bytes and
> + * writes the sequence number of the last word, so that word only needs the
> + * right sequence number, and the bytes before it may be zero.
> + */
> +static bool is_frag_valid_drv(struct xsk_umem_info *umem, u64 addr, u32 len,
> +			      u32 expected_pkt_nb, u32 bytes_processed,
> +			      u32 pkt_len, u32 grow)
> +{
> +	u32 payload_end = PKT_HDR_SIZE + ((pkt_len - PKT_HDR_SIZE) & ~3U);
> +	u8 *bytes = xsk_umem__get_data(umem->buffer, addr);
> +	u64 umem_sz = umem_size(umem);
> +	u32 i, off, word;
> +
> +	addr -= umem->base_addr;
> +	if (addr >= umem_sz || addr + len > umem_sz ||
> +	    addr % umem->frame_size + len > umem->frame_size) {
> +		ksft_print_msg("Frag invalid addr: %llx len: %u\n",
> +			       (unsigned long long)addr, len);
> +		return false;
> +	}
> +
> +	for (i = 0; i < len; i++) {
> +		off = bytes_processed + i;
> +		if (off < PKT_HDR_SIZE || off >= payload_end)
> +			continue;
> +		if (off >= pkt_len - grow && !bytes[i])
> +			continue;
> +
> +		off -= PKT_HDR_SIZE;
> +		word = htonl(expected_pkt_nb << 16 | (off / 4));
> +		if (off / 4 == (payload_end - PKT_HDR_SIZE) / 4 - 1 &&
> +		    off % 4 < 2)
> +			continue;

[Severity: Medium]
Does the zero-byte exemption in is_frag_valid_drv() also skip checking
the sequence number in the last 4-byte word when those bytes are zero?

Because the final word at [payload_end - 4, payload_end) also satisfies
off >= pkt_len - grow when grow >= 4, an all-zero final word where
xsk_xdp_adjust_tail() never wrote seq_num (or wrote zero bytes in the
wrong positions) satisfies !bytes[i] and passes validation.  Also, the
off % 4 < 2 check on the last word is not gated on grow > 0, so the
upper 16 bits (expected_pkt_nb) of the last payload word are never
checked when grow == 0.

[ ... ]

> @@ -1050,46 +1151,74 @@ static int __receive_pkts(struct test_spec *test, struct xsk_socket_info *xsk)
[ ... ]
>  	if (nb_frags) {
>  		/* In the middle of a packet. Start over from beginning of packet. */
>  		idx_rx -= nb_frags;
>  		xsk_ring_cons__cancel(&xsk->rx, nb_frags);
> -		if (ifobj->use_fill_ring) {
> +		if (ifobj->use_fill_ring && !opt_drv_layout) {
>  			idx_fq -= nb_frags;
>  			xsk_ring_prod__cancel(&umem->fq, nb_frags);
>  		}
>  		frags_processed -= nb_frags;
> +		fills -= pkt_fills;
>  		pkt_stream_cancel(pkt_stream);
>  		pkts_sent--;
>  	}
>  
> -	if (ifobj->use_fill_ring)
> +	if (ifobj->use_fill_ring && opt_drv_layout) {
> +		xsk_ring_prod__cancel(&umem->fq, rcvd - fills);
> +		xsk_ring_prod__submit(&umem->fq, fills);
> +	} else if (ifobj->use_fill_ring) {
>  		xsk_ring_prod__submit(&umem->fq, frags_processed);
> +	}

[Severity: Medium]
Can __receive_pkts() spin forever reserving rcvd slots in umem->fq when
multiple RX descriptors share UMEM chunks?

Before this loop, __receive_pkts() reserves rcvd entries in umem->fq:

tools/testing/selftests/net/lib/xsk/test_xsk.c:__receive_pkts() {
	if (ifobj->use_fill_ring) {
		ret = xsk_ring_prod__reserve(&umem->fq, rcvd, &idx_fq);
		while (ret != rcvd) {
			if (xsk_ring_prod__needs_wakeup(&umem->fq)) {
				ret = poll(&fds, 1, POLL_TMOUT);
				if (ret < 0)
					return TEST_FAILURE;
			}
			ret = xsk_ring_prod__reserve(&umem->fq, rcvd, &idx_fq);
		}
	}
}

In testapp_hw_sw_max_ring_size(), umem->num_frames and umem->fill_size
are both set to max_descs (8192), so xsk_populate_fill_ring() fills all
8192 slots of umem->fq before bind().  When the device packs multiple
buffers into each page-sized chunk, C chunks consumed from umem->fq can
produce rcvd > C RX descriptors while leaving only C free slots in
umem->fq, so xsk_ring_prod__reserve(&umem->fq, rcvd, &idx_fq) returns 0
and the while (ret != rcvd) loop spins forever.

[ ... ]

> @@ -1600,6 +1742,21 @@ static int thread_common_ops(struct test_spec *test, struct ifobject *ifobject)
>  	if (ret)
>  		return ret;
>  
> +	/* In the device's buffer layout, the queue takes its first buffers
> +	 * from FILL when bind starts it: fill FILL first, or the first
> +	 * packets find no buffer. A test without the fill ring wants FILL
> +	 * to run dry, so it fills after bind as before.
> +	 */
> +	fill_first = opt_drv_layout && test->mode == TEST_MODE_DRV &&
> +		     ifobject->rx_on && ifobject->use_fill_ring;
> +	if (fill_first) {
> +		ret = xsk_populate_fill_ring(umem,
> +					     ifobject->xsk_arr[0].pkt_stream,
> +					     ifobject->use_fill_ring);
> +		if (ret)
> +			return ret;
> +	}
> +
>  	ret = xsk_configure(test, ifobject, umem, false);

[Severity: Medium]
Does testapp_stats_fill_empty() work in drv_layout(test) mode, or should
it be skipped like testapp_stats_rx_full()?

In testapp_stats_fill_empty(), use_fill_ring is false, so fill_first is
false and xsk_configure() starts the RX queue via netif_mp_open_rxq()
while the FILL ring is empty.  On drivers such as bnxt that allocate RX
ring buffers during netif_mp_open_rxq() and only allocate replacement
buffers on RX packet completions, starting the queue with an empty FILL
ring leaves 0 buffers posted to hardware and receive_pkts() hangs until
timeout.

Even if the 1024 initial chunks were populated before bind, 1024 page
chunks in XDP_UMEM_DRV_LAYOUT mode do not map 1:1 to 1024 received
packets without FILL recycling: chunks are held in secondary rings and
the RX ring itself, while devices that pack multiple 64-byte packets per
4 KiB chunk can receive more than the expected 1024 packets in a batch
and fail in __receive_pkts().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124112707.118678-1-bjorn@kernel.org?part=14

  reply	other threads:[~2026-11-25 13:00 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 11:26 [PATCH net-next 00/15] xsk: Receive in the device's buffer layout Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 01/15] xdp: Let memory providers offer XDP a view of their net_iovs Björn Töpel
2026-11-25 13:00   ` sashiko-bot
2026-11-24 12:56 ` [PATCH net-next 02/15] xdp: Keep the shared info of a buffer in kernel memory Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 03/15] net: Add memory providers that only feed XDP Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 04/15] page_pool: Let memory providers take back net_iovs Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 05/15] xdp: Run programs on buffers that must not hold kernel structures Björn Töpel
2026-11-25 13:00   ` sashiko-bot
2026-11-24 12:56 ` [PATCH net-next 06/15] xsk: Lend UMEM chunks to the page pools of a queue Björn Töpel
2026-11-24 14:34   ` Magnus Karlsson
2026-11-24 15:12     ` Björn Töpel
2026-11-25 13:00   ` sashiko-bot
2026-11-24 12:56 ` [PATCH net-next 07/15] xsk: Deliver to the socket in the device's buffer layout Björn Töpel
2026-11-25 13:00   ` sashiko-bot
2026-11-24 12:56 ` [PATCH net-next 08/15] xsk: Receive " Björn Töpel
2026-11-25 13:00   ` sashiko-bot
2026-11-24 12:56 ` [PATCH net-next 09/15] eth: fbnic: Support XDP redirect Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 10/15] eth: fbnic: Receive into XDP-only memory providers Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 11/15] net: Add netif_rxq_has_xdp_only_mp() Björn Töpel
2026-11-24 12:56 ` [PATCH net-next 12/15] eth: mlx5e: Receive into XDP-only memory providers Björn Töpel
2026-11-25 13:00   ` sashiko-bot
2026-11-24 12:56 ` [PATCH net-next 13/15] eth: bnxt: " Björn Töpel
2026-11-25 13:00   ` sashiko-bot
2026-11-24 12:56 ` [PATCH net-next 14/15] selftests: net: xsk: Test the device's RX buffer layout Björn Töpel
2026-11-25 13:00   ` sashiko-bot [this message]
2026-11-24 12:56 ` [PATCH net-next 15/15] Documentation: networking: Describe AF_XDP RX in the device's layout Björn Töpel
2026-11-25 13:00 ` [PATCH net-next 00/15] xsk: Receive in the device's buffer layout sashiko-bot

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=sashiko-outbox-233424@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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