BPF List
 help / color / mirror / Atom feed
* [PATCH net] net: stmmac: remove STMMAC_DOWN
@ 2026-12-01  9:12 Zxyan Zhu
  2026-12-02  9:04 ` Maxime Chevallier
  2026-12-02  9:13 ` sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: Zxyan Zhu @ 2026-12-01  9:12 UTC (permalink / raw)
  To: Maxime Chevallier, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev
  Cc: Andrew Lunn, Jose Abreu, Maxime Coquelin, Alexandre Torgue,
	Sebastian Andrzej Siewior, ClarkWilliams, Steven Rostedt,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Stanislav Fomichev, linux-stm32, linux-arm-kernel,
	linux-rt-devel, bpf, Zxyan Zhu

STMMAC_DOWN was introduced by commit 34877a15f787 ("net: stmmac: Rework and fix
TX Timeout code") to mark the window where stmmac_reset_subtask() runs
dev_close()/dev_open().  However, the flag is only ever set and cleared
inside stmmac_reset_subtask(), yet most of its call sites treat it as if
it meant "interface is down".  That mismatch is not just misleading, it
is the source of an interrupt storm.

On a PREEMPT_RT system, fault-injecting an uncorrectable dwxgmac2 safety
error (src3 FSM RX parity) while traffic is running makes
stmmac_global_err() schedule stmmac_reset_subtask(), which does
dev_close()/dev_open().  While dev_close() blocks in synchronize_net()
waiting for an RCU grace period, a pending level-triggered DMA interrupt
makes the handlers bail out early:

        /* Check if adapter is up */
        if (test_bit(STMMAC_DOWN, &priv->state))
                return IRQ_HANDLED;

without clearing any interrupt status.  The level IRQ stays asserted, the
interrupt counter storms from ~2.7k to ~14M in about 28 s (~500k irqs/s),
starving the rcuc kthread so the RCU grace period never completes:

        rcu: INFO: rcu_preempt self-detected stall on CPU
        rcu:     0-....: (7499 ticks this GP) ... rcuc=7499 jiffies(starved)

        __wait_rcu_gp
        synchronize_rcu_normal
        synchronize_rcu_expedited
        synchronize_net
        dev_deactivate_many
        __dev_close_many
        netif_close_many
        netif_close
        dev_close
        stmmac_service_task

The board then panics on panic_on_rcu_stall.

The STMMAC_DOWN early-returns do not actually protect anything: the
concurrent teardown is already serialized by free_irq(), which
synchronizes with in-flight handlers before freeing the DMA descriptors,
so the interrupt handlers can run normally during the reset window.
Remove the flag entirely and let the handlers clear the interrupt status
as they normally do.  This matches the direction suggested by the stmmac
maintainer: the flag only causes problems while the call sites already
work without it.

The remaining uses are covered by existing mechanisms instead of a
dedicated flag: stmmac_service_event_schedule() is already guarded by
STMMAC_SERVICE_SCHED; stmmac_xdp_xmit() and stmmac_xsk_wakeup() now test
STMMAC_RESETING, which stmmac_reset_subtask() sets before dev_close() and
clears after dev_open(), so the whole reset window (including the
ndo_open() half, where netif_running() is already true before the DMA
rings are rebuilt) is rejected; and stmmac_reset_subtask() is guarded by
STMMAC_RESET_REQUESTED plus STMMAC_RESETING.

With the fix, on a local board (dwxgmac2), injecting the same safety
error while traffic is running completes the reset cleanly and the main
IRQ counter no longer storms.

Fixes: 34877a15f787 ("net: stmmac: Rework and fix TX Timeout code")
Suggested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Link: https://lore.kernel.org/netdev/20240327110142.159851-1-cathy.cai@unisoc.com/
Signed-off-by: Zxyan Zhu <zxyan0222@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac.h  |  1 -
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 32 ++-----------------
 2 files changed, 3 insertions(+), 30 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index b76acfe0d958..f5c0ff3af1d2 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -397,7 +397,6 @@ struct stmmac_priv {
 };
 
 enum stmmac_state {
-	STMMAC_DOWN,
 	STMMAC_RESET_REQUESTED,
 	STMMAC_RESETING,
 	STMMAC_SERVICE_SCHED,
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index a685ce4638f6..7f7be965604e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -337,8 +337,7 @@ static void stmmac_enable_all_queues(struct stmmac_priv *priv)
 
 static void stmmac_service_event_schedule(struct stmmac_priv *priv)
 {
-	if (!test_bit(STMMAC_DOWN, &priv->state) &&
-	    !test_and_set_bit(STMMAC_SERVICE_SCHED, &priv->state))
+	if (!test_and_set_bit(STMMAC_SERVICE_SCHED, &priv->state))
 		queue_work(priv->wq, &priv->service_task);
 }
 
@@ -6487,10 +6486,6 @@ static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
 	struct net_device *dev = (struct net_device *)dev_id;
 	struct stmmac_priv *priv = netdev_priv(dev);
 
-	/* Check if adapter is up */
-	if (test_bit(STMMAC_DOWN, &priv->state))
-		return IRQ_HANDLED;
-
 	/* Check ASP error if it isn't delivered via an individual IRQ */
 	if (priv->sfty_irq <= 0 && stmmac_safety_feat_interrupt(priv))
 		return IRQ_HANDLED;
@@ -6509,10 +6504,6 @@ static irqreturn_t stmmac_mac_interrupt(int irq, void *dev_id)
 	struct net_device *dev = (struct net_device *)dev_id;
 	struct stmmac_priv *priv = netdev_priv(dev);
 
-	/* Check if adapter is up */
-	if (test_bit(STMMAC_DOWN, &priv->state))
-		return IRQ_HANDLED;
-
 	/* To handle Common interrupts */
 	stmmac_common_interrupt(priv);
 
@@ -6527,10 +6518,6 @@ static irqreturn_t stmmac_safety_interrupt(int irq, void *dev_id)
 	struct net_device *dev = (struct net_device *)dev_id;
 	struct stmmac_priv *priv = netdev_priv(dev);
 
-	/* Check if adapter is up */
-	if (test_bit(STMMAC_DOWN, &priv->state))
-		return IRQ_HANDLED;
-
 	/* Check if a fatal error happened */
 	stmmac_safety_feat_interrupt(priv);
 
@@ -6548,10 +6535,6 @@ static irqreturn_t stmmac_msi_intr_tx(int irq, void *data)
 	dma_conf = container_of(tx_q, struct stmmac_dma_conf, tx_queue[chan]);
 	priv = container_of(dma_conf, struct stmmac_priv, dma_conf);
 
-	/* Check if adapter is up */
-	if (test_bit(STMMAC_DOWN, &priv->state))
-		return IRQ_HANDLED;
-
 	status = stmmac_napi_check(priv, chan, DMA_DIR_TX);
 
 	if (unlikely(status & tx_hard_error_bump_tc)) {
@@ -6574,10 +6557,6 @@ static irqreturn_t stmmac_msi_intr_rx(int irq, void *data)
 	dma_conf = container_of(rx_q, struct stmmac_dma_conf, rx_queue[chan]);
 	priv = container_of(dma_conf, struct stmmac_priv, dma_conf);
 
-	/* Check if adapter is up */
-	if (test_bit(STMMAC_DOWN, &priv->state))
-		return IRQ_HANDLED;
-
 	stmmac_napi_check(priv, chan, DMA_DIR_RX);
 
 	return IRQ_HANDLED;
@@ -7150,7 +7129,7 @@ static int stmmac_xdp_xmit(struct net_device *dev, int num_frames,
 	int i, nxmit = 0;
 	int queue;
 
-	if (unlikely(test_bit(STMMAC_DOWN, &priv->state)))
+	if (unlikely(test_bit(STMMAC_RESETING, &priv->state)))
 		return -ENETDOWN;
 
 	if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
@@ -7418,7 +7397,7 @@ int stmmac_xsk_wakeup(struct net_device *dev, u32 queue, u32 flags)
 	struct stmmac_tx_queue *tx_q;
 	struct stmmac_channel *ch;
 
-	if (test_bit(STMMAC_DOWN, &priv->state) ||
+	if (test_bit(STMMAC_RESETING, &priv->state) ||
 	    !netif_carrier_ok(priv->dev))
 		return -ENETDOWN;
 
@@ -7527,9 +7506,6 @@ static void stmmac_reset_subtask(struct stmmac_priv *priv)
 {
 	if (!test_and_clear_bit(STMMAC_RESET_REQUESTED, &priv->state))
 		return;
-	if (test_bit(STMMAC_DOWN, &priv->state))
-		return;
-
 	netdev_err(priv->dev, "Reset adapter.\n");
 
 	rtnl_lock();
@@ -7537,10 +7513,8 @@ static void stmmac_reset_subtask(struct stmmac_priv *priv)
 	while (test_and_set_bit(STMMAC_RESETING, &priv->state))
 		usleep_range(1000, 2000);
 
-	set_bit(STMMAC_DOWN, &priv->state);
 	dev_close(priv->dev);
 	dev_open(priv->dev, NULL);
-	clear_bit(STMMAC_DOWN, &priv->state);
 	clear_bit(STMMAC_RESETING, &priv->state);
 	rtnl_unlock();
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: stmmac: remove STMMAC_DOWN
  2026-12-01  9:12 [PATCH net] net: stmmac: remove STMMAC_DOWN Zxyan Zhu
@ 2026-12-02  9:04 ` Maxime Chevallier
  2026-12-02  9:13 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: Maxime Chevallier @ 2026-12-02  9:04 UTC (permalink / raw)
  To: Zxyan Zhu, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev
  Cc: Andrew Lunn, Jose Abreu, Maxime Coquelin, Alexandre Torgue,
	Sebastian Andrzej Siewior, ClarkWilliams, Steven Rostedt,
	Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
	John Fastabend, Stanislav Fomichev, linux-stm32, linux-arm-kernel,
	linux-rt-devel, bpf

Hi,

On 12/1/26 10:12, Zxyan Zhu wrote:
> STMMAC_DOWN was introduced by commit 34877a15f787 ("net: stmmac: Rework and fix
> TX Timeout code") to mark the window where stmmac_reset_subtask() runs
> dev_close()/dev_open().  However, the flag is only ever set and cleared
> inside stmmac_reset_subtask(), yet most of its call sites treat it as if
> it meant "interface is down".  That mismatch is not just misleading, it
> is the source of an interrupt storm.
> 
> On a PREEMPT_RT system, fault-injecting an uncorrectable dwxgmac2 safety
> error (src3 FSM RX parity) while traffic is running makes
> stmmac_global_err() schedule stmmac_reset_subtask(), which does
> dev_close()/dev_open().  While dev_close() blocks in synchronize_net()
> waiting for an RCU grace period, a pending level-triggered DMA interrupt
> makes the handlers bail out early:
> 
>         /* Check if adapter is up */
>         if (test_bit(STMMAC_DOWN, &priv->state))
>                 return IRQ_HANDLED;
> 
> without clearing any interrupt status.  The level IRQ stays asserted, the
> interrupt counter storms from ~2.7k to ~14M in about 28 s (~500k irqs/s),
> starving the rcuc kthread so the RCU grace period never completes:
> 
>         rcu: INFO: rcu_preempt self-detected stall on CPU
>         rcu:     0-....: (7499 ticks this GP) ... rcuc=7499 jiffies(starved)
> 
>         __wait_rcu_gp
>         synchronize_rcu_normal
>         synchronize_rcu_expedited
>         synchronize_net
>         dev_deactivate_many
>         __dev_close_many
>         netif_close_many
>         netif_close
>         dev_close
>         stmmac_service_task
> 
> The board then panics on panic_on_rcu_stall.
> 
> The STMMAC_DOWN early-returns do not actually protect anything: the
> concurrent teardown is already serialized by free_irq(), which
> synchronizes with in-flight handlers before freeing the DMA descriptors,
> so the interrupt handlers can run normally during the reset window.
> Remove the flag entirely and let the handlers clear the interrupt status
> as they normally do.  This matches the direction suggested by the stmmac
> maintainer: the flag only causes problems while the call sites already
> work without it.
> 
> The remaining uses are covered by existing mechanisms instead of a
> dedicated flag: stmmac_service_event_schedule() is already guarded by
> STMMAC_SERVICE_SCHED; stmmac_xdp_xmit() and stmmac_xsk_wakeup() now test
> STMMAC_RESETING, which stmmac_reset_subtask() sets before dev_close() and
> clears after dev_open(), so the whole reset window (including the
> ndo_open() half, where netif_running() is already true before the DMA
> rings are rebuilt) is rejected; and stmmac_reset_subtask() is guarded by
> STMMAC_RESET_REQUESTED plus STMMAC_RESETING.
> 
> With the fix, on a local board (dwxgmac2), injecting the same safety
> error while traffic is running completes the reset cleanly and the main
> IRQ counter no longer storms.
> 
> Fixes: 34877a15f787 ("net: stmmac: Rework and fix TX Timeout code")
> Suggested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> Link: https://lore.kernel.org/netdev/20240327110142.159851-1-cathy.cai@unisoc.com/
> Signed-off-by: Zxyan Zhu <zxyan0222@gmail.com>

Thanks for working on this. The commit log is quite verbose and the
"why" is drowned in details, if you need to resend when sashiko/clashiko
look at this, feel free to reduce a bit the commit message or even
better, write it by hand :)

Anyway,

Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>

Maxime


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: stmmac: remove STMMAC_DOWN
  2026-12-01  9:12 [PATCH net] net: stmmac: remove STMMAC_DOWN Zxyan Zhu
  2026-12-02  9:04 ` Maxime Chevallier
@ 2026-12-02  9:13 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-02  9:13 UTC (permalink / raw)
  To: Zxyan Zhu; +Cc: linux-rt-devel, bpf, linux-kernel

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] net: stmmac: use-after-free in stmmac_xdp_xmit() [1]
--

commit b3472c0c67723fdc6361e7e9ee949e73296b5d41
Author: Zxyan Zhu <zxyan0222@gmail.com>

net: stmmac: remove STMMAC_DOWN

This commit removes the STMMAC_DOWN state flag so interrupt handlers can
continue clearing interrupt status during a reset, and replaces the
remaining checks in stmmac_xdp_xmit() and stmmac_xsk_wakeup() with
STMMAC_RESETING.

Link: https://lore.kernel.org/netdev/20240327110142.159851-1-cathy.cai@unisoc.com/

> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index a685ce4638f61..7f7be965604e0 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
[ ... ]
> @@ -7150,7 +7129,7 @@ static int stmmac_xdp_xmit(struct net_device *dev, int num_frames,
>  	int i, nxmit = 0;
>  	int queue;
>  
> -	if (unlikely(test_bit(STMMAC_DOWN, &priv->state)))
> +	if (unlikely(test_bit(STMMAC_RESETING, &priv->state)))
>  		return -ENETDOWN;
>  
>  	if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))

[Severity: Critical]
This problem wasn't introduced by this patch, but can stmmac_xdp_xmit() and
stmmac_xdp_xmit_back() hit a use-after-free and NULL pointer dereference
[1] when racing with XSK pool setup?

CPU0                                  CPU1
stmmac_xdp_enable_pool()
  stmmac_disable_tx_queue()
    netif_tx_stop_queue(txq)
    __free_dma_tx_desc_resources()
      kfree(tx_q->tx_skbuff_dma)
      tx_q->dma_tx = NULL
                                      stmmac_xdp_xmit()
                                        __netif_tx_lock(nq, cpu)
                                        stmmac_xdp_xmit_xdpf()
                                          tx_q->tx_skbuff_dma[...]  <-- UAF
                                          stmmac_get_tx_desc()      <-- NULL

stmmac_disable_tx_queue() stops the netdev TX queue and frees the queue's
DMA descriptor ring and tx_skbuff_dma array without setting
STMMAC_RESETING.  Because stmmac_xdp_xmit() and stmmac_xdp_xmit_back() lock
the TX queue without checking netif_tx_queue_stopped(nq), a concurrent XDP
transmit proceeds into stmmac_xdp_xmit_xdpf() after the queue's descriptor
resources have been torn down.

[1] https://sashiko.dev/#/bug/linux-036a9552-9d2b-427c-9ba1-a4c73d79872e

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201091256.3000677-1-zxyan0222@gmail.com?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-02  9:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  9:12 [PATCH net] net: stmmac: remove STMMAC_DOWN Zxyan Zhu
2026-12-02  9:04 ` Maxime Chevallier
2026-12-02  9:13 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox