Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: magnusleatti@kernelriot.com
Cc: me@ziyao.cc, maxime.chevallier@bootlin.com,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, mcoquelin.stm32@gmail.com,
	alexandre.torgue@foss.st.com, g.nespolino@gmail.com,
	netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 1/2] net: stmmac: dwmac-motorcomm: quiesce the device at shutdown
Date: Wed, 18 Nov 2026 09:18:30 +0000	[thread overview]
Message-ID: <179499351041.3136.14889707783816630750@kernel.org> (raw)
In-Reply-To: <20261116091757.1656602-2-magnusleatti@kernelriot.com>

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

  parent reply	other threads:[~2026-11-18  9:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  9:17 [PATCH net-next 0/2] net: stmmac: dwmac-motorcomm: shutdown hook and Wake-on-LAN from S5 Magnus Leatti
2026-11-16  9:17 ` [PATCH net-next 1/2] net: stmmac: dwmac-motorcomm: quiesce the device at shutdown Magnus Leatti
2026-11-16 14:33   ` Yao Zi
2026-11-16 14:58     ` Magnus Leatti
2026-11-18  9:18   ` netdev-bot+sashiko [this message]
2026-11-16  9:17 ` [PATCH net-next 2/2] net: stmmac: dwmac-motorcomm: support Wake-on-LAN from S5 Magnus Leatti
2026-11-16 15:08   ` Yao Zi
2026-11-16 15:17     ` Yao Zi
2026-11-16 16:48       ` Magnus Leatti
2026-11-16 17:26         ` Yao Zi
2026-11-17  1:27         ` Andrew Lunn
2026-11-17 10:26           ` Yao Zi
2026-11-18  9:18   ` netdev-bot+sashiko
2026-11-16 11:23 ` [PATCH net-next 0/2] net: stmmac: dwmac-motorcomm: shutdown hook and " Giuseppe Nespolino
2026-11-16 11:36   ` Magnus Leatti

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=179499351041.3136.14889707783816630750@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=g.nespolino@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=magnusleatti@kernelriot.com \
    --cc=maxime.chevallier@bootlin.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=me@ziyao.cc \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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