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 5AE7D606A32C for ; Thu, 3 Dec 2026 20:31:32 +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=IOrUFOqS; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SmshtGRK 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=EGuw7EYxtoS94oEdwh10c86cVrkWRLHlpK4V3ulo2Fs=; b=IOrUFOqSEUCxWmogaNyj2gjvm0 u2u9THqhzV+th/MULQ6HZ4oZglIPXRQjfOOSWMZZgf0mxECkdJtw0ry9bqEv/R09vf+gW0mPivdwc cIY1RjUUdROQwwaZsLYMApGv9qNKp+kDxaIRbpXH4oLWDgOTBE0gYN5V0ZVlJJ6YS8y0bzvITZOPG 3uLiMA/5IC5f1BgIQkVNpJAWm8u86+E4xy+nUjwbEUXBY/Mjsk2O9Yc5Jtmy97Poy/Q7WN0CzhHSB tpWFSn+AAKMYvLwr3fxbVeKf+iNIWz34dd4yfCJhSYgEKUUnZjdY6fzHY/TRDmBLiLD9U6ZDTWKKh 3wUHIIXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZDSd-0000000FwEX-2yNK; Thu, 03 Dec 2026 20:31:23 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZDSb-0000000FwDS-3kI4; Thu, 03 Dec 2026 20:31:22 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id B084D613F9; Thu, 3 Dec 2026 20:31:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4C9A1F000C2; Thu, 3 Dec 2026 20:31:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796329880; bh=EGuw7EYxtoS94oEdwh10c86cVrkWRLHlpK4V3ulo2Fs=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=SmshtGRKT4zqZQGVnYNCyb5XkOm9m3WbjV26Lj1NlD+1XjTm1rEyQRLvEwwPOpkbY fJH9o2ecIEyRVjK4I57/6x/PWM2/WAoe5QYWlVrzZ98nHiBuUU3+v1vVpE7WF9C0vQ 2bqO7iZY3TXPaxICjyiXXAKwKufWvCLnVWTKL/TLIUzmpcZMaQpshC5vK+4g7NSAQi XkFFXg+XCyuYVvV5otWdJNPydgp5n3EbaNPb77DO47FkTxTOI0vS99YnuJUvxbfm9i 3KqaJbjbbNDko13QtxRGkUfvVTnpbnVFwY/7eFzTDKN2rZXOy0NocoK3V4PJZdDSs7 StaQJ4PRJ4j9w== Subject: Re: [PATCH net v10 5/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM From: netdev-bot+sashiko@kernel.org To: iav@iav.lv Cc: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, tglx@kernel.org, linux-pm@vger.kernel.org, maxime.chevallier@bootlin.com, lukas@wunner.de, rafael.j.wysocki@intel.com, wei.fang@nxp.com, niklas.soderlund@ragnatech.se, paul@pbarker.dev, florian.fainelli@broadcom.com, opendmb@gmail.com, Thangaraj.S@microchip.com, shenwei.wang@nxp.com, Haoning.CHENG@cn.bosch.com, willemb@google.com, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org Date: Thu, 03 Dec 2026 20:31:18 +0000 Message-ID: <179632987837.3146.12860767392112121060@kernel.org> In-Reply-To: <20261202-b4-phylib-mac-pm-irq-v3-v10-5-2f938d473f17@iav.lv> References: <20261202-b4-phylib-mac-pm-irq-v3-v10-5-2f938d473f17@iav.lv> 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 4 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 2 · Low: 2 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] For MAC-managed PHYs, link interrupts now go unacknowledged from the prepare callback onwards, and the new noirq callback re-… - [Medium] mdio_bus_phy_suspend_noirq() calls enable_irq() only when irqd_is_wakeup_armed() is true. - [Low] Several comments no longer match the code. - [Low] phy_interrupt() now reads phydev->mac_managed_pm in its postponed branch without phydev->lock. -- net: phy: postpone PHY interrupts during sleep with MAC-managed PM For PHYs with MAC-managed PM, this patch starts postponing PHY interrupts in a new prepare callback and replays them in a new complete callback. This keeps the PHY driver's handler off an MDIO bus that the MAC has powered down. It also adds noirq suspend/resume callbacks that re-enable, for the noirq phase, a wake-armed line that a postponed interrupt disabled, and it stops postponed interrupts on MAC-managed PHYs from reporting a wakeup. > diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c > index 6dce49f01d2ba..4a33100fa809b 100644 > --- a/drivers/net/phy/phy.c > +++ b/drivers/net/phy/phy.c > @@ -1419,7 +1419,10 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat) > if (IS_ENABLED(CONFIG_PM_SLEEP) && READ_ONCE(phydev->irq_suspended)) { > struct net_device *netdev = phydev->attached_dev; > > - if (netdev) { > + /* With MAC-managed PM, a postponed interrupt cannot tell > + * Wake-on-LAN from a link change the MAC causes. > + */ > + if (netdev && !phydev->mac_managed_pm) { [Severity: Low] The threaded handler reads phydev->mac_managed_pm here without phydev->lock. mac_managed_pm is an unsigned :1 bitfield. It shares a word with suspended, wol_enabled, link, autoneg and autoneg_complete. Between prepare and complete, the MAC's suspend and resume callbacks run phy_suspend(), phy_resume() and the state machine. Those do read-modify-write stores to the same word. Could KCSAN report a data race on this load? The result is still correct, because mac_managed_pm does not change after attach. Still, this patch's own phy.h comment keeps the irq_* flags out of bitfields for this reason: /* Not bitfields: a bitfield store rewrites the whole word and can undo * a concurrent store to another of its bits */ [ ... ] > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c > index 16b398794486f..2f413147c3112 100644 > --- a/drivers/net/phy/phy_device.c > +++ b/drivers/net/phy/phy_device.c [ ... ] > @@ -446,8 +475,48 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev) > return 0; > } > > -static SIMPLE_DEV_PM_OPS(mdio_bus_phy_pm_ops, mdio_bus_phy_suspend, > - mdio_bus_phy_resume); > +static __maybe_unused int mdio_bus_phy_suspend_noirq(struct device *dev) > +{ > + struct phy_device *phydev = to_phy_device(dev); > + struct irq_data *d; > + > + mutex_lock(&phydev->irq_pm_lock); > + /* We enable the line a postponed interrupt disabled if the irq core > + * armed it for wakeup, so that it wakes the system. > + */ > + if (phydev->irq_rerun) { > + d = irq_get_irq_data(phydev->irq_rerun_line); > + if (d && irqd_irq_disabled(d) && irqd_is_wakeup_armed(d)) { [Severity: Medium] Can this condition ever be true when phydev->irq is a nested-threaded child, such as regmap-irq, an I2C/SPI GPIO expander or a switch irqchip? suspend_device_irqs() skips those descriptors, and suspend_device_irq() is the only place that sets IRQD_WAKEUP_ARMED: kernel/irq/pm.c:suspend_device_irqs() { ... for_each_irq_desc(irq, desc) { bool sync; if (irq_settings_is_nested_thread(desc)) continue; ... } phylib does expect PHYs on nested-threaded lines. See the comment in mdio_bus_phy_resume_irq(): /* A nested threaded line has no thread; we run the handler */ Take a MAC-managed PHY on such a line with an interrupt between prepare and the noirq phase. It reaches phy_interrupt(), reports no wakeup because of the new mac_managed_pm check, and calls disable_irq_nosync(). The check above then always fails, so the child stays disabled for the whole sleep. Some parent chips mask a disabled child in hardware. regmap_irq_disable() does this: it sets the bit in mask_buf, and regmap_irq_sync_unlock() writes it out. Does the parent line then ever fire for the PHY, or does the system sleep through Wake-on-LAN? That is the case these noirq callbacks were added to handle. Before this patch, MAC-managed PHYs were never postponed, so this path is new for them. I haven't found such a board in tree. Chips that disable lazily would still let the parent wake the system. > + enable_irq(phydev->irq_rerun_line); > + phydev->irq_wake_enabled = true; > + } > + } [Severity: Medium] Can this enable_irq() abort every suspend with Wake-on-LAN on a level-triggered line? This happens when the PHY driver does not mask its link interrupt in its suspend callback. >>From mdio_bus_phy_prepare() onwards, phy_interrupt() no longer reads or acknowledges a link interrupt on a MAC-managed PHY. It disables the line while the line is still asserted. This code then enables the still-asserted line while IRQD_WAKEUP_ARMED is set. The flow handler goes through irq_pm_handle_wakeup()->pm_system_irq_wakeup(), and the suspend aborts. The commit message makes PHY drivers responsible for this: its driver has to restrict the interrupt to Wake-on-LAN in its suspend callback, as rtl8211f_suspend() does Existing drivers do not seem to have been checked against that. For example, bcm_phy_set_wol() arms phydev->irq with enable_irq_wake(), and BCM54210E sets PHY_ALWAYS_CALL_SUSPEND. With WoL enabled, bcm54xx_suspend() returns before it touches the link interrupts: drivers/net/phy/broadcom.c:bcm54xx_suspend() { ... /* Acknowledge any Wake-on-LAN interrupt prior to suspend */ ret = bcm_phy_read_exp(phydev, BCM54XX_WOL_INT_STATUS); if (ret < 0) return ret; if (phydev->wol_enabled) return bcm54xx_set_wakeup_irq(phydev, true); ... } The link, speed and duplex interrupts set up by bcm_phy_config_intr() stay enabled, and phy_stop() doesn't disable them either. stmmac sets wol_phy_speed_ctrl, so phylink_suspend() renegotiates the link after phylink_stop(): if (phylink_phy_pm_speed_ctrl(pl)) phylink_speed_down(pl, false); so every suspend would go like this: phylink_suspend()->phylink_speed_down() link interrupt -> phy_interrupt() with irq_suspended set no status read, no wakeup reported, disable_irq_nosync() suspend_device_irqs() sets IRQD_WAKEUP_ARMED, leaves the line disabled mdio_bus_phy_suspend_noirq() enable_irq() on the still-asserted level line irq_pm_handle_wakeup()->pm_system_irq_wakeup() Some boards don't do the speed-down, such as GENET, bcmasp or bcmsysport with a BCM54xx PHY. On those, any link change between prepare and suspend_device_irqs() would now abort that suspend attempt. Before this patch the handler acknowledged it. I couldn't confirm that a board with the stmmac and BCM54210E combination exists in tree. Before this patch, the link-up interrupt after renegotiation could probably already arrive after the line was armed and wake the system. The immediate abort through this noirq re-enable looks new. The commit message says "no MAC driver needs a change". Should it also list the existing PHY drivers that do need a change, or should this series update them? [ ... ] > diff --git a/include/linux/phy.h b/include/linux/phy.h > index 23d88cfa858be..2dba4f2bbc935 100644 > --- a/include/linux/phy.h > +++ b/include/linux/phy.h [ ... ] > @@ -677,9 +682,9 @@ struct phy_oatc14_sqi_capability { > * @max_n_ports: Max number of ports this PHY can expose > * @lock: Mutex for serialization access to PHY > * @irq_pm_lock: Held by the PM callbacks, and by the requesting and freeing > - * of the interrupt where they test and clear @irq_rerun; > - * protects @irq_requested; taken before @lock; > - * phy_interrupt() never takes it > + * of the interrupt where they test and clear @irq_rerun and > + * @irq_wake_enabled; protects @irq_requested; taken before > + * @lock; phy_interrupt() never takes it [Severity: Low] This isn't a bug, but a few comments no longer match the code. "Held by the PM callbacks" is not true for the new mdio_bus_phy_prepare() and mdio_bus_phy_complete(). They write irq_suspended and set, test and clear irq_prepared without irq_pm_lock. Nothing documents what protects irq_prepared. In practice the PM core serialises prepare and complete. The comments above mdio_bus_phy_suspend_irq() and in phy_interrupt() still say: /* Wakeup interrupts may occur during the system sleep transition when * the PHY is inaccessible. Set flag to postpone handling until the PHY * has resumed. Wait for concurrent interrupt handler to complete. */ and /* Wakeup interrupts may occur during a system sleep transition. * Postpone handling until the PHY has resumed. */ For MAC-managed PHYs, postponing now starts in prepare and ends in complete, and phylib never resumes the PHY. Could these comments be updated to match the new @irq_suspended kernel-doc ("with MAC-managed PM until the complete callback")? [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-b4-phylib-mac-pm-irq-v3-v10-0-2f938d473f17%40iav.lv