* [PATCH v6 net 1/8] xsk: tighten UMEM headroom validation to account for tailroom and min frame
2026-04-02 15:49 [PATCH v6 net 0/8] xsk: tailroom reservation and MTU validation Maciej Fijalkowski
@ 2026-04-02 15:49 ` Maciej Fijalkowski
2026-04-04 0:01 ` Jakub Kicinski
2026-04-02 15:49 ` [PATCH v6 net 2/8] xsk: respect tailroom for ZC setups Maciej Fijalkowski
` (7 subsequent siblings)
8 siblings, 1 reply; 18+ messages in thread
From: Maciej Fijalkowski @ 2026-04-02 15:49 UTC (permalink / raw)
To: netdev
Cc: bpf, magnus.karlsson, stfomichev, kuba, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn, Maciej Fijalkowski,
Stanislav Fomichev
The current headroom validation in xdp_umem_reg() could leave us with
insufficient space dedicated to even receive minimum-sized ethernet
frame. Furthermore if multi-buffer would come to play then
skb_shared_info stored at the end of XSK frame would be corrupted.
HW typically works with 128-aligned sizes so let us provide this value
as bare minimum.
Multi-buffer setting is known later in the configuration process so
besides accounting for 128 bytes, let us also take care of tailroom space
upfront.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Fixes: 99e3a236dd43 ("xsk: Add missing check on user supplied headroom size")
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
net/xdp/xdp_umem.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c
index 066ce07c506d..58da2f4f4397 100644
--- a/net/xdp/xdp_umem.c
+++ b/net/xdp/xdp_umem.c
@@ -203,7 +203,8 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
if (!unaligned_chunks && chunks_rem)
return -EINVAL;
- if (headroom >= chunk_size - XDP_PACKET_HEADROOM)
+ if (headroom > chunk_size - XDP_PACKET_HEADROOM -
+ SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) - 128)
return -EINVAL;
if (mr->flags & XDP_UMEM_TX_METADATA_LEN) {
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v6 net 1/8] xsk: tighten UMEM headroom validation to account for tailroom and min frame
2026-04-02 15:49 ` [PATCH v6 net 1/8] xsk: tighten UMEM headroom validation to account for tailroom and min frame Maciej Fijalkowski
@ 2026-04-04 0:01 ` Jakub Kicinski
2026-04-04 10:07 ` Maciej Fijalkowski
0 siblings, 1 reply; 18+ messages in thread
From: Jakub Kicinski @ 2026-04-04 0:01 UTC (permalink / raw)
To: Maciej Fijalkowski
Cc: netdev, bpf, magnus.karlsson, stfomichev, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn, Stanislav Fomichev
On Thu, 2 Apr 2026 17:49:51 +0200 Maciej Fijalkowski wrote:
> The current headroom validation in xdp_umem_reg() could leave us with
> insufficient space dedicated to even receive minimum-sized ethernet
> frame. Furthermore if multi-buffer would come to play then
> skb_shared_info stored at the end of XSK frame would be corrupted.
>
> HW typically works with 128-aligned sizes so let us provide this value
> as bare minimum.
>
> Multi-buffer setting is known later in the configuration process so
> besides accounting for 128 bytes, let us also take care of tailroom space
> upfront.
I guess it's a bit late to ask this, but am I the only one that has
weird feelings about shinfo living in user-mapped memory?
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v6 net 1/8] xsk: tighten UMEM headroom validation to account for tailroom and min frame
2026-04-04 0:01 ` Jakub Kicinski
@ 2026-04-04 10:07 ` Maciej Fijalkowski
0 siblings, 0 replies; 18+ messages in thread
From: Maciej Fijalkowski @ 2026-04-04 10:07 UTC (permalink / raw)
To: Jakub Kicinski
Cc: netdev, bpf, magnus.karlsson, stfomichev, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn, Stanislav Fomichev
On Fri, Apr 03, 2026 at 05:01:26PM -0700, Jakub Kicinski wrote:
> On Thu, 2 Apr 2026 17:49:51 +0200 Maciej Fijalkowski wrote:
> > The current headroom validation in xdp_umem_reg() could leave us with
> > insufficient space dedicated to even receive minimum-sized ethernet
> > frame. Furthermore if multi-buffer would come to play then
> > skb_shared_info stored at the end of XSK frame would be corrupted.
> >
> > HW typically works with 128-aligned sizes so let us provide this value
> > as bare minimum.
> >
> > Multi-buffer setting is known later in the configuration process so
> > besides accounting for 128 bytes, let us also take care of tailroom space
> > upfront.
>
> I guess it's a bit late to ask this, but am I the only one that has
> weird feelings about shinfo living in user-mapped memory?
This was the approach was picked to be consistent with XDP side and allow
to use mbuf related helpers. I can imagine you would be suggesting to pick
up pages from system page pool but that would be a major refactor (however
I have not put much not thought into it - i'm here without a coffee and in
easter mode).
Outside of this rewrite this set fixes existing memory corruption, so I
feel it is needed and we can think how should we address the concern you
are bringing up later?
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v6 net 2/8] xsk: respect tailroom for ZC setups
2026-04-02 15:49 [PATCH v6 net 0/8] xsk: tailroom reservation and MTU validation Maciej Fijalkowski
2026-04-02 15:49 ` [PATCH v6 net 1/8] xsk: tighten UMEM headroom validation to account for tailroom and min frame Maciej Fijalkowski
@ 2026-04-02 15:49 ` Maciej Fijalkowski
2026-04-02 15:49 ` [PATCH v6 net 3/8] xsk: fix XDP_UMEM_SG_FLAG issues Maciej Fijalkowski
` (6 subsequent siblings)
8 siblings, 0 replies; 18+ messages in thread
From: Maciej Fijalkowski @ 2026-04-02 15:49 UTC (permalink / raw)
To: netdev
Cc: bpf, magnus.karlsson, stfomichev, kuba, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn, Maciej Fijalkowski,
Stanislav Fomichev
Multi-buffer XDP stores information about frags in skb_shared_info that
sits at the tailroom of a packet. The storage space is reserved via
xdp_data_hard_end():
((xdp)->data_hard_start + (xdp)->frame_sz - \
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
and then we refer to it via macro below:
static inline struct skb_shared_info *
xdp_get_shared_info_from_buff(const struct xdp_buff *xdp)
{
return (struct skb_shared_info *)xdp_data_hard_end(xdp);
}
Currently we do not respect this tailroom space in multi-buffer AF_XDP
ZC scenario. To address this, introduce xsk_pool_get_tailroom() and use
it within xsk_pool_get_rx_frame_size() which is used in ZC drivers to
configure length of HW Rx buffer.
Typically drivers on Rx Hw buffers side work on 128 byte alignment so
let us align the value returned by xsk_pool_get_rx_frame_size() in order
to avoid addressing this on driver's side. This addresses the fact that
idpf uses mentioned function *before* pool->dev being set so we were at
risk that after subtracting tailroom we would not provide 128-byte
aligned value to HW.
Since xsk_pool_get_rx_frame_size() is actively used in xsk_rcv_check()
and __xsk_rcv(), add a variant of this routine that will not include 128
byte alignment and therefore old behavior is preserved.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Fixes: 24ea50127ecf ("xsk: support mbuf on ZC RX")
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
include/net/xdp_sock_drv.h | 23 ++++++++++++++++++++++-
net/xdp/xsk.c | 4 ++--
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h
index 6b9ebae2dc95..46797645a0c2 100644
--- a/include/net/xdp_sock_drv.h
+++ b/include/net/xdp_sock_drv.h
@@ -41,16 +41,37 @@ static inline u32 xsk_pool_get_headroom(struct xsk_buff_pool *pool)
return XDP_PACKET_HEADROOM + pool->headroom;
}
+static inline u32 xsk_pool_get_tailroom(bool mbuf)
+{
+ return mbuf ? SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) : 0;
+}
+
static inline u32 xsk_pool_get_chunk_size(struct xsk_buff_pool *pool)
{
return pool->chunk_size;
}
-static inline u32 xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool)
+static inline u32 __xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool)
{
return xsk_pool_get_chunk_size(pool) - xsk_pool_get_headroom(pool);
}
+static inline u32 xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool)
+{
+ u32 frame_size = __xsk_pool_get_rx_frame_size(pool);
+ struct xdp_umem *umem = pool->umem;
+ bool mbuf;
+
+ /* Reserve tailroom only for zero-copy pools that opted into
+ * multi-buffer. The reserved area is used for skb_shared_info,
+ * matching the XDP core's xdp_data_hard_end() layout.
+ */
+ mbuf = pool->dev && (umem->flags & XDP_UMEM_SG_FLAG);
+ frame_size -= xsk_pool_get_tailroom(mbuf);
+
+ return ALIGN_DOWN(frame_size, 128);
+}
+
static inline u32 xsk_pool_get_rx_frag_step(struct xsk_buff_pool *pool)
{
return pool->unaligned ? 0 : xsk_pool_get_chunk_size(pool);
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index c078c9e4b243..000cbfb66d5b 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -250,7 +250,7 @@ static u32 xsk_copy_xdp(void *to, void **from, u32 to_len,
static int __xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
{
- u32 frame_size = xsk_pool_get_rx_frame_size(xs->pool);
+ u32 frame_size = __xsk_pool_get_rx_frame_size(xs->pool);
void *copy_from = xsk_copy_xdp_start(xdp), *copy_to;
u32 from_len, meta_len, rem, num_desc;
struct xdp_buff_xsk *xskb;
@@ -350,7 +350,7 @@ static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
if (xs->dev != xdp->rxq->dev || xs->queue_id != xdp->rxq->queue_index)
return -EINVAL;
- if (len > xsk_pool_get_rx_frame_size(xs->pool) && !xs->sg) {
+ if (len > __xsk_pool_get_rx_frame_size(xs->pool) && !xs->sg) {
xs->rx_dropped++;
return -ENOSPC;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v6 net 3/8] xsk: fix XDP_UMEM_SG_FLAG issues
2026-04-02 15:49 [PATCH v6 net 0/8] xsk: tailroom reservation and MTU validation Maciej Fijalkowski
2026-04-02 15:49 ` [PATCH v6 net 1/8] xsk: tighten UMEM headroom validation to account for tailroom and min frame Maciej Fijalkowski
2026-04-02 15:49 ` [PATCH v6 net 2/8] xsk: respect tailroom for ZC setups Maciej Fijalkowski
@ 2026-04-02 15:49 ` Maciej Fijalkowski
2026-04-03 23:56 ` Jakub Kicinski
2026-04-02 15:49 ` [PATCH v6 net 4/8] xsk: validate MTU against usable frame size on bind Maciej Fijalkowski
` (5 subsequent siblings)
8 siblings, 1 reply; 18+ messages in thread
From: Maciej Fijalkowski @ 2026-04-02 15:49 UTC (permalink / raw)
To: netdev
Cc: bpf, magnus.karlsson, stfomichev, kuba, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn, Maciej Fijalkowski
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.
Fixes: d609f3d228a8 ("xsk: add multi-buffer support for sockets sharing umem")
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
include/net/xdp_sock.h | 2 +-
net/xdp/xsk_buff_pool.c | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
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;
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v6 net 3/8] xsk: fix XDP_UMEM_SG_FLAG issues
2026-04-02 15:49 ` [PATCH v6 net 3/8] xsk: fix XDP_UMEM_SG_FLAG issues Maciej Fijalkowski
@ 2026-04-03 23:56 ` Jakub Kicinski
2026-04-04 10:11 ` Maciej Fijalkowski
0 siblings, 1 reply; 18+ messages in thread
From: Jakub Kicinski @ 2026-04-03 23:56 UTC (permalink / raw)
To: Maciej Fijalkowski
Cc: netdev, bpf, magnus.karlsson, stfomichev, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn
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)
> 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;
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v6 net 3/8] xsk: fix XDP_UMEM_SG_FLAG issues
2026-04-03 23:56 ` Jakub Kicinski
@ 2026-04-04 10:11 ` Maciej Fijalkowski
2026-04-07 1:45 ` Jakub Kicinski
0 siblings, 1 reply; 18+ messages in thread
From: Maciej Fijalkowski @ 2026-04-04 10:11 UTC (permalink / raw)
To: Jakub Kicinski
Cc: netdev, bpf, magnus.karlsson, stfomichev, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn
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;
> >
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v6 net 3/8] xsk: fix XDP_UMEM_SG_FLAG issues
2026-04-04 10:11 ` Maciej Fijalkowski
@ 2026-04-07 1:45 ` Jakub Kicinski
0 siblings, 0 replies; 18+ messages in thread
From: Jakub Kicinski @ 2026-04-07 1:45 UTC (permalink / raw)
To: Maciej Fijalkowski
Cc: netdev, bpf, magnus.karlsson, stfomichev, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn
On Sat, 4 Apr 2026 12:11:01 +0200 Maciej Fijalkowski wrote:
> > 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? ;)
Quick edit breaks the build, probably missing an include.
Let's leave it for a follow up 'cause I'm gonna break something :S
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v6 net 4/8] xsk: validate MTU against usable frame size on bind
2026-04-02 15:49 [PATCH v6 net 0/8] xsk: tailroom reservation and MTU validation Maciej Fijalkowski
` (2 preceding siblings ...)
2026-04-02 15:49 ` [PATCH v6 net 3/8] xsk: fix XDP_UMEM_SG_FLAG issues Maciej Fijalkowski
@ 2026-04-02 15:49 ` Maciej Fijalkowski
2026-04-04 0:03 ` Jakub Kicinski
2026-04-02 15:49 ` [PATCH v6 net 5/8] selftests: bpf: introduce a common routine for reading procfs Maciej Fijalkowski
` (4 subsequent siblings)
8 siblings, 1 reply; 18+ messages in thread
From: Maciej Fijalkowski @ 2026-04-02 15:49 UTC (permalink / raw)
To: netdev
Cc: bpf, magnus.karlsson, stfomichev, kuba, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn, Maciej Fijalkowski
AF_XDP bind currently accepts zero-copy pool configurations without
verifying that the device MTU fits into the usable frame space provided
by the UMEM chunk.
This becomes a problem since we started to respect tailroom which is
subtracted from chunk_size (among with headroom). 2k chunk size might
not provide enough space for standard 1500 MTU, so let us catch such
settings at bind time. Furthermore, validate whether underlying HW will
be able to satisfy configured MTU wrt XSK's frame size multiplied by
supported Rx buffer chain length (that is exposed via
net_device::xdp_zc_max_segs).
Fixes: 24ea50127ecf ("xsk: support mbuf on ZC RX")
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
net/xdp/xsk_buff_pool.c | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
index 729602a3cec0..cd7bc50872f6 100644
--- a/net/xdp/xsk_buff_pool.c
+++ b/net/xdp/xsk_buff_pool.c
@@ -10,6 +10,8 @@
#include "xdp_umem.h"
#include "xsk.h"
+#define ETH_PAD_LEN (ETH_HLEN + 2 * VLAN_HLEN + ETH_FCS_LEN)
+
void xp_add_xsk(struct xsk_buff_pool *pool, struct xdp_sock *xs)
{
if (!xs->tx)
@@ -157,8 +159,12 @@ static void xp_disable_drv_zc(struct xsk_buff_pool *pool)
int xp_assign_dev(struct xsk_buff_pool *pool,
struct net_device *netdev, u16 queue_id, u16 flags)
{
+ u32 needed = netdev->mtu + ETH_PAD_LEN;
+ u32 segs = netdev->xdp_zc_max_segs;
+ bool mbuf = flags & XDP_USE_SG;
bool force_zc, force_copy;
struct netdev_bpf bpf;
+ u32 frame_size;
int err = 0;
ASSERT_RTNL();
@@ -178,7 +184,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool,
if (err)
return err;
- if (flags & XDP_USE_SG)
+ if (mbuf)
pool->umem->flags |= XDP_UMEM_SG_FLAG;
if (flags & XDP_USE_NEED_WAKEUP)
@@ -200,8 +206,24 @@ int xp_assign_dev(struct xsk_buff_pool *pool,
goto err_unreg_pool;
}
- if (netdev->xdp_zc_max_segs == 1 && (flags & XDP_USE_SG)) {
- err = -EOPNOTSUPP;
+ if (mbuf) {
+ if (segs == 1) {
+ err = -EOPNOTSUPP;
+ goto err_unreg_pool;
+ }
+ } else {
+ segs = 1;
+ }
+
+ /* open-code xsk_pool_get_rx_frame_size() as pool->dev is not
+ * set yet at this point; we are before getting down to driver
+ */
+ frame_size = __xsk_pool_get_rx_frame_size(pool) -
+ xsk_pool_get_tailroom(mbuf);
+ frame_size = ALIGN_DOWN(frame_size, 128);
+
+ if (needed > frame_size * segs) {
+ err = -EINVAL;
goto err_unreg_pool;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v6 net 4/8] xsk: validate MTU against usable frame size on bind
2026-04-02 15:49 ` [PATCH v6 net 4/8] xsk: validate MTU against usable frame size on bind Maciej Fijalkowski
@ 2026-04-04 0:03 ` Jakub Kicinski
2026-04-04 10:02 ` Maciej Fijalkowski
0 siblings, 1 reply; 18+ messages in thread
From: Jakub Kicinski @ 2026-04-04 0:03 UTC (permalink / raw)
To: Maciej Fijalkowski
Cc: netdev, bpf, magnus.karlsson, stfomichev, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn
On Thu, 2 Apr 2026 17:49:54 +0200 Maciej Fijalkowski wrote:
> AF_XDP bind currently accepts zero-copy pool configurations without
> verifying that the device MTU fits into the usable frame space provided
> by the UMEM chunk.
>
> This becomes a problem since we started to respect tailroom which is
> subtracted from chunk_size (among with headroom). 2k chunk size might
> not provide enough space for standard 1500 MTU, so let us catch such
> settings at bind time. Furthermore, validate whether underlying HW will
> be able to satisfy configured MTU wrt XSK's frame size multiplied by
> supported Rx buffer chain length (that is exposed via
> net_device::xdp_zc_max_segs).
For multi-buf - I suppose it's fine, but wouldn't this be potentially
a regression for setups which use single buf? Suddenly we expect the
user to provide space for shinfo which was not part of the initial
AF_XDP design?
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v6 net 4/8] xsk: validate MTU against usable frame size on bind
2026-04-04 0:03 ` Jakub Kicinski
@ 2026-04-04 10:02 ` Maciej Fijalkowski
2026-04-06 18:00 ` Jakub Kicinski
0 siblings, 1 reply; 18+ messages in thread
From: Maciej Fijalkowski @ 2026-04-04 10:02 UTC (permalink / raw)
To: Jakub Kicinski
Cc: netdev, bpf, magnus.karlsson, stfomichev, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn
On Fri, Apr 03, 2026 at 05:03:57PM -0700, Jakub Kicinski wrote:
> On Thu, 2 Apr 2026 17:49:54 +0200 Maciej Fijalkowski wrote:
> > AF_XDP bind currently accepts zero-copy pool configurations without
> > verifying that the device MTU fits into the usable frame space provided
> > by the UMEM chunk.
> >
> > This becomes a problem since we started to respect tailroom which is
> > subtracted from chunk_size (among with headroom). 2k chunk size might
> > not provide enough space for standard 1500 MTU, so let us catch such
> > settings at bind time. Furthermore, validate whether underlying HW will
> > be able to satisfy configured MTU wrt XSK's frame size multiplied by
> > supported Rx buffer chain length (that is exposed via
> > net_device::xdp_zc_max_segs).
>
> For multi-buf - I suppose it's fine, but wouldn't this be potentially
> a regression for setups which use single buf? Suddenly we expect the
> user to provide space for shinfo which was not part of the initial
> AF_XDP design?
For single buf xsk_pool_get_tailroom() gives you 0 so it is not taken into
account when we do comparison of mtu vs xsk frame size (in this case frame
size is defined as chunk size minus headrooms (xdp and user provided
one)).
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v6 net 4/8] xsk: validate MTU against usable frame size on bind
2026-04-04 10:02 ` Maciej Fijalkowski
@ 2026-04-06 18:00 ` Jakub Kicinski
0 siblings, 0 replies; 18+ messages in thread
From: Jakub Kicinski @ 2026-04-06 18:00 UTC (permalink / raw)
To: Maciej Fijalkowski
Cc: netdev, bpf, magnus.karlsson, stfomichev, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn
On Sat, 4 Apr 2026 12:02:28 +0200 Maciej Fijalkowski wrote:
> On Fri, Apr 03, 2026 at 05:03:57PM -0700, Jakub Kicinski wrote:
> > On Thu, 2 Apr 2026 17:49:54 +0200 Maciej Fijalkowski wrote:
> > > AF_XDP bind currently accepts zero-copy pool configurations without
> > > verifying that the device MTU fits into the usable frame space provided
> > > by the UMEM chunk.
> > >
> > > This becomes a problem since we started to respect tailroom which is
> > > subtracted from chunk_size (among with headroom). 2k chunk size might
> > > not provide enough space for standard 1500 MTU, so let us catch such
> > > settings at bind time. Furthermore, validate whether underlying HW will
> > > be able to satisfy configured MTU wrt XSK's frame size multiplied by
> > > supported Rx buffer chain length (that is exposed via
> > > net_device::xdp_zc_max_segs).
> >
> > For multi-buf - I suppose it's fine, but wouldn't this be potentially
> > a regression for setups which use single buf? Suddenly we expect the
> > user to provide space for shinfo which was not part of the initial
> > AF_XDP design?
>
> For single buf xsk_pool_get_tailroom() gives you 0 so it is not taken into
> account when we do comparison of mtu vs xsk frame size (in this case frame
> size is defined as chunk size minus headrooms (xdp and user provided
> one)).
Ah, missed the xsk_pool_get_tailroom() magic. The rest can be a follow
up, my main concern was adding stricter check for non-mbuf mode.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v6 net 5/8] selftests: bpf: introduce a common routine for reading procfs
2026-04-02 15:49 [PATCH v6 net 0/8] xsk: tailroom reservation and MTU validation Maciej Fijalkowski
` (3 preceding siblings ...)
2026-04-02 15:49 ` [PATCH v6 net 4/8] xsk: validate MTU against usable frame size on bind Maciej Fijalkowski
@ 2026-04-02 15:49 ` Maciej Fijalkowski
2026-04-02 15:49 ` [PATCH v6 net 6/8] selftests: bpf: fix pkt grow tests Maciej Fijalkowski
` (3 subsequent siblings)
8 siblings, 0 replies; 18+ messages in thread
From: Maciej Fijalkowski @ 2026-04-02 15:49 UTC (permalink / raw)
To: netdev
Cc: bpf, magnus.karlsson, stfomichev, kuba, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn, Maciej Fijalkowski
Parametrize current way of getting MAX_SKB_FRAGS value from {sys,proc}fs
so that it can be re-used to get cache line size of system's CPU. All
that just to mimic and compute size of kernel's struct skb_shared_info
which for xsk and test suite interpret as tailroom.
Introduce two variables to ifobject struct that will carry count of skb
frags and tailroom size. Do the reading and computing once, at the
beginning of test suite execution in xskxceiver, but for test_progs such
way is not possible as in this environment each test setups and torns
down ifobject structs.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
.../selftests/bpf/prog_tests/test_xsk.c | 25 +------------------
.../selftests/bpf/prog_tests/test_xsk.h | 23 +++++++++++++++++
tools/testing/selftests/bpf/prog_tests/xsk.c | 19 ++++++++++++++
tools/testing/selftests/bpf/xskxceiver.c | 23 +++++++++++++++++
4 files changed, 66 insertions(+), 24 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/test_xsk.c b/tools/testing/selftests/bpf/prog_tests/test_xsk.c
index 7e38ec6e656b..62118ffba661 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_xsk.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_xsk.c
@@ -179,25 +179,6 @@ int xsk_configure_socket(struct xsk_socket_info *xsk, struct xsk_umem_info *umem
return xsk_socket__create(&xsk->xsk, ifobject->ifindex, 0, umem->umem, rxr, txr, &cfg);
}
-#define MAX_SKB_FRAGS_PATH "/proc/sys/net/core/max_skb_frags"
-static unsigned int get_max_skb_frags(void)
-{
- unsigned int max_skb_frags = 0;
- FILE *file;
-
- file = fopen(MAX_SKB_FRAGS_PATH, "r");
- if (!file) {
- ksft_print_msg("Error opening %s\n", MAX_SKB_FRAGS_PATH);
- return 0;
- }
-
- if (fscanf(file, "%u", &max_skb_frags) != 1)
- ksft_print_msg("Error reading %s\n", MAX_SKB_FRAGS_PATH);
-
- fclose(file);
- return max_skb_frags;
-}
-
static int set_ring_size(struct ifobject *ifobj)
{
int ret;
@@ -2242,11 +2223,7 @@ int testapp_too_many_frags(struct test_spec *test)
if (test->mode == TEST_MODE_ZC) {
max_frags = test->ifobj_tx->xdp_zc_max_segs;
} else {
- max_frags = get_max_skb_frags();
- if (!max_frags) {
- ksft_print_msg("Can't get MAX_SKB_FRAGS from system, using default (17)\n");
- max_frags = 17;
- }
+ max_frags = test->ifobj_tx->max_skb_frags;
max_frags += 1;
}
diff --git a/tools/testing/selftests/bpf/prog_tests/test_xsk.h b/tools/testing/selftests/bpf/prog_tests/test_xsk.h
index 8fc78a057de0..1ab8aee4ce56 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_xsk.h
+++ b/tools/testing/selftests/bpf/prog_tests/test_xsk.h
@@ -31,6 +31,9 @@
#define SOCK_RECONF_CTR 10
#define USLEEP_MAX 10000
+#define MAX_SKB_FRAGS_PATH "/proc/sys/net/core/max_skb_frags"
+#define SMP_CACHE_BYTES_PATH "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"
+
extern bool opt_verbose;
#define print_verbose(x...) do { if (opt_verbose) ksft_print_msg(x); } while (0)
@@ -45,6 +48,24 @@ static inline u64 ceil_u64(u64 a, u64 b)
return (a + b - 1) / b;
}
+static inline unsigned int read_procfs_val(const char *path)
+{
+ unsigned int read_val = 0;
+ FILE *file;
+
+ file = fopen(path, "r");
+ if (!file) {
+ ksft_print_msg("Error opening %s\n", path);
+ return 0;
+ }
+
+ if (fscanf(file, "%u", &read_val) != 1)
+ ksft_print_msg("Error reading %s\n", path);
+
+ fclose(file);
+ return read_val;
+}
+
/* Simple test */
enum test_mode {
TEST_MODE_SKB,
@@ -115,6 +136,8 @@ struct ifobject {
int mtu;
u32 bind_flags;
u32 xdp_zc_max_segs;
+ u32 umem_tailroom;
+ u32 max_skb_frags;
bool tx_on;
bool rx_on;
bool use_poll;
diff --git a/tools/testing/selftests/bpf/prog_tests/xsk.c b/tools/testing/selftests/bpf/prog_tests/xsk.c
index dd4c35c0e428..6e2f63ee2a6c 100644
--- a/tools/testing/selftests/bpf/prog_tests/xsk.c
+++ b/tools/testing/selftests/bpf/prog_tests/xsk.c
@@ -62,6 +62,7 @@ int configure_ifobj(struct ifobject *tx, struct ifobject *rx)
static void test_xsk(const struct test_spec *test_to_run, enum test_mode mode)
{
+ u32 max_frags, umem_tailroom, cache_line_size;
struct ifobject *ifobj_tx, *ifobj_rx;
struct test_spec test;
int ret;
@@ -84,6 +85,24 @@ static void test_xsk(const struct test_spec *test_to_run, enum test_mode mode)
ifobj_tx->set_ring.default_rx = ifobj_tx->ring.rx_pending;
}
+ cache_line_size = read_procfs_val(SMP_CACHE_BYTES_PATH);
+ if (!cache_line_size)
+ cache_line_size = 64;
+
+ max_frags = read_procfs_val(MAX_SKB_FRAGS_PATH);
+ if (!max_frags)
+ max_frags = 17;
+
+ ifobj_tx->max_skb_frags = max_frags;
+ ifobj_rx->max_skb_frags = max_frags;
+
+ /* 48 bytes is a part of skb_shared_info w/o frags array;
+ * 16 bytes is sizeof(skb_frag_t)
+ */
+ umem_tailroom = ALIGN(48 + (max_frags * 16), cache_line_size);
+ ifobj_tx->umem_tailroom = umem_tailroom;
+ ifobj_rx->umem_tailroom = umem_tailroom;
+
if (!ASSERT_OK(init_iface(ifobj_rx, worker_testapp_validate_rx), "init RX"))
goto delete_rx;
if (!ASSERT_OK(init_iface(ifobj_tx, worker_testapp_validate_tx), "init TX"))
diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
index 05b3cebc5ca9..7dad8556a722 100644
--- a/tools/testing/selftests/bpf/xskxceiver.c
+++ b/tools/testing/selftests/bpf/xskxceiver.c
@@ -80,6 +80,7 @@
#include <linux/mman.h>
#include <linux/netdev.h>
#include <linux/ethtool.h>
+#include <linux/align.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <locale.h>
@@ -333,6 +334,7 @@ static void print_tests(void)
int main(int argc, char **argv)
{
const size_t total_tests = ARRAY_SIZE(tests) + ARRAY_SIZE(ci_skip_tests);
+ u32 cache_line_size, max_frags, umem_tailroom;
struct pkt_stream *rx_pkt_stream_default;
struct pkt_stream *tx_pkt_stream_default;
struct ifobject *ifobj_tx, *ifobj_rx;
@@ -354,6 +356,27 @@ int main(int argc, char **argv)
setlocale(LC_ALL, "");
+ cache_line_size = read_procfs_val(SMP_CACHE_BYTES_PATH);
+ if (!cache_line_size) {
+ ksft_print_msg("Can't get SMP_CACHE_BYTES from system, using default (64)\n");
+ cache_line_size = 64;
+ }
+
+ max_frags = read_procfs_val(MAX_SKB_FRAGS_PATH);
+ if (!max_frags) {
+ ksft_print_msg("Can't get MAX_SKB_FRAGS from system, using default (17)\n");
+ max_frags = 17;
+ }
+ ifobj_tx->max_skb_frags = max_frags;
+ ifobj_rx->max_skb_frags = max_frags;
+
+ /* 48 bytes is a part of skb_shared_info w/o frags array;
+ * 16 bytes is sizeof(skb_frag_t)
+ */
+ umem_tailroom = ALIGN(48 + (max_frags * 16), cache_line_size);
+ ifobj_tx->umem_tailroom = umem_tailroom;
+ ifobj_rx->umem_tailroom = umem_tailroom;
+
parse_command_line(ifobj_tx, ifobj_rx, argc, argv);
if (opt_print_tests) {
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v6 net 6/8] selftests: bpf: fix pkt grow tests
2026-04-02 15:49 [PATCH v6 net 0/8] xsk: tailroom reservation and MTU validation Maciej Fijalkowski
` (4 preceding siblings ...)
2026-04-02 15:49 ` [PATCH v6 net 5/8] selftests: bpf: introduce a common routine for reading procfs Maciej Fijalkowski
@ 2026-04-02 15:49 ` Maciej Fijalkowski
2026-04-02 15:49 ` [PATCH v6 net 7/8] selftests: bpf: have a separate variable for drop test Maciej Fijalkowski
` (2 subsequent siblings)
8 siblings, 0 replies; 18+ messages in thread
From: Maciej Fijalkowski @ 2026-04-02 15:49 UTC (permalink / raw)
To: netdev
Cc: bpf, magnus.karlsson, stfomichev, kuba, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn, Maciej Fijalkowski
Skip tail adjust tests in xskxceiver for SKB mode as it is not very
friendly for it. multi-buffer case does not work as xdp_rxq_info that is
registered for generic XDP does not report ::frag_size. The non-mbuf
path copies packet via skb_pp_cow_data() which only accounts for
headroom, leaving us with no tailroom and causing underlying XDP prog to
drop packets therefore.
For multi-buffer test on other modes, change the amount of bytes we use
for growth, assume worst-case scenario and take care of headroom and
tailroom.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
.../selftests/bpf/prog_tests/test_xsk.c | 24 ++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/test_xsk.c b/tools/testing/selftests/bpf/prog_tests/test_xsk.c
index 62118ffba661..ee60bcc22ee4 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_xsk.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_xsk.c
@@ -2528,16 +2528,34 @@ int testapp_adjust_tail_shrink_mb(struct test_spec *test)
int testapp_adjust_tail_grow(struct test_spec *test)
{
+ if (test->mode == TEST_MODE_SKB)
+ return TEST_SKIP;
+
/* Grow by 4 bytes for testing purpose */
return testapp_adjust_tail(test, 4, MIN_PKT_SIZE * 2);
}
int testapp_adjust_tail_grow_mb(struct test_spec *test)
{
+ u32 grow_size;
+
+ if (test->mode == TEST_MODE_SKB)
+ return TEST_SKIP;
+
+ /* worst case scenario is when underlying setup will work on 3k
+ * buffers, let us account for it; given that we will use 6k as
+ * pkt_len, expect that it will be broken down to 2 descs each
+ * with 3k payload;
+ *
+ * 4k is truesize, 3k payload, 256 HR, 320 TR;
+ */
+ grow_size = XSK_UMEM__MAX_FRAME_SIZE -
+ XSK_UMEM__LARGE_FRAME_SIZE -
+ XDP_PACKET_HEADROOM -
+ test->ifobj_tx->umem_tailroom;
test->mtu = MAX_ETH_JUMBO_SIZE;
- /* Grow by (frag_size - last_frag_Size) - 1 to stay inside the last fragment */
- return testapp_adjust_tail(test, (XSK_UMEM__MAX_FRAME_SIZE / 2) - 1,
- XSK_UMEM__LARGE_FRAME_SIZE * 2);
+
+ return testapp_adjust_tail(test, grow_size, XSK_UMEM__LARGE_FRAME_SIZE * 2);
}
int testapp_tx_queue_consumer(struct test_spec *test)
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v6 net 7/8] selftests: bpf: have a separate variable for drop test
2026-04-02 15:49 [PATCH v6 net 0/8] xsk: tailroom reservation and MTU validation Maciej Fijalkowski
` (5 preceding siblings ...)
2026-04-02 15:49 ` [PATCH v6 net 6/8] selftests: bpf: fix pkt grow tests Maciej Fijalkowski
@ 2026-04-02 15:49 ` Maciej Fijalkowski
2026-04-02 15:49 ` [PATCH v6 net 8/8] selftests: bpf: adjust rx_dropped xskxceiver's test to respect tailroom Maciej Fijalkowski
2026-04-07 1:50 ` [PATCH v6 net 0/8] xsk: tailroom reservation and MTU validation patchwork-bot+netdevbpf
8 siblings, 0 replies; 18+ messages in thread
From: Maciej Fijalkowski @ 2026-04-02 15:49 UTC (permalink / raw)
To: netdev
Cc: bpf, magnus.karlsson, stfomichev, kuba, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn, Maciej Fijalkowski
Currently two different XDP programs share a static variable for
different purposes (picking where to redirect on shared umem test &
whether to drop a packet). This can be a problem when running full test
suite - idx can be written by shared umem test and this value can cause
a false behavior within XDP drop half test.
Introduce a dedicated variable for drop half test so that these two
don't step on each other toes. There is no real need for using
__sync_fetch_and_add here as XSK tests are executed on single CPU.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
tools/testing/selftests/bpf/progs/xsk_xdp_progs.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/progs/xsk_xdp_progs.c b/tools/testing/selftests/bpf/progs/xsk_xdp_progs.c
index 683306db8594..023d8befd4ca 100644
--- a/tools/testing/selftests/bpf/progs/xsk_xdp_progs.c
+++ b/tools/testing/selftests/bpf/progs/xsk_xdp_progs.c
@@ -26,8 +26,10 @@ SEC("xdp.frags") int xsk_def_prog(struct xdp_md *xdp)
SEC("xdp.frags") int xsk_xdp_drop(struct xdp_md *xdp)
{
+ static unsigned int drop_idx;
+
/* Drop every other packet */
- if (idx++ % 2)
+ if (drop_idx++ % 2)
return XDP_DROP;
return bpf_redirect_map(&xsk, 0, XDP_DROP);
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v6 net 8/8] selftests: bpf: adjust rx_dropped xskxceiver's test to respect tailroom
2026-04-02 15:49 [PATCH v6 net 0/8] xsk: tailroom reservation and MTU validation Maciej Fijalkowski
` (6 preceding siblings ...)
2026-04-02 15:49 ` [PATCH v6 net 7/8] selftests: bpf: have a separate variable for drop test Maciej Fijalkowski
@ 2026-04-02 15:49 ` Maciej Fijalkowski
2026-04-07 1:50 ` [PATCH v6 net 0/8] xsk: tailroom reservation and MTU validation patchwork-bot+netdevbpf
8 siblings, 0 replies; 18+ messages in thread
From: Maciej Fijalkowski @ 2026-04-02 15:49 UTC (permalink / raw)
To: netdev
Cc: bpf, magnus.karlsson, stfomichev, kuba, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn, Maciej Fijalkowski
Since we have changed how big user defined headroom in umem can be,
change the logic in testapp_stats_rx_dropped() so we pass updated
headroom validation in xdp_umem_reg() and still drop half of frames.
Test works on non-mbuf setup so __xsk_pool_get_rx_frame_size() that is
called on xsk_rcv_check() will not account skb_shared_info size. Taking
the tailroom size into account in test being fixed is needed as
xdp_umem_reg() defaults to respect it.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
tools/testing/selftests/bpf/prog_tests/test_xsk.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/test_xsk.c b/tools/testing/selftests/bpf/prog_tests/test_xsk.c
index ee60bcc22ee4..7950c504ed28 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_xsk.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_xsk.c
@@ -1959,15 +1959,17 @@ int testapp_headroom(struct test_spec *test)
int testapp_stats_rx_dropped(struct test_spec *test)
{
+ u32 umem_tr = test->ifobj_tx->umem_tailroom;
+
if (test->mode == TEST_MODE_ZC) {
ksft_print_msg("Can not run RX_DROPPED test for ZC mode\n");
return TEST_SKIP;
}
- if (pkt_stream_replace_half(test, MIN_PKT_SIZE * 4, 0))
+ if (pkt_stream_replace_half(test, (MIN_PKT_SIZE * 3) + umem_tr, 0))
return TEST_FAILURE;
test->ifobj_rx->umem->frame_headroom = test->ifobj_rx->umem->frame_size -
- XDP_PACKET_HEADROOM - MIN_PKT_SIZE * 3;
+ XDP_PACKET_HEADROOM - (MIN_PKT_SIZE * 2) - umem_tr;
if (pkt_stream_receive_half(test))
return TEST_FAILURE;
test->ifobj_rx->validation_func = validate_rx_dropped;
--
2.43.0
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v6 net 0/8] xsk: tailroom reservation and MTU validation
2026-04-02 15:49 [PATCH v6 net 0/8] xsk: tailroom reservation and MTU validation Maciej Fijalkowski
` (7 preceding siblings ...)
2026-04-02 15:49 ` [PATCH v6 net 8/8] selftests: bpf: adjust rx_dropped xskxceiver's test to respect tailroom Maciej Fijalkowski
@ 2026-04-07 1:50 ` patchwork-bot+netdevbpf
8 siblings, 0 replies; 18+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-04-07 1:50 UTC (permalink / raw)
To: Maciej Fijalkowski
Cc: netdev, bpf, magnus.karlsson, stfomichev, kuba, pabeni, horms,
larysa.zaremba, aleksander.lobakin, bjorn
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 2 Apr 2026 17:49:50 +0200 you wrote:
> v5->v6:
> - refrain from relying on umem refcnt when disabling zc on error path
> (Sashiko)
> - have a separate __xsk_pool_get_rx_frame_size() which preserves old
> behavior and use it on copy path (Sashiko)
> - drop driver cleanups
>
> [...]
Here is the summary with links:
- [v6,net,1/8] xsk: tighten UMEM headroom validation to account for tailroom and min frame
https://git.kernel.org/netdev/net/c/a315e022a72d
- [v6,net,2/8] xsk: respect tailroom for ZC setups
https://git.kernel.org/netdev/net/c/1ee1605138fc
- [v6,net,3/8] xsk: fix XDP_UMEM_SG_FLAG issues
https://git.kernel.org/netdev/net/c/93e84fe45b75
- [v6,net,4/8] xsk: validate MTU against usable frame size on bind
https://git.kernel.org/netdev/net/c/36ee60b569ba
- [v6,net,5/8] selftests: bpf: introduce a common routine for reading procfs
https://git.kernel.org/netdev/net/c/c5866a6be472
- [v6,net,6/8] selftests: bpf: fix pkt grow tests
https://git.kernel.org/netdev/net/c/3197c51ce2fa
- [v6,net,7/8] selftests: bpf: have a separate variable for drop test
https://git.kernel.org/netdev/net/c/16546954e117
- [v6,net,8/8] selftests: bpf: adjust rx_dropped xskxceiver's test to respect tailroom
https://git.kernel.org/netdev/net/c/62838e363e4f
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 18+ messages in thread