mirror of https://lore.kernel.org/lkml/
 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, netdev@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v7 4/5] net: phy: run a postponed PHY interrupt handler directly on resume
Date: Sun, 22 Nov 2026 22:03:06 +0000	[thread overview]
Message-ID: <179538498682.3135.2758040683110452863@kernel.org> (raw)
In-Reply-To: <20261119-b4-phylib-mac-pm-irq-v3-v7-4-d8b8f43b5a62@iav.lv>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message claims that for a PHY without MAC-managed PM,
  mdio_bus_phy_resume() calls phy_init_hw() before the rerun, so…
- [Low] In mdio_bus_phy_resume_irq()
  (drivers/net/phy/phy_device.c:365-366), the new check `phydev->irq ==…
- [Low] The kernel-doc for @irq_pm_lock (include/linux/phy.h:678-679) and
  the comment on the member (line 814-817) say the lock 'Serializes…

--

net: phy: run a postponed PHY interrupt handler directly on resume

This commit replaces irq_wake_thread() in mdio_bus_phy_resume_irq() with
a direct call to the PHY driver's handle_interrupt() under phydev->lock.
This keeps a postponed interrupt on a nested threaded line from being
lost. The call is skipped when the PHY has freed its interrupt, and
phy_free_interrupt() now calls phy_disable_interrupts() under
irq_pm_lock.

> For a PHY without MAC-managed PM, mdio_bus_phy_resume() calls
> phy_init_hw() before the rerun, and config_intr() there acknowledges
> the latched status in drivers such as realtek. A later patch brings
> PHYs with MAC-managed PM under postponing, and stmmac, for one, does
> not call phy_init_hw() on resume.

[Severity: Low]
Is this true for every PHY without MAC-managed PM?

When mdio_bus_phy_may_suspend() returns false, mdio_bus_phy_suspend()
returns early. That happens with WoL enabled, device_may_wakeup() set on
the netdev or its parent, a PHY that is already suspended, or a driver
with no .suspend. In that case suspended_by_mdio_bus is never set:

drivers/net/phy/phy_device.c:mdio_bus_phy_suspend() {
    ...
	if (!mdio_bus_phy_may_suspend(phydev))
		return 0;

	ret = phy_suspend(phydev);
    ...
	phydev->suspended_by_mdio_bus = 1;
    ...
}

mdio_bus_phy_resume() then skips phy_init_hw() completely:

drivers/net/phy/phy_device.c:mdio_bus_phy_resume() {
    ...
	if (!phydev->suspended_by_mdio_bus)
		goto no_resume;
    ...
	ret = phy_init_hw(phydev);
    ...
no_resume:
	mdio_bus_phy_resume_irq(phydev);
    ...
}

So in the current tree, without the later MAC-managed PM patch, a
WoL-enabled PHY on a nested threaded line already loses its postponed
interrupt to irq_wake_thread(). The code change fixes this case too.

Could the commit message say that the problem exists even without the
later patch?

> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 2d2058c29f300..8bc394ff7d2d2 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -355,12 +355,19 @@ static __maybe_unused void mdio_bus_phy_resume_irq(struct phy_device *phydev)
>  	mutex_lock(&phydev->irq_pm_lock);
>  	if (phy_interrupt_is_valid(phydev))
>  		synchronize_irq(phydev->irq);
> -	/* The PHY may have fallen back to polling since it disabled the line */
> +	/* The PHY may have fallen back to polling since it disabled the line,
> +	 * or freed its interrupt while another user keeps the line.
> +	 */
>  	if (phydev->irq_rerun) {
>  		phydev->irq_rerun = false;
>  		enable_irq(phydev->irq_rerun_line);
> -		if (phydev->irq == phydev->irq_rerun_line)
> -			irq_wake_thread(phydev->irq, phydev);
> +		/* A nested threaded line has no thread; we run the handler */
> +		if (phydev->irq == phydev->irq_rerun_line &&
> +		    phydev->interrupts) {

[Severity: Low]
This check treats phydev->interrupts as meaning that the PHY has not
freed its interrupt. Can a driver's .resume callback set that bit again
after phy_free_interrupt()?

mdio_bus_phy_resume() calls phy_init_hw() and phy_resume() ->
drv->resume() before mdio_bus_phy_resume_irq(). Several resume
callbacks set the bit again based only on the IRQ number:

drivers/net/phy/micrel.c:kszphy_resume() {
    ...
	/* Enable PHY Interrupts */
	if (phy_interrupt_is_valid(phydev)) {
		phydev->interrupts = PHY_INTERRUPT_ENABLED;
		if (phydev->drv->config_intr)
			phydev->drv->config_intr(phydev);
	}
    ...
}

ksz9477_resume(), ksz8061_resume(), dp83867_resume() and
mv88q2xxx_resume() do the same.

phy_free_interrupt() clears phydev->interrupts through
phy_disable_interrupts(), but it leaves phydev->irq valid. On a shared
line that still has another action, it also leaves irq_rerun set.

Consider this sequence:

  PHY suspended by the MDIO bus, postponed interrupt sets irq_rerun
  phy_disconnect() -> phy_free_interrupt(), another user keeps the line
  mdio_bus_phy_resume()
    phy_resume() -> kszphy_resume()     /* interrupts set again */
    mdio_bus_phy_resume_irq()
      phydev->drv->handle_interrupt(phydev)

Wouldn't this run the handler on a detached PHY that has no irqaction,
which is the case the new check is meant to exclude? Before this patch,
irq_wake_thread() found no action with this dev_id after free_irq() and
did nothing.

The visible effect looks small. These handlers read the status register
and call phy_trigger_machine() on a PHY in PHY_HALTED, and these
drivers' resume callbacks have just re-enabled the PHY's interrupts.

> +			mutex_lock(&phydev->lock);
> +			phydev->drv->handle_interrupt(phydev);
> +			mutex_unlock(&phydev->lock);

[Severity: Low]
Does the irq_pm_lock documentation still match the code? The kernel-doc
in include/linux/phy.h says:

 * @irq_pm_lock: Serializes requesting and freeing the interrupt against the
 *               PM callbacks; phy_interrupt() never takes it

After this patch, the free side runs entirely under irq_pm_lock, and
this new call reads phydev->interrupts under it. The request side holds
the lock only around the irq_rerun check:

drivers/net/phy/phy.c:phy_request_interrupt() {
	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,
    ...
		if (phy_enable_interrupts(phydev)) {
    ...
}

So request_threaded_irq() and phy_enable_interrupts() run outside the
lock, and phy_enable_interrupts() is what sets phydev->interrupts and
calls config_intr().

I could not find a concrete failure from this. A race with dev_open()
from an unfrozen workqueue either skips the handler or overlaps with
config_intr(), and phy_interrupt() can already overlap with it the same
way.

Could the comment be updated to say that only freeing is serialized?
Could it also mention the new irq_pm_lock -> phydev->lock nesting
introduced here?

>  		}
>  	}
>  	mutex_unlock(&phydev->irq_pm_lock);
>  }

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

  reply	other threads:[~2026-11-22 22:03 UTC|newest]

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

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=179538498682.3135.2758040683110452863@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 \
    /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

all inboxes | Powered by JetHome®