Subject: Re: [PATCH v6 net 3/8] xsk: fix XDP_UMEM_SG_FLAG issues

From: Maciej Fijalkowski <[email-masked]>
Date: Sat, 4 Apr 2026 12:11:01 +0200

On Fri, Apr 03, 2026 at 04:56:36PM -0700, Jakub Kicinski wrote:
> On Thu,  2 Apr 2026 17:49:53 +0200 Maciej Fijalkowski wrote:
> > Currently xp_assign_dev_shared() is missing XDP_USE_SG being propagated
> > to flags so set it in order to preserve mtu check that is supposed to be
> > done only when no multi-buffer setup is in picture.
> > 
> > Also, this flag has the same value as XDP_UMEM_TX_SW_CSUM so we could
> > get unexpected SG setups for software Tx checksums. Since csum flag is
> > UAPI, modify value of XDP_UMEM_SG_FLAG.
> 
> should we maybe add:
> 
> BUILD_BUG_ON(XDP_UMEM_SG_FLAG & XDP_UMEM_FLAGS_VALID)
> 
> somewhere or use a hack like this ?
> 
> #define XDP_UMEM_SG_FLAG	(XDP_UMEM_FLAGS_VALID + 1)

Good idea i'd lean towards the latter version. I can send v7 after easter
or if there wouldn't be other issues related to set maybe maintainer could
adjust it? ;)

> 
> > diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h
> > index 23e8861e8b25..ebac60a3d8a1 100644
> > --- a/include/net/xdp_sock.h
> > +++ b/include/net/xdp_sock.h
> > @@ -14,7 +14,7 @@
> >  #include <linux/mm.h>
> >  #include <net/sock.h>
> >  
> > -#define XDP_UMEM_SG_FLAG (1 << 1)
> > +#define XDP_UMEM_SG_FLAG BIT(3)
> >  
> >  struct net_device;
> >  struct xsk_queue;
> > diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
> > index 37b7a68b89b3..729602a3cec0 100644
> > --- a/net/xdp/xsk_buff_pool.c
> > +++ b/net/xdp/xsk_buff_pool.c
> > @@ -247,6 +247,10 @@ int xp_assign_dev_shared(struct xsk_buff_pool *pool, struct xdp_sock *umem_xs,
> >  	struct xdp_umem *umem = umem_xs->umem;
> >  
> >  	flags = umem->zc ? XDP_ZEROCOPY : XDP_COPY;
> > +
> > +	if (umem->flags & XDP_UMEM_SG_FLAG)
> > +		flags |= XDP_USE_SG;
> > +
> >  	if (umem_xs->pool->uses_need_wakeup)
> >  		flags |= XDP_USE_NEED_WAKEUP;
> >  
>