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 2/5] net: phy: fix three paths that unbalance a postponed PHY interrupt line
Date: Thu, 03 Dec 2026 20:31:14 +0000 [thread overview]
Message-ID: <179632987448.3146.13504006246619970930@kernel.org> (raw)
In-Reply-To: <20261202-b4-phylib-mac-pm-irq-v3-v10-2-2f938d473f17@iav.lv>
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · 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] This patch decides whether mdio_bus_phy_resume_irq() still
owes an enable_irq(irq_rerun_line) by calling irq_has_action() in…
- [Low] The new kernel-doc for @irq_pm_lock in include/linux/phy.h (lines
678-680) says it is "Held by the PM callbacks, and by the requesting…
--
net: phy: fix three paths that unbalance a postponed PHY interrupt line
This patch makes phy_interrupt() disable a postponed PHY interrupt line
only once, and it records which line it disabled. irq_rerun is cleared in
phy_free_interrupt() and phy_request_interrupt() when irq_has_action()
reports that the line has no users, and otherwise mdio_bus_phy_resume()
enables the recorded line. A new per-PHY irq_pm_lock serializes these
checks with the rerun after resume.
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index 9af303d60bd6b..b917238678928 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);
> @@ -1507,7 +1517,15 @@ EXPORT_SYMBOL(phy_request_interrupt);
> void phy_free_interrupt(struct phy_device *phydev)
> {
> phy_disable_interrupts(phydev);
> +
> + mutex_lock(&phydev->irq_pm_lock);
> free_irq(phydev->irq, phydev);
> + /* free_irq() shuts down a line left without users and the next request
> + * resets its depth; mdio_bus_phy_resume_irq() enables a shared line.
> + */
> + if (phydev->irq_rerun && !irq_has_action(phydev->irq_rerun_line))
> + phydev->irq_rerun = false;
> + mutex_unlock(&phydev->irq_pm_lock);
> }
> EXPORT_SYMBOL(phy_free_interrupt);
[Severity: Medium]
Can irq_rerun stay set after the line's depth has already been reset?
irq_pm_lock belongs to one PHY, and the other users of a shared line never
take it. The first request after the line has had no users resets the
depth:
kernel/irq/chip.c:irq_startup() {
...
desc->depth = 0;
...
}
One bool and a single irq_has_action() check at one moment cannot show
whether the line went through irq_shutdown() and irq_startup() after this
PHY's disable_irq_nosync(). These orderings leave the flag set:
(a) phy_free_interrupt() runs while other users remain, so irq_rerun is
kept. All users later free the line, and another user requests it first,
so the line restarts at depth 0. phy_request_interrupt() then sees an
action and keeps irq_rerun.
(b) Another user requests the line between free_irq() and the
irq_has_action() check in phy_free_interrupt().
(c) The last other user frees the line between the irq_has_action() check
in phy_request_interrupt() and request_threaded_irq().
In each case mdio_bus_phy_resume_irq() then does:
if (phydev->irq_rerun) {
phydev->irq_rerun = false;
enable_irq(phydev->irq_rerun_line);
Would this hit the "Unbalanced enable for IRQ %d" WARN in __enable_irq(),
or cancel a disable_irq() that another user of the shared line took on
purpose?
Until resume, the stale irq_rerun also makes phy_interrupt() skip
disable_irq_nosync(). A level-triggered PHY source that cannot be acked
while irq_suspended is set would then keep firing after each ONESHOT
unmask.
The commit message lists these three cases as still unbalanced. The
kernel-internal close and open paths it names could produce these
orderings: MAC suspend callbacks that close the interface, and a reset
work that does not freeze, such as stmmac_reset_subtask().
The later patches in the series keep the same irq_has_action() approach.
At the end of the series phy_request_interrupt() holds irq_pm_lock across
the check and request_threaded_irq(), but the other users of the line
still do not take that lock.
[ ... ]
> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 23539e90c9870..42004e45fb3a4 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
[ ... ]
> @@ -675,6 +675,9 @@ 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: Held by the PM callbacks, and by the requesting and freeing
> + * of the interrupt where they test and clear @irq_rerun;
> + * phy_interrupt() never takes it
[Severity: Low]
This isn't a bug, but is this kernel-doc accurate? Not every PM callback
takes irq_pm_lock. mdio_bus_phy_suspend() calls mdio_bus_phy_suspend_irq(),
which writes irq_suspended and calls synchronize_irq() without the lock:
static __maybe_unused void mdio_bus_phy_suspend_irq(struct phy_device *phydev)
{
if (!phy_interrupt_is_valid(phydev))
return;
WRITE_ONCE(phydev->irq_suspended, true);
synchronize_irq(phydev->irq);
}
Only mdio_bus_phy_resume_irq() takes the lock. phy_free_interrupt() also
calls phy_disable_interrupts() before it takes the lock.
The in-struct comment added in this same patch is narrower: "Held where
the PM callbacks and the requesting and freeing of the interrupt test and
clear irq_rerun". So the two descriptions of the same lock disagree.
At the end of the series the kernel-doc still says "Held by the PM
callbacks", while mdio_bus_phy_prepare() and mdio_bus_phy_suspend() still
call mdio_bus_phy_suspend_irq() without the lock.
Could the kernel-doc be changed to match the in-struct comment?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-b4-phylib-mac-pm-irq-v3-v10-0-2f938d473f17%40iav.lv
next prev parent 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 [this message]
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
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=179632987448.3146.13504006246619970930@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