* [PATCH net v6 0/4] net: phy: postpone PHY interrupts during sleep with MAC-managed PM
@ 2026-11-13 21:06 Igor Velkov via B4 Relay
2026-11-13 21:06 ` [PATCH net v6 1/4] net: phy: move irq_suspended and irq_rerun out of the bitfield Igor Velkov via B4 Relay
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-13 21:06 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: 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
When the MAC driver manages PHY PM, phylib never sets irq_suspended, and
a PHY interrupt during the sleep transition runs the PHY driver's
handler while the MDIO bus may be powered down. On Helios64 (dwmac-rk)
this hangs the board on suspend as well as on resume.
mac_managed_pm hands phy_suspend(), phy_resume() and the state machine
to the MAC driver, since commit fba863b81604 ("net: phy: make PHY PM
ops a no-op if MAC driver manages PHY PM"); the PHY interrupt stays
with phylib, and so does postponing it.
Patches 1-3 fix the postponing that phylib applies to other PHYs, so
that patch 4 can extend it to MAC-managed ones. Patch 1 moves the two
flags out of a bitfield they share with the link state written under
phydev->lock. Patch 2 keeps the line of a postponed interrupt balanced
when an edge reruns the IRQ thread or the PHY frees a line it was alone
on during the transition. Patch 3 undoes the postponing when
phy_suspend() fails. Patch 4 sets irq_suspended for MAC-managed PHYs
too; their postponed interrupts report no wakeup.
Patch 4 fixes a hang seen on Helios64 (dwmac-rk, RTL8211F): in s2idle
without WoL the board hung or reset 10 of 10 times without the series.
The PHY IRQ thread stalls its CPU on an MDIO read while the GMAC clocks
are off, so that CPU never answers the NMI:
watchdog: CPU0: Watchdog detected hard LOCKUP on cpu 1
After 10 seconds, these CPUS still haven't responded to the NMI: 1
Patches 1-3 fix defects found by code inspection and Sashiko review;
they were not triggered.
With MAC-managed PM, a postponed interrupt cannot tell Wake-on-LAN from
a link change that the MAC causes, so it reports no wakeup: a magic
packet during the transition does not abort it. A PHY that leaves its
link interrupt unmasked under Wake-on-LAN still disables its line when
stmmac lowers the link speed, and may not wake the system from that
sleep.
Not covered: MDIO accesses from closing or opening the interface during
the transition, and a MAC resume that fails to power the bus up. On a
shared line, a postponed PHY interrupt disables the line for its other
users until the PHY resumes, also when the PHY frees its interrupt in
between; patch 4 extends that to MAC-managed PHYs. When
mdio_bus_phy_resume() fails, the interrupts stay postponed.
phy_free_interrupt() checks irq_has_action() after free_irq(), so a
driver that requests the line in between gets an unbalanced enable_irq()
at resume. A nested threaded PHY interrupt is not replayed
(irq_wake_thread() has no thread to wake), and
mdio_bus_phy_may_suspend() does not ask phy_may_wakeup() about an
attached PHY.
Tested on Helios64 (dwmac-rk, RTL8211F); Haoning Cheng tested v5 on
i.MX6 (fec).
Changes in v6:
- patch 2: phy_free_interrupt() enables no line; it clears irq_rerun
when the PHY was alone on the line, and mdio_bus_phy_resume()
enables a shared line. Enabling it in phy_free_interrupt() could
unmask a source that phy_disable_interrupts() failed to clear, or
unbalance a wakeup line in the noirq phase (Sashiko on v5)
- patch 3: the resume error path is left as in net; clearing
irq_suspended there let the handler reach a PHY that failed to
resume (Sashiko on v5)
- patch 4: with mac_managed_pm, a postponed interrupt reports no
wakeup, and other PHYs report what they report in net; irq_wake,
wol_phy and the barriers are gone. A wakeup on Wake-on-LAN in the
PHY let link interrupts that the MAC causes abort suspend on PHYs
that leave them unmasked (Sashiko on v5)
- patch 1: the comment names the writers of the two flags (Sashiko on
v5)
- patch 2: irq_pm_lock sits next to lock in struct phy_device
- comments say again that postponing lasts until the PHY has resumed
- the cover letter says what was reproduced (Jakub)
- Haoning Cheng's Tested-by on v5 kept on patch 1 only
- rebased on net
- tests rerun on v6
- Link to v5: https://lore.kernel.org/r/20261111-b4-phylib-mac-pm-irq-v3-v5-0-bbfdb5afb7d3@iav.lv
Changes in v5:
- v4 patch 2 alone could leave irq_rerun set across
phy_free_interrupt() and a new request, after which a postponed
level interrupt fired without end; it is merged with v4 patch 3 into
patch 2. phy_free_interrupt() re-enables the line after free_irq(),
not before, and only while other users of a shared line remain, so
the handler cannot keep running on a source it cannot quiet;
irq_rerun stays a bool (Sashiko on v4)
- patch 3: when the PHY fails to resume, the line a postponed
interrupt disabled stays off, as before this series, instead of
rerunning a handler that may not reach the PHY (Sashiko on v4)
- patch 4: with mac_managed_pm, only Wake-on-LAN in the PHY makes a
postponed interrupt a wakeup; the ethtool flag may describe
Wake-on-LAN in the MAC, as with fec (Sashiko on v4); for a PHY that
phy_suspend() already suspended, the PHY part of its Wake-on-LAN
state is kept in the new wol_phy
- patch 4: Fixes: now points at 1758bde2e4aa, which added the
postponing after the early return for MAC-managed PHY PM
- comments say that postponing lasts until the transition ends
- Haoning Cheng's Tested-by on v4 kept on patch 1 only: patches 2-4
changed
- rebased on net
- tests rerun on v5
- Link to v4: https://lore.kernel.org/r/20261031-b4-phylib-mac-pm-irq-v3-v4-0-5ba23b3ff9a4@iav.lv
Changes in v4:
- new patches 2-4, one pre-existing defect each
- patch 2: an edge that reruns the IRQ thread no longer disables the
line twice
- patch 3: phy_free_interrupt() during the transition keeps the line
balanced (Sashiko on v3)
- patch 4: a failing PHY PM callback no longer leaves the interrupt
postponed (Sashiko on v2 and v3)
- patch 5: the wakeup event is decided in mdio_bus_phy_suspend(), where
phy_may_wakeup() can still read the PHY (Sashiko on v3); Fixes: now
points at the stmmac commit that took its PHYs out of postponing
- v3 asked phylib or phylink_suspend(): phylib, as macb sets
mac_managed_pm but suspends with phylink_stop()
- tests rerun on v4
- Link to v3: https://lore.kernel.org/r/20261029-b4-phylib-mac-pm-irq-v3-v3-0-5907045f3210@iav.lv
Changes in v3:
- with mac_managed_pm, a postponed interrupt signals a wakeup event only
with Wake-on-LAN; with MAC power/wakeup enabled and no WoL, v2 aborted
s2idle on Helios64 3 of 3 times, v3 0 of 3 (reported by Sashiko)
- phy_free_interrupt(): stop postponing and re-enable the line before
free_irq(), not after it (reported by Sashiko)
- mdio_bus_phy_suspend() comment narrowed to the MDIO bus (reported by
Sashiko)
- patch 1: Andrew suggested taking phydev->lock in phy_interrupt();
the commit message says why that does not close the race
- tests rerun on v3
- Link to v2: https://lore.kernel.org/r/20261026045343.837889-1-iav@iav.lv
Signed-off-by: Igor Velkov <iav@iav.lv>
---
Igor Velkov (4):
net: phy: move irq_suspended and irq_rerun out of the bitfield
net: phy: keep the line of a postponed PHY interrupt balanced
net: phy: stop postponing PHY interrupts when phy_suspend() fails
net: phy: postpone PHY interrupts during sleep with MAC-managed PM
drivers/net/phy/phy.c | 22 +++++++++---
drivers/net/phy/phy_device.c | 79 ++++++++++++++++++++++++++++++--------------
include/linux/phy.h | 18 ++++++----
3 files changed, 85 insertions(+), 34 deletions(-)
---
base-commit: ead6fa9a0ab194f02a2f36d634b193e9c5f9a1c6
change-id: 20261029-b4-phylib-mac-pm-irq-v3-f656d4e1c64f
Best regards,
--
Igor Velkov <iav@iav.lv>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net v6 1/4] net: phy: move irq_suspended and irq_rerun out of the bitfield
2026-11-13 21:06 [PATCH net v6 0/4] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
@ 2026-11-13 21:06 ` Igor Velkov via B4 Relay
2026-11-13 21:06 ` [PATCH net v6 2/4] net: phy: keep the line of a postponed PHY interrupt balanced Igor Velkov via B4 Relay
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-13 21:06 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: 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] 7+ messages in thread
* [PATCH net v6 2/4] net: phy: keep the line of a postponed PHY interrupt balanced
2026-11-13 21:06 [PATCH net v6 0/4] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
2026-11-13 21:06 ` [PATCH net v6 1/4] net: phy: move irq_suspended and irq_rerun out of the bitfield Igor Velkov via B4 Relay
@ 2026-11-13 21:06 ` Igor Velkov via B4 Relay
2026-11-17 12:08 ` netdev-bot+sashiko
2026-11-13 21:06 ` [PATCH net v6 3/4] net: phy: stop postponing PHY interrupts when phy_suspend() fails Igor Velkov via B4 Relay
2026-11-13 21:06 ` [PATCH net v6 4/4] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
3 siblings, 1 reply; 7+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-13 21:06 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: 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. Two 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. If the PHY was alone
on the line, a new request starts the line at depth 0, and the
enable_irq() in mdio_bus_phy_resume() is unbalanced.
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. Let
phy_free_interrupt() clear irq_rerun when free_irq() leaves the line
without users: free_irq() has shut it down, and the next request resets
its depth. A shared line keeps irq_rerun, and mdio_bus_phy_resume()
enables it, as before. Enabling it 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 phy_free_interrupt() does not clear 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 stays a plain bool: one thread runs the
handler, and the other two access it only under the lock, after
free_irq() or synchronize_irq(). Mark the irq_suspended accesses with
READ_ONCE() and WRITE_ONCE(): the handler reads it while the PM
callbacks write it.
This does not keep close and open off the MDIO bus: on close,
phy_disconnect() calls phy_stop(), 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 | 17 +++++++++++---
drivers/net/phy/phy_device.c | 56 +++++++++++++++++++++++++++-----------------
include/linux/phy.h | 7 ++++--
3 files changed, 54 insertions(+), 26 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 9af303d60bd6..8e03c99fce8f 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,11 @@ 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 = true;
+ disable_irq_nosync(irq);
+ }
return IRQ_HANDLED;
}
@@ -1507,7 +1510,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..573eb234dc79 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -332,6 +332,38 @@ 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);
+ if (!phy_interrupt_is_valid(phydev))
+ return;
+
+ mutex_lock(&phydev->irq_pm_lock);
+ synchronize_irq(phydev->irq);
+ if (phydev->irq_rerun) {
+ phydev->irq_rerun = false;
+ enable_irq(phydev->irq);
+ 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 +371,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 +418,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 +724,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..96d14b6b544f 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -651,8 +651,7 @@ 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
* @default_timestamp: Flag indicating whether we are using the phy
* timestamp as the default one
* @interface: enum phy_interface_t value
@@ -675,6 +674,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 phy_free_interrupt() against the rerun of a
+ * postponed interrupt; 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
@@ -808,6 +809,8 @@ struct phy_device {
struct delayed_work state_queue;
struct mutex lock;
+ /* Serializes phy_free_interrupt() against mdio_bus_phy_resume_irq() */
+ 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] 7+ messages in thread
* [PATCH net v6 3/4] net: phy: stop postponing PHY interrupts when phy_suspend() fails
2026-11-13 21:06 [PATCH net v6 0/4] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
2026-11-13 21:06 ` [PATCH net v6 1/4] net: phy: move irq_suspended and irq_rerun out of the bitfield Igor Velkov via B4 Relay
2026-11-13 21:06 ` [PATCH net v6 2/4] net: phy: keep the line of a postponed PHY interrupt balanced Igor Velkov via B4 Relay
@ 2026-11-13 21:06 ` Igor Velkov via B4 Relay
2026-11-13 21:06 ` [PATCH net v6 4/4] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
3 siblings, 0 replies; 7+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-13 21:06 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: 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.
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 573eb234dc79..39e232a3144a 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -367,6 +367,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;
@@ -384,9 +385,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] 7+ messages in thread
* [PATCH net v6 4/4] net: phy: postpone PHY interrupts during sleep with MAC-managed PM
2026-11-13 21:06 [PATCH net v6 0/4] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
` (2 preceding siblings ...)
2026-11-13 21:06 ` [PATCH net v6 3/4] net: phy: stop postponing PHY interrupts when phy_suspend() fails Igor Velkov via B4 Relay
@ 2026-11-13 21:06 ` Igor Velkov via B4 Relay
2026-11-17 12:08 ` netdev-bot+sashiko
3 siblings, 1 reply; 7+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-13 21:06 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: 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").
Set irq_suspended for these PHYs too. 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. 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: 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, and a PHY that leaves its link interrupt unmasked would
abort every suspend. Its postponed interrupt still disables the line,
which may then stay masked until resume, so such a PHY may not wake the
system from that sleep, and a magic packet that arrives during the
transition does not abort it.
Tested on Helios64 with 7.3.4, s2idle with the link up:
- no Wake-on-LAN, GMAC clocks off in suspend: 10 of 10 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 4 of 4 times, no suspend
aborted.
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 | 5 ++++-
drivers/net/phy/phy_device.c | 11 ++++++++---
include/linux/phy.h | 4 ++--
3 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 8e03c99fce8f..ccf0658c4d10 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)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 39e232a3144a..c043071784f5 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -369,11 +369,14 @@ static __maybe_unused int mdio_bus_phy_suspend(struct device *dev)
struct phy_device *phydev = to_phy_device(dev);
int ret;
+ /* An interrupt can fire while the MAC has the MDIO bus powered
+ * down, whether or not the MAC manages PHY PM.
+ */
+ mdio_bus_phy_suspend_irq(phydev);
+
if (phydev->mac_managed_pm)
return 0;
- mdio_bus_phy_suspend_irq(phydev);
-
/* We must stop the state machine manually, otherwise it stops out of
* control, possibly with the phydev->lock held. Upon resume, netdev
* may call phy routines that try to grab the same lock, and that may
@@ -406,8 +409,10 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev)
struct phy_device *phydev = to_phy_device(dev);
int ret;
- if (phydev->mac_managed_pm)
+ if (phydev->mac_managed_pm) {
+ mdio_bus_phy_resume_irq(phydev);
return 0;
+ }
if (!phydev->suspended_by_mdio_bus)
goto no_resume;
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 96d14b6b544f..3238432989c3 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -649,8 +649,8 @@ 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
* @default_timestamp: Flag indicating whether we are using the phy
* timestamp as the default one
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net v6 2/4] net: phy: keep the line of a postponed PHY interrupt balanced
2026-11-13 21:06 ` [PATCH net v6 2/4] net: phy: keep the line of a postponed PHY interrupt balanced Igor Velkov via B4 Relay
@ 2026-11-17 12:08 ` netdev-bot+sashiko
0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 12:08 UTC (permalink / raw)
To: iav
Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
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: 1 · Medium: 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).
- [High] phy_free_interrupt() decides once, from irq_has_action() right
after this PHY's free_irq(), whether irq_rerun still owns a unit of…
- [Medium] On a shared line, phy_free_interrupt() (drivers/net/phy/phy.c)
keeps irq_rerun set and leaves the rebalance to resume.
--
net: phy: keep the line of a postponed PHY interrupt balanced
With this change, only the first postponed run of phy_interrupt() disables
the PHY interrupt line. phy_free_interrupt() now clears irq_rerun when
free_irq() leaves the line without users. It also adds irq_pm_lock to
serialize phy_free_interrupt() against the rerun after resume, and moves
the postpone/rerun logic into mdio_bus_phy_suspend_irq() and
mdio_bus_phy_resume_irq().
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index 9af303d60bd6b..8e03c99fce8f5 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
[ ... ]
> @@ -1430,8 +1430,11 @@ 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 = true;
> + disable_irq_nosync(irq);
> + }
> return IRQ_HANDLED;
> }
>
> @@ -1507,7 +1510,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);
> }
[Severity: High]
Can irq_rerun go stale on a shared line here?
Whether to keep irq_rerun is decided once, by irq_has_action() right after
this PHY's free_irq(). If another user is still on the line, irq_rerun
stays true.
When that remaining user frees the line later, __free_irq() shuts the line
down. The next request then goes through irq_startup(), which resets
desc->depth to 0. Nothing clears the first PHY's irq_rerun at that point.
Take two PHYs sharing one IRQF_SHARED line behind cpsw, which sets
mac_managed_pm. A later patch in this series brings those PHYs under
postponing:
wakeup interrupt
phy_interrupt(PHY0): irq_rerun0 = true, disable_irq_nosync() depth 1
phy_interrupt(PHY1): irq_rerun1 = true, disable_irq_nosync() depth 2
cpsw_suspend()->cpsw_ndo_stop()->phy_disconnect()
phy_free_interrupt(PHY0): PHY1 still on line, irq_rerun0 stays true
phy_free_interrupt(PHY1): line empty, shut down, irq_rerun1 = false
cpsw_resume()->cpsw_ndo_open()->phy_request_interrupt()
irq_startup() resets depth to 0, irq_rerun0 still true
mdio_bus_phy_resume_irq(PHY0)
enable_irq() at depth 0
Wouldn't this hit the "Unbalanced enable for IRQ" warning in
__enable_irq()? That is the symptom the commit message says is fixed.
The new guard in phy_interrupt() also seems to make a stale irq_rerun
worse. Between the line restart and the PHY's resume, a postponed
level-triggered interrupt now returns IRQ_HANDLED without being serviced
or masked:
if (!phydev->irq_rerun) {
phydev->irq_rerun = true;
disable_irq_nosync(irq);
}
return IRQ_HANDLED;
The ONESHOT unmask would then keep firing it until that PHY resumes.
Before this patch, such an interrupt disabled the line again, and resume
balanced it.
There is also a race. irq_has_action() runs after free_irq() has dropped
desc->request_mutex, and irq_pm_lock is per phydev. So a request_irq() or
free_irq() by another driver on the same line can change the answer
between the two calls.
Would it be possible to tie irq_rerun to the lifetime of the line, rather
than to a snapshot taken at free time?
> EXPORT_SYMBOL(phy_free_interrupt);
>
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 1791d578f4dde..573eb234dc799 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -332,6 +332,38 @@ 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);
> + if (!phy_interrupt_is_valid(phydev))
> + return;
[Severity: Medium]
The new comment in phy_free_interrupt() says "mdio_bus_phy_resume_irq()
enables a shared line". Is that always true?
This early return comes before irq_rerun is checked.
phy_request_interrupt() sets phydev->irq to PHY_POLL in two failure cases:
drivers/net/phy/phy.c:phy_request_interrupt() {
...
if (err) {
...
phydev->irq = PHY_POLL;
} else {
if (phy_enable_interrupts(phydev)) {
...
phy_free_interrupt(phydev);
phydev->irq = PHY_POLL;
}
}
}
Suppose a postponed interrupt took a disable on a shared line. Then
phy_free_interrupt() runs during the sleep window while another user stays
on the line, for example from cpsw_suspend() or stmmac_reset_subtask()
through phy_disconnect(). irq_rerun is still true at that point.
If the reopen then fails in one of these two ways, for instance because of
an MDIO error while the bus is down, phydev->irq becomes PHY_POLL. In the
second case, phy_free_interrupt() again keeps irq_rerun, because the other
user is still on the line.
mdio_bus_phy_resume_irq() then returns here without calling enable_irq().
Since phydev->irq is never set back to the old number, can anything ever
balance that disable? It looks like the other users of the shared line
would stay masked for good.
> +
> + mutex_lock(&phydev->irq_pm_lock);
> + synchronize_irq(phydev->irq);
> + if (phydev->irq_rerun) {
> + phydev->irq_rerun = false;
> + enable_irq(phydev->irq);
> + irq_wake_thread(phydev->irq, phydev);
> + }
> + mutex_unlock(&phydev->irq_pm_lock);
> +}
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-b4-phylib-mac-pm-irq-v3-v6-0-05af2503cb23%40iav.lv
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net v6 4/4] net: phy: postpone PHY interrupts during sleep with MAC-managed PM
2026-11-13 21:06 ` [PATCH net v6 4/4] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
@ 2026-11-17 12:08 ` netdev-bot+sashiko
0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 12:08 UTC (permalink / raw)
To: iav
Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
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 5 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 4 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] net: phy: inverted PM IRQ ordering when consumer MAC links to
PHY
- [Medium] PHY Wake-on-LAN can be lost for MAC-managed PHYs whose
interrupt line is also their wake IRQ.
- [Medium] The postponed interrupt is lost for MAC-managed PHYs whose
interrupt is a nested threaded IRQ (for example PHY INT routed through…
- [Medium] A shared IRQ line's disable depth can leak when a MAC-managed
PHY's interrupt is re-requested from the MAC's resume callback.
- [Medium] net: phy: unbalanced enable_irq() in mdio_bus_phy_resume_irq()
on shared IRQ
--
net: phy: postpone PHY interrupts during sleep with MAC-managed PM
This commit makes mdio_bus_phy_suspend() and mdio_bus_phy_resume() set
and clear irq_suspended for PHYs whose PM is managed by the MAC driver.
phy_interrupt() then postpones handling during the sleep transition
instead of touching a possibly powered-down MDIO bus. For MAC-managed
PHYs, the postponed interrupt no longer reports a wakeup event.
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index 8e03c99fce8f5..ccf0658c4d101 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -1419,7 +1419,10 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
> if (IS_ENABLED(CONFIG_PM_SLEEP) && READ_ONCE(phydev->irq_suspended)) {
> struct net_device *netdev = phydev->attached_dev;
>
> - if (netdev) {
> + /* With MAC-managed PM, a postponed interrupt cannot tell
> + * Wake-on-LAN from a link change the MAC causes.
> + */
> + if (netdev && !phydev->mac_managed_pm) {
> struct device *parent = netdev->dev.parent;
>
> if (netdev->ethtool->wol_enabled)
[Severity: Medium]
With this patch, a MAC-managed PHY gets irq_suspended set in
mdio_bus_phy_suspend() before the MAC's own suspend callback runs. Any
PHY interrupt from then until mdio_bus_phy_resume() takes this postponed
path. For mac_managed_pm no wakeup is reported, but the line is still
disabled:
if (!phydev->irq_rerun) {
phydev->irq_rerun = true;
disable_irq_nosync(irq);
}
Could this lose PHY Wake-on-LAN for the whole sleep on PHYs whose
interrupt line is also their wake IRQ? Both rtl8211f_probe() and
an8801r_probe() register phydev->irq as the wake IRQ:
devm_pm_set_wake_irq(dev, phydev->irq);
In the noirq phase, suspend_device_irq() re-enables a disabled
wake-armed line only when the irqchip has
IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND:
kernel/irq/pm.c:suspend_device_irq() {
...
if ((chipflags & IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND) &&
irqd_irq_disabled(irqd)) {
...
__enable_irq(desc);
...
}
On other irqchips the line would stay masked until resume. A later PME
or magic packet interrupt then could not wake the system.
One concrete case is stmmac with an RTL8211F and PHY WoL enabled. The
link partner changes the link after irq_suspended is set, but before
rtl8211f_suspend() switches INER to PME only:
if (device_may_wakeup(&phydev->mdio.dev)) {
ret = phy_write_paged(phydev, 0xa42, RTL821x_INER,
RTL8211F_INER_PME);
rtl8211f_suspend() then clears INTB. The software disable of the line
stays in place until mdio_bus_phy_resume_irq().
Before this patch, phy_interrupt() ran handle_interrupt() here and the
oneshot line was unmasked again. On boards whose MDIO bus stays
powered, WoL kept working in this case.
The phylink_speed_down() renegotiation in phylink_suspend() does not
appear to trigger this for RTL8211F or AN8801.
phylink_stop()->phy_stop()->phy_suspend() already restricts the
interrupt mask before that point. It would only matter for a wake IRQ
PHY that leaves link interrupts unmasked in suspend.
The commit message says the line "may then stay masked until resume, so
such a PHY may not wake the system from that sleep". It does not say
that any link event in this window disables WoL for the whole sleep
cycle.
The Helios64 WoL test also runs on gpio-rockchip, and
rockchip_irq_suspend() does this:
irq_reg_writel(gc, ~gc->wake_active, bank->gpio_regs->int_mask);
That unmasks wake pins in hardware whatever the software disable state
is. Would that test be able to show this regression?
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 39e232a3144a2..c043071784f5b 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -369,11 +369,14 @@ static __maybe_unused int mdio_bus_phy_suspend(struct device *dev)
> struct phy_device *phydev = to_phy_device(dev);
> int ret;
>
> + /* An interrupt can fire while the MAC has the MDIO bus powered
> + * down, whether or not the MAC manages PHY PM.
> + */
> + mdio_bus_phy_suspend_irq(phydev);
> +
> if (phydev->mac_managed_pm)
> return 0;
[Severity: Medium]
For a MAC-managed PHY, irq_suspended is now set here, before the MAC's
suspend callback runs. cpsw and cpsw_new set mac_managed_pm, and they
also disconnect the PHY from that callback. cpsw_suspend() calls
cpsw_ndo_stop(), which ends in phy_disconnect(), and cpsw_resume()
connects the PHY again.
Can this leave a stale irq_rerun and an unbalanced enable_irq() on a
board where the two slave PHYs share one interrupt line?
phy_request_interrupt() uses IRQF_ONESHOT | IRQF_SHARED, so phy0 and
phy1 each have an action on the same irq_desc. If the line fires after
both mdio_bus_phy_suspend() calls, both threads run. Each
phy_interrupt() takes the postponed path, sets its own irq_rerun and
calls disable_irq_nosync(). The depth is then 2.
cpsw_suspend() then disconnects phy0. phy_free_interrupt() keeps
phy0->irq_rerun set, because phy1 still has an action on the line:
if (!irq_has_action(phydev->irq))
phydev->irq_rerun = false;
Disconnecting phy1 removes the last action. free_irq() shuts the line
down and phy1->irq_rerun is cleared, but phy0->irq_rerun stays true.
On resume, cpsw_resume() runs before mdio_bus_phy_resume() and calls
phy_request_interrupt() again. With no actions left on the line,
__setup_irq() calls irq_startup() and the depth goes back to 0.
mdio_bus_phy_resume_irq() for phy0 still sees irq_rerun:
if (phydev->irq_rerun) {
phydev->irq_rerun = false;
enable_irq(phydev->irq);
irq_wake_thread(phydev->irq, phydev);
}
Wouldn't that enable_irq() hit the unbalanced enable WARN in
__enable_irq()?
The stale flag also matters before that point. Suppose the line fires
after cpsw_resume() has requested phy0's IRQ but before
mdio_bus_phy_resume(). phy_interrupt() for phy0 sees irq_rerun already
set and skips disable_irq_nosync(). It returns IRQ_HANDLED without
touching the PHY. If phy1 has not been reconnected yet, nothing masks a
level-triggered line, so the oneshot thread keeps being woken.
MAC-managed PHYs could not get here before, because irq_suspended was
never set for them. Should phy_free_interrupt() undo this PHY's own
disable_irq_nosync() whenever irq_rerun is set, instead of basing the
cleanup on irq_has_action()?
[Severity: Medium]
For MAC-managed PHYs, irq_suspended is now set here and cleared only in
mdio_bus_phy_resume(). That runs after the MAC's resume callback, so
the flag is still true while the MAC resumes.
ravb and sh_eth set mac_managed_pm. They call phy_disconnect() in
suspend and of_phy_connect() in resume. So the PHY IRQ is requested
again while irq_suspended is true:
ravb_resume()->ravb_open()->...->phy_request_interrupt()
Can this leave a shared IRQ line disabled?
On an IRQF_SHARED line, the other device can interrupt after
request_threaded_irq(). phy_interrupt() then takes the postponed path,
sets irq_rerun and calls disable_irq_nosync(). Suppose
phy_enable_interrupts() then fails:
drivers/net/phy/phy.c:phy_request_interrupt() {
...
if (phy_enable_interrupts(phydev)) {
phydev_warn(phydev, "Can't enable interrupt, falling back to polling\n");
phy_free_interrupt(phydev);
phydev->irq = PHY_POLL;
}
...
}
phy_free_interrupt() clears irq_rerun only when the line has no other
actions left. On a shared line it still has one:
if (!irq_has_action(phydev->irq))
phydev->irq_rerun = false;
mdio_bus_phy_resume_irq() then returns early because the IRQ is now
PHY_POLL:
WRITE_ONCE(phydev->irq_suspended, false);
if (!phy_interrupt_is_valid(phydev))
return;
The matching enable_irq() never runs. Wouldn't the other device on that
line stop getting interrupts, with irq_rerun left stale?
MAC-managed PHYs could not reach this path before, because irq_suspended
was never set for them.
>
> - mdio_bus_phy_suspend_irq(phydev);
> -
> /* We must stop the state machine manually, otherwise it stops out of
> * control, possibly with the phydev->lock held. Upon resume, netdev
> * may call phy routines that try to grab the same lock, and that may
[ ... ]
> @@ -406,8 +409,10 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev)
> struct phy_device *phydev = to_phy_device(dev);
> int ret;
>
> - if (phydev->mac_managed_pm)
> + if (phydev->mac_managed_pm) {
> + mdio_bus_phy_resume_irq(phydev);
> return 0;
> + }
[Severity: High]
The ordering argument in the commit message needs the MAC to be the
MDIO bus parent or one of its ancestors. That does not hold when the
PHY sits on an MDIO bus owned by another device. In that case
phy_attach_direct() calls device_link_add() with dev->dev.parent as
consumer and &phydev->mdio.dev as supplier.
device_link_add() moves the consumer to the tail of dpm_list. The MAC
then suspends before mdio_bus_phy_suspend() and resumes after
mdio_bus_phy_resume(). Examples are two FEC instances with
FEC_QUIRK_SINGLE_MDIO, dual stmmac or macb sharing one MDIO bus, and
MACs behind an mdio-mux.
On resume, mdio_bus_phy_resume() for such a PHY clears irq_suspended
and replays the postponed interrupt before the consumer's resume
callback has run. handle_interrupt() then reads the PHY before
fec_resume() has re-enabled fep->reg_phy and fep->clk_enet_out. It
also runs before phy_resume() has turned the PHY driver's own clock
back on, as rtl821x_resume() does with priv->clk. Interrupts after this
point are not postponed either.
If that MDIO access fails, the handler calls phy_error() and the state
becomes PHY_ERROR. phy_start() from the MAC's resume only accepts
PHY_READY or PHY_HALTED, so it hits its WARN and returns without
starting the PHY. The link then stays down after resume.
If the access succeeds, phydev->state is still PHY_HALTED.
phy_trigger_machine() then queues a state machine run that takes the
PHY_STATE_WORK_SUSPEND path and calls phy_suspend() outside
phydev->lock. Can that race with the MAC's later
phy_start()->__phy_resume()?
The suspend side is not covered for this topology either. The
consumer's suspend callback runs before mdio_bus_phy_suspend() sets
irq_suspended. That callback may call phy_stop(), call
phylink_speed_down() as stmmac_suspend() does, or gate clocks and
regulators as fec_suspend() does. A link-down interrupt caused there
still runs the handler directly.
So for these PHYs the patch only moves the handler from
resume_device_irqs() to mdio_bus_phy_resume(), still ahead of the MAC.
Should the replay for a PHY with phydev->devlink wait until the
consumer has resumed? Or should the commit message say that this
topology is not covered?
[Severity: Medium]
For a MAC-managed PHY, this replay now runs without a phy_init_hw() call
before it:
if (phydev->irq_rerun) {
phydev->irq_rerun = false;
enable_irq(phydev->irq);
irq_wake_thread(phydev->irq, phydev);
}
Is the postponed interrupt lost when the PHY interrupt is a nested
threaded IRQ? One example is a PHY INT routed through an I2C or SPI GPIO
expander such as pca953x.
For a nested IRQ, __setup_irq() creates no thread. irq_wake_thread()
only wakes a thread that exists:
kernel/irq/manage.c:irq_wake_thread() {
...
if (action->dev_id == dev_id) {
if (action->thread)
__irq_wake_thread(desc, action);
break;
}
...
}
The postponed path in phy_interrupt() disabled the line without reading
the PHY's interrupt status. Getting there only takes the MAC's suspend
stopping the PHY and the link going down, as the commit message
describes.
After resume, nothing reads the latched status (for example RTL8211F
INSR), so INT stays asserted. An edge-triggered expander input would
then never see a new edge.
For non-MAC-managed PHYs this is hidden: mdio_bus_phy_resume() calls
phy_init_hw()->config_intr() before the replay. stmmac_resume() does not
call phy_init_hw(), while fec_resume() does.
The state machine is in interrupt mode and does not poll. On such stmmac
boards, could link up go unreported after resume, leaving the network
down until the interface is reinitialised?
>
> if (!phydev->suspended_by_mdio_bus)
> goto no_resume;
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-b4-phylib-mac-pm-irq-v3-v6-0-05af2503cb23%40iav.lv
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-17 12:09 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 21:06 [PATCH net v6 0/4] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
2026-11-13 21:06 ` [PATCH net v6 1/4] net: phy: move irq_suspended and irq_rerun out of the bitfield Igor Velkov via B4 Relay
2026-11-13 21:06 ` [PATCH net v6 2/4] net: phy: keep the line of a postponed PHY interrupt balanced Igor Velkov via B4 Relay
2026-11-17 12:08 ` netdev-bot+sashiko
2026-11-13 21:06 ` [PATCH net v6 3/4] net: phy: stop postponing PHY interrupts when phy_suspend() fails Igor Velkov via B4 Relay
2026-11-13 21:06 ` [PATCH net v6 4/4] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
2026-11-17 12:08 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox