xsk: restore UMEM flags after failed pool assignment
Subsystems (5)
PATCH 1/1 xsk: restore UMEM flags after failed pool assignment
xp_assign_dev() sets XDP_UMEM_SG_FLAG before checking whether the device supports multibuffer zero-copy. If assignment fails, xsk_bind() destroys the pool but retains the registered UMEM. A subsequent bind without XDP_USE_SG inherits the stale flag.
The flag also changes RX buffer sizing after DMA mapping. On igc, a failed SG bind followed by a non-SG retry with 4096-byte chunks and 1792 bytes of headroom passes admission with 2048 bytes, but programs a 1024-byte RX buffer. On I225-V hardware, an ordinary 1514-byte frame is truncated to 1024 bytes or 1008 with RX timestamps enabled. Restoring the original flags eliminates the truncation in both cases.
Save the UMEM flags before assignment and restore them on failure.
--- net/xdp/xsk_buff_pool.c | 2 ++ 1 file changed, 2 insertions(+)
net/xdp/xsk_buff_pool.c +2 -0
@@ -166,6 +166,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool, {u32 needed = netdev->mtu +ETH_PAD_LEN ;u32 segs = netdev->xdp_zc_max_segs; +u8 umem_flags = pool->umem->flags;bool mbuf = flags &XDP_USE_SG ;bool force_zc, force_copy;struct netdev_bpf bpf;
@@ -268,6 +269,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool,if (!force_zc) err =0 ;/* fallback to copy mode */ if (err) { + pool->umem->flags = umem_flags;xsk_clear_pool_at_qid (netdev, queue_id);hlist_del (&pool->dev_node); pool->netdev =NULL ;
Signature · 1 line
2.56.GIT
Quoted 4 lines · Paul Moses
xp_assign_dev()setsXDP_UMEM_SG_FLAGbefore checking whether the device supports multibuffer zero-copy. If assignment fails,xsk_bind()destroys the pool but retains the registered UMEM. A subsequent bind withoutXDP_USE_SGinherits the stale flag.
so you opened a socket, tried binding with XDP_USE_SG, failed then retried without the flag and you noticed unexpected rx frame size due to kept XDP_UMEM_SG_FLAG - do i get this right?
socket not being closed kept the umem alive...
Quoted 7 lines
The flag also changes RX buffer sizing after DMA mapping. On igc, a failed SG bind followed by a non-SG retry with 4096-byte chunks and 1792 bytes of headroom passes admission with 2048 bytes, but programs a 1024-byte RX buffer. On I225-V hardware, an ordinary 1514-byte frame is truncated to 1024 bytes or 1008 with RX timestamps enabled. Restoring the original flags eliminates the truncation in both cases.
It should be enough to state that sg flag presence takes into account tailroom size and therefore has influence on final rx frame size provided to driver.
Quoted 2 lines
Save the UMEM flags before assignment and restore them on failure.
Regarding the patch content:
Quoted 33 lines
Fixes d609f3d228a8 ("xsk: add multi-buffer support for sockets sharing umem")Signed-off-by Paul Moses <[email protected]>--- net/xdp/xsk_buff_pool.c | 2 ++ 1 file changed, 2 insertions(+)net/xdp/xsk_buff_pool.c +2
-0@@ -166,6 +166,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool, {u32 needed = netdev->mtu +ETH_PAD_LEN ;u32 segs = netdev->xdp_zc_max_segs; +u8 umem_flags = pool->umem->flags;bool mbuf = flags &XDP_USE_SG ;bool force_zc, force_copy;struct netdev_bpf bpf;@@ -268,6 +269,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool,if (!force_zc) err =0 ;/* fallback to copy mode */ if (err) { + pool->umem->flags = umem_flags;xsk_clear_pool_at_qid (netdev, queue_id);hlist_del (&pool->dev_node); pool->netdev =NULL ;Signature · 2 lines
-- 2.56.GIT
Quoted 59 lines · Maciej Fijalkowski
Quoted 4 lines · Paul Moses
xp_assign_dev()setsXDP_UMEM_SG_FLAGbefore checking whether the device supports multibuffer zero-copy. If assignment fails,xsk_bind()destroys the pool but retains the registered UMEM. A subsequent bind withoutXDP_USE_SGinherits the stale flag.so you opened a socket, tried binding with
XDP_USE_SG, failed then retried without the flag and you noticed unexpected rx frame size due to keptXDP_UMEM_SG_FLAG- do i get this right?socket not being closed kept the umem alive...
Quoted 7 lines
The flag also changes RX buffer sizing after DMA mapping. On igc, a failed SG bind followed by a non-SG retry with 4096-byte chunks and 1792 bytes of headroom passes admission with 2048 bytes, but programs a 1024-byte RX buffer. On I225-V hardware, an ordinary 1514-byte frame is truncated to 1024 bytes or 1008 with RX timestamps enabled. Restoring the original flags eliminates the truncation in both cases.
It should be enough to state that sg flag presence takes into account tailroom size and therefore has influence on final rx frame size provided to driver.
Quoted 2 lines
Save the UMEM flags before assignment and restore them on failure.
Regarding the patch content:
Quoted 29 lines
Fixes d609f3d228a8 ("xsk: add multi-buffer support for sockets sharing umem")Signed-off-by Paul Moses <[email protected]>--- net/xdp/xsk_buff_pool.c | 2 ++ 1 file changed, 2 insertions(+)net/xdp/xsk_buff_pool.c +2
-0@@ -166,6 +166,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool, {u32 needed = netdev->mtu +ETH_PAD_LEN ;u32 segs = netdev->xdp_zc_max_segs; +u8 umem_flags = pool->umem->flags;bool mbuf = flags &XDP_USE_SG ;bool force_zc, force_copy;struct netdev_bpf bpf;@@ -268,6 +269,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool,if (!force_zc) err =0 ;/* fallback to copy mode */ if (err) { + pool->umem->flags = umem_flags;xsk_clear_pool_at_qid (netdev, queue_id);hlist_del (&pool->dev_node); pool->netdev =NULL ;
Quoted 5 lines
Quoted 4 lines
--
2.56.GIT
Right, evidence suggests igc handles it gracefully, I had attempted to provide multiple examples of real world impact to satiate Sashiko, but only igc survived final edit. It needs to be open for the failed bind and successful retry, it can be closed after and bad state remains. If you're looking for greater impact, look at stmmac. I'll send out a v2 without naming drivers specifically soon.
Maciej Fijalkowski
maintainerQuoted 67 lines · Paul Moses
Quoted 59 lines · Maciej Fijalkowski
Quoted 4 lines · Paul Moses
xp_assign_dev()setsXDP_UMEM_SG_FLAGbefore checking whether the device supports multibuffer zero-copy. If assignment fails,xsk_bind()destroys the pool but retains the registered UMEM. A subsequent bind withoutXDP_USE_SGinherits the stale flag.so you opened a socket, tried binding with
XDP_USE_SG, failed then retried without the flag and you noticed unexpected rx frame size due to keptXDP_UMEM_SG_FLAG- do i get this right?socket not being closed kept the umem alive...
Quoted 7 lines
The flag also changes RX buffer sizing after DMA mapping. On igc, a failed SG bind followed by a non-SG retry with 4096-byte chunks and 1792 bytes of headroom passes admission with 2048 bytes, but programs a 1024-byte RX buffer. On I225-V hardware, an ordinary 1514-byte frame is truncated to 1024 bytes or 1008 with RX timestamps enabled. Restoring the original flags eliminates the truncation in both cases.
It should be enough to state that sg flag presence takes into account tailroom size and therefore has influence on final rx frame size provided to driver.
Quoted 2 lines
Save the UMEM flags before assignment and restore them on failure.
Regarding the patch content:
Quoted 29 lines
Fixes d609f3d228a8 ("xsk: add multi-buffer support for sockets sharing umem")Signed-off-by Paul Moses <[email protected]>--- net/xdp/xsk_buff_pool.c | 2 ++ 1 file changed, 2 insertions(+)net/xdp/xsk_buff_pool.c +2
-0@@ -166,6 +166,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool, {u32 needed = netdev->mtu +ETH_PAD_LEN ;u32 segs = netdev->xdp_zc_max_segs; +u8 umem_flags = pool->umem->flags;bool mbuf = flags &XDP_USE_SG ;bool force_zc, force_copy;struct netdev_bpf bpf;@@ -268,6 +269,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool,if (!force_zc) err =0 ;/* fallback to copy mode */ if (err) { + pool->umem->flags = umem_flags;xsk_clear_pool_at_qid (netdev, queue_id);hlist_del (&pool->dev_node); pool->netdev =NULL ;Quoted 5 lines
Quoted 4 lines
--
2.56.GIT
Quoted 6 lines
Right, evidence suggests igc handles it gracefully, I had attempted to provide multiple examples of real world impact to satiate Sashiko, but only igc survived final edit. It needs to be open for the failed bind and successful retry, it can be closed after and bad state remains. If you're looking for greater impact, look at stmmac. I'll send out a v2 without naming drivers specifically soon.
Not really needed to go with v2 with reworded message. Let us wait for bot reports first.
Jakub Kicinski
maintainerQuoted 9 lines · On Thu, 22 Oct 2026 19:10:08 +0200 Maciej Fijalkowski wrote:
Quoted 6 lines
Right, evidence suggests igc handles it gracefully, I had attempted to provide multiple examples of real world impact to satiate Sashiko, but only igc survived final edit. It needs to be open for the failed bind and successful retry, it can be closed after and bad state remains. If you're looking for greater impact, look at stmmac. I'll send out a v2 without naming drivers specifically soon.
Not really needed to go with v2 with reworded message. Let us wait for bot reports first.
Bots look happy, but I'm slightly confused by Paul's "only igc survived final edit" statement. Was this issue discovered in normal development or by an LLM bug hunt? Was it tested on I225-V hardware, or LLM just suggest that HW as a NIC that would be impacted?
Quoted 8 lines · Jakub Kicinski
Quoted 7 lines · On Thu, 22 Oct 2026 19:10:08 +0200 Maciej Fijalkowski wrote:
Quoted 6 lines
Right, evidence suggests igc handles it gracefully, I had attempted to provide multiple examples of real world impact to satiate Sashiko, but only igc survived final edit. It needs to be open for the failed bind and successful retry, it can be closed after and bad state remains. If you're looking for greater impact, look at stmmac. I'll send out a v2 without naming drivers specifically soon.
Quoted 8 lines
Quoted 2 lines
Not really needed to go with v2 with reworded message. Let us wait for bot reports first.
Bots look happy, but I'm slightly confused by Paul's "only igc survived final edit" statement. Was this issue discovered in normal development or by an LLM bug hunt? Was it tested on I225-V hardware, or LLM just suggest that HW as a NIC that would be impacted?
What I meant is that it was admittedly awkward the way I left it.
I do use LLMs to a certain extent, but they have no autonomy or ability to communicate, I am a CS major that has a long history/love for C and been configuring/compiling the kernel since 2.4 (old gentoo user), so I didn't wander in off the street. The bug was found through development, I have a little n305 with dual I225-V, working on v3 for that initial patch I sent out, I now agree that it needs to be reworked. Currently experimenting with tracking frame position and these are the side quests...
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 5 lines · On Wed, 21 Oct 2026 22:47:33 +0000 you wrote:
xp_assign_dev()setsXDP_UMEM_SG_FLAGbefore checking whether the device supports multibuffer zero-copy. If assignment fails,xsk_bind()destroys the pool but retains the registered UMEM. A subsequent bind withoutXDP_USE_SGinherits the stale flag.
Quoted 8 lines
The flag also changes RX buffer sizing after DMA mapping. On igc, a failed SG bind followed by a non-SG retry with 4096-byte chunks and 1792 bytes of headroom passes admission with 2048 bytes, but programs a 1024-byte RX buffer. On I225-V hardware, an ordinary 1514-byte frame is truncated to 1024 bytes or 1008 with RX timestamps enabled. Restoring the original flags eliminates the truncation in both cases.
[...]
Here is the summary with links:
- [net] xsk: restore UMEM flags after failed pool assignment
https://git.kernel.org/netdev/net/c/b88b826ec54a
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html