🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
4 messages
4 total messages Started by Magnus Karlsson Tue, 24 Nov 2026 13:48
[PATCH net] xsk: parse Tx batches in packet units for all shared-UMEM pools
#21805
Author: Magnus Karlsson
Date: Tue, 24 Nov 2026 13:48
72 lines
11542 bytes
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
Re: [PATCH net] xsk: parse Tx batches in packet units for all shared-UMEM pools
#21884
Author: Maciej Fijalkowski
Date: Tue, 24 Nov 2026 15:03
83 lines
23431 bytes
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
> 
Re: [PATCH net] xsk: parse Tx batches in packet units for all shared-UMEM pools
#21909
Author: Magnus Karlsson
Date: Tue, 24 Nov 2026 15:33
89 lines
15291 bytes
On Tue, 24 Nov 2026 at 16:05, Maciej Fijalkowski
<maciej.fijalkowski@intel.com> wrote:
>
> 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.

Should have said explicitly that it is not included here as it has to
go to net-next. I will contribute it as soon as your stuff is in.

> 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
> >
Re: [PATCH net] xsk: parse Tx batches in packet units for all shared-UMEM pools
#25614
Author: patchwork-bot+netdevbpf
Date: Wed, 02 Dec 2026 04:20
25 lines
8893 bytes
Hello:

This patch was applied to netdev/net.git (main)
by Willem de Bruijn <willemb@google.com>:

On Tue, 24 Nov 2026 14:48:08 +0100 you 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.
> 
> [...]

Here is the summary with links:
  - [net] xsk: parse Tx batches in packet units for all shared-UMEM pools
    https://git.kernel.org/netdev/net/c/0d546d385c30

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads