Re: [PATCH net-next 1/2] net: stmmac: dwmac-motorcomm: quiesce the device at shutdown
From: netdev-bot+sashiko
Date: Wed Nov 18 2026 - 04:18:45 EST
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 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).
- [High] motorcomm_shutdown() (drivers/net/ethernet/stmicro/stmmac/dwmac-
motorcomm.c) tries to stop stmmac_suspend() from running a second time…
- [Medium] motorcomm_shutdown() calls stmmac_suspend() from the PCI
.shutdown hook without holding rtnl_lock.
--
net: stmmac: dwmac-motorcomm: quiesce the device at shutdown
This adds a PCI .shutdown hook to the Motorcomm dwmac glue. The hook calls
stmmac_suspend() to stop the DMA, MAC and PHY before reboot, kexec or
power-off, then turns PME back off with pci_wake_from_d3(). It skips all
of this when the netdev is not present, so that stmmac_suspend() does not
run twice after a failed resume.
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
> index 42f0b11a7b606..1e142ad39e33a 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
> @@ -204,6 +204,27 @@ static int motorcomm_resume(struct device *dev, void *bsp_priv)
> return 0;
> }
>
> +static void motorcomm_shutdown(struct pci_dev *pdev)
> +{
> + struct net_device *ndev = dev_get_drvdata(&pdev->dev);
> +
> + /*
> + * A failed resume leaves the netdev detached with NAPI disabled, and
> + * stmmac_suspend() must not run on it a second time.
> + */
> + if (!netif_device_present(ndev))
> + return;
[Severity: High]
Does this check catch a failed resume when the interface was down at
suspend time?
stmmac_suspend() only detaches the netdev on the netif_running() path:
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_suspend() {
if (!ndev || !netif_running(ndev))
goto suspend_bsp;
...
netif_device_detach(ndev);
...
suspend_bsp:
if (priv->plat->suspend)
return priv->plat->suspend(dev, priv->plat->bsp_priv);
...
}
With the interface down, system suspend goes straight to
stmmac_pci_plat_suspend(). That calls pci_disable_device() and drops
enable_cnt from 1 to 0, and the netdev stays present.
Resume can then fail in motorcomm_resume()->stmmac_pci_plat_resume() if
pci_enable_device() returns an error. In that case
pci_enable_device_flags() decrements enable_cnt back to 0 and the device
stays disabled. stmmac_resume() returns the error and leaves the detach
state alone.
At reboot the guard above does not fire, and the sequence is:
motorcomm_shutdown()
stmmac_suspend()
/* !netif_running(), goto suspend_bsp */
stmmac_pci_plat_suspend()
pci_disable_device()
dev_WARN_ONCE(..., "disabling already-disabled device")
atomic_dec_return(&dev->enable_cnt) /* enable_cnt is now -1 */
Isn't this the case the commit message describes as "Skip the hook in
that state: stmmac_suspend() must not run a second time."? With
panic_on_warn set, this would panic instead of rebooting.
Being detached is not the same as having a failed resume. Would a
different state check fit better here, such as pci_is_enabled(pdev) or a
driver-owned flag set when resume fails?
The follow-up commit "net: stmmac: dwmac-motorcomm: support Wake-on-LAN
from S5" does not change this guard.
> +
> + /* Stop the device before reboot, kexec or power-off */
> + stmmac_suspend(&pdev->dev);
[Severity: Medium]
Can this race with dev_close() and hang the reboot?
device_shutdown() runs without the freezer, so userspace and priv->wq
are still active. stmmac_suspend() checks netif_running() without rtnl.
It disables NAPI under priv->lock only and takes rtnl afterwards:
mutex_lock(&priv->lock);
netif_device_detach(ndev);
stmmac_disable_all_queues(priv);
...
mutex_unlock(&priv->lock);
rtnl_lock();
phylink_suspend(priv->phylink, !!priv->wolopts);
The ndo_stop path, stmmac_release()->__stmmac_release(), runs under rtnl
only. It does not take priv->lock or check netif_device_present(), so it
calls stmmac_disable_all_queues() a second time.
napi_disable_locked() loops in usleep_range() while NAPIF_STATE_SCHED is
set. A disabled NAPI keeps that bit set, so the second napi_disable()
never returns.
One possible interleaving:
CPU0 CPU1
motorcomm_shutdown()
stmmac_suspend()
stmmac_disable_all_queues()
ip link set down, or
stmmac_reset_subtask()
rtnl_lock()
dev_close()
__stmmac_release()
stmmac_disable_all_queues()
napi_disable() spins
rtnl_lock() blocks forever
After the hook returns, the netdev is still IFF_UP, detached, with NAPI
disabled. Any dev_close() before the machine halts would spin while
holding rtnl. Any later .shutdown hook that takes rtnl, such as
rtl_shutdown() in r8169, would then hang.
Other drivers serialize shutdown with rtnl, as rtl_shutdown() does:
rtnl_lock();
rtl8169_net_suspend(tp);
rtnl_unlock();
Others make ndo_stop a no-op on a detached device, as igb_close() does by
checking netif_device_present(). Is something along those lines needed
here?
The follow-up commit "net: stmmac: dwmac-motorcomm: support Wake-on-LAN
from S5" does not change this either.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116091757.1656602-1-magnusleatti%40kernelriot.com