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=1796110248; b=r/2+iPgI4lXggLJPBDqiRv88/7Rs7DLIsO+0GThVISP7kWtI4m2ELKnkT8qocIYJDFyn gz8TPp4041rxfCVwTlYKuDjvBd/TK4I+QyQqKhNmnmQsxHrUyjltvycnWhH2uBktYYAAd B81uUkNUobRcbTe2C/rcWmg1sJcTmUtEB7mAzjXEND3JqqGWTSD3Y3oY4Fe+v/Bj17cxC 7kBWDOSixbfStQWxHWWKoamrsL7P0XS++IlOdmmF3y1DcB+dqxwzRrWnRvpaaaXhsOKHD flcVU96stub5DrHKOS0mGhuZC0fQSEbSWTLYxMZx3kJ6olQWz0BesUTyCcHfLELVsqw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796110248; 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=IwVqEuINVfOqpL03PQCZOhxmJcqXxTk/2k9LaEK7xhA=; b=RLshsReTSbOaN4WkQO+akP5Cnguziju3LrFYXpJysy+3ZsngcCOCU0X3JMXVmYVrMqx9 8D/cUd9ft4XOGnp8NUEdp3mZqJjXu7CsbDGd9GA7Mwj/yl6FVo5fXiMlk99hlaJfZLwWh K6e3zyeE4RfanyJ0+nU7e0ouyMCNebXrYq3EjCugkMZxJ2u+hH3IU74j7qHVp68s+Khql kOEsq1LvAMdys98jJ2aIZ/HfdPotbtCx6YQV76WTcggXnnHe8ZBEN+GlzgpslqJrz3P2b uc4DeJmijPPbrE/90xCmJ9iWmPUMW7NftHSqEx1aYx8lpqIkJld5EPiZHg2bKueuKgw== 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=EcXzGeZU; 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 8C0E0606A33B; Tue, 1 Dec 2026 07:30:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EcXzGeZU Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C5F71F00893; Tue, 1 Dec 2026 07:30:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796110248; bh=IwVqEuINVfOqpL03PQCZOhxmJcqXxTk/2k9LaEK7xhA=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=EcXzGeZUfRyOJ9MrlSC0LHkduUUHhowiBNrMOIoN3yd73Qs69gUilJFO9nH15SHRl Pji57s+NeRF/OdAoELKytsx9pc5lyREoIBYhmMG9Xf9A2I+bpTlY8jvfiNcfrfKWvO cE/lYe3KMvdutqIYS7H2yVFEevfVePm1+CwuAIqGFHA8Cm8sSUypBUMqZ3ArTG57I5 7bEZQZqk1RP2Xa6y9rgK2FYUiIdi5S3sf5gxX3awNtB5aIpuncaIX9ZLDyoQ1X+UL7 BmE8V8ZTCCFOB/ebIr5WwE72hc1/kj3AuqsmC267/nfowH2dzArcjsVw6Bi1SfhQtJ /pdFhFNPGe6eg== Subject: Re: [PATCH net v9 2/5] net: phy: fix three paths that unbalance a postponed PHY interrupt line 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: Tue, 01 Dec 2026 07:30:46 +0000 Message-ID: <179611024612.3146.9721290308822470504@kernel.org> In-Reply-To: <20261130-b4-phylib-mac-pm-irq-v3-v9-2-7b9c3c9ac9f7@iav.lv> References: <20261130-b4-phylib-mac-pm-irq-v3-v9-2-7b9c3c9ac9f7@iav.lv> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-pm@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 1 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 (2) · 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). - [Medium] Stale irq_rerun on a shared PHY interrupt line. Pre-existing issues: - [Medium] Concern: in mdio_bus_phy_suspend(), irq_suspended is set and phy_suspend()'s error is returned without undoing the postponing. - [Medium] Concern: mdio_bus_phy_resume_irq() replays the postponed interrupt with irq_wake_thread(). -- net: phy: fix three paths that unbalance a postponed PHY interrupt line With this patch, only the postponed phy_interrupt() run that sets irq_rerun disables the line, and the patch records which line that run disabled. phy_free_interrupt() and phy_request_interrupt() now clear irq_rerun when the line has no users. The patch also adds irq_pm_lock and moves the postpone and rerun logic into mdio_bus_phy_suspend_irq() and mdio_bus_phy_resume_irq(). > diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c > index 9af303d60bd6b..b917238678928 100644 > --- a/drivers/net/phy/phy.c > +++ b/drivers/net/phy/phy.c [ ... ] > @@ -1430,8 +1430,12 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat) > pm_wakeup_dev_event(parent, 0, true); > } > > - phydev->irq_rerun = true; > - disable_irq_nosync(irq); > + /* Disable the line only once: an edge can rerun the thread. */ > + if (!phydev->irq_rerun) { > + phydev->irq_rerun_line = irq; > + phydev->irq_rerun = true; > + disable_irq_nosync(irq); > + } > return IRQ_HANDLED; > } > > @@ -1480,6 +1484,12 @@ void phy_request_interrupt(struct phy_device *phydev) > { > int err; > > + /* A line without users restarts at depth 0, so our disable is gone */ > + mutex_lock(&phydev->irq_pm_lock); > + if (phydev->irq_rerun && !irq_has_action(phydev->irq_rerun_line)) > + phydev->irq_rerun = false; > + mutex_unlock(&phydev->irq_pm_lock); > + > err = request_threaded_irq(phydev->irq, NULL, phy_interrupt, > IRQF_ONESHOT | IRQF_SHARED, > phydev_name(phydev), phydev); > @@ -1507,7 +1517,15 @@ EXPORT_SYMBOL(phy_request_interrupt); > void phy_free_interrupt(struct phy_device *phydev) > { > phy_disable_interrupts(phydev); > + > + mutex_lock(&phydev->irq_pm_lock); > free_irq(phydev->irq, phydev); > + /* free_irq() shuts down a line left without users and the next request > + * resets its depth; mdio_bus_phy_resume_irq() enables a shared line. > + */ > + if (phydev->irq_rerun && !irq_has_action(phydev->irq_rerun_line)) > + phydev->irq_rerun = false; > + mutex_unlock(&phydev->irq_pm_lock); > } > EXPORT_SYMBOL(phy_free_interrupt); [Severity: Medium] Can irq_rerun go stale on a shared line? irq_rerun is a per-PHY bool, but the disable it stands for is counted in the depth of the shared irq_desc. Both irq_has_action() checks run under the per-PHY irq_pm_lock, and that lock does not serialize against the other users of the line. For example, take PHY A and user B sharing line L. A postpones an interrupt, so L is at depth 1: A: phy_free_interrupt() free_irq() /* B still holds L */ irq_has_action() == true /* irq_rerun kept */ B: free_irq() /* irq_shutdown() */ B: request_irq() /* irq_startup(): desc->depth = 0 */ A: phy_request_interrupt() irq_has_action() == true /* irq_rerun kept */ request_threaded_irq() Two windows lead to the same state. One is between free_irq() and the irq_has_action() check in phy_free_interrupt(). The other is between the irq_has_action() check and request_threaded_irq() in phy_request_interrupt(). >>From then on, while A is still postponed, the new guard in phy_interrupt() skips the disable: if (!phydev->irq_rerun) { ... disable_irq_nosync(irq); } Take a level-triggered PHY interrupt whose status cannot be read. The handler returns IRQ_HANDLED, the ONESHOT completion unmasks the line, and the interrupt fires again right away. Would the IRQ thread then spin until mdio_bus_phy_resume_irq() runs? Before this patch, every postponed run masked the line. After that, mdio_bus_phy_resume_irq() calls enable_irq(phydev->irq_rerun_line) unconditionally. Would that hit the "Unbalanced enable for IRQ %d" WARN in __enable_irq(), or cancel a disable_irq() that another driver on the line still holds? The commit message lists these cases: "Three cases on a shared line stay unbalanced ... until then a postponed interrupt does not disable the line again, so a level-triggered one keeps firing." However, the repeated firing of a level-triggered line comes from the new guard in phy_interrupt(). The later patches in the series do not change this code; they only add irq_requested and irq_wake_enabled handling. > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c > index 1791d578f4dde..f2e2370b4be7c 100644 > --- a/drivers/net/phy/phy_device.c > +++ b/drivers/net/phy/phy_device.c [ ... ] > +/* Rerun interrupts which were postponed by phy_interrupt() > + * because they occurred during the system sleep transition. > + */ > +static __maybe_unused void mdio_bus_phy_resume_irq(struct phy_device *phydev) > +{ > + WRITE_ONCE(phydev->irq_suspended, false); > + > + mutex_lock(&phydev->irq_pm_lock); > + if (phy_interrupt_is_valid(phydev)) > + synchronize_irq(phydev->irq); > + /* The PHY may have fallen back to polling since it disabled the line */ > + if (phydev->irq_rerun) { > + phydev->irq_rerun = false; > + enable_irq(phydev->irq_rerun_line); > + if (phydev->irq == phydev->irq_rerun_line) > + irq_wake_thread(phydev->irq, phydev); [Severity: Medium] This is a pre-existing issue, but does irq_wake_thread() do anything on a nested-threaded line, such as a PHY interrupt behind an I2C or SPI GPIO expander? On such a line action->thread is NULL, so the postponed PHY event would be lost. The old mdio_bus_phy_resume() used irq_wake_thread() the same way. This seems to be addressed later in the series by "net: phy: run a postponed PHY interrupt handler directly on resume". That patch calls phydev->drv->handle_interrupt() under phydev->lock instead. > + } > + mutex_unlock(&phydev->irq_pm_lock); > +} [ ... ] > @@ -393,19 +419,7 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev) > if (ret < 0) > return ret; > no_resume: [Severity: Medium] This isn't a bug introduced by this patch, but the early returns after a phy_init_hw() or phy_resume() failure skip mdio_bus_phy_resume_irq(). Would irq_suspended then stay set, along with the postponed line, including the other users of a shared line, staying disabled? mdio_bus_phy_suspend() has a similar path at this commit. It sets irq_suspended through mdio_bus_phy_suspend_irq() and then returns the result of phy_suspend() without undoing the postponing: phydev->suspended_by_mdio_bus = 1; return phy_suspend(phydev); The suspend half is addressed later in the series by "net: phy: stop postponing PHY interrupts when phy_suspend() fails". That patch calls mdio_bus_phy_resume_irq() and phy_start_machine() on failure. The same later commit keeps the resume error returns on purpose: "Undoing the postponing there would run the handler, from the next interrupt on, on a PHY that did not resume". > - if (phy_interrupt_is_valid(phydev)) { > - phydev->irq_suspended = false; > - synchronize_irq(phydev->irq); > - > - /* Rerun interrupts which were postponed by phy_interrupt() > - * because they occurred during the system sleep transition. > - */ > - if (phydev->irq_rerun) { > - phydev->irq_rerun = false; > - enable_irq(phydev->irq); > - irq_wake_thread(phydev->irq, phydev); > - } > - } > + mdio_bus_phy_resume_irq(phydev); [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-b4-phylib-mac-pm-irq-v3-v9-0-7b9c3c9ac9f7%40iav.lv