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=1796329876; b=OzaM0onz4Dv1DdfA48He4e+vQaT8CNma3EHMlecvZJoIsCBVyfuR8ZdyKu756tFpsp8o J2lBD1FKwWx65VIQXF/v4sC8yXivddtGDx17n1Tk1W0WgAHW7q8ctSMK5nJBHNTAofQzd 7A53G3xBninZZv7razRVh2wr7H+SbpADK90CUEpkII/FBUTg7cClwnmE2YIRKGqR/24J0 WBQPEcJZ1XDmUXd1vxhr6QuR8SPsuQMDlb11ePBpAIg1A0k4FqUNAGRzhOQ1Orq1tJFwZ BzlmbHZ9rk59uIGYFzctWrMXyKrnLYibaxVCD47M5HrKnQ/P37fbmy8ZnTGuN50e9Fw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796329876; 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=POkZb3OyudlRjtI0mJEA6PLMmvbN53xrIM7aGV1iMFg=; b=3E/BOC92URg89w6ARrLkMYojnGn7UrS8a8RHVMxI2K900+LfSLmRRd9Jo9b1P05DZ/IV whgPKasKnN0MEUqV2gWYa3GhZ3Pv88I5f4xFvkkqC/jKKWoW6cX46bSs3wcabkgfIQ8fP +72Mjh8ooKOf6yyqdyPeebrXshstnWodOelNbiYQKJ/3wu6sPJa1oHXraMEMhp669qiUR /i0m7HK0YZpThc5vCGut1vI1cK4/TTMRvHKHMOQugDncMwepPT4zVSCkgBzkB8VlEhhnj MHRqVi/oGU4wqmuaRXSdDqXIS+dQtiL/+ujLjsFvwxdcdNW/24hXkpqESXIh2glJjRA== 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=H51dAeDD; 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 9B40F606A322; Thu, 3 Dec 2026 20:31:16 +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=H51dAeDD Received: by smtp.kernel.org (Postfix) with ESMTPSA id E62861F000C2; Thu, 3 Dec 2026 20:31:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796329876; bh=POkZb3OyudlRjtI0mJEA6PLMmvbN53xrIM7aGV1iMFg=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=H51dAeDDCYUsn3XnVwGHV3OzuBhs36SIYLhfIAgiZViLNZwKoK/CiLGuAZVix8cjH 8TX7pQjjiE/2ROfrjPJIQmZcrqFHU+3HFZUFYZz4GF1LUKCTyCpE/R1w77cW2xZJMw lGvcoKIuGfhTnbfVLJCzvyrye1FIqfd7UzsvXtLv9KFS7JQd2G7yHJ+dasTVANL/4d O0xATyyLeXyJsxw/RxFmjE6P7+3HtXdl1JJwg6t8s76KAQ5kYE5d5c10DWhOLgzQTV FmLKk/fevIQ6ctXzlnwdPYzZKM6M9g32+J/SEDXOvQnhquM+UUQF/ro3SVEXgmLKyW Szilk7Nprn5Lw== Subject: Re: [PATCH net v10 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: Thu, 03 Dec 2026 20:31:14 +0000 Message-ID: <179632987448.3146.13504006246619970930@kernel.org> In-Reply-To: <20261202-b4-phylib-mac-pm-irq-v3-v10-2-2f938d473f17@iav.lv> References: <20261202-b4-phylib-mac-pm-irq-v3-v10-2-2f938d473f17@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 2 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · Low: 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] This patch decides whether mdio_bus_phy_resume_irq() still owes an enable_irq(irq_rerun_line) by calling irq_has_action() in… - [Low] The new kernel-doc for @irq_pm_lock in include/linux/phy.h (lines 678-680) says it is "Held by the PM callbacks, and by the requesting… -- net: phy: fix three paths that unbalance a postponed PHY interrupt line This patch makes phy_interrupt() disable a postponed PHY interrupt line only once, and it records which line it disabled. irq_rerun is cleared in phy_free_interrupt() and phy_request_interrupt() when irq_has_action() reports that the line has no users, and otherwise mdio_bus_phy_resume() enables the recorded line. A new per-PHY irq_pm_lock serializes these checks with the rerun after resume. > 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 [ ... ] > @@ -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 stay set after the line's depth has already been reset? irq_pm_lock belongs to one PHY, and the other users of a shared line never take it. The first request after the line has had no users resets the depth: kernel/irq/chip.c:irq_startup() { ... desc->depth = 0; ... } One bool and a single irq_has_action() check at one moment cannot show whether the line went through irq_shutdown() and irq_startup() after this PHY's disable_irq_nosync(). These orderings leave the flag set: (a) phy_free_interrupt() runs while other users remain, so irq_rerun is kept. All users later free the line, and another user requests it first, so the line restarts at depth 0. phy_request_interrupt() then sees an action and keeps irq_rerun. (b) Another user requests the line between free_irq() and the irq_has_action() check in phy_free_interrupt(). (c) The last other user frees the line between the irq_has_action() check in phy_request_interrupt() and request_threaded_irq(). In each case mdio_bus_phy_resume_irq() then does: if (phydev->irq_rerun) { phydev->irq_rerun = false; enable_irq(phydev->irq_rerun_line); Would this hit the "Unbalanced enable for IRQ %d" WARN in __enable_irq(), or cancel a disable_irq() that another user of the shared line took on purpose? Until resume, the stale irq_rerun also makes phy_interrupt() skip disable_irq_nosync(). A level-triggered PHY source that cannot be acked while irq_suspended is set would then keep firing after each ONESHOT unmask. The commit message lists these three cases as still unbalanced. The kernel-internal close and open paths it names could produce these orderings: MAC suspend callbacks that close the interface, and a reset work that does not freeze, such as stmmac_reset_subtask(). The later patches in the series keep the same irq_has_action() approach. At the end of the series phy_request_interrupt() holds irq_pm_lock across the check and request_threaded_irq(), but the other users of the line still do not take that lock. [ ... ] > diff --git a/include/linux/phy.h b/include/linux/phy.h > index 23539e90c9870..42004e45fb3a4 100644 > --- a/include/linux/phy.h > +++ b/include/linux/phy.h [ ... ] > @@ -675,6 +675,9 @@ struct phy_oatc14_sqi_capability { > * @n_ports: Number of ports currently attached to the PHY > * @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; > + * phy_interrupt() never takes it [Severity: Low] This isn't a bug, but is this kernel-doc accurate? Not every PM callback takes irq_pm_lock. mdio_bus_phy_suspend() calls mdio_bus_phy_suspend_irq(), which writes irq_suspended and calls synchronize_irq() without the lock: static __maybe_unused void mdio_bus_phy_suspend_irq(struct phy_device *phydev) { if (!phy_interrupt_is_valid(phydev)) return; WRITE_ONCE(phydev->irq_suspended, true); synchronize_irq(phydev->irq); } Only mdio_bus_phy_resume_irq() takes the lock. phy_free_interrupt() also calls phy_disable_interrupts() before it takes the lock. The in-struct comment added in this same patch is narrower: "Held where the PM callbacks and the requesting and freeing of the interrupt test and clear irq_rerun". So the two descriptions of the same lock disagree. At the end of the series the kernel-doc still says "Held by the PM callbacks", while mdio_bus_phy_prepare() and mdio_bus_phy_suspend() still call mdio_bus_phy_suspend_irq() without the lock. Could the kernel-doc be changed to match the in-struct comment? [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-b4-phylib-mac-pm-irq-v3-v10-0-2f938d473f17%40iav.lv