From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796120303; b=HCXc8wm7QDIvSdkZEYg6w6dRsDtdzB51IrIknrfD2V/bLYdzBFAjM1we55K4r/kIfQ1y Mfa+hZpWSMlxSXaioaziu1p81la5hjtoJ3LFMAaSHnJN36cFgXI3w+n4j0eXO14LJvjof 3QPy0pymnlUAe6SAB0bPvOJNWck8AMA5OAt3MAOW2iFKEd63V3e+9Gf40XmH346oKgCSu 7eadNfky6zUENkVananLXMUwCR8vrhg8C/O+zbXe7kv9lFEgcBnTtP5kG0BSzd7j9028H BSTz91oLlIOzRzyEIB2JrWAgNze+W0ODn2HAGgVAoINEgH69W9TY8jSBqqvCyrR/FRg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796120303; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=STJpZbam8rhPbVCXFAL9lmRhjephAMXjOMkGR8b0cr8=; b=3NEVUCMZ+tz2sDGrlGD8i05XucbdrddsLxcrvIW1wPdGFnF6QMcQ503QSkZqBLvjLH8a QYfi+I2sSuJxBfqnlcFWgSWeUfX9QtFPAN1nIGJmb8ancfT3jGo0uwDb3P9wxQA9Tx2Lr bFrjS3DKLvm/l0FbUnfc6/sEYVMiP+Em49q9eSxaRS/85tpR9YEWWZ0S+U98bFSuUteVb /3Pjws6WW/pFU/0Zj4wVEqdaKU/vFlP/nf2PSQw7zUmAdoA9RyDUx9AaBgmRDTRrY1TaN 1pvDJCXMODY31xRvA5PQ0kV9nqsoQLcHql8XayzPjESAtGkvuG1VdTE0++k0Zj3tHOg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=G7a3vh+1; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F9D0606A32C; Tue, 1 Dec 2026 10:18:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=G7a3vh+1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0B211F00897; Tue, 1 Dec 2026 10:18:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796120302; bh=STJpZbam8rhPbVCXFAL9lmRhjephAMXjOMkGR8b0cr8=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=G7a3vh+1KCTzmKGdO682Y+jJZ7of+askoCqPPjj1qcWnBSkShMns5n/KPzGmdFmgD AwgR/zlwcjh67mWA4nJXovOeOPU+dOGVJzZP8jEJxjBpRzsSjhP4B1P05s8bcvc6rV vQ65Lhe5rMFOF5erTAmf+y4NUwEm1H7+s+Ix2SAyPVj9jkfPFl4BJrZ5s03YFAeQc6 TzZpQAAOKj3nHOijQ2WmFqVSftgPALaWFlWRG8UuVZg/yGNRim5G/v3cR3cwrl9Qw0 /kucWky7ML7cbYL8eN4Qtu4agtNZTMTheUUcRWDUjqVBVJAa8fAPCb2uNxgyhcDOwC /4xblKQxWzgmw== Subject: Re: [PATCH net-next v3 1/2] net: stmmac: dwmac-motorcomm: remove the device at shutdown 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 Date: Tue, 01 Dec 2026 10:18:21 +0000 Message-ID: <179612030127.3146.1025291153395765710@kernel.org> In-Reply-To: <20261130101700.1715598-2-magnusleatti@kernelriot.com> References: <20261130101700.1715598-2-magnusleatti@kernelriot.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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