๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25041

Re: [PATCH net v9 2/5] net: phy: fix three paths that unbalance a postponed PHY interrupt line

#25041
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 07:30
224 lines
16480 bytes
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
Technical Details
Message-ID: <179611024612.3146.9721290308822470504@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder2.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374795-linux-kernel-netdev=dewy.ru
References: <20261130-b4-phylib-mac-pm-irq-v3-v9-2-7b9c3c9ac9f7@iav.lv>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder2.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374795-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v9 2/5] net: phy: fix three paths that unbalance a postponed PHY interrupt line
Date: Tue, 01 Dec 2026 07:30:46 +0000
Organization: Usenet Network
Message-ID: <179611024612.3146.9721290308822470504@kernel.org>
References: <20261130-b4-phylib-mac-pm-irq-v3-v9-2-7b9c3c9ac9f7@iav.lv>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="1648369"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:4uTWyX0y5631BXSVv6j6ZFDEpZU= sha256:EJY6mC3AJwV/jJmIszYAgNEBWc/1wixVLQu6GBk82Ks= sha1:+gyUivTGiWTTDkB/krDnbFz5V0M= sha256:Hrg+4HTPDFADmyFKmG6vH2QUY3+7y4T3DYHmGWr0i/k=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id BBB8811729C; Tue,  1 Dec 2026 10:31:06 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.5
X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pdJG35dK_LyM; Tue,  1 Dec 2026 10:31:02 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-374795-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 73C60117299; Tue,  1 Dec 2026 10:30:54 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 3EEAD25FF9; Tue,  1 Dec 2026 07:30:53 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796110249; b=sTfmwfyvAdX+1yqyznzZVz2xa9xJ9xxep9itAVrhTYbLepdzqMCGmQkrt4LzAsD3+fTI WOAO61cDge3cnVXKi3M8OKwBZ2voUYd7sAbBnuEyV1lk48ScFAV36S9Gj6REtuRT9jBP0 6mY88yy6W+GqxkmDUG3VcwyT8DabTOkgRCuk9ohRF6As8xkub0BISrQTgwOqTzVpfwYK0 wUeitDiUyguhCC4KMYRajm9xU2caZexLKA/w+Ickh6dlcQuuF1cELEX/+NpYtud0wwzcf lnxwzwTiUf6O60JOVHWvV8OEift/vxxB1ruyn2W0MNoNFBn45vmECSE/KfMiEjrEskw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796110249; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=IwVqEuINVfOqpL03PQCZOhxmJcqXxTk/2k9LaEK7xhA=; b=mFD/2nVDrjwLiCMsAFEymiQHCnQLsjO/IqXPGy+WDvjLu/vQ1jm1s2t86oDKXValcdPj 3cxzmWWxZ5M96fKP2h0goXNQRB0H7uTor1vg4FnbQ4r6uiA7Wgk0jaJUD9gVDpgmjw1gL TQD5jT74OFarY8DL20gi+V9tUYDyHoSmv/AjRi9hFP4gVQwCa5LwgPKPCSoITmNSJB9yY hr+6CFYZUBKeR6TWaFOrptJje6QPt9flwK6KLgrRFq16namFsmyGLipinsxgWF3TaXKgv EXg3M4RPN8MkNIBq26swDNMkyTjlWw2RU20hrnEXnTJNEK8xNqVTfLfuEOuZcmltQAQ==
X-ARC-Authentication-Results: i=2; 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=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71A03606A687; Tue,  1 Dec 2026 07:30:49 +0000 (UTC)
X-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=EcXzGeZU
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-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==
X-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==
X-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
X-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)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C5F71F00893; Tue,  1 Dec 2026 07:30:46 +0000 (UTC)
X-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==
X-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
X-In-Reply-To: <20261130-b4-phylib-mac-pm-irq-v3-v9-2-7b9c3c9ac9f7@iav.lv>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list