🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26575

Re: [PATCH net v10 5/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM

#26575
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 20:31
264 lines
18214 bytes
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 2

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] For MAC-managed PHYs, link interrupts now go unacknowledged
  from the prepare callback onwards, and the new noirq callback re-…
- [Medium] mdio_bus_phy_suspend_noirq() calls enable_irq() only when
  irqd_is_wakeup_armed() is true.
- [Low] Several comments no longer match the code.
- [Low] phy_interrupt() now reads phydev->mac_managed_pm in its postponed
  branch without phydev->lock.

--

net: phy: postpone PHY interrupts during sleep with MAC-managed PM

For PHYs with MAC-managed PM, this patch starts postponing PHY interrupts
in a new prepare callback and replays them in a new complete callback.
This keeps the PHY driver's handler off an MDIO bus that the MAC has
powered down. It also adds noirq suspend/resume callbacks that re-enable,
for the noirq phase, a wake-armed line that a postponed interrupt
disabled, and it stops postponed interrupts on MAC-managed PHYs from
reporting a wakeup.

> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index 6dce49f01d2ba..4a33100fa809b 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -1419,7 +1419,10 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
>  	if (IS_ENABLED(CONFIG_PM_SLEEP) && READ_ONCE(phydev->irq_suspended)) {
>  		struct net_device *netdev = phydev->attached_dev;
>  
> -		if (netdev) {
> +		/* With MAC-managed PM, a postponed interrupt cannot tell
> +		 * Wake-on-LAN from a link change the MAC causes.
> +		 */
> +		if (netdev && !phydev->mac_managed_pm) {

[Severity: Low]
The threaded handler reads phydev->mac_managed_pm here without
phydev->lock. mac_managed_pm is an unsigned :1 bitfield. It shares a word
with suspended, wol_enabled, link, autoneg and autoneg_complete.

Between prepare and complete, the MAC's suspend and resume callbacks run
phy_suspend(), phy_resume() and the state machine. Those do
read-modify-write stores to the same word.

Could KCSAN report a data race on this load?

The result is still correct, because mac_managed_pm does not change after
attach. Still, this patch's own phy.h comment keeps the irq_* flags out of
bitfields for this reason:

	/* Not bitfields: a bitfield store rewrites the whole word and can undo
	 * a concurrent store to another of its bits
	 */

[ ... ]

> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 16b398794486f..2f413147c3112 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c

[ ... ]

> @@ -446,8 +475,48 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev)
>  	return 0;
>  }
>  
> -static SIMPLE_DEV_PM_OPS(mdio_bus_phy_pm_ops, mdio_bus_phy_suspend,
> -			 mdio_bus_phy_resume);
> +static __maybe_unused int mdio_bus_phy_suspend_noirq(struct device *dev)
> +{
> +	struct phy_device *phydev = to_phy_device(dev);
> +	struct irq_data *d;
> +
> +	mutex_lock(&phydev->irq_pm_lock);
> +	/* We enable the line a postponed interrupt disabled if the irq core
> +	 * armed it for wakeup, so that it wakes the system.
> +	 */
> +	if (phydev->irq_rerun) {
> +		d = irq_get_irq_data(phydev->irq_rerun_line);
> +		if (d && irqd_irq_disabled(d) && irqd_is_wakeup_armed(d)) {

[Severity: Medium]
Can this condition ever be true when phydev->irq is a nested-threaded
child, such as regmap-irq, an I2C/SPI GPIO expander or a switch irqchip?

suspend_device_irqs() skips those descriptors, and suspend_device_irq() is
the only place that sets IRQD_WAKEUP_ARMED:

kernel/irq/pm.c:suspend_device_irqs() {
    ...
	for_each_irq_desc(irq, desc) {
		bool sync;

		if (irq_settings_is_nested_thread(desc))
			continue;
    ...
}

phylib does expect PHYs on nested-threaded lines. See the comment in
mdio_bus_phy_resume_irq():

		/* A nested threaded line has no thread; we run the handler */

Take a MAC-managed PHY on such a line with an interrupt between prepare
and the noirq phase. It reaches phy_interrupt(), reports no wakeup
because of the new mac_managed_pm check, and calls disable_irq_nosync().
The check above then always fails, so the child stays disabled for the
whole sleep.

Some parent chips mask a disabled child in hardware. regmap_irq_disable()
does this: it sets the bit in mask_buf, and regmap_irq_sync_unlock()
writes it out. Does the parent line then ever fire for the PHY, or does
the system sleep through Wake-on-LAN?

That is the case these noirq callbacks were added to handle. Before this
patch, MAC-managed PHYs were never postponed, so this path is new for
them.

I haven't found such a board in tree. Chips that disable lazily would
still let the parent wake the system.

> +			enable_irq(phydev->irq_rerun_line);
> +			phydev->irq_wake_enabled = true;
> +		}
> +	}

[Severity: Medium]
Can this enable_irq() abort every suspend with Wake-on-LAN on a
level-triggered line? This happens when the PHY driver does not mask its
link interrupt in its suspend callback.

>From mdio_bus_phy_prepare() onwards, phy_interrupt() no longer reads or
acknowledges a link interrupt on a MAC-managed PHY. It disables the line
while the line is still asserted.

This code then enables the still-asserted line while IRQD_WAKEUP_ARMED is
set. The flow handler goes through
irq_pm_handle_wakeup()->pm_system_irq_wakeup(), and the suspend aborts.

The commit message makes PHY drivers responsible for this:

    its driver has to restrict the
    interrupt to Wake-on-LAN in its suspend callback, as rtl8211f_suspend()
    does

Existing drivers do not seem to have been checked against that.

For example, bcm_phy_set_wol() arms phydev->irq with enable_irq_wake(),
and BCM54210E sets PHY_ALWAYS_CALL_SUSPEND. With WoL enabled,
bcm54xx_suspend() returns before it touches the link interrupts:

drivers/net/phy/broadcom.c:bcm54xx_suspend() {
    ...
	/* Acknowledge any Wake-on-LAN interrupt prior to suspend */
	ret = bcm_phy_read_exp(phydev, BCM54XX_WOL_INT_STATUS);
	if (ret < 0)
		return ret;

	if (phydev->wol_enabled)
		return bcm54xx_set_wakeup_irq(phydev, true);
    ...
}

The link, speed and duplex interrupts set up by bcm_phy_config_intr()
stay enabled, and phy_stop() doesn't disable them either.

stmmac sets wol_phy_speed_ctrl, so phylink_suspend() renegotiates the
link after phylink_stop():

	if (phylink_phy_pm_speed_ctrl(pl))
		phylink_speed_down(pl, false);

so every suspend would go like this:

phylink_suspend()->phylink_speed_down()
  link interrupt -> phy_interrupt() with irq_suspended set
    no status read, no wakeup reported, disable_irq_nosync()
suspend_device_irqs()
  sets IRQD_WAKEUP_ARMED, leaves the line disabled
mdio_bus_phy_suspend_noirq()
  enable_irq() on the still-asserted level line
    irq_pm_handle_wakeup()->pm_system_irq_wakeup()

Some boards don't do the speed-down, such as GENET, bcmasp or bcmsysport
with a BCM54xx PHY. On those, any link change between prepare and
suspend_device_irqs() would now abort that suspend attempt. Before this
patch the handler acknowledged it.

I couldn't confirm that a board with the stmmac and BCM54210E
combination exists in tree. Before this patch, the link-up interrupt
after renegotiation could probably already arrive after the line was
armed and wake the system. The immediate abort through this noirq
re-enable looks new.

The commit message says "no MAC driver needs a change". Should it also
list the existing PHY drivers that do need a change, or should this
series update them?

[ ... ]

> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 23d88cfa858be..2dba4f2bbc935 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h

[ ... ]

> @@ -677,9 +682,9 @@ struct phy_oatc14_sqi_capability {
>   * @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;
> - *               protects @irq_requested; taken before @lock;
> - *               phy_interrupt() never takes it
> + *               of the interrupt where they test and clear @irq_rerun and
> + *               @irq_wake_enabled; protects @irq_requested; taken before
> + *               @lock; phy_interrupt() never takes it

[Severity: Low]
This isn't a bug, but a few comments no longer match the code.

"Held by the PM callbacks" is not true for the new
mdio_bus_phy_prepare() and mdio_bus_phy_complete(). They write
irq_suspended and set, test and clear irq_prepared without irq_pm_lock.

Nothing documents what protects irq_prepared. In practice the PM core
serialises prepare and complete.

The comments above mdio_bus_phy_suspend_irq() and in phy_interrupt()
still say:

/* Wakeup interrupts may occur during the system sleep transition when
 * the PHY is inaccessible. Set flag to postpone handling until the PHY
 * has resumed. Wait for concurrent interrupt handler to complete.
 */

and

	/* Wakeup interrupts may occur during a system sleep transition.
	 * Postpone handling until the PHY has resumed.
	 */

For MAC-managed PHYs, postponing now starts in prepare and ends in
complete, and phylib never resumes the PHY.

Could these comments be updated to match the new @irq_suspended
kernel-doc ("with MAC-managed PM until the complete callback")?

[ ... ]

-- 
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: <179632987837.3146.12860767392112121060@kernel.org>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376850-linux-kernel-netdev=dewy.ru
References: <20261202-b4-phylib-mac-pm-irq-v3-v10-5-2f938d473f17@iav.lv>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376850-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v10 5/5] net: phy: postpone PHY interrupts during
 sleep with MAC-managed PM
Date: Thu, 03 Dec 2026 20:31:18 +0000
Organization: Usenet Network
Message-ID: <179632987837.3146.12860767392112121060@kernel.org>
References: <20261202-b4-phylib-mac-pm-irq-v3-v10-5-2f938d473f17@iav.lv>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2588433"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:x0pQViSB8m73Cv7pjP+e2gsNWVg= sha256:QjPNu2tSGwXNEAtg/gHsp+MxzTub4A16ZwAF7yRyyCs=
	sha1:FNer5r2z2K5jX8T+BJ4XqV+aIME= sha256:ThAcmhrZmoaaG5S/5Vd8fFVROh0mnvOnINHY2RIh8TY=
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 1DD57117A29; Thu,  3 Dec 2026 23:31:42 +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 50uSkVbeQGhJ;
	Thu,  3 Dec 2026 23:31:39 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376850-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 E28051179BD; Thu,  3 Dec 2026 23:31:30 +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 E964428DA4; Thu,  3 Dec 2026 20:31:21 +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=1796329881;
	b=x+QKn47hUviojktw8wxwf1Gxm9jFliQK3l6bbSBEChRhOfaVifMQGgwgs1NsnnVAdKgM
	 rizS+At95gvbslI6BaaQO0hs3+oZPcT/Lx9IxjTUAu/PfjfR0zB6AP9DUzKy9+8Qo8TfQ
	 f02bO5pM6hEprJOs20WOFqps+K9M4TbIl+icQjCL2Uqm0KiHW5jhA+J0QwHq+VjPltDEQ
	 EzDwTVyba3BjvNVDtV4X7NH5bAvQsMTRXuTtN4/hXfvUx9Zw0AmhxJzDu5sAmUSsa8+y2
	 Lq4Q4j4ZBAzq+ORm7GJNHIp05qUsVIRdUcBJZ3i5LboXDIJNiPtd7Hsm/LciQBkWQhA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796329881;
	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=EGuw7EYxtoS94oEdwh10c86cVrkWRLHlpK4V3ulo2Fs=;
	b=O+PNgbBA7cuP27+ojEunvu3Bfu6A+b2Idzi5hzBWbpv520nwgzrOvFpPXVMlK8Tb0HUs
	 cCn8FnjFpDBwKydTZrsb7WgH2Q2lSRm4OPo+IjC2cgf3LR45leMbnOInlbH7Kpo6RcvhJ
	 05X8Kc5PqPedWjn+7DWDsVbcRk6Rnvb/VngH2GFEfulEV1Kazo6moNK+qwYPdqTJspF1i
	 VBygrWN2s7WcBddVu8s3P/11kAZiEJvAsUedgHOfty0ykbla3lMgPMjlk8YacQiyuBxWk
	 v84Ebx0aOxWAxXW1lakW/Lh+7xgj8wyDW4uermZ7bJ9xK+RUh4CK/Gj9Ip0rAtXjdSg==
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=SmshtGRK;
	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 6D681606A685;
	Thu,  3 Dec 2026 20:31:21 +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=SmshtGRK
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=1796329880;
	b=sfkiRAOAwnA7TgNwx9tX+xsFTdB2iRee8LZ5SUmp2djH8DlmbWcQHapa2z6RRl7b2A5x
	 Hlfix6wW13W1NkxMOMUkLxlwpgk5MfePxuZGGTjhMbKUUDiG9zelyDg72lEog1u5tZI56
	 g4Ct9e2zTPc7fgRdbiLBXcXxTCLzReLUPB8Sty5npOoCQSCOP2ROd0oUMb/82vppNz1Ob
	 K/bRvMm9AiJAb0tV1HgMe1GKtOi6IovxQKAKJmKTYEwy0Qe3An2qP2wgMQcRpeNAt2Ai0
	 YC/540NmVgCpg+b9sfGv3Ig1iwr9vPGDIrlXqRhDKl5rngmaRkDBjNjiDZvc9m3Mz2Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796329880;
	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=EGuw7EYxtoS94oEdwh10c86cVrkWRLHlpK4V3ulo2Fs=;
	b=iE2GW9XzBqdTEdk3YAnISVWgozmw3vQRQp6Wb9dMGUder0aw/e0YebZec2rpg4zIkoJx
	 wlCvhlsOPZO4p4BKX/Emz8o9ivn2XcVTg1WEestF9JjDeBsdLl2SlV0JWZuZoFKqi5MZv
	 jMVr7977R2Vhf5LMvAHFuav1C7e6t5rhGs47SBdNWqAx7Ao5yreK51n2aPuITVdVJUKeB
	 34w5eKro7uGL/hTNmclF0KLOya/VGUWJYQj7mat8YdfdeDqLEEgSNszDRQizlCUzjWl2T
	 edNzzDHec2KbLgP77wgTBe9H6jrWMDz87QfSsFpRx/L5sOY/AscXtYIU3HGvPXLpQnw==
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=SmshtGRK;
	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 8D289606A32D;
	Thu,  3 Dec 2026 20:31:20 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4C9A1F000C2;
	Thu,  3 Dec 2026 20:31:18 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796329880;
	bh=EGuw7EYxtoS94oEdwh10c86cVrkWRLHlpK4V3ulo2Fs=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=SmshtGRKT4zqZQGVnYNCyb5XkOm9m3WbjV26Lj1NlD+1XjTm1rEyQRLvEwwPOpkbY
	 fJH9o2ecIEyRVjK4I57/6x/PWM2/WAoe5QYWlVrzZ98nHiBuUU3+v1vVpE7WF9C0vQ
	 2bqO7iZY3TXPaxICjyiXXAKwKufWvCLnVWTKL/TLIUzmpcZMaQpshC5vK+4g7NSAQi
	 XkFFXg+XCyuYVvV5otWdJNPydgp5n3EbaNPb77DO47FkTxTOI0vS99YnuJUvxbfm9i
	 3KqaJbjbbNDko13QtxRGkUfvVTnpbnVFwY/7eFzTDKN2rZXOy0NocoK3V4PJZdDSs7
	 StaQJ4PRJ4j9w==
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-5-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