From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46321606A327 for ; Tue, 1 Dec 2026 10:25:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=g57i1RNi; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=G7a3vh+1 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Message-ID:Date :Cc:To:From:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=STJpZbam8rhPbVCXFAL9lmRhjephAMXjOMkGR8b0cr8=; b=g57i1RNibxqkgYsVjKkeSTA2+A bD0YmcSxiTopRPjRvq81ApB+S8We2X2w+ayef0Btl3feGXTPc5xb2oDgZ8KEMq63LGIaDePnnrbLI COaXoZZ107PorGzNqxzv1tcjOO4jmMXSqGSnskraJ36VxvbQVBbED18A4IBXP5FgV/G6LAiyaYfnE mBJIsvWUjPmJQuRjAHoDoFg6kLmp1eGshIYf7sYCPCgSWugpdPsWOQEBf+O/SUx7/lDOdJCh6RhcU cGNtIJu1YdjKhbjA/A2+XafYXIzsppx82MolaBEOvhGiHM8a8l+yHYCUEH7SKJZ1hYoBVPlsklT9V e+L9yddQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYKwO-00000007L2M-2Ush; Tue, 01 Dec 2026 10:18:28 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYKwJ-00000007L0a-1DxF for linux-arm-kernel@lists.infradead.org; Tue, 01 Dec 2026 10:18:27 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id BBAD343AA3; Tue, 1 Dec 2026 10:18:22 +0000 (UTC) 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-Archived-By: MIME-Version: 1.0 X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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