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, saikrishnag@marvell.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 v3 1/2] net: stmmac: dwmac-motorcomm: remove the device at shutdown
Date: Tue, 01 Dec 2026 10:18:21 +0000	[thread overview]
Message-ID: <179612030127.3146.1025291153395765710@kernel.org> (raw)
In-Reply-To: <20261130101700.1715598-2-magnusleatti@kernelriot.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1 (1)

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] Remove can run twice on one bound device, ending in BUG_ON()
  or a use-after-free.
- [Low] The commit message gives no user-visible symptom, yet the patch
  carries a Fixes: tag.

Pre-existing issues:
- [Low] (Baseline decision: false; kept only because
  requires_validation=true.) The concern is that the new shutdown path…

--

net: stmmac: dwmac-motorcomm: remove the device at shutdown

This patch points the pci_driver .shutdown callback of the Motorcomm
YT6801 glue driver at motorcomm_remove(). As a result,
stmmac_dvr_remove() runs at reboot, kexec and power-off. The intent is to
close the interface, stop the DMA and MAC, and drop the PHY before the
system goes down.

> No .shutdown here, so reboot, kexec and power-off leave the MAC and
> DMA running. This chip keeps its registers through S5 too.

[Severity: Low]
The patch carries a Fixes: tag. Could the commit message say what
user-visible symptom it fixes?

For kexec, pci_device_shutdown() already clears bus mastering after the
driver's shutdown hook, even when no .shutdown is set:

drivers/pci/pci-driver.c:pci_device_shutdown() {
    ...
	if (kexec_in_progress && (pci_dev->current_state <= PCI_D3hot))
		pci_clear_master(pci_dev);
}

The next kernel's motorcomm_probe() also calls motorcomm_reset() before
any other setup.

For a regular reboot, the comment in pci_device_shutdown() notes that
firmware stops device DMA anyway.

That leaves the S5 register retention case. What actually goes wrong
there? It could be stale DMA once firmware re-enables bus mastering,
extra standby power, or something else.

> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
> index 42f0b11a7b606..63ce2301a0f69 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c
> @@ -374,6 +374,7 @@ static struct pci_driver dwmac_motorcomm_pci_driver = {
>  	.id_table = dwmac_motorcomm_pci_id_table,
>  	.probe = motorcomm_probe,
>  	.remove = motorcomm_remove,
> +	.shutdown = motorcomm_remove,

[Severity: Medium]
Can stmmac_dvr_remove() now run twice for the same bound device?

pci_device_shutdown() calls drv->shutdown() but leaves the driver bound.
The netdev comes from devm_alloc_etherdev_mqs(), so dev_get_drvdata()
still returns it afterwards. Any later .remove then runs the full
teardown again:

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_dvr_remove() {
    ...
	unregister_netdev(ndev);
    ...
	phylink_destroy(priv->phylink);
    ...
	destroy_workqueue(priv->wq);
	mutex_destroy(&priv->lock);
	mutex_destroy(&priv->est_lock);
	bitmap_free(priv->af_xdp_zc_qps);
    ...
}

None of these pointers are cleared. Nothing records that the teardown
has already run.

Here are some ways .remove can follow .shutdown:

- A PCIe hot-unplug or link-down handled by pciehp or DPC between this
  device's shutdown and its parent port's shutdown. device_shutdown()
  holds device_lock only around each ->shutdown. Its own comment says
  "device unplug events may also start pulling devices offline, even as
  the system is shutting down".

- A sysfs unbind or rmmod racing with reboot, since userspace is not
  frozen.

- A failed power-off. reboot(2) with LINUX_REBOOT_CMD_POWER_OFF does
  kernel_power_off(); do_exit(0); so the system keeps running with the
  driver bound but already torn down. A later unbind or rmmod then calls
  .remove.

On the second pass, unregister_netdevice_many_notify() would hit:

	BUG_ON(dev->reg_state != NETREG_REGISTERED);

phylink_destroy() and bitmap_free() would also double free, and
destroy_workqueue() would run on a freed workqueue.

Before this patch there was no .shutdown, so the teardown could only run
once.

The follow-up commit "net: stmmac: dwmac-motorcomm: support Wake-on-LAN
from S5" replaces this with a dedicated motorcomm_shutdown(). That
function still calls stmmac_dvr_remove() without a guard, and it may
leave the device in D3hot before a later remove. So the problem still
exists at the end of the series.

dwmac-sun8i is the only other stmmac glue driver with a shutdown hook. It
uses a narrower sun8i_dwmac_shutdown() instead of reusing remove. Would a
similar shutdown-specific handler avoid the double teardown here?

[Severity: Low]
This isn't a bug introduced by this patch, but the new shutdown path
leaves the YT6801 wake logic disarmed at power-off. motorcomm_init()
disables OOB WoL at probe:

drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c:motorcomm_init() {
    ...
	writel(OOB_WOL_CTRL_DIS, priv->base + OOB_WOL_CTRL);
}

MAC PMT is not armed, PME_En is not set, and the device stays in D0, so
magic-packet wake from S5 still does not work.

Wake from S5 did not work before this patch either. stmmac arms PMT only
in stmmac_suspend(), and pci_wake_from_d3() was never called on
power-off.

The next commit in the series, "net: stmmac: dwmac-motorcomm: support
Wake-on-LAN from S5", fixes this. Its motorcomm_shutdown() first checks
that system_state == SYSTEM_POWER_OFF, the interface is running,
WAKE_MAGIC is set and device_may_wakeup() is true. If so, it:

- calls motorcomm_reset() to re-enable OOB WoL
- sets WOL_CTRL_PKT_EN
- calls pci_wake_from_d3(pdev, true)
- enters PCI_D3hot

That commit also documents 'wol u' as unsupported.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130101700.1715598-1-magnusleatti%40kernelriot.com

  reply	other threads:[~2026-12-01 10:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 10:16 [PATCH net-next v3 0/2] net: stmmac: dwmac-motorcomm: shutdown hook and Wake-on-LAN from S5 Magnus Leatti
2026-11-30 10:16 ` [PATCH net-next v3 1/2] net: stmmac: dwmac-motorcomm: remove the device at shutdown Magnus Leatti
2026-12-01 10:18   ` netdev-bot+sashiko [this message]
2026-11-30 10:17 ` [PATCH net-next v3 2/2] net: stmmac: dwmac-motorcomm: support Wake-on-LAN from S5 Magnus Leatti
2026-12-01 10:18   ` netdev-bot+sashiko

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=179612030127.3146.1025291153395765710@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 \
    --cc=saikrishnag@marvell.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