* [PATCH net v8 1/5] net: phy: move irq_suspended and irq_rerun out of the bitfield
2026-11-23 0:46 [PATCH net v8 0/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
@ 2026-11-23 0:46 ` Igor Velkov via B4 Relay
2026-11-24 1:11 ` netdev-bot+sashiko
2026-11-23 0:46 ` [PATCH net v8 2/5] net: phy: fix three paths that unbalance a postponed PHY interrupt line Igor Velkov via B4 Relay
` (3 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-23 0:46 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Thomas Gleixner, linux-pm, Maxime Chevallier, Lukas Wunner,
Rafael J. Wysocki, Wei Fang, Niklas Söderlund, Paul Barker,
Florian Fainelli, Doug Berger, Thangaraj Samynathan, Shenwei Wang,
Haoning Cheng, netdev, linux-arm-kernel, linux-rockchip,
linux-kernel, Igor Velkov
From: Igor Velkov <iav@iav.lv>
irq_suspended and irq_rerun share a word with link, autoneg_complete
and interrupts. phy_interrupt() sets irq_rerun from the IRQ thread
without phydev->lock, while the state machine writes link and
autoneg_complete under it and phy_request_interrupt()/
phy_free_interrupt() write interrupts, so one read-modify-write can
undo another. A lost irq_rerun leaves the PHY interrupt disabled after
resume, as phy_interrupt() has already disabled the line.
The last patch of this series sets irq_suspended for PHYs whose MAC
driver manages PHY PM; with stmmac that happens before the MAC stops
the PHY, which widens the window.
Taking phydev->lock in phy_interrupt() alone does not close it:
phy_suspend() stores suspended in the same word and cannot hold the
lock across phy_may_wakeup(), which may take it, and phy_init_hw() and
mdio_bus_phy_suspend() write the word unlocked too. Locking every
writer, MAC drivers included, is a wide audit, and one missed now or
added later reopens the race.
Make both flags bools.
Fixes: 1758bde2e4aa ("net: phy: Don't trigger state machine while in suspend")
Tested-by: Haoning Cheng <Haoning.CHENG@cn.bosch.com>
Signed-off-by: Igor Velkov <iav@iav.lv>
---
drivers/net/phy/phy.c | 2 +-
drivers/net/phy/phy_device.c | 6 +++---
include/linux/phy.h | 7 +++++--
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index fce9bc7be330..9af303d60bd6 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -1430,7 +1430,7 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
pm_wakeup_dev_event(parent, 0, true);
}
- phydev->irq_rerun = 1;
+ phydev->irq_rerun = true;
disable_irq_nosync(irq);
return IRQ_HANDLED;
}
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index b39e945cebd7..1791d578f4dd 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -344,7 +344,7 @@ static __maybe_unused int mdio_bus_phy_suspend(struct device *dev)
* has resumed. Wait for concurrent interrupt handler to complete.
*/
if (phy_interrupt_is_valid(phydev)) {
- phydev->irq_suspended = 1;
+ phydev->irq_suspended = true;
synchronize_irq(phydev->irq);
}
@@ -394,14 +394,14 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev)
return ret;
no_resume:
if (phy_interrupt_is_valid(phydev)) {
- phydev->irq_suspended = 0;
+ 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 = 0;
+ phydev->irq_rerun = false;
enable_irq(phydev->irq);
irq_wake_thread(phydev->irq, phydev);
}
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 21afc2082b17..59c75296d535 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -726,8 +726,11 @@ struct phy_device {
/* Interrupts are enabled */
unsigned interrupts:1;
- unsigned irq_suspended:1;
- unsigned irq_rerun:1;
+ /* Not bitfields: phy_interrupt() and the PM callbacks write them
+ * without phydev->lock
+ */
+ bool irq_suspended;
+ bool irq_rerun;
unsigned default_timestamp:1;
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH net v8 1/5] net: phy: move irq_suspended and irq_rerun out of the bitfield
2026-11-23 0:46 ` [PATCH net v8 1/5] net: phy: move irq_suspended and irq_rerun out of the bitfield Igor Velkov via B4 Relay
@ 2026-11-24 1:11 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 1:11 UTC (permalink / raw)
To: iav
Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, tglx,
linux-pm, maxime.chevallier, lukas, rafael.j.wysocki, wei.fang,
niklas.soderlund, paul, florian.fainelli, opendmb, Thangaraj.S,
shenwei.wang, Haoning.CHENG, netdev, linux-arm-kernel,
linux-rockchip, linux-kernel
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 patch adds this comment above the two new bools in struct
phy_device (include/linux/phy.h): "Not bitfields: phy_interrupt() and…
--
net: phy: move irq_suspended and irq_rerun out of the bitfield
This commit turns irq_suspended and irq_rerun in struct phy_device from
1-bit bitfields into separate bools. phy_interrupt() and the PM callbacks
write them without phydev->lock, so a read-modify-write on the shared
bitfield word could lose a concurrent irq_rerun update. The call sites in
phy.c and phy_device.c are updated to use true/false.
[ ... ]
> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 21afc2082b174..59c75296d5355 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -726,8 +726,11 @@ struct phy_device {
>
> /* Interrupts are enabled */
> unsigned interrupts:1;
> - unsigned irq_suspended:1;
> - unsigned irq_rerun:1;
> + /* Not bitfields: phy_interrupt() and the PM callbacks write them
> + * without phydev->lock
> + */
[Severity: Low]
This isn't a bug, but could this comment mislead readers about the
bitfields that remain?
The reason it gives, written by the PM callbacks without phydev->lock,
also applies to interrupts:1 on the line just above it. PHY driver suspend
callbacks run from phy_suspend()->phydrv->suspend(), and phy_suspend()
does not take phydev->lock. For example, in dp83867_suspend():
drivers/net/phy/dp83867.c:dp83867_suspend() {
...
if (phy_interrupt_is_valid(phydev)) {
phydev->interrupts = PHY_INTERRUPT_DISABLED;
dp83867_config_intr(phydev);
}
...
}
marvell-88q2xxx.c and micrel.c do the same thing in their suspend paths.
phy_suspend() also sets phydev->suspended = true without the lock, and
suspended:1 is in the same bitfield word.
Both fields still share that word with link:1 and autoneg_complete:1,
which the state machine writes under phydev->lock. From this comment, a
reader could conclude that the remaining bitfields in the word are only
written under phydev->lock.
Would it be clearer to word the comment so it doesn't imply that rule?
It could, for example, just describe the irq_rerun race that this patch
fixes.
> + bool irq_suspended;
> + bool irq_rerun;
>
> unsigned default_timestamp:1;
>
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123-b4-phylib-mac-pm-irq-v3-v8-0-e9f706e79614%40iav.lv
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net v8 2/5] net: phy: fix three paths that unbalance a postponed PHY interrupt line
2026-11-23 0:46 [PATCH net v8 0/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
2026-11-23 0:46 ` [PATCH net v8 1/5] net: phy: move irq_suspended and irq_rerun out of the bitfield Igor Velkov via B4 Relay
@ 2026-11-23 0:46 ` Igor Velkov via B4 Relay
2026-11-24 1:11 ` netdev-bot+sashiko
2026-11-23 0:46 ` [PATCH net v8 3/5] net: phy: stop postponing PHY interrupts when phy_suspend() fails Igor Velkov via B4 Relay
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-23 0:46 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Thomas Gleixner, linux-pm, Maxime Chevallier, Lukas Wunner,
Rafael J. Wysocki, Wei Fang, Niklas Söderlund, Paul Barker,
Florian Fainelli, Doug Berger, Thangaraj Samynathan, Shenwei Wang,
Haoning Cheng, netdev, linux-arm-kernel, linux-rockchip,
linux-kernel, Igor Velkov
From: Igor Velkov <iav@iav.lv>
phy_interrupt() postpones interrupts during a system sleep transition:
it sets irq_rerun and disables the line, and mdio_bus_phy_resume()
re-enables the line once and reruns the handler. Three paths leave the
line unbalanced:
- On an edge-triggered line the IRQ core does not mask a ONESHOT
interrupt, so an edge that arrives before disable_irq_nosync() runs
the thread again. That second run disables the line again, and the
line stays disabled after resume.
- phy_free_interrupt() can run between the postponed interrupt and
mdio_bus_phy_resume() and leaves irq_rerun set. Once the line has no
users, free_irq() shuts it down and a new request starts it at depth
0, so the enable_irq() in mdio_bus_phy_resume() is unbalanced. On a
shared line this can happen once the other users free it too, as with
the two PHYs of dra72-evm-revc behind cpsw.
- If phy_request_interrupt() then leaves the PHY polling,
mdio_bus_phy_resume() returns before enable_irq(), and the other
users of a shared line stay disabled.
MAC drivers that close the interface in their suspend callback, such as
cpsw, and ravb with Wake-on-LAN off, reach phy_free_interrupt() through
phy_disconnect(), and so does dev_close() in a kernel-internal reset of
the MAC such as stmmac_reset_subtask(), whose workqueue does not freeze.
These drivers set mac_managed_pm, which a later patch brings under
postponing.
Let only the run that sets irq_rerun disable the line, and record the
line it disabled. Clear irq_rerun where the line starts again at depth
0: in phy_free_interrupt() when free_irq() leaves the line without
users, and in phy_request_interrupt() when the line has no users. Otherwise
mdio_bus_phy_resume() enables the recorded line, also for a PHY that
fell back to polling, and reruns the handler only if the PHY still uses
that line. Enabling the line in phy_free_interrupt() instead would
unmask a source that phy_disable_interrupts() failed to clear, and
inside the noirq phase it would unbalance a wakeup line that
suspend_device_irqs() enabled (IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND).
Add irq_pm_lock, so that requesting and freeing the interrupt do not
change irq_rerun between the check and the enable_irq() of the rerun
after resume, and move the postponing and the rerun into helpers.
phy_interrupt() never takes the lock, so synchronize_irq() and
free_irq() can wait for the handler under it. irq_rerun and
irq_rerun_line are plain fields: one thread runs the handler, and the
other paths access them only under the lock, after free_irq() or
synchronize_irq(), or before this PHY has requested the line. Mark the
irq_suspended accesses with READ_ONCE() and WRITE_ONCE(): the handler
reads it while the PM callbacks write it.
Three cases on a shared line stay unbalanced: after all users have freed
the line, another user requests it first, so it has users when this PHY
requests it; another user requests it between free_irq() and the
irq_has_action() check in phy_free_interrupt(); or the last other user
frees it between the irq_has_action() check and request_threaded_irq()
in phy_request_interrupt(). irq_rerun then stays, and the enable after
resume is unbalanced or reaches a line without users; until then a
postponed interrupt does not disable the line again, so a
level-triggered one keeps firing.
This does not keep close and open off the MDIO bus: on close,
phy_disconnect() calls phy_stop(), phy_free_interrupt() with its
phy_disable_interrupts() and, in phy_detach(), phy_suspend(); on open,
phy_attach_direct() calls phy_init_hw() and phy_request_interrupt()
calls phy_enable_interrupts(). A MAC driver that powers its MDIO bus
down during sleep must not close or open the interface until the bus is
back.
Fixes: 1758bde2e4aa ("net: phy: Don't trigger state machine while in suspend")
Signed-off-by: Igor Velkov <iav@iav.lv>
---
Haoning Cheng's Tested-by on v5 is not carried: phy_free_interrupt()
no longer enables a shared line.
---
drivers/net/phy/phy.c | 24 ++++++++++++++++---
drivers/net/phy/phy_device.c | 57 ++++++++++++++++++++++++++++----------------
include/linux/phy.h | 12 ++++++++--
3 files changed, 67 insertions(+), 26 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 9af303d60bd6..92ee4651bdbc 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -1416,7 +1416,7 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
/* Wakeup interrupts may occur during a system sleep transition.
* Postpone handling until the PHY has resumed.
*/
- if (IS_ENABLED(CONFIG_PM_SLEEP) && phydev->irq_suspended) {
+ if (IS_ENABLED(CONFIG_PM_SLEEP) && READ_ONCE(phydev->irq_suspended)) {
struct net_device *netdev = phydev->attached_dev;
if (netdev) {
@@ -1430,8 +1430,12 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
pm_wakeup_dev_event(parent, 0, true);
}
- phydev->irq_rerun = true;
- disable_irq_nosync(irq);
+ /* Disable the line only once: an edge can rerun the thread. */
+ if (!phydev->irq_rerun) {
+ phydev->irq_rerun_line = irq;
+ phydev->irq_rerun = true;
+ disable_irq_nosync(irq);
+ }
return IRQ_HANDLED;
}
@@ -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 (!irq_has_action(phydev->irq))
+ phydev->irq_rerun = false;
+ mutex_unlock(&phydev->irq_pm_lock);
}
EXPORT_SYMBOL(phy_free_interrupt);
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 1791d578f4dd..f2e2370b4be7 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -332,6 +332,39 @@ static bool mdio_bus_phy_may_suspend(struct phy_device *phydev)
return !phydev->suspended;
}
+/* 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.
+ */
+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);
+}
+
+/* Rerun interrupts which were postponed by phy_interrupt()
+ * because they occurred during the system sleep transition.
+ */
+static __maybe_unused void mdio_bus_phy_resume_irq(struct phy_device *phydev)
+{
+ WRITE_ONCE(phydev->irq_suspended, false);
+
+ 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 */
+ 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);
+ }
+ mutex_unlock(&phydev->irq_pm_lock);
+}
+
static __maybe_unused int mdio_bus_phy_suspend(struct device *dev)
{
struct phy_device *phydev = to_phy_device(dev);
@@ -339,14 +372,7 @@ static __maybe_unused int mdio_bus_phy_suspend(struct device *dev)
if (phydev->mac_managed_pm)
return 0;
- /* 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.
- */
- if (phy_interrupt_is_valid(phydev)) {
- phydev->irq_suspended = true;
- synchronize_irq(phydev->irq);
- }
+ 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
@@ -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);
if (phy_uses_state_machine(phydev))
phy_start_machine(phydev);
@@ -711,6 +725,7 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
dev->max_n_ports = 1;
mutex_init(&dev->lock);
+ mutex_init(&dev->irq_pm_lock);
INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine);
/* Request the appropriate module unconditionally; don't
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 59c75296d535..d84f7d8bc9df 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -651,8 +651,8 @@ struct phy_oatc14_sqi_capability {
* @interrupts: Flag interrupts have been enabled
* @irq_suspended: Flag indicating PHY is suspended and therefore interrupt
* handling shall be postponed until PHY has resumed
- * @irq_rerun: Flag indicating interrupts occurred while PHY was suspended,
- * requiring a rerun of the interrupt handler after resume
+ * @irq_rerun: Set by the postponed interrupt that disabled the line
+ * @irq_rerun_line: The line the postponed interrupt disabled
* @default_timestamp: Flag indicating whether we are using the phy
* timestamp as the default one
* @interface: enum phy_interface_t value
@@ -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
* @state_queue: Work queue for state machine
* @link_down_events: Number of times link was lost
* @shared: Pointer to private data shared by phys in one package
@@ -731,6 +734,7 @@ struct phy_device {
*/
bool irq_suspended;
bool irq_rerun;
+ int irq_rerun_line;
unsigned default_timestamp:1;
@@ -808,6 +812,10 @@ struct phy_device {
struct delayed_work state_queue;
struct mutex lock;
+ /* Held where the PM callbacks and the requesting and freeing of the
+ * interrupt test and clear irq_rerun
+ */
+ struct mutex irq_pm_lock;
/* This may be modified under the rtnl lock */
bool sfp_bus_attached;
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH net v8 2/5] net: phy: fix three paths that unbalance a postponed PHY interrupt line
2026-11-23 0:46 ` [PATCH net v8 2/5] net: phy: fix three paths that unbalance a postponed PHY interrupt line Igor Velkov via B4 Relay
@ 2026-11-24 1:11 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 1:11 UTC (permalink / raw)
To: iav
Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, tglx,
linux-pm, maxime.chevallier, lukas, rafael.j.wysocki, wei.fang,
niklas.soderlund, paul, florian.fainelli, opendmb, Thangaraj.S,
shenwei.wang, Haoning.CHENG, netdev, linux-arm-kernel,
linux-rockchip, linux-kernel
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · 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).
- [Medium] phy_request_interrupt() and phy_free_interrupt() use different
lines to decide whether this PHY's postponed disable is still counted.
- [Medium] The new gate in phy_interrupt() ('if (!phydev->irq_rerun) {
... disable_irq_nosync(irq); }') only disables the line when irq_rerun…
- [Medium] mdio_bus_phy_resume_irq()
(drivers/net/phy/phy_device.c:359-361) calls…
--
net: phy: fix three paths that unbalance a postponed PHY interrupt line
This commit changes phy_interrupt() so that only the first postponed run
disables the PHY interrupt line, and it records which line was disabled.
irq_rerun is now cleared in phy_free_interrupt() and
phy_request_interrupt() when the line has no users. The commit also adds
irq_pm_lock to serialize those paths against the rerun in
mdio_bus_phy_resume_irq().
> 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
[ ... ]
> @@ -1430,8 +1430,12 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
> pm_wakeup_dev_event(parent, 0, true);
> }
>
> - phydev->irq_rerun = true;
> - disable_irq_nosync(irq);
> + /* Disable the line only once: an edge can rerun the thread. */
> + if (!phydev->irq_rerun) {
> + phydev->irq_rerun_line = irq;
> + phydev->irq_rerun = true;
> + disable_irq_nosync(irq);
> + }
> return IRQ_HANDLED;
> }
[Severity: Medium]
Can a stale irq_rerun here turn a stuck line into an interrupt storm?
irq_pm_lock only serializes this PHY's own request, free and resume paths.
Other drivers on a shared line call request_irq() and free_irq() without
it. phy_request_interrupt() also drops the lock before
request_threaded_irq().
The commit message lists three windows where irq_rerun stays true after
the line is back at depth 0 with this PHY's handler registered. One
example is another user requesting the line first after all users freed
it. In that state, a later postponed interrupt returns IRQ_HANDLED without
disabling the line and without reading the PHY.
On a level-triggered IRQF_ONESHOT line, irq_finalize_oneshot() then
unmasks the line. The PHY source is still asserted, so the line fires
again, and this continues until mdio_bus_phy_resume_irq() clears
irq_suspended. The handler returns IRQ_HANDLED, so note_interrupt() never
treats these as spurious.
After that, mdio_bus_phy_resume_irq() calls enable_irq() on a depth-0
line, which hits WARN("Unbalanced enable for IRQ") in __enable_irq().
One path that seems to reach this, once the later patch in the series
puts mac_managed_pm PHYs under postponing:
shared PHY line, postponed interrupt sets irq_rerun
MAC closes in suspend (cpsw, ravb, or stmmac_reset_subtask())
-> phy_disconnect() -> phy_free_interrupt()
other users remain, irq_rerun kept
other users free the line
another user requests the line first
MAC resumes before the PHY and re-requests while irq_suspended is set
PHY level interrupt asserts
Before this patch, every postponed run disabled the line again. In this
case the line could get stuck, but it could not storm.
The commit message acknowledges "a level-triggered one keeps firing". Is
that an acceptable trade-off compared with the old behaviour here?
> @@ -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 (!irq_has_action(phydev->irq))
> + phydev->irq_rerun = false;
[Severity: Medium]
Should this check use phydev->irq_rerun_line rather than phydev->irq?
phy_request_interrupt() tests irq_has_action(phydev->irq_rerun_line),
which is the line phy_interrupt() actually disabled. This check tests the
line that was just freed. mdio_bus_phy_resume_irq() also expects the two
to differ:
if (phydev->irq == phydev->irq_rerun_line)
phydev->irq can change from the disabled line A to another valid line B
between the postponed interrupt and resume. phy_detach() resets it:
phydev->irq = phydev->mdio.bus->irq[phydev->mdio.addr];
Some MAC drivers, such as mlxbf_gige, lan78xx and smsc95xx, also write
phydev->irq directly.
In that case, freeing B clears irq_rerun because B has no users. That
free could come from the phy_enable_interrupts() failure fallback in
phy_request_interrupt(), or from a later disconnect. Line A still carries
this PHY's disable_irq_nosync() depth. mdio_bus_phy_resume_irq() would
then skip enable_irq(A), and A would stay disabled for its other users.
I couldn't find an in-tree path that switches phydev->irq between two
different valid lines within one sleep transition, so this may be
theoretical. Even so, the two checks disagree.
Would testing irq_rerun_line here, or requiring phydev->irq ==
phydev->irq_rerun_line, make them consistent?
> + mutex_unlock(&phydev->irq_pm_lock);
> }
> EXPORT_SYMBOL(phy_free_interrupt);
>
> 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
> @@ -332,6 +332,39 @@ static bool mdio_bus_phy_may_suspend(struct phy_device *phydev)
[ ... ]
> +/* Rerun interrupts which were postponed by phy_interrupt()
> + * because they occurred during the system sleep transition.
> + */
> +static __maybe_unused void mdio_bus_phy_resume_irq(struct phy_device *phydev)
> +{
> + WRITE_ONCE(phydev->irq_suspended, false);
> +
> + 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 */
> + if (phydev->irq_rerun) {
> + phydev->irq_rerun = false;
> + enable_irq(phydev->irq_rerun_line);
[Severity: Medium]
Is this PHY's disable still counted in the line's depth when this
enable_irq() runs?
phy_free_interrupt() keeps irq_rerun on purpose when other users still
hold the shared line. If those users then free the line, irq_shutdown()
runs. The next first request from another driver calls irq_startup(),
which resets depth to 0 and discards this PHY's disable.
The only re-check is in phy_request_interrupt(). It only helps if this
PHY re-requests before its own resume callback runs:
phy_interrupt() postpones, disable_irq_nosync(A), irq_rerun = true
MAC close in suspend -> phy_disconnect() -> phy_free_interrupt()
other users remain, irq_rerun kept
other users free A -> irq_shutdown()
another driver requests A on resume -> irq_startup(), depth = 0
mdio_bus_phy_resume() -> mdio_bus_phy_resume_irq()
enable_irq(A), before this PHY calls phy_request_interrupt()
This ordering seems possible in two cases:
- The PHY sits on an MDIO bus owned by a different MAC, and the device
link resumes the PHY before its consumer MAC reopens.
- The MAC's reopen fails.
At depth 0 this hits WARN("Unbalanced enable for IRQ") in __enable_irq().
If the other driver holds its own disable_irq() at that moment (depth 1),
wouldn't this enable_irq() call irq_startup() and cancel that driver's
disable?
If the line still has no users at that point, the enable is harmless,
because irq_shutdown() incremented depth.
This seems to be a gap in the second case the commit message says it
fixes, separate from the three windows it documents.
> + if (phydev->irq == phydev->irq_rerun_line)
> + irq_wake_thread(phydev->irq, phydev);
> + }
> + mutex_unlock(&phydev->irq_pm_lock);
> +}
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123-b4-phylib-mac-pm-irq-v3-v8-0-e9f706e79614%40iav.lv
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net v8 3/5] net: phy: stop postponing PHY interrupts when phy_suspend() fails
2026-11-23 0:46 [PATCH net v8 0/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
2026-11-23 0:46 ` [PATCH net v8 1/5] net: phy: move irq_suspended and irq_rerun out of the bitfield Igor Velkov via B4 Relay
2026-11-23 0:46 ` [PATCH net v8 2/5] net: phy: fix three paths that unbalance a postponed PHY interrupt line Igor Velkov via B4 Relay
@ 2026-11-23 0:46 ` Igor Velkov via B4 Relay
2026-11-23 0:46 ` [PATCH net v8 4/5] net: phy: run a postponed PHY interrupt handler directly on resume Igor Velkov via B4 Relay
2026-11-23 0:46 ` [PATCH net v8 5/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
4 siblings, 0 replies; 10+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-23 0:46 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Thomas Gleixner, linux-pm, Maxime Chevallier, Lukas Wunner,
Rafael J. Wysocki, Wei Fang, Niklas Söderlund, Paul Barker,
Florian Fainelli, Doug Berger, Thangaraj Samynathan, Shenwei Wang,
Haoning Cheng, netdev, linux-arm-kernel, linux-rockchip,
linux-kernel, Igor Velkov
From: Igor Velkov <iav@iav.lv>
When phy_suspend() fails in mdio_bus_phy_suspend(), irq_suspended
stays set and the state machine stays stopped: the PM core does not
resume a device whose suspend callback failed, and the next PHY
interrupt disables the line until the next resume.
Undo the postponing and restart the state machine when phy_suspend()
fails. Set suspended_by_mdio_bus only after phy_suspend() succeeds.
Set before it, the flag outlived a failed suspend, and in a later cycle
where mdio_bus_phy_may_suspend() returns false, mdio_bus_phy_resume()
ran phy_init_hw() and phy_resume() on a PHY that the MDIO bus had not
suspended.
The error returns of mdio_bus_phy_resume(), after phy_init_hw() or
phy_resume() failed, stay as they are: the postponing goes on, and a
line that a postponed interrupt disabled stays disabled. Undoing the
postponing there would run the handler, from the next interrupt on, on
a PHY that did not resume.
Fixes: 1758bde2e4aa ("net: phy: Don't trigger state machine while in suspend")
Signed-off-by: Igor Velkov <iav@iav.lv>
---
Haoning Cheng's Tested-by on v5 is not carried: this patch no longer
changes the resume error path.
---
drivers/net/phy/phy_device.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index f2e2370b4be7..2d2058c29f30 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -368,6 +368,7 @@ static __maybe_unused void mdio_bus_phy_resume_irq(struct phy_device *phydev)
static __maybe_unused int mdio_bus_phy_suspend(struct device *dev)
{
struct phy_device *phydev = to_phy_device(dev);
+ int ret;
if (phydev->mac_managed_pm)
return 0;
@@ -385,9 +386,20 @@ static __maybe_unused int mdio_bus_phy_suspend(struct device *dev)
if (!mdio_bus_phy_may_suspend(phydev))
return 0;
+ ret = phy_suspend(phydev);
+ if (ret) {
+ /* The PM core skips the resume callback of a device whose
+ * suspend callback failed.
+ */
+ mdio_bus_phy_resume_irq(phydev);
+ if (phy_uses_state_machine(phydev))
+ phy_start_machine(phydev);
+ return ret;
+ }
+
phydev->suspended_by_mdio_bus = 1;
- return phy_suspend(phydev);
+ return 0;
}
static __maybe_unused int mdio_bus_phy_resume(struct device *dev)
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH net v8 4/5] net: phy: run a postponed PHY interrupt handler directly on resume
2026-11-23 0:46 [PATCH net v8 0/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
` (2 preceding siblings ...)
2026-11-23 0:46 ` [PATCH net v8 3/5] net: phy: stop postponing PHY interrupts when phy_suspend() fails Igor Velkov via B4 Relay
@ 2026-11-23 0:46 ` Igor Velkov via B4 Relay
2026-11-24 1:11 ` netdev-bot+sashiko
2026-11-23 0:46 ` [PATCH net v8 5/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
4 siblings, 1 reply; 10+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-23 0:46 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Thomas Gleixner, linux-pm, Maxime Chevallier, Lukas Wunner,
Rafael J. Wysocki, Wei Fang, Niklas Söderlund, Paul Barker,
Florian Fainelli, Doug Berger, Thangaraj Samynathan, Shenwei Wang,
Haoning Cheng, netdev, linux-arm-kernel, linux-rockchip,
linux-kernel, Igor Velkov
From: Igor Velkov <iav@iav.lv>
mdio_bus_phy_resume_irq() reruns a postponed interrupt with
irq_wake_thread(). A PHY interrupt behind a nested threaded interrupt
controller, such as an I2C or SPI GPIO expander, has no interrupt
thread, so irq_wake_thread() does nothing and the postponed interrupt
is lost: the PHY keeps its status latched and its INT line asserted.
For a PHY that the MDIO bus suspended, 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 PHY that the bus did
not suspend, as with Wake-on-LAN enabled, gets no phy_init_hw() and
loses the interrupt today. A later patch brings PHYs with MAC-managed
PM under postponing, and stmmac, for one, does not call phy_init_hw()
on resume.
Call the PHY driver's handler from mdio_bus_phy_resume_irq(), as
phy_interrupt() does, unless the PHY has its interrupts disabled, as
after phy_free_interrupt(): on a shared line irq_rerun outlives the
free, and the handler would run on a PHY that no longer uses the line.
Hold irq_pm_lock across the call and
around phy_disable_interrupts() in phy_free_interrupt(), so that the
free waits for the handler, as free_irq() waits for the thread.
Fixes: 1758bde2e4aa ("net: phy: Don't trigger state machine while in suspend")
Signed-off-by: Igor Velkov <iav@iav.lv>
---
drivers/net/phy/phy.c | 3 +--
drivers/net/phy/phy_device.c | 13 ++++++++++---
include/linux/phy.h | 2 +-
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 92ee4651bdbc..6cc94b525e09 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -1516,9 +1516,8 @@ EXPORT_SYMBOL(phy_request_interrupt);
*/
void phy_free_interrupt(struct phy_device *phydev)
{
- phy_disable_interrupts(phydev);
-
mutex_lock(&phydev->irq_pm_lock);
+ phy_disable_interrupts(phydev);
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.
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 2d2058c29f30..8bc394ff7d2d 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) {
+ mutex_lock(&phydev->lock);
+ phydev->drv->handle_interrupt(phydev);
+ mutex_unlock(&phydev->lock);
+ }
}
mutex_unlock(&phydev->irq_pm_lock);
}
diff --git a/include/linux/phy.h b/include/linux/phy.h
index d84f7d8bc9df..9253a07e84be 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -677,7 +677,7 @@ struct phy_oatc14_sqi_capability {
* @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
+ * taken before @lock; phy_interrupt() never takes it
* @state_queue: Work queue for state machine
* @link_down_events: Number of times link was lost
* @shared: Pointer to private data shared by phys in one package
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH net v8 4/5] net: phy: run a postponed PHY interrupt handler directly on resume
2026-11-23 0:46 ` [PATCH net v8 4/5] net: phy: run a postponed PHY interrupt handler directly on resume Igor Velkov via B4 Relay
@ 2026-11-24 1:11 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 1:11 UTC (permalink / raw)
To: iav
Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, tglx,
linux-pm, maxime.chevallier, lukas, rafael.j.wysocki, wei.fang,
niklas.soderlund, paul, florian.fainelli, opendmb, Thangaraj.S,
shenwei.wang, Haoning.CHENG, netdev, linux-arm-kernel,
linux-rockchip, linux-kernel
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] This patch's only protection against running the handler on a
PHY that has freed its interrupt is the phydev->interrupts bit, and…
- [Medium] The new check in mdio_bus_phy_resume_irq() reads
phydev->interrupts under irq_pm_lock, and phy_free_interrupt() writes…
- [Low] irq_pm_lock now does more than its documentation says, and its
two descriptions disagree.
--
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(), so that a postponed
interrupt on a nested threaded line is not lost. The handler is skipped
when phydev->interrupts is clear, as after phy_free_interrupt(). The
handler call and phy_disable_interrupts() in phy_free_interrupt() both
run under irq_pm_lock.
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index 92ee4651bdbc6..6cc94b525e093 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -1516,9 +1516,8 @@ EXPORT_SYMBOL(phy_request_interrupt);
> */
> void phy_free_interrupt(struct phy_device *phydev)
> {
> - phy_disable_interrupts(phydev);
> -
> mutex_lock(&phydev->irq_pm_lock);
> + phy_disable_interrupts(phydev);
> 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.
> 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) {
> + mutex_lock(&phydev->lock);
> + phydev->drv->handle_interrupt(phydev);
> + mutex_unlock(&phydev->lock);
> + }
[Severity: Medium]
Can phydev->interrupts reliably tell us that the PHY still has its
interrupt requested at this point?
The commit message says the handler is skipped "unless the PHY has its
interrupts disabled, as after phy_free_interrupt()". Some PHY driver
resume callbacks set the bit again based only on the irq number. For
example, kszphy_resume() in drivers/net/phy/micrel.c:
/* Enable PHY Interrupts */
if (phy_interrupt_is_valid(phydev)) {
phydev->interrupts = PHY_INTERRUPT_ENABLED;
if (phydev->drv->config_intr)
phydev->drv->config_intr(phydev);
}
dp83867_resume() and the mv88q2xxx resume callback do the same thing.
phy_disconnect()->phy_free_interrupt() leaves phydev->irq valid, so
phy_interrupt_is_valid() still passes after the free.
mdio_bus_phy_resume() runs these callbacks before the rerun:
mdio_bus_phy_resume()
phy_init_hw()
phy_resume()
__phy_resume()
drv->resume() /* interrupts = 1 */
no_resume:
mdio_bus_phy_resume_irq()
Take a PHY that the MDIO bus suspended, on a shared line:
1. A postponed interrupt sets irq_rerun.
2. phy_free_interrupt() sets interrupts = 0. Another user still holds
the line, so irq_has_action() is true and irq_rerun stays set.
3. On resume, the driver's resume callback sets interrupts back to 1.
4. mdio_bus_phy_resume_irq() sees irq_rerun set, irq equal to
irq_rerun_line and interrupts == 1, so it calls handle_interrupt().
Another patch in this series, "net: phy: fix three paths that unbalance
a postponed PHY interrupt line", says that phy_free_interrupt() can run
between the postponed interrupt and mdio_bus_phy_resume().
Before this patch, irq_wake_thread() on a freed action did nothing.
Could the handler now do MDIO reads and acks, and call
phy_trigger_machine() or phy_error(), on a PHY that is detached and no
longer uses the line?
Would it be safer to gate on a state that only phy_request_interrupt()
and phy_free_interrupt() write, rather than on a field that drivers set
directly?
[Severity: Medium]
Is this read of phydev->interrupts really serialized against the write in
phy_free_interrupt()? interrupts is still a 1-bit bitfield in struct
phy_device:
/* Interrupts are enabled */
unsigned interrupts:1;
/* Not bitfields: phy_interrupt() and the PM callbacks write them
* without phydev->lock
*/
It shares a word with suspended, suspended_by_mdio_bus, wol_enabled,
autoneg, link, autoneg_complete, pause and asym_pause. Several of those
are written under other locks, or under no lock:
- mdio_bus_phy_resume() writes suspended_by_mdio_bus = 0 with no lock
- phy_init_hw() writes suspended = 0 with no lock
- __phy_resume() writes suspended under phydev->lock only
- phy_attach_direct() and phy_request_interrupt()->phy_enable_interrupts()
write interrupts outside irq_pm_lock
A bitfield store is a read-modify-write of the whole word. Can a
concurrent store to a neighbouring bit undo the interrupts = 0 written by
phy_free_interrupt()?
resume path phy_free_interrupt()
load word (interrupts == 1)
interrupts = 0
free_irq() (shared, irq_rerun kept)
store word (stale interrupts == 1)
mdio_bus_phy_resume_irq()
handle_interrupt() on the freed PHY
The series gives one way for phy_free_interrupt() to run in that window:
dev_close() from stmmac_reset_subtask() on a workqueue that does not
freeze.
The earlier patch "net: phy: move irq_suspended and irq_rerun out of the
bitfield" moved fields out of this word for the same reason: "one
read-modify-write can undo another". The end of the series still leaves
interrupts as a bitfield.
If this bit is now the gate checked under irq_pm_lock, should it get the
same treatment? Alternatively, could the gate use a separate field that
is not a bitfield?
> }
> mutex_unlock(&phydev->irq_pm_lock);
> }
> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index d84f7d8bc9df8..9253a07e84be2 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -677,7 +677,7 @@ struct phy_oatc14_sqi_capability {
> * @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
> + * taken before @lock; phy_interrupt() never takes it
[Severity: Low]
This isn't a bug, but the two descriptions of irq_pm_lock no longer
match. The kernel-doc gains "taken before @lock", but the inline comment
on the field is unchanged:
struct mutex lock;
/* Held where the PM callbacks and the requesting and freeing of the
* interrupt test and clear irq_rerun
*/
struct mutex irq_pm_lock;
Neither comment says that the lock now serializes drv->handle_interrupt()
in mdio_bus_phy_resume_irq() against phy_disable_interrupts() in
phy_free_interrupt(). Neither says that it covers the phydev->interrupts
check either. Later in the series both comments gain irq_wake_enabled.
They still don't describe this serialization, and the inline comment
still lacks the lock ordering rule.
Could both comments be updated, so that a later change doesn't move
phy_disable_interrupts() back out of the critical section?
> * @state_queue: Work queue for state machine
> * @link_down_events: Number of times link was lost
> * @shared: Pointer to private data shared by phys in one package
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123-b4-phylib-mac-pm-irq-v3-v8-0-e9f706e79614%40iav.lv
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net v8 5/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM
2026-11-23 0:46 [PATCH net v8 0/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
` (3 preceding siblings ...)
2026-11-23 0:46 ` [PATCH net v8 4/5] net: phy: run a postponed PHY interrupt handler directly on resume Igor Velkov via B4 Relay
@ 2026-11-23 0:46 ` Igor Velkov via B4 Relay
2026-11-24 1:11 ` netdev-bot+sashiko
4 siblings, 1 reply; 10+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-23 0:46 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Thomas Gleixner, linux-pm, Maxime Chevallier, Lukas Wunner,
Rafael J. Wysocki, Wei Fang, Niklas Söderlund, Paul Barker,
Florian Fainelli, Doug Berger, Thangaraj Samynathan, Shenwei Wang,
Haoning Cheng, netdev, linux-arm-kernel, linux-rockchip,
linux-kernel, Igor Velkov
From: Igor Velkov <iav@iav.lv>
mdio_bus_phy_suspend() and mdio_bus_phy_resume() return early when the
MAC driver manages PHY PM, so the PHY never gets irq_suspended and
phy_interrupt() runs the PHY driver's handler at any point of the sleep
transition. If the MAC driver powers the MDIO bus down, the MDIO access
in that handler can stall the CPU. This happens on both sides:
- suspend: the MAC's suspend callback stops the PHY, the link goes
down, and the handler runs while the MAC powers down;
- resume: resume_device_irqs() re-enables a pending interrupt before
the MAC resumes.
On Helios64 (dwmac-rk, RTL8211F with its interrupt line described in DT)
both hang the board: the handler reads INSR while the GMAC clocks are
off, after rk_gmac_suspend() or before rk_gmac_resume(). The commit in
the Fixes tag added the postponing after the early return for
MAC-managed PHY PM, and stmmac has set mac_managed_pm since commit
f151c147b3af ("net: stmmac: Enable mac_managed_pm phylink config").
Postpone the interrupts of these PHYs too, and start in the prepare
callback. The PM core calls prepare for all devices before the first
suspend callback, so irq_suspended is set before any MAC driver
suspends. The system still runs between prepare and the suspend
callbacks, and for hibernation it allocates the image memory there: a
link change of such a PHY in that window is handled only after resume or
complete. mdio_bus_phy_suspend() is too late when the PHY sits on an
MDIO bus the MAC does not own: phy_attach_direct() links the MAC as a
consumer of the PHY, and the MAC suspends first. ODROID-HC4 (stmmac,
RTL8211F behind mdio-mux-meson-g12a) takes this path. There, without
this series, a magic packet that arrived after stmmac_suspend() ran the
handler, which acknowledged the PME; the RTL8211F raises PME once per
arming, and the board slept through the packets that followed. PHYs
without MAC-managed PM still start postponing in mdio_bus_phy_suspend().
The PM core skips the resume callback of a device whose suspend
callback it did not call, so the complete callback stops the postponing
when the transition aborted before mdio_bus_phy_suspend().
The PHY device is a child of its MDIO bus, so mdio_bus_phy_resume() runs
after the resume callbacks of the bus and its parents (with stmmac, the
MAC) and replays the postponed interrupt then. The PM core resumes
children of a device whose resume callback failed, and phylib cannot
tell: if the MAC fails to power the bus up, the replay still reaches the
bus. Behind the device link the PHY resumes before the MAC, so there
the replay still runs before the MAC resumes, as the handler did from
resume_device_irqs() before this change. phy_suspend(), phy_resume() and
the state machine stay with the MAC driver, and no MAC driver needs a
change. Doing this in phylink_suspend() instead would miss macb, which
sets mac_managed_pm but suspends with phylink_stop().
A postponed interrupt cannot read the PHY, so it cannot tell Wake-on-LAN
from a link change. A PHY without MAC-managed PM reports what
phy_interrupt() reports today. A PHY with MAC-managed PM reports no
wakeup from the postponed interrupt: the MAC can change the link in its
suspend callback, as stmmac lowers the link speed through
phylink_suspend() when the PHY may wake the system.
A postponed interrupt leaves its line disabled. suspend_device_irqs()
runs before the noirq callbacks: it arms a wakeup line and leaves a
disabled one disabled unless the irqchip has
IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND, so a PHY whose interrupt line is also
its wake IRQ would sleep through a wakeup. Enable the line a postponed
interrupt disabled in the noirq suspend callback while it is still
disabled and armed for wakeup, and disable it again in the noirq resume
callback, before resume_device_irqs(). The irq core turns an interrupt
on an armed line into a wakeup without running the handler, and clears
the armed state before it disables the line, so a line that already woke
the system is left alone, and so is a line that is no longer disabled.
An edge the postponed interrupt consumed does not repeat, so on an
edge-triggered line a magic packet that arrives during the transition
does not abort it. The next one wakes the system if the PHY raises
another edge for it; the RTL8211F, which raises PME once per arming,
does not. On a level-triggered line, a PHY that keeps a link interrupt
asserted, such as the one from the speed change above, aborts every
suspend with Wake-on-LAN enabled: its driver has to restrict the
interrupt to Wake-on-LAN in its suspend callback, as rtl8211f_suspend()
does; with Wake-on-LAN enabled, phy_suspend() calls that callback only
for a driver that sets PHY_ALWAYS_CALL_SUSPEND. The noirq callbacks also
run as freeze_noirq and thaw_noirq, so all of this holds while a
hibernation image is created.
Tested with 7.4-rc3 and this series, s2idle with the link up.
Helios64:
- no Wake-on-LAN, GMAC clocks off in suspend: 7 of 7 cycles suspended
and resumed; on 7.3 without this series the same test hung or reset
the board after the link went down 10 of 10 times;
- MAC power/wakeup enabled, no Wake-on-LAN: 3 of 3 slept;
- Wake-on-LAN in the PHY, so phylink_suspend() also drops the link
speed: a magic packet woke the board 2 of 2 times, no suspend
aborted;
- the same under a flood of magic packets: a packet after
rtl8211f_suspend() was postponed and disabled the line, the noirq
callback enabled it, and the wakeup aborted the suspend 5 of 5 times
(traced).
ODROID-HC4:
- Wake-on-LAN in the PHY under a flood of magic packets: a packet
after stmmac_suspend() was postponed, and the wakeup aborted the
suspend 6 of 6 times (5 traced); without this series the board slept
until the RTC alarm 5 of 5 times;
- Wake-on-LAN in the PHY, no packets: 5 of 5 slept until the RTC
alarm, with no PHY interrupt.
Fixes: 1758bde2e4aa ("net: phy: Don't trigger state machine while in suspend")
Signed-off-by: Igor Velkov <iav@iav.lv>
---
Haoning Cheng's Tested-by on v5 is not carried: MAC-managed PHYs no
longer report a wakeup.
---
drivers/net/phy/phy.c | 13 ++++++--
drivers/net/phy/phy_device.c | 79 ++++++++++++++++++++++++++++++++++++++++++--
include/linux/phy.h | 17 +++++++---
3 files changed, 98 insertions(+), 11 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 6cc94b525e09..45891570a56e 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)
@@ -1486,8 +1489,10 @@ void phy_request_interrupt(struct phy_device *phydev)
/* 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))
+ if (phydev->irq_rerun && !irq_has_action(phydev->irq_rerun_line)) {
phydev->irq_rerun = false;
+ phydev->irq_wake_enabled = false;
+ }
mutex_unlock(&phydev->irq_pm_lock);
err = request_threaded_irq(phydev->irq, NULL, phy_interrupt,
@@ -1522,8 +1527,10 @@ void phy_free_interrupt(struct phy_device *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 (!irq_has_action(phydev->irq))
+ if (!irq_has_action(phydev->irq)) {
phydev->irq_rerun = false;
+ phydev->irq_wake_enabled = false;
+ }
mutex_unlock(&phydev->irq_pm_lock);
}
EXPORT_SYMBOL(phy_free_interrupt);
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 8bc394ff7d2d..082ae31c2234 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -18,6 +18,7 @@
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/io.h>
+#include <linux/irq.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/mdio.h>
@@ -372,11 +373,41 @@ static __maybe_unused void mdio_bus_phy_resume_irq(struct phy_device *phydev)
mutex_unlock(&phydev->irq_pm_lock);
}
+static __maybe_unused int mdio_bus_phy_prepare(struct device *dev)
+{
+ struct phy_device *phydev = to_phy_device(dev);
+
+ /* The MAC can suspend the PHY or power the MDIO bus down before our
+ * suspend callback runs, so we postpone interrupts from here on.
+ */
+ if (phydev->mac_managed_pm) {
+ mdio_bus_phy_suspend_irq(phydev);
+ phydev->irq_prepared = true;
+ }
+
+ return 0;
+}
+
+static __maybe_unused void mdio_bus_phy_complete(struct device *dev)
+{
+ struct phy_device *phydev = to_phy_device(dev);
+
+ /* The PM core skips our resume callback if the transition aborted
+ * before our suspend callback.
+ */
+ if (phydev->irq_prepared) {
+ phydev->irq_prepared = false;
+ mdio_bus_phy_resume_irq(phydev);
+ }
+}
+
static __maybe_unused int mdio_bus_phy_suspend(struct device *dev)
{
struct phy_device *phydev = to_phy_device(dev);
int ret;
+ phydev->irq_prepared = false;
+
if (phydev->mac_managed_pm)
return 0;
@@ -414,8 +445,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;
+ }
if (!phydev->suspended_by_mdio_bus)
goto no_resume;
@@ -446,8 +479,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)) {
+ enable_irq(phydev->irq_rerun_line);
+ phydev->irq_wake_enabled = true;
+ }
+ }
+ mutex_unlock(&phydev->irq_pm_lock);
+
+ return 0;
+}
+
+static __maybe_unused int mdio_bus_phy_resume_noirq(struct device *dev)
+{
+ struct phy_device *phydev = to_phy_device(dev);
+
+ mutex_lock(&phydev->irq_pm_lock);
+ if (phydev->irq_wake_enabled) {
+ phydev->irq_wake_enabled = false;
+ disable_irq_nosync(phydev->irq_rerun_line);
+ }
+ mutex_unlock(&phydev->irq_pm_lock);
+
+ return 0;
+}
+
+static const struct dev_pm_ops mdio_bus_phy_pm_ops = {
+ .prepare = pm_sleep_ptr(mdio_bus_phy_prepare),
+ .complete = pm_sleep_ptr(mdio_bus_phy_complete),
+ SET_SYSTEM_SLEEP_PM_OPS(mdio_bus_phy_suspend, mdio_bus_phy_resume)
+ SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(mdio_bus_phy_suspend_noirq,
+ mdio_bus_phy_resume_noirq)
+};
/**
* genphy_match_phy_device - match a PHY device with a PHY driver
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 9253a07e84be..048f6b743099 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -649,10 +649,14 @@ struct phy_oatc14_sqi_capability {
* @mdix_ctrl: User setting of crossover
* @pma_extable: Cached value of PMA/PMD Extended Abilities Register
* @interrupts: Flag interrupts have been enabled
- * @irq_suspended: Flag indicating PHY is suspended and therefore interrupt
- * handling shall be postponed until PHY has resumed
+ * @irq_suspended: Flag indicating a system sleep transition, so interrupt
+ * handling shall be postponed until the PHY has resumed
* @irq_rerun: Set by the postponed interrupt that disabled the line
* @irq_rerun_line: The line the postponed interrupt disabled
+ * @irq_wake_enabled: Set while @irq_rerun_line is enabled for the noirq
+ * phase, as it wakes the system
+ * @irq_prepared: Set for a PHY with MAC-managed PM from the prepare callback
+ * until the suspend callback runs
* @default_timestamp: Flag indicating whether we are using the phy
* timestamp as the default one
* @interface: enum phy_interface_t value
@@ -676,8 +680,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;
- * taken before @lock; phy_interrupt() never takes it
+ * of the interrupt where they test and clear @irq_rerun and
+ * @irq_wake_enabled; taken before @lock; phy_interrupt()
+ * never takes it
* @state_queue: Work queue for state machine
* @link_down_events: Number of times link was lost
* @shared: Pointer to private data shared by phys in one package
@@ -735,6 +740,8 @@ struct phy_device {
bool irq_suspended;
bool irq_rerun;
int irq_rerun_line;
+ bool irq_wake_enabled;
+ bool irq_prepared;
unsigned default_timestamp:1;
@@ -813,7 +820,7 @@ struct phy_device {
struct mutex lock;
/* Held where the PM callbacks and the requesting and freeing of the
- * interrupt test and clear irq_rerun
+ * interrupt test and clear irq_rerun and irq_wake_enabled
*/
struct mutex irq_pm_lock;
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH net v8 5/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM
2026-11-23 0:46 ` [PATCH net v8 5/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
@ 2026-11-24 1:11 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 1:11 UTC (permalink / raw)
To: iav
Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, tglx,
linux-pm, maxime.chevallier, lukas, rafael.j.wysocki, wei.fang,
niklas.soderlund, paul, florian.fainelli, opendmb, Thangaraj.S,
shenwei.wang, Haoning.CHENG, netdev, linux-arm-kernel,
linux-rockchip, linux-kernel
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 (1) · 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).
- [Medium] On a level-triggered wake line, a Broadcom BCM54210E PHY under
stmmac with PHY Wake-on-LAN now aborts every suspend.
- [Medium] The noirq wake fix does not work for nested-threaded PHY
interrupt lines, which the series explicitly supports (commit "net:…
Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but the new
replay still does MDIO access before the MAC has resumed in some…
--
net: phy: postpone PHY interrupts during sleep with MAC-managed PM
For PHYs with MAC-managed PM, this patch postpones PHY interrupts from the
prepare callback and replays them from mdio_bus_phy_resume(). If a
transition aborts, the complete callback stops the postponing. New noirq
callbacks re-enable a line that a postponed interrupt disabled, when the
irq core has armed it for wakeup, and disable it again on noirq resume.
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 8bc394ff7d2d2..082ae31c22341 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
[ ... ]
> @@ -414,8 +445,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: Medium]
This is a pre-existing issue, not one this patch introduces, but in some
topologies the replay here can still reach the MDIO bus before the MAC has
resumed.
phy_attach_direct() can add a device link between the MAC and the PHY:
if (dev && phydev->mdio.bus->parent && dev->dev.parent != phydev->mdio.bus->parent)
phydev->devlink = device_link_add(dev->dev.parent, &phydev->mdio.dev,
DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
The PHY is then the supplier, so it resumes before the MAC, and this path
runs first:
mdio_bus_phy_resume()
mdio_bus_phy_resume_irq()
phydev->drv->handle_interrupt() /* MDIO read */
The MAC's resume callback has not restored its MDIO controller at that
point. The same thing happens in the parent-child topology when the MAC's
resume callback fails, because the PM core still resumes the children.
Could a MAC that gates its MDIO clocks in its regular suspend callback,
and whose MDIO accessors are not guarded by runtime PM, stall on this
access?
The commit message already describes this limitation. Before this patch
the handler ran even earlier, from resume_device_irqs(). Now it runs after
device_resume_early() has re-enabled runtime PM, and stmmac's MDIO
accessors call pm_runtime_resume_and_get(). So the patch moves the access
later and does not widen exposure.
I could not find an in-tree board that pairs this topology with such a
MAC. I am listing it for completeness only.
[ ... ]
> @@ -446,8 +479,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)) {
> + enable_irq(phydev->irq_rerun_line);
> + phydev->irq_wake_enabled = true;
> + }
> + }
[Severity: Medium]
Can this abort every suspend for a Broadcom BCM54210E behind stmmac with
PHY Wake-on-LAN on a level-triggered line?
bcm_phy_set_wol() selects INTR on LED4 and makes the main PHY interrupt
the wake IRQ:
drivers/net/phy/bcm-phy-lib.c:bcm_phy_set_wol() {
...
if (phy_interrupt_is_valid(phydev))
enable_irq_wake(phydev->irq);
...
}
When Wake-on-LAN is enabled, bcm54xx_suspend() does not restrict
MII_BCM54XX_IMR, so link, speed and duplex interrupts stay on INTR:
drivers/net/phy/broadcom.c:bcm54xx_suspend() {
...
if (phydev->wol_enabled)
return bcm54xx_set_wakeup_irq(phydev, true);
...
}
stmmac sets mac_managed_pm and wol_phy_speed_ctrl, so the sequence looks
like this:
stmmac_suspend()
phylink_suspend()
phylink_stop()->phy_stop()->phy_suspend()->bcm54xx_suspend()
phylink_speed_down() /* restarts autoneg, raises a link interrupt */
phy_interrupt()
irq_suspended already set by mdio_bus_phy_prepare()
MII_BCM54XX_ISR is not read, disable_irq_nosync()
suspend_device_irqs()
sets IRQD_WAKEUP_ARMED on the line
mdio_bus_phy_suspend_noirq()
line is disabled and armed, so enable_irq()
the level interrupt is still asserted
irq_pm_handle_wakeup()->pm_system_irq_wakeup()
suspend aborts
The next attempt repeats the speed down. Would the system ever stay
suspended in this configuration?
The commit message says "its driver has to restrict the interrupt to
Wake-on-LAN in its suspend callback, as rtl8211f_suspend() does". The
Broadcom driver sets PHY_ALWAYS_CALL_SUSPEND, so bcm54xx_suspend() does
run, but it does not restrict the interrupt this way.
I could not find an in-tree board with this exact combination. Before this
patch, the link-up interrupt after renegotiation may already have caused a
spurious wakeup once the system was asleep. So this may mostly change how
the configuration fails, but the noirq re-enable here makes the abort
newly reachable.
Should bcm54xx_suspend() mask the non-WoL interrupt sources as well?
[Severity: Medium]
Can the irqd_is_wakeup_armed() check ever pass for a nested-threaded PHY
line, such as one behind an I2C or SPI expander? Other patches in this
series explicitly support such lines.
suspend_device_irqs() skips nested-thread descriptors:
kernel/irq/pm.c:suspend_device_irqs() {
...
if (irq_settings_is_nested_thread(desc))
continue;
...
}
So IRQD_WAKEUP_ARMED is never set on them, even after irq_set_irq_wake()
has set IRQD_WAKEUP_STATE.
With this patch a MAC-managed PHY is postponed from mdio_bus_phy_prepare(),
so any PHY interrupt during the transition calls disable_irq_nosync() on
the nested line.
Some parent chips implement .irq_disable, such as regmap-irq with
regmap_irq_disable(). On those, the disable masks the PHY's source in the
parent's hardware.
mdio_bus_phy_suspend_noirq() then skips enable_irq(), and the source stays
masked through sleep. A later Wake-on-LAN event from the PHY never asserts
the parent's wake-armed line, and the system keeps sleeping.
Isn't this the "would sleep through a wakeup" case the noirq callbacks are
meant to close? Could the check fall back to irqd_is_wakeup_set() for
nested-thread lines?
Lazy-disable parents that implement only irq_mask, such as pca953x, are
not affected, because the pin stays unmasked. I could not confirm an
in-tree board that combines a MAC-managed PHY with such a parent irqchip
and Wake-on-LAN.
> + mutex_unlock(&phydev->irq_pm_lock);
> +
> + return 0;
> +}
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123-b4-phylib-mac-pm-irq-v3-v8-0-e9f706e79614%40iav.lv
^ permalink raw reply [flat|nested] 10+ messages in thread