Hi,
On Thu, Dec 3, 2026 at 5:15 PM <netd…@kernel.org> wrote:
>
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 (1) · Medium: 1 · Low: 0
>
> 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] A fatal error raised during the reset window can now be
> consumed and its reset request silently dropped.
This is a known trade-off of removing STMMAC_DOWN. For a persistent
fault, the next error re-asserts the status and re-queues the service
task, so the device recovers; only a single fault landing exactly in the
narrow request_irq()..clear_bit(STMMAC_SERVICE_SCHED) window would strand
the request, leaving the device down (not a panic) until a link event or
an down/up.
The alternative fixes make it worse: re-checking STMMAC_RESET_REQUESTED
and re-queuing the work (or clearing STMMAC_SERVICE_SCHED before the
reset) turns a persistent fault into back-to-back dev_close()/dev_open()
cycles that hold rtnl_lock across synchronize_net() almost continuously.
The dropped-request window above is a much smaller cost than that.
>
> Pre-existing issues:
> - [High] This problem wasn't introduced by this patch, but it can cause a
> hang or use-after-free on driver removal.
Since it's orthogonal to the interrupt-storm fix here, I'd rather address
it in a separate patch than fold it into this one.
Thanks,
Zxyan
>
> --
>
> net: stmmac: remove STMMAC_DOWN
>
> This patch removes the STMMAC_DOWN state bit. That bit was only ever set
> inside stmmac_reset_subtask(), around dev_close()/dev_open(). The interrupt
> handlers no longer return early during the reset window, and
> stmmac_xdp_xmit() and stmmac_xsk_wakeup() test STMMAC_RESETING instead.
>
> Link: https://lore.kernel.org/netdev/2024…@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
> > @@ -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);
> > }
>
> [Severity: Medium]
> Can a reset request raised during the reset window get lost here?
>
> The commit message says stmmac_service_event_schedule() is "already
> guarded by STMMAC_SERVICE_SCHED". However, that bit stays set for the whole
> reset, because stmmac_service_task() clears it only after
> stmmac_reset_subtask() returns:
>
> stmmac_service_task() {
> stmmac_reset_subtask(priv);
> clear_bit(STMMAC_SERVICE_SCHED, &priv->state);
> }
>
> With the STMMAC_DOWN early returns gone, stmmac_interrupt(),
> stmmac_safety_interrupt() and (on GMAC4) stmmac_mac_interrupt() ->
> stmmac_dma_err_interrupt() now run normally during that window.
>
> In the dev_open() half, __stmmac_open() re-arms the safety features in
> stmmac_hw_setup(). It then calls phylink_start() and stmmac_request_irq()
> before dev_open() returns.
>
> If an uncorrectable safety error or fatal DMA error fires after the IRQs
> are requested, the handler consumes it. On XGMAC, dwxgmac3_handle_mac_err()
> writes the status back to clear it, and then:
>
> stmmac_safety_feat_interrupt()
> stmmac_global_err()
> netif_carrier_off(priv->dev);
> set_bit(STMMAC_RESET_REQUESTED, &priv->state);
> stmmac_service_event_schedule()
> test_and_set_bit(STMMAC_SERVICE_SCHED) returns 1, no queue_work()
>
> stmmac_reset_subtask() already consumed STMMAC_RESET_REQUESTED with
> test_and_clear_bit() before dev_close(), and nothing checks it again
> afterwards. The hardware status has been cleared, so the IRQ doesn't fire
> again.
>
> Wouldn't this leave the MAC running after an uncorrectable fault with no
> reset pending? If phylink had already resolved link-up, carrier also stays
> off. dev_watchdog() doesn't call ndo_tx_timeout while carrier is off.
> That means nothing seems to re-queue the service task until a link event
> or an admin down/up.
>
> A narrower form of this race existed before, between
> clear_bit(STMMAC_DOWN) and clear_bit(STMMAC_SERVICE_SCHED). Before this
> patch, though, the handlers did not touch latched errors during the rest
> of the reset window.
>
> Would it help to clear STMMAC_SERVICE_SCHED before calling
> stmmac_reset_subtask()? Alternatively, the service task could check
> STMMAC_RESET_REQUESTED again after clearing STMMAC_SERVICE_SCHED, and
> requeue the work if it is set.
>
> [ ... ]
>
> > @@ -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();
> > }
>
> [Severity: High]
> This isn't a bug introduced by this patch, but can this dev_open() run
> on a netdev that is being unregistered?
>
> stmmac_dvr_remove() doesn't cancel priv->service_task before teardown:
>
> stmmac_dvr_remove() {
> ...
> unregister_netdev(ndev);
> ...
> phylink_destroy(priv->phylink);
> ...
> stmmac_mdio_unregister(ndev);
>
> destroy_workqueue(priv->wq);
> ...
> }
>
> stmmac_global_err() can queue the work in two ways:
>
> - from an IRQ handler, before free_irq() runs in the unregister close
> path
> - from ndo_tx_timeout, just before unregister_netdev()
>
> The worker then blocks in rtnl_lock() here.
>
> Once unregister_netdev() drops RTNL in netdev_run_todo(), the worker
> continues. Its dev_close() does nothing because IFF_UP is clear, and
> dev_open() reaches __dev_open().
>
> __dev_open() only checks netif_device_present(), and unregister doesn't
> clear __LINK_STATE_PRESENT. So stmmac_open() runs: it connects the PHY,
> requests IRQs and allocates DMA rings, and dev_activate() attaches qdiscs
> that hold netdev references.
>
> Depending on timing, couldn't this make netdev_wait_allrefs_any() wait
> forever? Or could stmmac_dvr_remove() go on to phylink_destroy() and
> stmmac_mdio_unregister() while the worker is still using priv->phylink?
> destroy_workqueue() only drains the work after those calls.
>
> The STMMAC_DOWN check removed above never covered this, since the bit was
> only set inside this same function. Is a cancel_work_sync() on
> priv->service_task needed before unregister_netdev()? Some other check
> that stops the reset once the device is going away would also work.
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40gmail.com