Netdev List
 help / color / mirror / Atom feed
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
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	[thread overview]
Message-ID: <179632987837.3146.12860767392112121060@kernel.org> (raw)
In-Reply-To: <20261202-b4-phylib-mac-pm-irq-v3-v10-5-2f938d473f17@iav.lv>

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

      reply	other threads:[~2026-12-03 20:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 20:16 [PATCH net v10 0/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
2026-12-02 20:16 ` [PATCH net v10 1/5] net: phy: move irq_suspended and irq_rerun out of the bitfield Igor Velkov via B4 Relay
2026-12-02 20:16 ` [PATCH net v10 2/5] net: phy: fix three paths that unbalance a postponed PHY interrupt line Igor Velkov via B4 Relay
2026-12-03 20:31   ` netdev-bot+sashiko
2026-12-02 20:16 ` [PATCH net v10 3/5] net: phy: stop postponing PHY interrupts when phy_suspend() fails Igor Velkov via B4 Relay
2026-12-02 20:16 ` [PATCH net v10 4/5] net: phy: run a postponed PHY interrupt handler directly on resume Igor Velkov via B4 Relay
2026-12-03 20:31   ` netdev-bot+sashiko
2026-12-02 20:16 ` [PATCH net v10 5/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
2026-12-03 20:31   ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179632987837.3146.12860767392112121060@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=Haoning.CHENG@cn.bosch.com \
    --cc=Thangaraj.S@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=hkallweit1@gmail.com \
    --cc=iav@iav.lv \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=lukas@wunner.de \
    --cc=maxime.chevallier@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=niklas.soderlund@ragnatech.se \
    --cc=opendmb@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=paul@pbarker.dev \
    --cc=rafael.j.wysocki@intel.com \
    --cc=shenwei.wang@nxp.com \
    --cc=tglx@kernel.org \
    --cc=wei.fang@nxp.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox