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 2/5] net: phy: fix three paths that unbalance a postponed PHY interrupt line
Date: Sun, 22 Nov 2026 22:03:04 +0000	[thread overview]
Message-ID: <179538498448.3135.18241540181099733767@kernel.org> (raw)
In-Reply-To: <20261119-b4-phylib-mac-pm-irq-v3-v7-2-d8b8f43b5a62@iav.lv>

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

Critical: 0 · High: 0 · Medium: 2 · 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] mdio_bus_phy_resume() (drivers/net/phy/phy_device.c) can still
  leave a postponed PHY interrupt line disabled for good.
- [Medium] Whether irq_rerun is still valid depends on whether the shared
  line was shut down and started again since this PHY disabled it.
- [Low] The new kernel-doc for irq_pm_lock (include/linux/phy.h:678) and
  the in-struct comment (include/linux/phy.h:814) say it 'Serializes…

--

net: phy: fix three paths that unbalance a postponed PHY interrupt line

With this patch, phy_interrupt() disables a postponed PHY interrupt line
only once and records which line it disabled. phy_request_interrupt() and
phy_free_interrupt() now clear irq_rerun when the line has no users. The
postpone and rerun logic moves into mdio_bus_phy_suspend_irq() and
mdio_bus_phy_resume_irq(), and a new per-PHY irq_pm_lock mutex guards it.

> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index 9af303d60bd6b..92ee4651bdbc6 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);

[Severity: Medium]
Can irq_rerun go stale on a shared line in ways the commit message does
not list?

irq_pm_lock belongs to one phydev. It does not order this check against
free_irq() or request_threaded_irq() from the other users of the line,
and a second PHY on the line has its own irq_pm_lock.

First window: PHY A postpones on line L, so irq_rerun is set and the
depth is at least 1. A then frees L while user B still holds it, so A
keeps irq_rerun. Later:

PHY A                                  user B
phy_request_interrupt()
  irq_has_action(L) == true
  mutex_unlock(&irq_pm_lock)
                                       free_irq(L)  /* last action */
                                         irq_shutdown()  /* depth++ */
  request_threaded_irq(L)
    __setup_irq()
      irq_startup()  /* depth = 0 */

A's disable is gone, but A's irq_rerun is still true.

Second window: A frees L while B is present, so A keeps irq_rerun. Then
B's phy_free_interrupt() empties the line, but it clears only B's own
flag:

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

If B requests the line again first, or A does not request it again
before resume, nothing clears A's flag.

In both cases, mdio_bus_phy_resume_irq() for A calls
enable_irq(irq_rerun_line) based on the stale flag.

If the depth is 0, this triggers the "Unbalanced enable for IRQ"
warning.

If B was postponed in the meantime, A's enable cancels B's disable and
unmasks L while B is still postponed. B's thread sees its irq_rerun is
already set and does not disable the line again. On a level-triggered
line the IRQF_ONESHOT thread then keeps rerunning until B resumes, and
B's own enable_irq() then triggers the same warning.

If nobody has requested L again, the enable starts a line that has no
action.

The commit message names two cases that stay unbalanced. It also says
irq_rerun is cleared:

    in phy_free_interrupt() when free_irq() leaves the line without
    users

Does that hold for the dra72-evm-revc two-PHY setup if the other PHY is
the one whose free empties the line?

[ ... ]

> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 1791d578f4dde..f2e2370b4be7c 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c

[ ... ]

> @@ -393,19 +419,7 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev)
>  	if (ret < 0)
>  		return ret;
>  no_resume:
> -	if (phy_interrupt_is_valid(phydev)) {
> -		phydev->irq_suspended = false;
> -		synchronize_irq(phydev->irq);
> -
> -		/* Rerun interrupts which were postponed by phy_interrupt()
> -		 * because they occurred during the system sleep transition.
> -		 */
> -		if (phydev->irq_rerun) {
> -			phydev->irq_rerun = false;
> -			enable_irq(phydev->irq);
> -			irq_wake_thread(phydev->irq, phydev);
> -		}
> -	}
> +	mdio_bus_phy_resume_irq(phydev);

[Severity: Medium]
What happens to a postponed line if phy_init_hw() or phy_resume() fails
just above this label?

drivers/net/phy/phy_device.c:mdio_bus_phy_resume() {
	...
	ret = phy_init_hw(phydev);
	if (ret < 0)
		return ret;

	ret = phy_resume(phydev);
	if (ret < 0)
		return ret;
no_resume:
	mdio_bus_phy_resume_irq(phydev);
	...
}

Both early returns skip mdio_bus_phy_resume_irq(), so irq_suspended
stays true. If a postponed interrupt already called disable_irq_nosync(),
the line stays disabled. If not, the next phy_interrupt() takes the
postpone branch and disables it.

Nothing calls enable_irq(irq_rerun_line) until a later sleep cycle
resumes successfully. Until then, this PHY loses its interrupts, and so
does every other user of a shared line, such as the second PHY on
dra72-evm-revc.

The early returns themselves are not new. The result, though, matches
the third bullet of the commit message, reached through a different
return:

    mdio_bus_phy_resume() returns before enable_irq(), and the other
    users of a shared line stay disabled.

The new comment in phy_free_interrupt() ("mdio_bus_phy_resume_irq()
enables a shared line") also assumes the helper always runs.

A later patch in the series, "net: phy: stop postponing PHY interrupts
when phy_suspend() fails", fixes the suspend-side version by calling
mdio_bus_phy_resume_irq() on that error path. The resume-side error
returns are still unchanged at the end of the series.

Should these error paths also call mdio_bus_phy_resume_irq()?

[ ... ]

> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 59c75296d5355..f370690d62a73 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h

[ ... ]

> @@ -675,6 +675,8 @@ 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: Serializes requesting and freeing the interrupt against the
> + *               PM callbacks; phy_interrupt() never takes it

[Severity: Low]
Is this description accurate for phy_request_interrupt()?

The mutex is held only around the irq_rerun and irq_has_action() check.
request_threaded_irq(), phy_enable_interrupts() and the two
"phydev->irq = PHY_POLL" fallbacks all run after mutex_unlock().

mdio_bus_phy_resume_irq() reads phydev->irq under the lock, both for
phy_interrupt_is_valid() and for the irq_rerun_line comparison. Those
reads are not serialized against the request.

The commit message states the narrower guarantee: request and free do
not change irq_rerun between the check and the enable_irq() after
resume.

Could this kernel-doc, and the matching comment above the irq_pm_lock
field in struct phy_device, describe that narrower guarantee instead?

[ ... ]

-- 
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 [this message]
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
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=179538498448.3135.18241540181099733767@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®