🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26573

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

#26573
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 20:31
165 lines
14699 bytes
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
Technical Details
Message-ID: <179632987448.3146.13504006246619970930@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376848-linux-kernel-netdev=dewy.ru
References: <20261202-b4-phylib-mac-pm-irq-v3-v10-2-2f938d473f17@iav.lv>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376848-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v10 2/5] net: phy: fix three paths that unbalance a
 postponed PHY interrupt line
Date: Thu, 03 Dec 2026 20:31:14 +0000
Organization: Usenet Network
Message-ID: <179632987448.3146.13504006246619970930@kernel.org>
References: <20261202-b4-phylib-mac-pm-irq-v3-v10-2-2f938d473f17@iav.lv>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2588183"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:nJ7hJ7Y+T42bNuwPlLv9Lp42GEw= sha256:0g15GFvunD6o4eOFDU5eSvcAVjFwlBibbeXuFZhjjIU=
	sha1:+GBvdww6iYrKNXiu1mS7xss2b4E= sha256:YCFCopygLqLen4uqlAi9eRdfQiJ56wA76YTMdpFFU9U=
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 2FD7C117A29; Thu,  3 Dec 2026 23:31:33 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.64
X-Spam-Status: No, score=-3.64 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.24, 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 P7j4KvvXbXLS;
	Thu,  3 Dec 2026 23:31:30 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376848-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 05AF81179BD; Thu,  3 Dec 2026 23:31:21 +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 3797527CA3; Thu,  3 Dec 2026 20:31:18 +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=1796329877;
	b=tSQqPsiEwwM5XJt2ZuUx5zbxahxLDYyZuNmvn+Pmxch4Ak41DtgK5q5GLIWph/utecSR
	 SFA0mZarqeetgpwBMx3pob6FFWlAxFFwmsCHZRfZwC8WYsXd4cVKe5oSDDUyKSl5T1Toa
	 T3kKGlfxqAHxwhZkT+tAAe0QaxNKhqNANGd3h8qth/NOuKhft8GP8v4ZMI7VR4Li+QKJJ
	 QD8nAkBQlhmwhPBrAAwm2qcusvzv0rLPuHHM5Jzj/W9pNSMmnFK2p4Xxw2dq8kkgMwoNH
	 m+bw4fZAJvNcJ83Hc9e8fapUwRU7/WOrTK6vSXNYtjiqzErSYnifzs4/uKGUOiyiPDw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796329877;
	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=POkZb3OyudlRjtI0mJEA6PLMmvbN53xrIM7aGV1iMFg=;
	b=p88jLtO321CtYvf5O5I8A/TaxnCDnE/fh24IZ2hk6hVdcgsEqfpaDRzZ1NuAMXgESjbz
	 0g3RVj75yt1Oj5e5NiazOrlCHlh4pMMzrP5Srh2KbzcM4I/Ktg3/tNXf4mBMf6AGGDYRl
	 z6zt2rtHzGUzy/zFEQdwwqftraoEOMS2yYL1oOqj6sxLDLsfm4tzWT0fN8Tlxha7D5Lak
	 YhZQnW+Zmf70i0QOTUK7E8D6/uYKKcQaT+YkNRD3HfxX3/MZ03sUugafx6rJMao77fYKT
	 +Gw2vYdbgimwihUSWI77ip7iujPlQlqMCpQw4EtL069Bnn5iu5EseMjWwWOuyS1P3Fg==
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=H51dAeDD;
	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 7CDB0606A33A;
	Thu,  3 Dec 2026 20:31:17 +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=H51dAeDD
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=1796329876;
	b=OzaM0onz4Dv1DdfA48He4e+vQaT8CNma3EHMlecvZJoIsCBVyfuR8ZdyKu756tFpsp8o
	 J2lBD1FKwWx65VIQXF/v4sC8yXivddtGDx17n1Tk1W0WgAHW7q8ctSMK5nJBHNTAofQzd
	 7A53G3xBninZZv7razRVh2wr7H+SbpADK90CUEpkII/FBUTg7cClwnmE2YIRKGqR/24J0
	 WBQPEcJZ1XDmUXd1vxhr6QuR8SPsuQMDlb11ePBpAIg1A0k4FqUNAGRzhOQ1Orq1tJFwZ
	 BzlmbHZ9rk59uIGYFzctWrMXyKrnLYibaxVCD47M5HrKnQ/P37fbmy8ZnTGuN50e9Fw==
X-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==
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=H51dAeDD;
	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 9B40F606A322;
	Thu,  3 Dec 2026 20:31:16 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E62861F000C2;
	Thu,  3 Dec 2026 20:31:14 +0000 (UTC)
X-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==
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: <20261202-b4-phylib-mac-pm-irq-v3-v10-2-2f938d473f17@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