* [PATCH net v3 0/2] xsk: fix negative overflow issues in zerocopy xmit
@ 2025-07-23 14:23 Jason Xing
2025-07-23 14:23 ` [PATCH net v3 1/2] stmmac: xsk: fix negative overflow of budget in zerocopy mode Jason Xing
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jason Xing @ 2025-07-23 14:23 UTC (permalink / raw)
To: anthony.l.nguyen, przemyslaw.kitszel, andrew+netdev, davem,
edumazet, kuba, pabeni, bjorn, magnus.karlsson,
maciej.fijalkowski, jonathan.lemon, sdf, ast, daniel, hawk,
john.fastabend, mcoquelin.stm32, alexandre.torgue
Cc: linux-stm32, bpf, intel-wired-lan, netdev, Jason Xing
From: Jason Xing <kernelxing@tencent.com>
Fix two negative overflow issues around {stmmac_xdp|igb}_xmit_zc().
Jason Xing (2):
stmmac: xsk: fix negative overflow of budget in zerocopy mode
igb: xsk: solve negative overflow of nb_pkts in zerocopy mode
drivers/net/ethernet/intel/igb/igb_xsk.c | 3 +--
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
--
2.41.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net v3 1/2] stmmac: xsk: fix negative overflow of budget in zerocopy mode
2025-07-23 14:23 [PATCH net v3 0/2] xsk: fix negative overflow issues in zerocopy xmit Jason Xing
@ 2025-07-23 14:23 ` Jason Xing
2025-07-23 14:23 ` [PATCH net v3 2/2] igb: xsk: solve negative overflow of nb_pkts " Jason Xing
2025-07-26 18:30 ` [PATCH net v3 0/2] xsk: fix negative overflow issues in zerocopy xmit patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Jason Xing @ 2025-07-23 14:23 UTC (permalink / raw)
To: anthony.l.nguyen, przemyslaw.kitszel, andrew+netdev, davem,
edumazet, kuba, pabeni, bjorn, magnus.karlsson,
maciej.fijalkowski, jonathan.lemon, sdf, ast, daniel, hawk,
john.fastabend, mcoquelin.stm32, alexandre.torgue
Cc: linux-stm32, bpf, intel-wired-lan, netdev, Jason Xing,
Aleksandr Loktionov
From: Jason Xing <kernelxing@tencent.com>
A negative overflow can happen when the budget number of descs are
consumed. as long as the budget is decreased to zero, it will again go
into while (budget-- > 0) statement and get decreased by one, so the
overflow issue can happen. It will lead to returning true whereas the
expected value should be false.
In this case where all the budget is used up, it means zc function
should return false to let the poll run again because normally we
might have more data to process. Without this patch, zc function would
return true instead.
Fixes: 132c32ee5bc0 ("net: stmmac: Add TX via XDP zero-copy socket")
Signed-off-by: Jason Xing <kernelxing@tencent.com>
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
---
v3
Link: https://lore.kernel.org/all/CAL+tcoAnB+8ZLPyWQ3XsvWTa=JO1yCKWvrKVp+2WCP=kGpfSPg@mail.gmail.com/
1. collect reviewed-by tag
2. replace 'underflow' with 'negative overflow' in a technical way.
v2
Link: https://lore.kernel.org/all/20250721083343.16482-1-kerneljasonxing@gmail.com/
1. target net tree instead of net-next
2. revise commit message
3. use for loop to replace while loop
---
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index f350a6662880..f1abf4242cd2 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -2596,7 +2596,7 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
budget = min(budget, stmmac_tx_avail(priv, queue));
- while (budget-- > 0) {
+ for (; budget > 0; budget--) {
struct stmmac_metadata_request meta_req;
struct xsk_tx_metadata *meta = NULL;
dma_addr_t dma_addr;
--
2.41.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net v3 2/2] igb: xsk: solve negative overflow of nb_pkts in zerocopy mode
2025-07-23 14:23 [PATCH net v3 0/2] xsk: fix negative overflow issues in zerocopy xmit Jason Xing
2025-07-23 14:23 ` [PATCH net v3 1/2] stmmac: xsk: fix negative overflow of budget in zerocopy mode Jason Xing
@ 2025-07-23 14:23 ` Jason Xing
2025-07-26 18:30 ` [PATCH net v3 0/2] xsk: fix negative overflow issues in zerocopy xmit patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Jason Xing @ 2025-07-23 14:23 UTC (permalink / raw)
To: anthony.l.nguyen, przemyslaw.kitszel, andrew+netdev, davem,
edumazet, kuba, pabeni, bjorn, magnus.karlsson,
maciej.fijalkowski, jonathan.lemon, sdf, ast, daniel, hawk,
john.fastabend, mcoquelin.stm32, alexandre.torgue
Cc: linux-stm32, bpf, intel-wired-lan, netdev, Jason Xing,
Aleksandr Loktionov
From: Jason Xing <kernelxing@tencent.com>
There is no break time in the while() loop, so every time at the end of
igb_xmit_zc(), negative overflow of nb_pkts will occur, which renders
the return value always false. But theoretically, the result should be
set after calling xsk_tx_peek_release_desc_batch(). We can take
i40e_xmit_zc() as a good example.
Returning false means we're not done with transmission and we need one
more poll, which is exactly what igb_xmit_zc() always did before this
patch. After this patch, the return value depends on the nb_pkts value.
Two cases might happen then:
1. if (nb_pkts < budget), it means we process all the possible data, so
return true and no more necessary poll will be triggered because of
this.
2. if (nb_pkts == budget), it means we might have more data, so return
false to let another poll run again.
Fixes: f8e284a02afc ("igb: Add AF_XDP zero-copy Tx support")
Signed-off-by: Jason Xing <kernelxing@tencent.com>
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
---
v3
Link: https://lore.kernel.org/all/CAL+tcoAnB+8ZLPyWQ3XsvWTa=JO1yCKWvrKVp+2WCP=kGpfSPg@mail.gmail.com/
1. collect reviewed-by tag
2. replace 'underflow' with 'negative overflow' in a technical way.
v2
Link: https://lore.kernel.org/all/20250721083343.16482-1-kerneljasonxing@gmail.com/
1. target net tree instead of net-next
2. use for loop instead
---
drivers/net/ethernet/intel/igb/igb_xsk.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/intel/igb/igb_xsk.c b/drivers/net/ethernet/intel/igb/igb_xsk.c
index 5cf67ba29269..30ce5fbb5b77 100644
--- a/drivers/net/ethernet/intel/igb/igb_xsk.c
+++ b/drivers/net/ethernet/intel/igb/igb_xsk.c
@@ -482,7 +482,7 @@ bool igb_xmit_zc(struct igb_ring *tx_ring, struct xsk_buff_pool *xsk_pool)
if (!nb_pkts)
return true;
- while (nb_pkts-- > 0) {
+ for (; i < nb_pkts; i++) {
dma = xsk_buff_raw_get_dma(xsk_pool, descs[i].addr);
xsk_buff_raw_dma_sync_for_device(xsk_pool, dma, descs[i].len);
@@ -512,7 +512,6 @@ bool igb_xmit_zc(struct igb_ring *tx_ring, struct xsk_buff_pool *xsk_pool)
total_bytes += descs[i].len;
- i++;
tx_ring->next_to_use++;
tx_buffer_info->next_to_watch = tx_desc;
if (tx_ring->next_to_use == tx_ring->count)
--
2.41.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net v3 0/2] xsk: fix negative overflow issues in zerocopy xmit
2025-07-23 14:23 [PATCH net v3 0/2] xsk: fix negative overflow issues in zerocopy xmit Jason Xing
2025-07-23 14:23 ` [PATCH net v3 1/2] stmmac: xsk: fix negative overflow of budget in zerocopy mode Jason Xing
2025-07-23 14:23 ` [PATCH net v3 2/2] igb: xsk: solve negative overflow of nb_pkts " Jason Xing
@ 2025-07-26 18:30 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-07-26 18:30 UTC (permalink / raw)
To: Jason Xing
Cc: anthony.l.nguyen, przemyslaw.kitszel, andrew+netdev, davem,
edumazet, kuba, pabeni, bjorn, magnus.karlsson,
maciej.fijalkowski, jonathan.lemon, sdf, ast, daniel, hawk,
john.fastabend, mcoquelin.stm32, alexandre.torgue, linux-stm32,
bpf, intel-wired-lan, netdev, kernelxing
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Wed, 23 Jul 2025 22:23:25 +0800 you wrote:
> From: Jason Xing <kernelxing@tencent.com>
>
> Fix two negative overflow issues around {stmmac_xdp|igb}_xmit_zc().
>
> Jason Xing (2):
> stmmac: xsk: fix negative overflow of budget in zerocopy mode
> igb: xsk: solve negative overflow of nb_pkts in zerocopy mode
>
> [...]
Here is the summary with links:
- [net,v3,1/2] stmmac: xsk: fix negative overflow of budget in zerocopy mode
https://git.kernel.org/netdev/net/c/2764ab51d5f0
- [net,v3,2/2] igb: xsk: solve negative overflow of nb_pkts in zerocopy mode
https://git.kernel.org/netdev/net/c/3b7c13dfdcc2
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] 4+ messages in thread
end of thread, other threads:[~2025-07-26 18:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-23 14:23 [PATCH net v3 0/2] xsk: fix negative overflow issues in zerocopy xmit Jason Xing
2025-07-23 14:23 ` [PATCH net v3 1/2] stmmac: xsk: fix negative overflow of budget in zerocopy mode Jason Xing
2025-07-23 14:23 ` [PATCH net v3 2/2] igb: xsk: solve negative overflow of nb_pkts " Jason Xing
2025-07-26 18:30 ` [PATCH net v3 0/2] xsk: fix negative overflow issues in zerocopy xmit patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).