* [PATCH] net: stmmac: close reset IRQ window and avoid double free
@ 2026-03-20 6:19 yangg9
2026-03-20 8:41 ` Russell King (Oracle)
2026-03-20 15:41 ` Russell King (Oracle)
0 siblings, 2 replies; 3+ messages in thread
From: yangg9 @ 2026-03-20 6:19 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, kuba, yangg9, edumazet, pabeni,
mcoquelin.stm32, alexandre.torgue, rmk+kernel, maxime.chevallier,
vladimir.oltean, linux-stm32, linux-arm-kernel, linux-kernel
From: yangg9 <yangg9@xiaopeng.com>
During reset, stmmac_reset_subtask() used to set STMMAC_DOWN before IRQs
were freed in __stmmac_release(). That leaves a window where interrupts can
still fire after the device is marked down, which may lead to interrupt
storms while the interface is transitioning.
Move stmmac_free_irq() earlier in the reset flow, before setting
STMMAC_DOWN, so the reset path no longer has that interrupt window.
Since IRQs are now released in stmmac_reset_subtask(), guard IRQ release in
__stmmac_release() with STMMAC_DOWN to avoid a second free_irq() during the
same reset sequence.
This removes the interrupt-storm window in reset and prevents double IRQ
release.
Signed-off-by: yangg9 <yangg9@xiaopeng.com>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 124d7a00f9f0..99b661379d9c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -4212,8 +4212,9 @@ static void __stmmac_release(struct net_device *dev)
netif_tx_disable(dev);
- /* Free the IRQ lines */
- stmmac_free_irq(dev, REQ_IRQ_ERR_ALL, 0);
+ /* In reset flow IRQs can be freed before dev_close(). */
+ if (!test_bit(STMMAC_DOWN, &priv->state))
+ stmmac_free_irq(dev, REQ_IRQ_ERR_ALL, 0);
/* Stop TX/RX DMA and clear the descriptors */
stmmac_stop_all_dma(priv);
@@ -7331,6 +7332,8 @@ static void stmmac_reset_subtask(struct stmmac_priv *priv)
while (test_and_set_bit(STMMAC_RESETING, &priv->state))
usleep_range(1000, 2000);
+ stmmac_free_irq(priv->dev, REQ_IRQ_ERR_ALL, 0);
+
set_bit(STMMAC_DOWN, &priv->state);
dev_close(priv->dev);
dev_open(priv->dev, NULL);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: stmmac: close reset IRQ window and avoid double free
2026-03-20 6:19 [PATCH] net: stmmac: close reset IRQ window and avoid double free yangg9
@ 2026-03-20 8:41 ` Russell King (Oracle)
2026-03-20 15:41 ` Russell King (Oracle)
1 sibling, 0 replies; 3+ messages in thread
From: Russell King (Oracle) @ 2026-03-20 8:41 UTC (permalink / raw)
To: yangg9
Cc: netdev, andrew+netdev, davem, kuba, yangg9, edumazet, pabeni,
mcoquelin.stm32, alexandre.torgue, maxime.chevallier,
vladimir.oltean, linux-stm32, linux-arm-kernel, linux-kernel
On Fri, Mar 20, 2026 at 02:19:55PM +0800, yangg9 wrote:
> From: yangg9 <yangg9@xiaopeng.com>
>
> During reset, stmmac_reset_subtask() used to set STMMAC_DOWN before IRQs
> were freed in __stmmac_release(). That leaves a window where interrupts can
> still fire after the device is marked down, which may lead to interrupt
> storms while the interface is transitioning.
>
> Move stmmac_free_irq() earlier in the reset flow, before setting
> STMMAC_DOWN, so the reset path no longer has that interrupt window.
>
> Since IRQs are now released in stmmac_reset_subtask(), guard IRQ release in
> __stmmac_release() with STMMAC_DOWN to avoid a second free_irq() during the
> same reset sequence.
>
> This removes the interrupt-storm window in reset and prevents double IRQ
> release.
>
> Signed-off-by: yangg9 <yangg9@xiaopeng.com>
I want to review this, but from this afternoon I may be out of range of
LTE signal for about 24h, and thus have no Internet access.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: stmmac: close reset IRQ window and avoid double free
2026-03-20 6:19 [PATCH] net: stmmac: close reset IRQ window and avoid double free yangg9
2026-03-20 8:41 ` Russell King (Oracle)
@ 2026-03-20 15:41 ` Russell King (Oracle)
1 sibling, 0 replies; 3+ messages in thread
From: Russell King (Oracle) @ 2026-03-20 15:41 UTC (permalink / raw)
To: yangg9
Cc: netdev, andrew+netdev, davem, kuba, yangg9, edumazet, pabeni,
mcoquelin.stm32, alexandre.torgue, maxime.chevallier,
vladimir.oltean, linux-stm32, linux-arm-kernel, linux-kernel
On Fri, Mar 20, 2026 at 02:19:55PM +0800, yangg9 wrote:
> From: yangg9 <yangg9@xiaopeng.com>
>
> During reset, stmmac_reset_subtask() used to set STMMAC_DOWN before IRQs
> were freed in __stmmac_release(). That leaves a window where interrupts can
> still fire after the device is marked down, which may lead to interrupt
> storms while the interface is transitioning.
>
> Move stmmac_free_irq() earlier in the reset flow, before setting
> STMMAC_DOWN, so the reset path no longer has that interrupt window.
>
> Since IRQs are now released in stmmac_reset_subtask(), guard IRQ release in
> __stmmac_release() with STMMAC_DOWN to avoid a second free_irq() during the
> same reset sequence.
>
> This removes the interrupt-storm window in reset and prevents double IRQ
> release.
So, some points that need to be raised:
- What is the point of STMMAC_DOWN?
STMMAC_DOWN isn't set when the interface is administratively brought
down, the only place where this flag is set is in
stmmac_reset_subtask() and later cleared.
The flag appears to prevent stmmac_service_event_schedule() queueing
the service task while it's still operating, but STMMAC_SERVICE_SCHED
already does that.
It also prevents interrupts being serviced, which causes your
interrupt storm. However, does this matter? Surely stmmac_release()
can already cope with the interrupt handlers being active, since
taking an interface administratively down involves interacting with
it in an active state - when a packet may be received.
It's also used in stmmac_xdp_xmit() and stmmac_xsk_wakeup() to block
further processing in those paths. However, for stmmac_xsk_wakeup()
the only path which calls stmmac_service_event_schedule() is
stmmac_global_err() which nautily calls netif_carrier_off() behind
phylink's back, which will corrupt phylink's state and lead to
phylink API calls being made in weird orders to the driver (this
needs to die.) However, stmmac_xsk_wakeup() checks whether the
carrier is on as well, which is a duplicate check.
So, here's the question: do we need to test STMMAC_DOWN in the
interrupt handlers at all? Can we delete those tests? As you seem
to have a way of triggering the reset subtask, please try removing
those tests from the interrupt handlers, thus simplifying the code
rather than trying a more complex solution.
Thanks.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-20 15:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-20 6:19 [PATCH] net: stmmac: close reset IRQ window and avoid double free yangg9
2026-03-20 8:41 ` Russell King (Oracle)
2026-03-20 15:41 ` Russell King (Oracle)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox