* [PATCH net] xsk: parse Tx batches in packet units for all shared-UMEM pools
@ 2026-11-24 13:48 Magnus Karlsson
2026-11-24 15:03 ` Maciej Fijalkowski
0 siblings, 1 reply; 2+ messages in thread
From: Magnus Karlsson @ 2026-11-24 13:48 UTC (permalink / raw)
To: netdev, magnus.karlsson, magnus.karlsson, maciej.fijalkowski, sdf,
davem, edumazet, kuba, pabeni, horms, bjorn, kerneljasonxing
Zero-copy drivers that use xsk_tx_peek_release_desc_batch() are meant to
receive only complete packets of at most xdp_zc_max_segs descriptors.
Single-socket pools and shared-UMEM pools with XDP_UMEM_SG_FLAG get this
from xskq_cons_read_desc_batch(), which also drains invalid and
oversized packets. Shared-UMEM pools without XDP_UMEM_SG_FLAG still use
xsk_tx_peek_release_fallback(), which peeks one descriptor at a time,
on the assumption that such pools never carry multi-buffer packets.
That assumption does not hold. Descriptor validation accepts
XDP_PKT_CONTD whether or not the UMEM has XDP_UMEM_SG_FLAG, so
descriptors from such a pool can form multi-buffer packets, as they
already do on a single-socket pool. The fallback then hands the driver
a batch that can end in the middle of a packet, packets longer than
xdp_zc_max_segs, and, as xsk_tx_peek_desc() moves on to another socket
when the per-socket budget runs out, descriptors of another socket in
the middle of a packet. On ice, a packet with more than eight data
descriptors triggers a malicious driver detection event.
Use xsk_tx_peek_release_shared_desc_batch() for all shared-UMEM pools,
so that they are parsed like a single non-SG socket, and remove the now
unused fallback.
Implemented a test for this in xskxceiver that opens two sockets in
shared_umem mode and from one socket sends a packet with too many
fragments in between two single-fragment packets. Without this patch,
the NIC resets, but with it the two single-fragment packets are
received and the test passes.
Fixes: d5581966040f ("xsk: support ZC Tx multi-buffer in batch API")
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
---
net/xdp/xsk.c | 17 -----------------
1 file changed, 17 deletions(-)
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index ab2e4fa87a4f..7d0701e0e025 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -604,18 +604,6 @@ bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc)
}
EXPORT_SYMBOL(xsk_tx_peek_desc);
-static u32 xsk_tx_peek_release_fallback(struct xsk_buff_pool *pool, u32 max_entries)
-{
- struct xdp_desc *descs = pool->tx_descs;
- u32 nb_pkts = 0;
-
- while (nb_pkts < max_entries && xsk_tx_peek_desc(pool, &descs[nb_pkts]))
- nb_pkts++;
-
- xsk_tx_release(pool);
- return nb_pkts;
-}
-
static void xsk_tx_commit_batch(struct xsk_buff_pool *pool,
struct xsk_tx_batch *batch)
{
@@ -763,11 +751,6 @@ u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, u32 nb_pkts)
umem_shared = !list_is_singular(&pool->xsk_tx_list);
- if (umem_shared && !(pool->umem->flags & XDP_UMEM_SG_FLAG)) {
- rcu_read_unlock();
- return xsk_tx_peek_release_fallback(pool, nb_pkts);
- }
-
/* This is the backpressure mechanism for the Tx path. Try to
* reserve space in the completion queue for all packets, but
* if there are fewer slots available, just process that many
--
2.38.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net] xsk: parse Tx batches in packet units for all shared-UMEM pools
2026-11-24 13:48 [PATCH net] xsk: parse Tx batches in packet units for all shared-UMEM pools Magnus Karlsson
@ 2026-11-24 15:03 ` Maciej Fijalkowski
0 siblings, 0 replies; 2+ messages in thread
From: Maciej Fijalkowski @ 2026-11-24 15:03 UTC (permalink / raw)
To: Magnus Karlsson
Cc: netdev, magnus.karlsson, sdf, davem, edumazet, kuba, pabeni,
horms, bjorn, kerneljasonxing
On Tue, Nov 24, 2026 at 02:48:08PM +0100, Magnus Karlsson wrote:
> Zero-copy drivers that use xsk_tx_peek_release_desc_batch() are meant to
> receive only complete packets of at most xdp_zc_max_segs descriptors.
> Single-socket pools and shared-UMEM pools with XDP_UMEM_SG_FLAG get this
> from xskq_cons_read_desc_batch(), which also drains invalid and
> oversized packets. Shared-UMEM pools without XDP_UMEM_SG_FLAG still use
> xsk_tx_peek_release_fallback(), which peeks one descriptor at a time,
> on the assumption that such pools never carry multi-buffer packets.
>
> That assumption does not hold. Descriptor validation accepts
> XDP_PKT_CONTD whether or not the UMEM has XDP_UMEM_SG_FLAG, so
> descriptors from such a pool can form multi-buffer packets, as they
> already do on a single-socket pool. The fallback then hands the driver
> a batch that can end in the middle of a packet, packets longer than
> xdp_zc_max_segs, and, as xsk_tx_peek_desc() moves on to another socket
> when the per-socket budget runs out, descriptors of another socket in
> the middle of a packet. On ice, a packet with more than eight data
> descriptors triggers a malicious driver detection event.
>
> Use xsk_tx_peek_release_shared_desc_batch() for all shared-UMEM pools,
> so that they are parsed like a single non-SG socket, and remove the now
> unused fallback.
Should have done it from day 1 - thanks!
>
> Implemented a test for this in xskxceiver that opens two sockets in
> shared_umem mode and from one socket sends a packet with too many
> fragments in between two single-fragment packets. Without this patch,
> the NIC resets, but with it the two single-fragment packets are
> received and the test passes.
I don't see it anywhere so this reads a bit weird. I would appreciate the
follow-up with this new test case.
Acked-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
>
> Fixes: d5581966040f ("xsk: support ZC Tx multi-buffer in batch API")
> Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
> ---
> net/xdp/xsk.c | 17 -----------------
> 1 file changed, 17 deletions(-)
>
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index ab2e4fa87a4f..7d0701e0e025 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
> @@ -604,18 +604,6 @@ bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc)
> }
> EXPORT_SYMBOL(xsk_tx_peek_desc);
>
> -static u32 xsk_tx_peek_release_fallback(struct xsk_buff_pool *pool, u32 max_entries)
> -{
> - struct xdp_desc *descs = pool->tx_descs;
> - u32 nb_pkts = 0;
> -
> - while (nb_pkts < max_entries && xsk_tx_peek_desc(pool, &descs[nb_pkts]))
> - nb_pkts++;
> -
> - xsk_tx_release(pool);
> - return nb_pkts;
> -}
> -
> static void xsk_tx_commit_batch(struct xsk_buff_pool *pool,
> struct xsk_tx_batch *batch)
> {
> @@ -763,11 +751,6 @@ u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, u32 nb_pkts)
>
> umem_shared = !list_is_singular(&pool->xsk_tx_list);
>
> - if (umem_shared && !(pool->umem->flags & XDP_UMEM_SG_FLAG)) {
> - rcu_read_unlock();
> - return xsk_tx_peek_release_fallback(pool, nb_pkts);
> - }
> -
> /* This is the backpressure mechanism for the Tx path. Try to
> * reserve space in the completion queue for all packets, but
> * if there are fewer slots available, just process that many
> --
> 2.38.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-24 15:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 13:48 [PATCH net] xsk: parse Tx batches in packet units for all shared-UMEM pools Magnus Karlsson
2026-11-24 15:03 ` Maciej Fijalkowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox