From: netdev-bot+sashiko@kernel.org
To: zxyan0222@gmail.com
Cc: maxime.chevallier@bootlin.com, davem@davemloft.net,
edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
netdev@vger.kernel.org, andrew+netdev@lunn.ch,
Jose.Abreu@synopsys.com, mcoquelin.stm32@gmail.com,
alexandre.torgue@foss.st.com, bigeasy@linutronix.de,
clrkwllms@kernel.org, rostedt@goodmis.org, ast@kernel.org,
daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
sdf@fomichev.me, linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-rt-devel@lists.linux.dev, bpf@vger.kernel.org
Subject: Re: [PATCH net] net: stmmac: remove STMMAC_DOWN
Date: Thu, 03 Dec 2026 09:15:55 +0000 [thread overview]
Message-ID: <179628935561.3146.10251855086500360375@kernel.org> (raw)
In-Reply-To: <20261201091256.3000677-1-zxyan0222@gmail.com>
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.
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.
--
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/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
> @@ -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/20261201091256.3000677-1-zxyan0222%40gmail.com
prev parent reply other threads:[~2026-12-03 9:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 9:12 [PATCH net] net: stmmac: remove STMMAC_DOWN Zxyan Zhu
2026-12-02 9:04 ` Maxime Chevallier
2026-12-02 11:33 ` zhu xin
2026-12-03 9:15 ` netdev-bot+sashiko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179628935561.3146.10251855086500360375@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=Jose.Abreu@synopsys.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andrew+netdev@lunn.ch \
--cc=ast@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=bpf@vger.kernel.org \
--cc=clrkwllms@kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=maxime.chevallier@bootlin.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rostedt@goodmis.org \
--cc=sdf@fomichev.me \
--cc=zxyan0222@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox