* [PATCH net] net: stmmac: retry a failed RX refill from a timer
@ 2026-11-20 7:49 Anandu Padinhare
2026-11-22 18:01 ` Nicolai Buchwitz
2026-11-24 8:02 ` netdev-bot+sashiko
0 siblings, 2 replies; 10+ messages in thread
From: Anandu Padinhare @ 2026-11-20 7:49 UTC (permalink / raw)
To: maxime.chevallier@bootlin.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com
Cc: mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Sam Edwards,
Russell King (Oracle), David Wu, stable@vger.kernel.org,
netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org
stmmac_rx_refill() stops at the first page_pool allocation failure. The
refill is retried only from the next RX NAPI poll, and only an RX
interrupt schedules that poll. Once the DMA has used the buffers it
still had, it suspends, no RX interrupt comes, and receive can stay dead
even after memory is available again, until the interface is reopened.
Commit 0bb05e6adfa9 ("net: stmmac: Prevent NULL deref when RX memory
exhausted") describes this stall and leaves it for a later change.
When at most STMMAC_RX_REFILL_THRESH (16) slots are left with the DMA
after a poll, arm a per-channel timer that schedules the RX NAPI 10 ms
later. The poll retries the refill and re-arms the timer while
allocations keep failing, so NAPI does not keep polling while memory is
short. This follows the review of an earlier attempt (see Links). The
retry does not rely on the Receive Buffer Unavailable (RBU) interrupt,
which is not enabled on every core and kernel version.
The timer lives in struct stmmac_channel, because __stmmac_open()
replaces priv->dma_conf. It is cancelled after rx_napi is disabled, and
stmmac_enable_all_queues() re-arms it, because
stmmac_setup_tc_block_cb() disables and re-enables the queues without
re-initialising the rings.
Found while debugging a separate AF_XDP zero-copy RX stall, with the
help of an AI code review agent. Reproduced on an ADI ADSP-SC598
(dwmac 5.20) with a kernel based on ADI's 6.18.31, using error
injection: page_pool_alloc_netmems() was made to return NULL on every
call through fail_function (retval 0, probability 100, times -1) for 3 s
while receiving about 4000 frames/s. With the RBU interrupt disabled
(the dwmac4 default in 6.18), receive stayed dead in 6 of 6 runs until
ethtool -G.
Tested on the same board with the fix backported: receive came back by
itself in every run of the reproducer, with the RBU interrupt off and
on. Only build-tested on mainline. Other DMA cores were not tested.
Kernel selftests were not run.
Fixes: 47dd7a540b8a ("net: add support for STMicroelectronics Ethernet controllers.")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/netdev/20260331195927.3353cc6d@kernel.org/
Link: https://lore.kernel.org/netdev/20260402174049.0ac088cc@kernel.org/
Signed-off-by: Anandu Padinhare <Anandu.Padinhare@electrifex.com>
---
More testing on the board, with KASAN, lockdep and DEBUG_OBJECTS_TIMERS
and the RBU interrupt off and on: failure rates from 1 % to 99 %, up to
60 s of failures, RX rings of 64 to 1024 entries, and down/up, ethtool
-G/-L, MTU, tc flower, XDP and AF_XDP zero-copy changes while the ring
was empty. A driver unbind with a retry pending was also tested (RBU
interrupt off). Traced with ftrace, frames arrived again 31-37 ms after
the failures stopped. With 50 % to 100 % of the allocations failing and
the RBU interrupt off, the retry timer fired 52-61 times per second and
the CPU stayed 86-96 % idle.
With the RBU interrupt enabled (dwmac4 since v7.1), an RBU interrupt
storm follows on the test board when every allocation fails, with and
without this patch. Without this patch, receive came back through that
storm in 4 of 5 runs and stayed dead in one.
drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 +
.../net/ethernet/stmicro/stmmac/stmmac_main.c | 47 ++++++++++++++++++-
.../net/ethernet/stmicro/stmmac/stmmac_xdp.c | 1 +
3 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index b76acfe0d958..88b83dc3cf0f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -142,6 +142,7 @@ struct stmmac_channel {
struct napi_struct rx_napi ____cacheline_aligned_in_smp;
struct napi_struct tx_napi ____cacheline_aligned_in_smp;
struct napi_struct rxtx_napi ____cacheline_aligned_in_smp;
+ struct timer_list rx_refill_timer;
struct stmmac_priv *priv_data;
spinlock_t lock;
u32 index;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index a685ce4638f6..ad9873aaf2db 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -86,6 +86,8 @@ MODULE_PARM_DESC(phyaddr, "Physical device address");
#define STMMAC_XSK_TX_BUDGET_MAX 256
#define STMMAC_TX_XSK_AVAIL 16
#define STMMAC_RX_FILL_BATCH 16
+#define STMMAC_RX_REFILL_THRESH 16
+#define STMMAC_RX_REFILL_RETRY_MS 10
#define STMMAC_XDP_PASS 0
#define STMMAC_XDP_CONSUMED BIT(0)
@@ -263,6 +265,32 @@ static void stmmac_verify_args(void)
pr_warn("stmmac: module parameter 'flow_ctrl' is obsolete - please remove from your module configuration\n");
}
+/* The RX DMA suspends without an interrupt once it has used all its buffers,
+ * so a refill that failed for lack of memory would never be retried. Retry it
+ * from a timer when few slots are left with the DMA.
+ */
+static bool stmmac_rx_refill_needed(struct stmmac_priv *priv, u32 queue)
+{
+ struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
+
+ return CIRC_SPACE(rx_q->cur_rx, rx_q->dirty_rx,
+ priv->dma_conf.dma_rx_size) < STMMAC_RX_REFILL_THRESH;
+}
+
+static void stmmac_rx_refill_timer_arm(struct stmmac_channel *ch)
+{
+ if (!timer_pending(&ch->rx_refill_timer))
+ mod_timer(&ch->rx_refill_timer,
+ jiffies + msecs_to_jiffies(STMMAC_RX_REFILL_RETRY_MS));
+}
+
+static void stmmac_rx_refill_timer(struct timer_list *t)
+{
+ struct stmmac_channel *ch = timer_container_of(ch, t, rx_refill_timer);
+
+ napi_schedule(&ch->rx_napi);
+}
+
static void __stmmac_disable_all_queues(struct stmmac_priv *priv)
{
u8 rx_queues_cnt = priv->plat->rx_queues_to_use;
@@ -284,6 +312,10 @@ static void __stmmac_disable_all_queues(struct stmmac_priv *priv)
if (queue < tx_queues_cnt)
napi_disable(&ch->tx_napi);
}
+
+ /* With NAPI disabled no poll can re-arm the refill timers */
+ for (queue = 0; queue < rx_queues_cnt; queue++)
+ timer_delete_sync(&priv->channel[queue].rx_refill_timer);
}
/**
@@ -328,8 +360,17 @@ static void stmmac_enable_all_queues(struct stmmac_priv *priv)
continue;
}
- if (queue < rx_queues_cnt)
+ if (queue < rx_queues_cnt) {
+ /* Disabling the queues cancelled any pending refill
+ * retry, but the ring may have been kept as it was.
+ * Check it while no poll can run.
+ */
+ bool refill = stmmac_rx_refill_needed(priv, queue);
+
napi_enable(&ch->rx_napi);
+ if (refill)
+ stmmac_rx_refill_timer_arm(ch);
+ }
if (queue < tx_queues_cnt)
napi_enable(&ch->tx_napi);
}
@@ -6164,6 +6205,8 @@ static int stmmac_napi_poll_rx(struct napi_struct *napi, int budget)
u64_stats_update_end(&rxq_stats->napi_syncp);
work_done = stmmac_rx(priv, budget, chan);
+ if (unlikely(stmmac_rx_refill_needed(priv, chan)))
+ stmmac_rx_refill_timer_arm(ch);
if (work_done < budget && napi_complete_done(napi, work_done)) {
unsigned long flags;
@@ -7779,6 +7822,8 @@ static void stmmac_napi_add(struct net_device *dev)
if (queue < priv->plat->rx_queues_to_use) {
netif_napi_add(dev, &ch->rx_napi, stmmac_napi_poll_rx);
+ timer_setup(&ch->rx_refill_timer,
+ stmmac_rx_refill_timer, 0);
}
if (queue < priv->plat->tx_queues_to_use) {
netif_napi_add_tx(dev, &ch->tx_napi,
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c
index 9af9e0cb366c..c3e85ee1067c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c
@@ -35,6 +35,7 @@ static int stmmac_xdp_enable_pool(struct stmmac_priv *priv,
if (need_update) {
napi_disable(&ch->rx_napi);
+ timer_delete_sync(&ch->rx_refill_timer);
napi_disable(&ch->tx_napi);
stmmac_disable_rx_queue(priv, queue);
stmmac_disable_tx_queue(priv, queue);
base-commit: 325e921a7aa170181e1cce235d9c652cb0ad3a5b
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: stmmac: retry a failed RX refill from a timer
2026-11-20 7:49 [PATCH net] net: stmmac: retry a failed RX refill from a timer Anandu Padinhare
@ 2026-11-22 18:01 ` Nicolai Buchwitz
2026-11-22 20:20 ` Sam Edwards
2026-11-24 8:02 ` netdev-bot+sashiko
1 sibling, 1 reply; 10+ messages in thread
From: Nicolai Buchwitz @ 2026-11-22 18:01 UTC (permalink / raw)
To: Anandu Padinhare
Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
mcoquelin.stm32, alexandre.torgue, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Stanislav Fomichev, Sam Edwards, Russell King (Oracle), David Wu,
stable, netdev, linux-stm32, linux-arm-kernel, bpf
Hi Anandu
On 20.11.2026 08:49, Anandu Padinhare wrote:
> [...]
> @@ -6164,6 +6205,8 @@ static int stmmac_napi_poll_rx(struct napi_struct
> *napi, int budget)
> u64_stats_update_end(&rxq_stats->napi_syncp);
>
> work_done = stmmac_rx(priv, budget, chan);
> + if (unlikely(stmmac_rx_refill_needed(priv, chan)))
> + stmmac_rx_refill_timer_arm(ch);
After a successful retry, doesn't this leave the last received frame in
the ring until the next RX irq? Could the poll refill first?
> [...]
Regards,
Nicolai
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: stmmac: retry a failed RX refill from a timer
2026-11-22 18:01 ` Nicolai Buchwitz
@ 2026-11-22 20:20 ` Sam Edwards
2026-11-22 20:37 ` Nicolai Buchwitz
2026-11-22 21:02 ` Sam Edwards
0 siblings, 2 replies; 10+ messages in thread
From: Sam Edwards @ 2026-11-22 20:20 UTC (permalink / raw)
To: Nicolai Buchwitz
Cc: Anandu Padinhare, maxime.chevallier, andrew+netdev, davem,
edumazet, kuba, pabeni, mcoquelin.stm32, alexandre.torgue,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Russell King (Oracle),
David Wu, stable, netdev, linux-stm32, linux-arm-kernel, bpf
On Sun, Nov 22, 2026 at 10:01 AM Nicolai Buchwitz <nb@tipi-net.de> wrote:
>
> Hi Anandu
>
> On 20.11.2026 08:49, Anandu Padinhare wrote:
>
> > [...]
>
> > @@ -6164,6 +6205,8 @@ static int stmmac_napi_poll_rx(struct napi_struct
> > *napi, int budget)
> > u64_stats_update_end(&rxq_stats->napi_syncp);
> >
> > work_done = stmmac_rx(priv, budget, chan);
> > + if (unlikely(stmmac_rx_refill_needed(priv, chan)))
> > + stmmac_rx_refill_timer_arm(ch);
>
> After a successful retry, doesn't this leave the last received frame in
> the ring until the next RX irq? Could the poll refill first?
Do you mean "first as well" or "first instead"? Because "instead" can
cause avoidable packet loss:
1) Initially, network is idle and ring is full of empty DMA buffers
2) A burst of exactly one ring's worth of packets arrives
3) The RX irq fires and stmmac_rx() attempts its refill-first (none
needed) then depletes the ring to the maximally-dirty state; the
refill timer is armed
4) During the 10ms timer period, more traffic arrives
5) The RX irq doesn't fire again because no additional DMA is
happening: there are no usable buffers in the ring. So we're forced to
wait out the timer.
6) Any packets during this time (beyond the RxFIFO's capacity) are
discarded by the hardware
But, "first as well" sounds good to me: before entering the main loop,
refill 1 buffer (if possible) just to ensure either the IRQ fires
again immediately (if the FIFO is holding onto another packet for us),
or the inaccessible ring slot is clean (if the FIFO is empty).
Cheers,
Sam
>
> > [...]
>
> Regards,
> Nicolai
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: stmmac: retry a failed RX refill from a timer
2026-11-22 20:20 ` Sam Edwards
@ 2026-11-22 20:37 ` Nicolai Buchwitz
2026-11-22 21:02 ` Sam Edwards
1 sibling, 0 replies; 10+ messages in thread
From: Nicolai Buchwitz @ 2026-11-22 20:37 UTC (permalink / raw)
To: Sam Edwards
Cc: Anandu Padinhare, maxime.chevallier, andrew+netdev, davem,
edumazet, kuba, pabeni, mcoquelin.stm32, alexandre.torgue,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Russell King (Oracle),
David Wu, stable, netdev, linux-stm32, linux-arm-kernel, bpf
On 22.11.2026 21:20, Sam Edwards wrote:
> [...]
>> After a successful retry, doesn't this leave the last received frame
>> in
>> the ring until the next RX irq? Could the poll refill first?
>
> Do you mean "first as well" or "first instead"? Because "instead" can
> [...]
> But, "first as well" sounds good to me: before entering the main loop,
> refill 1 buffer (if possible) just to ensure either the IRQ fires
> again immediately (if the FIFO is holding onto another packet for us),
> or the inaccessible ring slot is clean (if the FIFO is empty).
This (first as well).
BR
Nicolai
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: stmmac: retry a failed RX refill from a timer
2026-11-22 20:20 ` Sam Edwards
2026-11-22 20:37 ` Nicolai Buchwitz
@ 2026-11-22 21:02 ` Sam Edwards
2026-11-22 21:09 ` Nicolai Buchwitz
1 sibling, 1 reply; 10+ messages in thread
From: Sam Edwards @ 2026-11-22 21:02 UTC (permalink / raw)
To: Nicolai Buchwitz
Cc: Anandu Padinhare, maxime.chevallier, andrew+netdev, davem,
edumazet, kuba, pabeni, mcoquelin.stm32, alexandre.torgue,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Russell King (Oracle),
David Wu, stable, netdev, linux-stm32, linux-arm-kernel, bpf
On Sun, Nov 22, 2026 at 12:20 PM Sam Edwards <cfsworks@gmail.com> wrote:
>
> On Sun, Nov 22, 2026 at 10:01 AM Nicolai Buchwitz <nb@tipi-net.de> wrote:
> >
> > Hi Anandu
> >
> > On 20.11.2026 08:49, Anandu Padinhare wrote:
> >
> > > [...]
> >
> > > @@ -6164,6 +6205,8 @@ static int stmmac_napi_poll_rx(struct napi_struct
> > > *napi, int budget)
> > > u64_stats_update_end(&rxq_stats->napi_syncp);
> > >
> > > work_done = stmmac_rx(priv, budget, chan);
> > > + if (unlikely(stmmac_rx_refill_needed(priv, chan)))
> > > + stmmac_rx_refill_timer_arm(ch);
> >
> > After a successful retry, doesn't this leave the last received frame in
> > the ring until the next RX irq? Could the poll refill first?
>
> Do you mean "first as well" or "first instead"? Because "instead" can
> cause avoidable packet loss:
> 1) Initially, network is idle and ring is full of empty DMA buffers
> 2) A burst of exactly one ring's worth of packets arrives
> 3) The RX irq fires and stmmac_rx() attempts its refill-first (none
> needed) then depletes the ring to the maximally-dirty state; the
> refill timer is armed
Thinking about it more: the "unreachable packet" problem happens at
this point too, even with the "first as well" behavior.
Maybe the best way to resolve it is to adopt stmmac_rx_zc()'s behavior
of refilling during the loop?
> 4) During the 10ms timer period, more traffic arrives
> 5) The RX irq doesn't fire again because no additional DMA is
> happening: there are no usable buffers in the ring. So we're forced to
> wait out the timer.
> 6) Any packets during this time (beyond the RxFIFO's capacity) are
> discarded by the hardware
>
> But, "first as well" sounds good to me: before entering the main loop,
> refill 1 buffer (if possible) just to ensure either the IRQ fires
> again immediately (if the FIFO is holding onto another packet for us),
> or the inaccessible ring slot is clean (if the FIFO is empty).
>
> Cheers,
> Sam
>
> >
> > > [...]
> >
> > Regards,
> > Nicolai
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: stmmac: retry a failed RX refill from a timer
2026-11-22 21:02 ` Sam Edwards
@ 2026-11-22 21:09 ` Nicolai Buchwitz
2026-11-22 21:34 ` Sam Edwards
0 siblings, 1 reply; 10+ messages in thread
From: Nicolai Buchwitz @ 2026-11-22 21:09 UTC (permalink / raw)
To: Sam Edwards
Cc: Anandu Padinhare, maxime.chevallier, andrew+netdev, davem,
edumazet, kuba, pabeni, mcoquelin.stm32, alexandre.torgue,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Russell King (Oracle),
David Wu, stable, netdev, linux-stm32, linux-arm-kernel, bpf
Hi Sam
On 22.11.2026 22:02, Sam Edwards wrote:
> [...]
>> Do you mean "first as well" or "first instead"? Because "instead" can
>> cause avoidable packet loss:
>> 1) Initially, network is idle and ring is full of empty DMA buffers
>> 2) A burst of exactly one ring's worth of packets arrives
>> 3) The RX irq fires and stmmac_rx() attempts its refill-first (none
>> needed) then depletes the ring to the maximally-dirty state; the
>> refill timer is armed
>
> Thinking about it more: the "unreachable packet" problem happens at
> this point too, even with the "first as well" behavior.
>
> Maybe the best way to resolve it is to adopt stmmac_rx_zc()'s behavior
> of refilling during the loop?
>
Only if the ring is no bigger than the NAPI budget, right?
Otherwise tne poll can't empty it unless a refill failed, and refill
first
covers that.
Refill in the loop sounds good, but this would be IMHO a net-next
follow-up.
> [...]
Regards
Nicolai
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: stmmac: retry a failed RX refill from a timer
2026-11-22 21:09 ` Nicolai Buchwitz
@ 2026-11-22 21:34 ` Sam Edwards
2026-11-22 22:14 ` Nicolai Buchwitz
0 siblings, 1 reply; 10+ messages in thread
From: Sam Edwards @ 2026-11-22 21:34 UTC (permalink / raw)
To: Nicolai Buchwitz
Cc: Anandu Padinhare, maxime.chevallier, andrew+netdev, davem,
edumazet, kuba, pabeni, mcoquelin.stm32, alexandre.torgue,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Russell King (Oracle),
David Wu, stable, netdev, linux-stm32, linux-arm-kernel, bpf
On Sun, Nov 22, 2026 at 1:09 PM Nicolai Buchwitz <nb@tipi-net.de> wrote:
>
> Hi Sam
>
> On 22.11.2026 22:02, Sam Edwards wrote:
>
> > [...]
>
> >> Do you mean "first as well" or "first instead"? Because "instead" can
> >> cause avoidable packet loss:
> >> 1) Initially, network is idle and ring is full of empty DMA buffers
> >> 2) A burst of exactly one ring's worth of packets arrives
> >> 3) The RX irq fires and stmmac_rx() attempts its refill-first (none
> >> needed) then depletes the ring to the maximally-dirty state; the
> >> refill timer is armed
> >
> > Thinking about it more: the "unreachable packet" problem happens at
> > this point too, even with the "first as well" behavior.
> >
> > Maybe the best way to resolve it is to adopt stmmac_rx_zc()'s behavior
> > of refilling during the loop?
> >
>
> Only if the ring is no bigger than the NAPI budget, right?
Right, but as pointed out in b6cb4541853c7 ("net: stmmac: avoid rx
queue overrun" -- the commit that introduced the "leave one behind"
behavior) the ring can be as small as 64 and that commit's author was
seeing budgets larger than that.
Perhaps NAPI should only be told to stop polling if we either:
a) Reach the clean tail of the ring (so we *know* there are no further
packets for us)
b) Run out of memory and have to arm the retry timer
Thoughts?
Sam
>
> Otherwise tne poll can't empty it unless a refill failed, and refill
> first
> covers that.
>
> Refill in the loop sounds good, but this would be IMHO a net-next
> follow-up.
>
> > [...]
>
> Regards
> Nicolai
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: stmmac: retry a failed RX refill from a timer
2026-11-22 21:34 ` Sam Edwards
@ 2026-11-22 22:14 ` Nicolai Buchwitz
2026-11-23 6:24 ` Anandu Padinhare
0 siblings, 1 reply; 10+ messages in thread
From: Nicolai Buchwitz @ 2026-11-22 22:14 UTC (permalink / raw)
To: Sam Edwards
Cc: Anandu Padinhare, maxime.chevallier, andrew+netdev, davem,
edumazet, kuba, pabeni, mcoquelin.stm32, alexandre.torgue,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Russell King (Oracle),
David Wu, stable, netdev, linux-stm32, linux-arm-kernel, bpf
On 22.11.2026 22:34, Sam Edwards wrote:
> [...]
>> Only if the ring is no bigger than the NAPI budget, right?
>
> Right, but as pointed out in b6cb4541853c7 ("net: stmmac: avoid rx
> queue overrun" -- the commit that introduced the "leave one behind"
> behavior) the ring can be as small as 64 and that commit's author was
> seeing budgets larger than that.
Fair, a 64 entry ring is enough to hit it.
>
> Perhaps NAPI should only be told to stop polling if we either:
> a) Reach the clean tail of the ring (so we *know* there are no further
> packets for us)
> b) Run out of memory and have to arm the retry timer
>
> Thoughts?
Agreed, simpler than refill in the loop. If stmmac_rx() stopped at
dirty_rx and the refill worked, return the full budget so NAPI polls
again.
Anandu, could you fold that into v2?
> [...]
Regards
Nicolai
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: stmmac: retry a failed RX refill from a timer
2026-11-22 22:14 ` Nicolai Buchwitz
@ 2026-11-23 6:24 ` Anandu Padinhare
0 siblings, 0 replies; 10+ messages in thread
From: Anandu Padinhare @ 2026-11-23 6:24 UTC (permalink / raw)
To: Nicolai Buchwitz, Sam Edwards
Cc: maxime.chevallier@bootlin.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, mcoquelin.stm32@gmail.com,
alexandre.torgue@foss.st.com, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
Russell King (Oracle), David Wu, stable@vger.kernel.org,
netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org
On 22.11.2026 23:14, Nicolai Buchwitz wrote:
> Agreed, simpler than refill in the loop. If stmmac_rx() stopped at
> dirty_rx and the refill worked, return the full budget so NAPI polls
> again.
>
> Anandu, could you fold that into v2?
Yes, thanks Nicolai and Sam. v2 will do that, and will also check
dirty_rx before reading the descriptor status, so a retry does not
count that frame again (the Medium item from Sashiko). Refill inside
the loop I'll leave out of this fix.
I'll test it on the SC598 and then post v2.
Regards,
Anandu
pw-bot: cr
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] net: stmmac: retry a failed RX refill from a timer
2026-11-20 7:49 [PATCH net] net: stmmac: retry a failed RX refill from a timer Anandu Padinhare
2026-11-22 18:01 ` Nicolai Buchwitz
@ 2026-11-24 8:02 ` netdev-bot+sashiko
1 sibling, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 8:02 UTC (permalink / raw)
To: Anandu.Padinhare
Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
mcoquelin.stm32, alexandre.torgue, ast, daniel, hawk,
john.fastabend, sdf, cfsworks, rmk+kernel, david.wu, stable,
netdev, linux-stm32, linux-arm-kernel, bpf
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 (2) · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] net: stmmac: stmmac_rx() runs receive loop before
stmmac_rx_refill() on retry
- [Low] The new block comment above stmmac_rx_refill_needed()
(stmmac_main.c lines 268-271) says: "The RX DMA suspends without an…
Pre-existing issues:
- [High] Suspend/resume while an RX refill is failing hands unpopulated
and stale descriptors back to the DMA.
- [High] stmmac_setup_tc_block_cb() can leave a channel's DMA RX
interrupt masked, which stalls RX on that channel.
--
net: stmmac: retry a failed RX refill from a timer
This commit adds a per-channel timer to stmmac. When a poll leaves at most
STMMAC_RX_REFILL_THRESH slots with the DMA, the timer schedules RX NAPI
10 ms later, so a refill that failed in page_pool is retried without
waiting for an RX interrupt. The timer is cancelled after rx_napi is
disabled, and stmmac_enable_all_queues() re-arms it if the ring is still
short of buffers.
Link: https://lore.kernel.org/netdev/20260331195927.3353cc6d@kernel.org/
Link: https://lore.kernel.org/netdev/20260402174049.0ac088cc@kernel.org/
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index a685ce4638f61..ad9873aaf2dba 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
[ ... ]
> @@ -263,6 +265,32 @@ static void stmmac_verify_args(void)
> pr_warn("stmmac: module parameter 'flow_ctrl' is obsolete - please remove from your module configuration\n");
> }
>
> +/* The RX DMA suspends without an interrupt once it has used all its buffers,
> + * so a refill that failed for lack of memory would never be retried. Retry it
> + * from a timer when few slots are left with the DMA.
> + */
[Severity: Low]
This isn't a bug, but is the first sentence of this comment accurate for
dwmac4?
In dwmac4_dma.h, DMA_CHAN_INTR_ABNORMAL includes DMA_CHAN_INTR_ENA_RBU.
That macro is part of DMA_CHAN_INTR_DEFAULT_MASK, which is written to
DMA_CHAN_INTR_ENA. dwmac4_dma_interrupt() then gets the RBU status but
only counts it:
if (unlikely(intr_status & DMA_CHAN_STATUS_RBU))
x->rx_buf_unav_irq++;
The sentence is true for dwxgmac2, where XGMAC_DMA_INT_DEFAULT_EN has no
RBUE, and for dwmac1000. The commit message also says the RBU interrupt
"is not enabled on every core and kernel version".
Could the comment say that RBU is not enabled on every core, or is not
used to drive the refill, rather than that there is no interrupt?
> +static bool stmmac_rx_refill_needed(struct stmmac_priv *priv, u32 queue)
> +{
> + struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
> +
> + return CIRC_SPACE(rx_q->cur_rx, rx_q->dirty_rx,
> + priv->dma_conf.dma_rx_size) < STMMAC_RX_REFILL_THRESH;
> +}
[ ... ]
> @@ -328,8 +360,17 @@ static void stmmac_enable_all_queues(struct stmmac_priv *priv)
> continue;
> }
>
> - if (queue < rx_queues_cnt)
> + if (queue < rx_queues_cnt) {
> + /* Disabling the queues cancelled any pending refill
> + * retry, but the ring may have been kept as it was.
> + * Check it while no poll can run.
> + */
> + bool refill = stmmac_rx_refill_needed(priv, queue);
[Severity: High]
This is a pre-existing issue, but does the "ring may have been kept as it
was" case also need to cover stmmac_resume() after a failed refill?
When stmmac_rx_refill() stops at a page_pool allocation failure, the
slots in [dirty_rx, cur_rx) keep buf->page == NULL. The DMA write-back
has already overwritten their buffer address words (RDES0/RDES1 on
dwmac4).
If the system suspends at that point, stmmac_suspend() leaves the ring as
it is, and resume does:
stmmac_resume()
stmmac_reset_queues_param()
stmmac_reset_rx_queue()
rx_q->cur_rx = 0;
rx_q->dirty_rx = 0;
stmmac_clear_descriptors()
stmmac_clear_rx_descriptors()
stmmac_init_rx_desc()
dwmac4_rd_init_rx_desc()
dwmac4_set_rx_owner(p, disable_rx_ic);
stmmac_hw_setup()
stmmac_init_dma_engine()
stmmac_set_queue_rx_tail_ptr(priv, rx_q, chan,
rx_q->buf_alloc_num);
stmmac_enable_all_queues()
Nothing in this sequence rewrites the buffer addresses from buf_pool.
Every descriptor gets the OWN bit, and the tail pointer gives the whole
ring to the DMA.
Could the DMA then write received frames to addresses taken from old
write-back data? Those may be garbage, or the stale DMA address of a page
already returned to the stack or page_pool.
When stmmac_rx() later reaches such a slot, it would call
dma_sync_single_for_cpu() on a stale buf->addr and page_address() on a
NULL buf->page, and pass the result to xdp_prepare_buff() and
napi_build_skb().
The new check here does not see this case. Resume has just set cur_rx
and dirty_rx to the same value, so stmmac_rx_refill_needed() returns
false and no retry is armed.
Even if a retry were armed, stmmac_rx_dirty() would return 0, so
stmmac_rx_refill() would not fill the NULL slots before the DMA uses
them.
> +
> napi_enable(&ch->rx_napi);
> + if (refill)
> + stmmac_rx_refill_timer_arm(ch);
> + }
[Severity: High]
This is a pre-existing issue, but can stmmac_setup_tc_block_cb() leave the
channel's DMA RX interrupt masked? The new re-arm logic does not cover
that case.
Consider this sequence:
CPU1 (RX interrupt and NAPI)
stmmac_napi_check()
stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 1, 0);
__napi_schedule()
stmmac_napi_poll_rx()
work_done == budget, so the IRQ re-enable is skipped
CPU2 (CAP_NET_ADMIN adds a tc u32 or flower offload rule)
stmmac_setup_tc_block_cb()
__stmmac_disable_all_queues()
napi_disable() <- sets NAPI_STATE_DISABLE
Then __napi_poll() in net/core/dev.c does this:
if (unlikely(napi_disable_pending(n))) {
napi_complete(n);
return work;
}
The core completes NAPI itself and napi_disable() returns. The only place
the RX IRQ is re-enabled, in stmmac_napi_poll_rx(), never runs:
if (work_done < budget && napi_complete_done(napi, work_done)) {
...
stmmac_enable_dma_irq(priv, priv->ioaddr, chan, 1, 0);
stmmac_enable_all_queues() then calls napi_enable(). It arms the refill
timer only when stmmac_rx_refill_needed() is true, which is usually not
the case because stmmac_rx() has refilled the ring.
The open, resume and XDP setup paths call stmmac_enable_all_dma_irq() or
schedule a poll. stmmac_setup_tc_block_cb() does neither.
On dwmac4, the RBU interrupt recovers the channel once the ring fills.
dwxgmac2 also uses dwmac510_tc_ops, but RBUE is not in
XGMAC_DMA_INT_DEFAULT_EN.
With per-channel MSI, or with RX-only traffic, would the dwxgmac2 channel
stay dead until the interface is reopened?
Would scheduling rx_napi after napi_enable() in this path fix both this
stall and the refill case?
[ ... ]
> @@ -6164,6 +6205,8 @@ static int stmmac_napi_poll_rx(struct napi_struct *napi, int budget)
> u64_stats_update_end(&rxq_stats->napi_syncp);
>
> work_done = stmmac_rx(priv, budget, chan);
> + if (unlikely(stmmac_rx_refill_needed(priv, chan)))
> + stmmac_rx_refill_timer_arm(ch);
> if (work_done < budget && napi_complete_done(napi, work_done)) {
> unsigned long flags;
>
[Severity: Medium]
Once memory is available again, does the retry poll deliver the frame
that is already waiting in the ring?
When the ring has run completely dry, stmmac_rx() stops on the last
descriptor the DMA completed, at rx_q->cur_rx. It stops there because
the next entry equals rx_q->dirty_rx:
next_entry = STMMAC_NEXT_ENTRY(rx_q->cur_rx,
priv->dma_conf.dma_rx_size);
if (unlikely(next_entry == rx_q->dirty_rx))
break;
The refill only runs after the receive loop, at the end of stmmac_rx().
The timer-driven poll that finally succeeds then does this:
stmmac_rx_refill_timer()
napi_schedule(&ch->rx_napi)
stmmac_napi_poll_rx()
stmmac_rx()
receive loop breaks at once on next_entry == rx_q->dirty_rx,
count == 0
stmmac_rx_refill() <- succeeds, dirty_rx catches up to cur_rx
stmmac_rx_refill_needed() <- false, timer not re-armed
napi_complete_done(napi, 0)
The DMA wrote the descriptor at cur_rx before it suspended, and it
resumes at the entry after it. It will not raise another RX interrupt
for that descriptor, and nothing else schedules a poll.
So the frame stays in the ring until another packet arrives on that
queue. If the frame spans several descriptors, the same applies to its
last segment, with the partial skb kept in rx_q->state.skb. On a quiet
queue that can take a long time, and this is the recovery path the
patch adds.
There is a smaller effect while allocations keep failing. Every 10 ms
retry calls stmmac_rx_status() again on the same descriptor at cur_rx
before it breaks. Any per-frame counters that call updates in
priv->xstats are counted again on each retry.
Could stmmac_rx() go back through the receive loop when the refill has
made room? Or could stmmac_napi_poll_rx() schedule another poll when
the refill advanced dirty_rx? Another option would be to refill before
the receive loop when the ring is full. Which of these fits the ring
accounting from commit 0bb05e6adfa9 best?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/MA0PR01MB921746F36D90C7080287ACC9FD782%40MA0PR01MB9217.INDPRD01.PROD.OUTLOOK.COM
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-11-24 8:02 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 7:49 [PATCH net] net: stmmac: retry a failed RX refill from a timer Anandu Padinhare
2026-11-22 18:01 ` Nicolai Buchwitz
2026-11-22 20:20 ` Sam Edwards
2026-11-22 20:37 ` Nicolai Buchwitz
2026-11-22 21:02 ` Sam Edwards
2026-11-22 21:09 ` Nicolai Buchwitz
2026-11-22 21:34 ` Sam Edwards
2026-11-22 22:14 ` Nicolai Buchwitz
2026-11-23 6:24 ` Anandu Padinhare
2026-11-24 8:02 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox