๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9250

Re: [PATCH net v4 2/5] net: phy: disable the line of a postponed PHY interrupt only once

#9250
From: netdev-bot+sashiko
Date: Sun, 01 Nov 2026 08:36
160 lines
13905 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 ยท High: 0 ยท Medium: 1 (1) ยท 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] This commit introduces the problem, and a later commit in the
  series fixes it.

Pre-existing issues:
- [Medium] Not fixed by this commit, and the series fixes it later.

--

net: phy: disable the line of a postponed PHY interrupt only once

This commit changes phydev->irq_rerun to an atomic_t. Only the postponed
phy_interrupt() run that sets it now calls disable_irq_nosync(), which
avoids a double disable when an edge reruns the thread during a sleep
transition. The irq_suspended accesses also get READ_ONCE() and
WRITE_ONCE() annotations.

> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index 9af303d60bd6b..b47f0d3d99e55 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c

[ ... ]

> @@ -1430,8 +1430,9 @@ 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 (!atomic_xchg(&phydev->irq_rerun, 1))
> +			disable_irq_nosync(irq);
>  		return IRQ_HANDLED;
>  	}

[Severity: Medium]
What happens here if irq_rerun is still 1 from an earlier cycle and the
line has since been re-requested?

At this commit, only the successful no_resume path of
mdio_bus_phy_resume() clears irq_rerun. phy_free_interrupt() does not
reset it:

drivers/net/phy/phy.c:phy_free_interrupt() {
	phy_disable_interrupts(phydev);
	free_irq(phydev->irq, phydev);
}

When the PHY is the only user of the line, free_irq() shuts it down. The
next request_threaded_irq() in phy_request_interrupt() goes through
irq_startup(), which sets desc->depth = 0. So the line is enabled while
irq_rerun is still 1.

There seem to be two ways to reach that state:

  a) mdio_bus_phy_resume() returns early on a phy_init_hw() or
     phy_resume() failure. That leaves irq_suspended == true and
     irq_rerun == 1. Later the interface is cycled through
     phy_disconnect()/phy_connect().

  b) A MAC driver without mac_managed_pm frees and re-requests the PHY
     IRQ in its own PM callbacks. The parent MAC resumes before the PHY,
     so the re-request runs while irq_suspended is still true.

In both cases, the next PHY interrupt takes the postponed branch and sees
irq_rerun == 1. It skips disable_irq_nosync() and returns IRQ_HANDLED
without calling drv->handle_interrupt().

The PHY interrupt status is never cleared. On a level-triggered
IRQF_ONESHOT line, the IRQ core unmasks after the thread returns and the
interrupt fires again right away.

Could this become an IRQ storm, with no end in case a) and lasting until
PHY resume in case b)?

In case b), mdio_bus_phy_resume() then runs:

		if (atomic_xchg(&phydev->irq_rerun, 0)) {
			enable_irq(phydev->irq);

on a line at depth 0. Would that trigger the "Unbalanced enable for IRQ"
warning? Before this patch, every postponed run disabled the line, so
the later enable_irq() stayed balanced.

Two later patches in this series appear to resolve this: "net: phy:
balance a postponed PHY interrupt when the interrupt is freed" and "net:
phy: stop postponing PHY interrupts when a PHY PM callback fails". The
first resets irq_rerun in phy_free_interrupt(). The second routes the
resume error paths through mdio_bus_phy_resume_irq().

Since this commit has a Fixes: tag, would a stable backport of it
without those follow-ups bring in this regression?

> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 79dba43d703a2..d5d0efc104187 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -344,7 +344,7 @@ static __maybe_unused int mdio_bus_phy_suspend(struct device *dev)
>  	 * has resumed. Wait for concurrent interrupt handler to complete.
>  	 */
>  	if (phy_interrupt_is_valid(phydev)) {
> -		phydev->irq_suspended = true;
> +		WRITE_ONCE(phydev->irq_suspended, true);
>  		synchronize_irq(phydev->irq);
>  	}

[Severity: Medium]
This is a pre-existing issue and was not introduced by this patch. What
clears irq_suspended if phy_suspend() fails?

mdio_bus_phy_suspend() sets the flag here and then ends with:

	phydev->suspended_by_mdio_bus = 1;

	return phy_suspend(phydev);

If phy_suspend() returns an error, the PM core skips this device's
resume callback in device_resume(), so irq_suspended stays true.

Every later phy_interrupt() run then takes the postponed branch. The
first one disables the line, and nothing re-enables it until another
full suspend/resume cycle.

mdio_bus_phy_resume() seems to end up the same way on its error paths:

	ret = phy_init_hw(phydev);
	if (ret < 0)
		return ret;

	ret = phy_resume(phydev);
	if (ret < 0)
		return ret;
no_resume:

Both returns skip the block that clears irq_suspended, consumes
irq_rerun and calls enable_irq().

Would the PHY link interrupt then stay disabled, so link changes are
lost?

The later patch in this series, "net: phy: stop postponing PHY
interrupts when a PHY PM callback fails", appears to fix both paths by
calling mdio_bus_phy_resume_irq() on these failures.

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261031-b4-phylib-mac-pm-irq-v3-v4-0-5ba23b3ff9a4%40iav.lv
Technical Details
Message-ID: <179352219260.3131.3775758268420642181@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354205-linux-kernel-netdev=dewy.ru
References: <20261031-b4-phylib-mac-pm-irq-v3-v4-2-5ba23b3ff9a4@iav.lv>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354205-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v4 2/5] net: phy: disable the line of a postponed PHY
 interrupt only once
Date: Sun, 01 Nov 2026 08:36:32 +0000
Organization: Usenet Network
Message-ID: <179352219260.3131.3775758268420642181@kernel.org>
References: <20261031-b4-phylib-mac-pm-irq-v3-v4-2-5ba23b3ff9a4@iav.lv>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2653883"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:K7cLm7feLfSRkhsNx/ilq8lM8Kk= sha256:KPF1d8Utr4JZEzXG3aIHOVox92RSrsIugvVz0VmGoIw=
	sha1:oGbZFO7yVwYghS/P5BGYjbCDTUk= sha256:m6vP705bUk/1bEZrg6wzAef6Gg/TwITYaLk7g1AXMbU=
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 4B5DE112305; Sun,  1 Nov 2026 11:37:31 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, 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] 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 ZPXIUkWNruyy;
	Sun,  1 Nov 2026 11:37:28 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-354205-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 9F3C11122FD; Sun,  1 Nov 2026 11:37:18 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id A70BE2A91E; Sun,  1 Nov 2026 08:36:42 +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=1793522202;
	b=FJn9RE6+RfWu0UhTS+DuDSFlNsMhU9U8lWs/TmOXycWovlrSZ47n3SdrgCVVJeKle3do
	 svkPUSoYOGtZ1GxTcOlobVPzwV5u++6iUfyiC/HcKgz8p2/VJd8GOnPfYqGVzrOleni2w
	 lH20K+w9BHbC/vbim76xjN3Exrj8kn8Fs9DZ6nyS3r3lRovhvWmpk8+lCTROtks2a0Qz8
	 9jj+9v6deTZ/nqWPjnpi3EpiWFSoybYW8hLS7NKzecJCLsyY7brzSfmZjIC+T+FQqzfPp
	 j6OLfcEQ+lnTImGjvO1Co/5kOqJUPU/VaIYhHY5j7PEslVidC/nHu6F2GarIoxpXEtg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793522202;
	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=Q8dXQ9ryUVTDCQ5xMUQGfCQz0vSmgN8XPPGnta6liS8=;
	b=nuojzI2vKRlkPv4EUVB0dsGz8qK+qI6PIQD6nqe+t+UJ9yCE2lhHpK42gIH5QqyfR7C2
	 PFwphFbfHM/cbxhVJoUtJpHgbrKZuvEy+TDMybggf/BIHq3KYJJMgmOihNWI1D9O+xjXq
	 dQCCxWgeb8UkmNbVIJpjF1Q5Kd/1SCWTEW2SOtIWMcv5WjwkC1G5PPpJ1xo4bSexP/lKg
	 6A6tDiYbtlK115wMtDc75WsxTm4OhVibWPllVkb1QWcRphxY+n+eX/ybgu/lZziqayj3J
	 xhjUOy41EBJ+XVXjzg/kJqM1jwix1NjWtLrTapTcQZKdJUd5Ejaq6RjZ84oj+EIPcWQ==
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="J/uAysWm";
	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 72FF3606A333;
	Sun,  1 Nov 2026 08:36:42 +0000 (UTC)
X-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=J/uAysWm
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=1793522194;
	b=hwz7mZjA2aHD24LAHtcNlXEDuIiAZ6SzgDu25evHWQ7SONIlOjwFj4THYp/8eiThVIVP
	 snbK5EYEw5xURnlclGDAD+PxMDzU1e6dbwO78n3/p99pYxQOCwvlL72Pmh3lg8fAIkpfN
	 I7aC52dZw+qnIm0Sw0bADp8YaW7Pbo/wRfu12ZW6ARm4gNwbwacEutFOgruCIQG2zENng
	 7QJkQak6BAqoKnM5WrFguRrOReinb4g0wETkZf7U/zhZqdP8Temj6gLNLJFt9TkgIDiFV
	 OyxSd4x8g68TvAdJrhIybzBxR5011QB3TnnwFSUTvBtKEU5FkLWEjcyESQJG+5v51Nw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793522194;
	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=Q8dXQ9ryUVTDCQ5xMUQGfCQz0vSmgN8XPPGnta6liS8=;
	b=mVGBbIo8cB1lvtglnhG2VhTHBh5Oew05c6zgZmvxyDhWtO9l5Qjp8x8dM+yHtAr77tv/
	 4F+ed7Ts0fqdNqbDWkeGRLrrUQT8QiHRsV3vfRkNzboijH4hriVLUBZbN4FJvlhnkeYG3
	 /YcJKez2upHHVwM5j256UBv0cVrozCpn7hG0L0TlOesIDFAugx9fQWZv0W8QTuZRJHh/r
	 V4l5p1QpUWCsAR/9DDLfwnKTixZCdNtSTj+zZjz42ZJyUKwGbwDjmvHi3YXoNuj7RdQmj
	 hLVpuT35XnqknQFqZBqwL8FRypUebnxWDi6I+KNzYSfXdLvYI2EFPN+lVuPCjvS6Z7Q==
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="J/uAysWm";
	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 85E9B606A324;
	Sun,  1 Nov 2026 08:36:34 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CC021F000C1;
	Sun,  1 Nov 2026 08:36:32 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793522194;
	bh=Q8dXQ9ryUVTDCQ5xMUQGfCQz0vSmgN8XPPGnta6liS8=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=J/uAysWm9ZhHLp+YN/QuxKhdNxuGmk50BVnad1guZOwNgSOEZ35cnq83H+5S0dEq2
	 oGuYALwj+BcaBnIwQ5Y965jZUm7w9LwWoEjgB6sn/nzPR4+mxBm3xpZwvmY1KTgb83
	 HcmKXWjijcDkHX78emx7Fac3wt7Oker6QtSlpDyMvgyv0ysugytq861MDrNWsPx5zw
	 yzOtiqbKpSg5DqKCdPjELPqWjdRLTciqQMEL7qhy5ntZ2KbYfPfigrex7PTqxwvUPr
	 s2oIZkdHvUxMFvWG2ByEpnUluGSkabMhVMxCP8IFviNV98swWhwtTrNgId2+B1kY6s
	 HD/4C8CVqIR2w==
X-Cc: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk,
 davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 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, netdev@vger.kernel.org,
 linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <20261031-b4-phylib-mac-pm-irq-v3-v4-2-5ba23b3ff9a4@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