Linux-Rockchip Archive on lore.kernel.org
 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, 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, netdev@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v6 4/4] net: phy: postpone PHY interrupts during sleep with MAC-managed PM
Date: Tue, 17 Nov 2026 12:08:26 +0000	[thread overview]
Message-ID: <179491730695.3136.5496741718229288871@kernel.org> (raw)
In-Reply-To: <20261113-b4-phylib-mac-pm-irq-v3-v6-4-05af2503cb23@iav.lv>

Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 4 · 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).

- [High] net: phy: inverted PM IRQ ordering when consumer MAC links to
  PHY
- [Medium] PHY Wake-on-LAN can be lost for MAC-managed PHYs whose
  interrupt line is also their wake IRQ.
- [Medium] The postponed interrupt is lost for MAC-managed PHYs whose
  interrupt is a nested threaded IRQ (for example PHY INT routed through…
- [Medium] A shared IRQ line's disable depth can leak when a MAC-managed
  PHY's interrupt is re-requested from the MAC's resume callback.
- [Medium] net: phy: unbalanced enable_irq() in mdio_bus_phy_resume_irq()
  on shared IRQ

--

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

This commit makes mdio_bus_phy_suspend() and mdio_bus_phy_resume() set
and clear irq_suspended for PHYs whose PM is managed by the MAC driver.
phy_interrupt() then postpones handling during the sleep transition
instead of touching a possibly powered-down MDIO bus. For MAC-managed
PHYs, the postponed interrupt no longer reports a wakeup event.

> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index 8e03c99fce8f5..ccf0658c4d101 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) {
>  			struct device *parent = netdev->dev.parent;
>  
>  			if (netdev->ethtool->wol_enabled)

[Severity: Medium]
With this patch, a MAC-managed PHY gets irq_suspended set in
mdio_bus_phy_suspend() before the MAC's own suspend callback runs. Any
PHY interrupt from then until mdio_bus_phy_resume() takes this postponed
path. For mac_managed_pm no wakeup is reported, but the line is still
disabled:

		if (!phydev->irq_rerun) {
			phydev->irq_rerun = true;
			disable_irq_nosync(irq);
		}

Could this lose PHY Wake-on-LAN for the whole sleep on PHYs whose
interrupt line is also their wake IRQ? Both rtl8211f_probe() and
an8801r_probe() register phydev->irq as the wake IRQ:

		devm_pm_set_wake_irq(dev, phydev->irq);

In the noirq phase, suspend_device_irq() re-enables a disabled
wake-armed line only when the irqchip has
IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND:

kernel/irq/pm.c:suspend_device_irq() {
    ...
		if ((chipflags & IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND) &&
		     irqd_irq_disabled(irqd)) {
			...
			__enable_irq(desc);
    ...
}

On other irqchips the line would stay masked until resume. A later PME
or magic packet interrupt then could not wake the system.

One concrete case is stmmac with an RTL8211F and PHY WoL enabled. The
link partner changes the link after irq_suspended is set, but before
rtl8211f_suspend() switches INER to PME only:

	if (device_may_wakeup(&phydev->mdio.dev)) {
		ret = phy_write_paged(phydev, 0xa42, RTL821x_INER,
				      RTL8211F_INER_PME);

rtl8211f_suspend() then clears INTB. The software disable of the line
stays in place until mdio_bus_phy_resume_irq().

Before this patch, phy_interrupt() ran handle_interrupt() here and the
oneshot line was unmasked again. On boards whose MDIO bus stays
powered, WoL kept working in this case.

The phylink_speed_down() renegotiation in phylink_suspend() does not
appear to trigger this for RTL8211F or AN8801.
phylink_stop()->phy_stop()->phy_suspend() already restricts the
interrupt mask before that point. It would only matter for a wake IRQ
PHY that leaves link interrupts unmasked in suspend.

The commit message says the line "may then stay masked until resume, so
such a PHY may not wake the system from that sleep". It does not say
that any link event in this window disables WoL for the whole sleep
cycle.

The Helios64 WoL test also runs on gpio-rockchip, and
rockchip_irq_suspend() does this:

	irq_reg_writel(gc, ~gc->wake_active, bank->gpio_regs->int_mask);

That unmasks wake pins in hardware whatever the software disable state
is. Would that test be able to show this regression?

> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 39e232a3144a2..c043071784f5b 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -369,11 +369,14 @@ static __maybe_unused int mdio_bus_phy_suspend(struct device *dev)
>  	struct phy_device *phydev = to_phy_device(dev);
>  	int ret;
>  
> +	/* An interrupt can fire while the MAC has the MDIO bus powered
> +	 * down, whether or not the MAC manages PHY PM.
> +	 */
> +	mdio_bus_phy_suspend_irq(phydev);
> +
>  	if (phydev->mac_managed_pm)
>  		return 0;

[Severity: Medium]
For a MAC-managed PHY, irq_suspended is now set here, before the MAC's
suspend callback runs. cpsw and cpsw_new set mac_managed_pm, and they
also disconnect the PHY from that callback. cpsw_suspend() calls
cpsw_ndo_stop(), which ends in phy_disconnect(), and cpsw_resume()
connects the PHY again.

Can this leave a stale irq_rerun and an unbalanced enable_irq() on a
board where the two slave PHYs share one interrupt line?

phy_request_interrupt() uses IRQF_ONESHOT | IRQF_SHARED, so phy0 and
phy1 each have an action on the same irq_desc. If the line fires after
both mdio_bus_phy_suspend() calls, both threads run. Each
phy_interrupt() takes the postponed path, sets its own irq_rerun and
calls disable_irq_nosync(). The depth is then 2.

cpsw_suspend() then disconnects phy0. phy_free_interrupt() keeps
phy0->irq_rerun set, because phy1 still has an action on the line:

	if (!irq_has_action(phydev->irq))
		phydev->irq_rerun = false;

Disconnecting phy1 removes the last action. free_irq() shuts the line
down and phy1->irq_rerun is cleared, but phy0->irq_rerun stays true.

On resume, cpsw_resume() runs before mdio_bus_phy_resume() and calls
phy_request_interrupt() again. With no actions left on the line,
__setup_irq() calls irq_startup() and the depth goes back to 0.
mdio_bus_phy_resume_irq() for phy0 still sees irq_rerun:

	if (phydev->irq_rerun) {
		phydev->irq_rerun = false;
		enable_irq(phydev->irq);
		irq_wake_thread(phydev->irq, phydev);
	}

Wouldn't that enable_irq() hit the unbalanced enable WARN in
__enable_irq()?

The stale flag also matters before that point. Suppose the line fires
after cpsw_resume() has requested phy0's IRQ but before
mdio_bus_phy_resume(). phy_interrupt() for phy0 sees irq_rerun already
set and skips disable_irq_nosync(). It returns IRQ_HANDLED without
touching the PHY. If phy1 has not been reconnected yet, nothing masks a
level-triggered line, so the oneshot thread keeps being woken.

MAC-managed PHYs could not get here before, because irq_suspended was
never set for them. Should phy_free_interrupt() undo this PHY's own
disable_irq_nosync() whenever irq_rerun is set, instead of basing the
cleanup on irq_has_action()?

[Severity: Medium]
For MAC-managed PHYs, irq_suspended is now set here and cleared only in
mdio_bus_phy_resume(). That runs after the MAC's resume callback, so
the flag is still true while the MAC resumes.

ravb and sh_eth set mac_managed_pm. They call phy_disconnect() in
suspend and of_phy_connect() in resume. So the PHY IRQ is requested
again while irq_suspended is true:

ravb_resume()->ravb_open()->...->phy_request_interrupt()

Can this leave a shared IRQ line disabled?

On an IRQF_SHARED line, the other device can interrupt after
request_threaded_irq(). phy_interrupt() then takes the postponed path,
sets irq_rerun and calls disable_irq_nosync(). Suppose
phy_enable_interrupts() then fails:

drivers/net/phy/phy.c:phy_request_interrupt() {
    ...
		if (phy_enable_interrupts(phydev)) {
			phydev_warn(phydev, "Can't enable interrupt, falling back to polling\n");
			phy_free_interrupt(phydev);
			phydev->irq = PHY_POLL;
		}
    ...
}

phy_free_interrupt() clears irq_rerun only when the line has no other
actions left. On a shared line it still has one:

	if (!irq_has_action(phydev->irq))
		phydev->irq_rerun = false;

mdio_bus_phy_resume_irq() then returns early because the IRQ is now
PHY_POLL:

	WRITE_ONCE(phydev->irq_suspended, false);
	if (!phy_interrupt_is_valid(phydev))
		return;

The matching enable_irq() never runs. Wouldn't the other device on that
line stop getting interrupts, with irq_rerun left stale?

MAC-managed PHYs could not reach this path before, because irq_suspended
was never set for them.

>  
> -	mdio_bus_phy_suspend_irq(phydev);
> -
>  	/* We must stop the state machine manually, otherwise it stops out of
>  	 * control, possibly with the phydev->lock held. Upon resume, netdev
>  	 * may call phy routines that try to grab the same lock, and that may

[ ... ]

> @@ -406,8 +409,10 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev)
>  	struct phy_device *phydev = to_phy_device(dev);
>  	int ret;
>  
> -	if (phydev->mac_managed_pm)
> +	if (phydev->mac_managed_pm) {
> +		mdio_bus_phy_resume_irq(phydev);
>  		return 0;
> +	}

[Severity: High]
The ordering argument in the commit message needs the MAC to be the
MDIO bus parent or one of its ancestors. That does not hold when the
PHY sits on an MDIO bus owned by another device. In that case
phy_attach_direct() calls device_link_add() with dev->dev.parent as
consumer and &phydev->mdio.dev as supplier.

device_link_add() moves the consumer to the tail of dpm_list. The MAC
then suspends before mdio_bus_phy_suspend() and resumes after
mdio_bus_phy_resume(). Examples are two FEC instances with
FEC_QUIRK_SINGLE_MDIO, dual stmmac or macb sharing one MDIO bus, and
MACs behind an mdio-mux.

On resume, mdio_bus_phy_resume() for such a PHY clears irq_suspended
and replays the postponed interrupt before the consumer's resume
callback has run. handle_interrupt() then reads the PHY before
fec_resume() has re-enabled fep->reg_phy and fep->clk_enet_out. It
also runs before phy_resume() has turned the PHY driver's own clock
back on, as rtl821x_resume() does with priv->clk. Interrupts after this
point are not postponed either.

If that MDIO access fails, the handler calls phy_error() and the state
becomes PHY_ERROR. phy_start() from the MAC's resume only accepts
PHY_READY or PHY_HALTED, so it hits its WARN and returns without
starting the PHY. The link then stays down after resume.

If the access succeeds, phydev->state is still PHY_HALTED.
phy_trigger_machine() then queues a state machine run that takes the
PHY_STATE_WORK_SUSPEND path and calls phy_suspend() outside
phydev->lock. Can that race with the MAC's later
phy_start()->__phy_resume()?

The suspend side is not covered for this topology either. The
consumer's suspend callback runs before mdio_bus_phy_suspend() sets
irq_suspended. That callback may call phy_stop(), call
phylink_speed_down() as stmmac_suspend() does, or gate clocks and
regulators as fec_suspend() does. A link-down interrupt caused there
still runs the handler directly.

So for these PHYs the patch only moves the handler from
resume_device_irqs() to mdio_bus_phy_resume(), still ahead of the MAC.
Should the replay for a PHY with phydev->devlink wait until the
consumer has resumed? Or should the commit message say that this
topology is not covered?

[Severity: Medium]
For a MAC-managed PHY, this replay now runs without a phy_init_hw() call
before it:

	if (phydev->irq_rerun) {
		phydev->irq_rerun = false;
		enable_irq(phydev->irq);
		irq_wake_thread(phydev->irq, phydev);
	}

Is the postponed interrupt lost when the PHY interrupt is a nested
threaded IRQ? One example is a PHY INT routed through an I2C or SPI GPIO
expander such as pca953x.

For a nested IRQ, __setup_irq() creates no thread. irq_wake_thread()
only wakes a thread that exists:

kernel/irq/manage.c:irq_wake_thread() {
    ...
		if (action->dev_id == dev_id) {
			if (action->thread)
				__irq_wake_thread(desc, action);
			break;
		}
    ...
}

The postponed path in phy_interrupt() disabled the line without reading
the PHY's interrupt status. Getting there only takes the MAC's suspend
stopping the PHY and the link going down, as the commit message
describes.

After resume, nothing reads the latched status (for example RTL8211F
INSR), so INT stays asserted. An edge-triggered expander input would
then never see a new edge.

For non-MAC-managed PHYs this is hidden: mdio_bus_phy_resume() calls
phy_init_hw()->config_intr() before the replay. stmmac_resume() does not
call phy_init_hw(), while fec_resume() does.

The state machine is in interrupt mode and does not poll. On such stmmac
boards, could link up go unreported after resume, leaving the network
down until the interface is reinitialised?

>  
>  	if (!phydev->suspended_by_mdio_bus)
>  		goto no_resume;

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-b4-phylib-mac-pm-irq-v3-v6-0-05af2503cb23%40iav.lv

_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

      reply	other threads:[~2026-11-17 12:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 21:06 [PATCH net v6 0/4] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
2026-11-13 21:06 ` [PATCH net v6 1/4] net: phy: move irq_suspended and irq_rerun out of the bitfield Igor Velkov via B4 Relay
2026-11-13 21:06 ` [PATCH net v6 2/4] net: phy: keep the line of a postponed PHY interrupt balanced Igor Velkov via B4 Relay
2026-11-17 12:08   ` netdev-bot+sashiko
2026-11-13 21:06 ` [PATCH net v6 3/4] net: phy: stop postponing PHY interrupts when phy_suspend() fails Igor Velkov via B4 Relay
2026-11-13 21:06 ` [PATCH net v6 4/4] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
2026-11-17 12:08   ` 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=179491730695.3136.5496741718229288871@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-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=wei.fang@nxp.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