* [PATCH net 0/4] net: phy: restore driver state after userspace MII resets
@ 2026-11-13 8:48 James Hilliard
2026-11-13 8:48 ` [PATCH net 1/4] net: b44: keep phylib ioctls outside the spinlock James Hilliard
` (5 more replies)
0 siblings, 6 replies; 13+ messages in thread
From: James Hilliard @ 2026-11-13 8:48 UTC (permalink / raw)
To: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Michael Chan, Hauke Mehrtens,
Andrew Lunn
Cc: netdev, linux-kernel, James Hilliard
An MII ioctl reset needs to restore the PHY driver's configuration and
software state before the PHY worker can access the device again.
This was observed while testing AC200 receive statistics: a userspace
BMCR reset cleared the hardware counters, and the next update interpreted
the decrease as counter wraparound.
First remove b44's spinlock around the sleeping phylib ioctl. Make phylib
propagate failed writes, wait for reset completion and keep the PHY worker
disabled until driver reinitialization finishes. Then use this path for
phylink BMCR reset requests targeting the attached Clause 22 PHY.
Assisted-by: Codex:gpt-6-astra
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
James Hilliard (4):
net: b44: keep phylib ioctls outside the spinlock
net: phy: propagate MII register write errors
net: phy: quiesce the state machine during MII resets
net: phylink: reinitialize the PHY after an MII reset
drivers/net/ethernet/broadcom/b44.c | 4 ++--
drivers/net/phy/phy.c | 42 +++++++++++++++++++++++++++++++------
drivers/net/phy/phy_device.c | 2 +-
drivers/net/phy/phylib-internal.h | 1 +
drivers/net/phy/phylink.c | 14 +++++++++----
5 files changed, 50 insertions(+), 13 deletions(-)
---
base-commit: ead6fa9a0ab194f02a2f36d634b193e9c5f9a1c6
change-id: 20261113-submit-phy-mii-reset-v1-1b9ec0e2be11
Best regards,
--
James Hilliard <james.hilliard1@gmail.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH net 1/4] net: b44: keep phylib ioctls outside the spinlock
2026-11-13 8:48 [PATCH net 0/4] net: phy: restore driver state after userspace MII resets James Hilliard
@ 2026-11-13 8:48 ` James Hilliard
2026-11-17 9:15 ` netdev-bot+sashiko
2026-11-13 8:48 ` [PATCH net 2/4] net: phy: propagate MII register write errors James Hilliard
` (4 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: James Hilliard @ 2026-11-13 8:48 UTC (permalink / raw)
To: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Michael Chan, Hauke Mehrtens,
Andrew Lunn
Cc: netdev, linux-kernel, James Hilliard
b44_ioctl() holds bp->lock with interrupts disabled while calling
phy_mii_ioctl() for an external PHY. That helper takes sleeping MDIO
mutexes and can wait for a PHY reset to complete.
Keep the spinlock around the legacy internal-PHY ioctl only. External
PHY register accesses are serialized by the MDIO bus mutex, as they
already are when called from the PHY state machine.
Fixes: 86f4ea63e696 ("b44: add phylib support")
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
drivers/net/ethernet/broadcom/b44.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/b44.c b/drivers/net/ethernet/broadcom/b44.c
index f994636fbd5f..e9f116dfaad9 100644
--- a/drivers/net/ethernet/broadcom/b44.c
+++ b/drivers/net/ethernet/broadcom/b44.c
@@ -2126,14 +2126,14 @@ static int b44_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
if (!netif_running(dev))
goto out;
- spin_lock_irq(&bp->lock);
if (bp->flags & B44_FLAG_EXTERNAL_PHY) {
BUG_ON(!dev->phydev);
err = phy_mii_ioctl(dev->phydev, ifr, cmd);
} else {
+ spin_lock_irq(&bp->lock);
err = generic_mii_ioctl(&bp->mii_if, if_mii(ifr), cmd, NULL);
+ spin_unlock_irq(&bp->lock);
}
- spin_unlock_irq(&bp->lock);
out:
return err;
}
--
2.53.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH net 2/4] net: phy: propagate MII register write errors
2026-11-13 8:48 [PATCH net 0/4] net: phy: restore driver state after userspace MII resets James Hilliard
2026-11-13 8:48 ` [PATCH net 1/4] net: b44: keep phylib ioctls outside the spinlock James Hilliard
@ 2026-11-13 8:48 ` James Hilliard
2026-11-13 8:48 ` [PATCH net 3/4] net: phy: quiesce the state machine during MII resets James Hilliard
` (3 subsequent siblings)
5 siblings, 0 replies; 13+ messages in thread
From: James Hilliard @ 2026-11-13 8:48 UTC (permalink / raw)
To: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Michael Chan, Hauke Mehrtens,
Andrew Lunn
Cc: netdev, linux-kernel, James Hilliard
phy_mii_ioctl() ignores MDIO write failures and can report success after a
failed write. It also updates the cached link settings and may restart
auto-negotiation or reinitialize the PHY even though the requested write
failed.
Check the write result before updating the cached settings or invoking
those follow-up operations, and return the MDIO error to the caller.
Fixes: 00db8189d984 ("This patch adds a PHY Abstraction Layer to the Linux Kernel, enabling ethernet drivers to remain as ignorant as is reasonable of the connected PHY's design and operation details.")
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
drivers/net/phy/phy.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index fce9bc7be330..4ac72a1b4f42 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -350,6 +350,15 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
prtad = mii_data->phy_id;
devad = mii_data->reg_num;
}
+
+ if (mdio_phy_id_is_c45(mii_data->phy_id))
+ ret = mdiobus_c45_write(phydev->mdio.bus, prtad, devad,
+ mii_data->reg_num, val);
+ else
+ ret = mdiobus_write(phydev->mdio.bus, prtad, devad, val);
+ if (ret < 0)
+ return ret;
+
if (prtad == phydev->mdio.addr) {
switch (devad) {
case MII_BMCR:
@@ -388,12 +397,6 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
}
}
- if (mdio_phy_id_is_c45(mii_data->phy_id))
- mdiobus_c45_write(phydev->mdio.bus, prtad, devad,
- mii_data->reg_num, val);
- else
- mdiobus_write(phydev->mdio.bus, prtad, devad, val);
-
if (prtad == phydev->mdio.addr &&
devad == MII_BMCR &&
val & BMCR_RESET)
--
2.53.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH net 3/4] net: phy: quiesce the state machine during MII resets
2026-11-13 8:48 [PATCH net 0/4] net: phy: restore driver state after userspace MII resets James Hilliard
2026-11-13 8:48 ` [PATCH net 1/4] net: b44: keep phylib ioctls outside the spinlock James Hilliard
2026-11-13 8:48 ` [PATCH net 2/4] net: phy: propagate MII register write errors James Hilliard
@ 2026-11-13 8:48 ` James Hilliard
2026-11-17 9:15 ` netdev-bot+sashiko
2026-11-13 8:48 ` [PATCH net 4/4] net: phylink: reinitialize the PHY after an MII reset James Hilliard
` (2 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: James Hilliard @ 2026-11-13 8:48 UTC (permalink / raw)
To: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Michael Chan, Hauke Mehrtens,
Andrew Lunn
Cc: netdev, linux-kernel, James Hilliard
phy_mii_ioctl() performs a BMCR reset write and calls phy_init_hw() while
the PHY state machine remains active. The worker can access the PHY after
reset but before the driver has restored its configuration and software
state. A statistics update in this window can interpret cleared hardware
counters as a wraparound.
Disable and drain the state-machine work before resetting the attached
Clause 22 PHY. Reenable it and trigger a new check afterward, including on
failure. Disabling the work also prevents interrupt notifications from
queuing it during reinitialization.
Wait for BMCR_RESET to clear before calling phy_init_hw(). Drivers without
a soft_reset callback otherwise begin initialization while the requested
reset may still be in progress. Share phy_poll_reset() internally for this
wait and propagate its read errors or timeout before initializing the PHY.
Do not hold the PHY mutex across phy_init_hw(): some driver initialization
callbacks acquire that mutex themselves.
Fixes: 00db8189d984 ("This patch adds a PHY Abstraction Layer to the Linux Kernel, enabling ethernet drivers to remain as ignorant as is reasonable of the connected PHY's design and operation details.")
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
drivers/net/phy/phy.c | 27 +++++++++++++++++++++++++++
drivers/net/phy/phy_device.c | 2 +-
drivers/net/phy/phylib-internal.h | 1 +
3 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 4ac72a1b4f42..5da8a699446c 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -297,6 +297,30 @@ void phy_ethtool_ksettings_get(struct phy_device *phydev,
}
EXPORT_SYMBOL(phy_ethtool_ksettings_get);
+static int phy_mii_ioctl_reset(struct phy_device *phydev, u16 val)
+{
+ int ret;
+
+ /* Keep the worker out until the driver has restored its state. */
+ disable_delayed_work_sync(&phydev->state_queue);
+
+ ret = phy_write(phydev, MII_BMCR, val);
+ if (ret < 0)
+ goto out;
+
+ ret = phy_poll_reset(phydev);
+ if (ret)
+ goto out;
+
+ phydev->autoneg = AUTONEG_ENABLE;
+ ret = phy_init_hw(phydev);
+out:
+ if (enable_delayed_work(&phydev->state_queue))
+ phy_trigger_machine(phydev);
+
+ return ret;
+}
+
/**
* phy_mii_ioctl - generic PHY MII ioctl interface
* @phydev: the phy_device struct
@@ -349,6 +373,9 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
} else {
prtad = mii_data->phy_id;
devad = mii_data->reg_num;
+ if (prtad == phydev->mdio.addr &&
+ devad == MII_BMCR && val & BMCR_RESET)
+ return phy_mii_ioctl_reset(phydev, val);
}
if (mdio_phy_id_is_c45(mii_data->phy_id))
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index b39e945cebd7..8b0c1f28963b 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1232,7 +1232,7 @@ EXPORT_SYMBOL(phy_disconnect);
* standard phy_init_hw() which will zero all the other bits in the BMCR
* and reapply all driver-specific and board-specific fixups.
*/
-static int phy_poll_reset(struct phy_device *phydev)
+int phy_poll_reset(struct phy_device *phydev)
{
/* Poll until the reset bit clears (50ms per retry == 0.6 sec) */
int ret, val;
diff --git a/drivers/net/phy/phylib-internal.h b/drivers/net/phy/phylib-internal.h
index 38ee294f3c96..680823633d98 100644
--- a/drivers/net/phy/phylib-internal.h
+++ b/drivers/net/phy/phylib-internal.h
@@ -24,6 +24,7 @@ void of_set_phy_timing_role(struct phy_device *phydev);
int phy_speed_down_core(struct phy_device *phydev);
void phy_check_downshift(struct phy_device *phydev);
int phy_scan_fixups(struct phy_device *phydev);
+int phy_poll_reset(struct phy_device *phydev);
int mdiobus_register_device(struct mdio_device *mdiodev);
int mdiobus_unregister_device(struct mdio_device *mdiodev);
--
2.53.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH net 4/4] net: phylink: reinitialize the PHY after an MII reset
2026-11-13 8:48 [PATCH net 0/4] net: phy: restore driver state after userspace MII resets James Hilliard
` (2 preceding siblings ...)
2026-11-13 8:48 ` [PATCH net 3/4] net: phy: quiesce the state machine during MII resets James Hilliard
@ 2026-11-13 8:48 ` James Hilliard
2026-11-17 9:15 ` netdev-bot+sashiko
2026-11-13 8:53 ` [PATCH net 0/4] net: phy: restore driver state after userspace MII resets netdev-bot+sinfo
2026-11-13 13:33 ` Andrew Lunn
5 siblings, 1 reply; 13+ messages in thread
From: James Hilliard @ 2026-11-13 8:48 UTC (permalink / raw)
To: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Michael Chan, Hauke Mehrtens,
Andrew Lunn
Cc: netdev, linux-kernel, James Hilliard
phylink handles SIOCSMIIREG with a raw MDIO write, bypassing the reset
handling in phy_mii_ioctl(). A BMCR reset of the attached Clause 22 PHY
therefore clears hardware state without running the driver initialization
callbacks. The PHY worker continues using the old software state.
Delegate BMCR reset writes for the attached Clause 22 PHY to
phy_mii_ioctl(), which quiesces the PHY worker across reset completion and
driver initialization. Select this path in the register-write helper after
the Clause 45 cases, retaining raw access for the other register writes.
Fixes: 9525ae83959b ("phylink: add phylink infrastructure")
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
drivers/net/phy/phylink.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index e885da1c2831..2f0e3a30615c 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -3570,10 +3570,13 @@ static int phylink_phy_read(struct phylink *pl, unsigned int phy_id,
return mdiobus_read(pl->phydev->mdio.bus, phy_id, reg);
}
-static int phylink_phy_write(struct phylink *pl, unsigned int phy_id,
- unsigned int reg, unsigned int val)
+static int phylink_phy_write(struct phylink *pl, struct ifreq *ifr)
{
+ struct mii_ioctl_data *mii = if_mii(ifr);
struct phy_device *phydev = pl->phydev;
+ u16 phy_id = mii->phy_id;
+ u16 reg = mii->reg_num;
+ u16 val = mii->val_in;
int prtad, devad;
if (mdio_phy_id_is_c45(phy_id)) {
@@ -3608,6 +3611,10 @@ static int phylink_phy_write(struct phylink *pl, unsigned int phy_id,
reg, val);
}
+ if (phy_id == phydev->mdio.addr && reg == MII_BMCR &&
+ (val & BMCR_RESET))
+ return phy_mii_ioctl(phydev, ifr, SIOCSMIIREG);
+
return mdiobus_write(phydev->mdio.bus, phy_id, reg, val);
}
@@ -3697,8 +3704,7 @@ int phylink_mii_ioctl(struct phylink *pl, struct ifreq *ifr, int cmd)
break;
case SIOCSMIIREG:
- ret = phylink_phy_write(pl, mii->phy_id, mii->reg_num,
- mii->val_in);
+ ret = phylink_phy_write(pl, ifr);
break;
default:
--
2.53.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net 0/4] net: phy: restore driver state after userspace MII resets
2026-11-13 8:48 [PATCH net 0/4] net: phy: restore driver state after userspace MII resets James Hilliard
` (3 preceding siblings ...)
2026-11-13 8:48 ` [PATCH net 4/4] net: phylink: reinitialize the PHY after an MII reset James Hilliard
@ 2026-11-13 8:53 ` netdev-bot+sinfo
2026-11-13 9:28 ` James Hilliard
2026-11-13 13:33 ` Andrew Lunn
5 siblings, 1 reply; 13+ messages in thread
From: netdev-bot+sinfo @ 2026-11-13 8:53 UTC (permalink / raw)
To: James Hilliard
Cc: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Michael Chan, Hauke Mehrtens,
Andrew Lunn, netdev, linux-kernel
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- What hardware the change was tested on. For driver fixes please
mention the device (and if relevant firmware version) used for
testing, or say that the change was not tested on real hardware.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account. If the series needs another revision for
other reasons, please include the information in the commit messages
then.
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net 0/4] net: phy: restore driver state after userspace MII resets
2026-11-13 8:53 ` [PATCH net 0/4] net: phy: restore driver state after userspace MII resets netdev-bot+sinfo
@ 2026-11-13 9:28 ` James Hilliard
0 siblings, 0 replies; 13+ messages in thread
From: James Hilliard @ 2026-11-13 9:28 UTC (permalink / raw)
To: netdev-bot+sinfo
Cc: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Michael Chan, Hauke Mehrtens,
Andrew Lunn, netdev, linux-kernel
On Fri, Nov 13, 2026 at 1:53 AM <netdev-bot+sinfo@kernel.org> wrote:
>
> Hi!
>
> This is an automated message. This series looks like a fix, but its
> commit messages seem to be missing some information:
>
> - What hardware the change was tested on. For driver fixes please
> mention the device (and if relevant firmware version) used for
> testing, or say that the change was not tested on real hardware.
This was observed while testing AC200 receive statistics.
>
> Please do not repost the series just to address the above. Instead,
> reply to this email with the missing information, so that reviewers
> can take it into account. If the series needs another revision for
> other reasons, please include the information in the commit messages
> then.
>
> The evaluation is done by an LLM so it may be wrong, if you think
> that is the case please reply and explain.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net 0/4] net: phy: restore driver state after userspace MII resets
2026-11-13 8:48 [PATCH net 0/4] net: phy: restore driver state after userspace MII resets James Hilliard
` (4 preceding siblings ...)
2026-11-13 8:53 ` [PATCH net 0/4] net: phy: restore driver state after userspace MII resets netdev-bot+sinfo
@ 2026-11-13 13:33 ` Andrew Lunn
2026-11-13 16:39 ` James Hilliard
5 siblings, 1 reply; 13+ messages in thread
From: Andrew Lunn @ 2026-11-13 13:33 UTC (permalink / raw)
To: James Hilliard
Cc: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Michael Chan, Hauke Mehrtens,
netdev, linux-kernel
On Fri, Nov 13, 2026 at 01:48:39AM -0700, James Hilliard wrote:
> An MII ioctl reset needs to restore the PHY driver's configuration and
> software state before the PHY worker can access the device again.
The MII ioctl is a footgun. If you use it for writing registers, don't
be surprised if bad things happen. Even reading registers can cause
bad side effects, like missed interrupts.
The whole design is broken, there is no fixing it, so we don't try to
fix it.
Sorry, but NACK.
Andrew
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net 0/4] net: phy: restore driver state after userspace MII resets
2026-11-13 13:33 ` Andrew Lunn
@ 2026-11-13 16:39 ` James Hilliard
2026-11-13 17:50 ` Andrew Lunn
0 siblings, 1 reply; 13+ messages in thread
From: James Hilliard @ 2026-11-13 16:39 UTC (permalink / raw)
To: Andrew Lunn
Cc: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Michael Chan, Hauke Mehrtens,
netdev, linux-kernel
On Fri, Nov 13, 2026 at 6:33 AM Andrew Lunn <andrew@lunn.ch> wrote:
>
> On Fri, Nov 13, 2026 at 01:48:39AM -0700, James Hilliard wrote:
> > An MII ioctl reset needs to restore the PHY driver's configuration and
> > software state before the PHY worker can access the device again.
>
> The MII ioctl is a footgun. If you use it for writing registers, don't
> be surprised if bad things happen. Even reading registers can cause
> bad side effects, like missed interrupts.
>
> The whole design is broken, there is no fixing it, so we don't try to
> fix it.
Would it make sense to submit patches 1 and 2 as standalone fixes,
separate from the reset recovery changes?
The b44 patch removes a spinlock held across sleeping phylib/MDIO
operations, including ordinary register reads. The write-error patch
propagates MDIO failures and avoids updating cached settings or running
follow-up operations after a failed write.
These fixes are independent of each other and neither adds reset
recovery or attempts to make arbitrary register access safe.
>
> Sorry, but NACK.
>
> Andrew
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net 0/4] net: phy: restore driver state after userspace MII resets
2026-11-13 16:39 ` James Hilliard
@ 2026-11-13 17:50 ` Andrew Lunn
0 siblings, 0 replies; 13+ messages in thread
From: Andrew Lunn @ 2026-11-13 17:50 UTC (permalink / raw)
To: James Hilliard
Cc: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Michael Chan, Hauke Mehrtens,
netdev, linux-kernel
On Fri, Nov 13, 2026 at 09:39:17AM -0700, James Hilliard wrote:
> On Fri, Nov 13, 2026 at 6:33 AM Andrew Lunn <andrew@lunn.ch> wrote:
> >
> > On Fri, Nov 13, 2026 at 01:48:39AM -0700, James Hilliard wrote:
> > > An MII ioctl reset needs to restore the PHY driver's configuration and
> > > software state before the PHY worker can access the device again.
> >
> > The MII ioctl is a footgun. If you use it for writing registers, don't
> > be surprised if bad things happen. Even reading registers can cause
> > bad side effects, like missed interrupts.
> >
> > The whole design is broken, there is no fixing it, so we don't try to
> > fix it.
>
> Would it make sense to submit patches 1 and 2 as standalone fixes,
> separate from the reset recovery changes?
Ask the b44 Maintainers. It is unusual for MDIO to be none blocking,
so i do wounder about the other path.
> The b44 patch removes a spinlock held across sleeping phylib/MDIO
> operations, including ordinary register reads. The write-error patch
> propagates MDIO failures and avoids updating cached settings or running
> follow-up operations after a failed write.
We don't care about the cached settings. If you have used this API,
you must expect bad things to happen. It says so in the comment above.
Andrew
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net 1/4] net: b44: keep phylib ioctls outside the spinlock
2026-11-13 8:48 ` [PATCH net 1/4] net: b44: keep phylib ioctls outside the spinlock James Hilliard
@ 2026-11-17 9:15 ` netdev-bot+sashiko
0 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 9:15 UTC (permalink / raw)
To: james.hilliard1
Cc: hkallweit1, linux, davem, edumazet, kuba, pabeni, michael.chan,
hauke, andrew, netdev, 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] The fix is incomplete: b44 still makes sleeping phylib calls
while holding a spinlock with IRQs off.
- [Medium] The commit message says 'External PHY register accesses are
serialized by the MDIO bus mutex'.
--
net: b44: keep phylib ioctls outside the spinlock
With this patch, b44_ioctl() holds bp->lock only around
generic_mii_ioctl() for the internal PHY. The external PHY path now
calls phy_mii_ioctl() without the spinlock and relies on the MDIO bus
mutex for serialization.
> diff --git a/drivers/net/ethernet/broadcom/b44.c b/drivers/net/ethernet/broadcom/b44.c
> index f994636fbd5f1..e9f116dfaad99 100644
> --- a/drivers/net/ethernet/broadcom/b44.c
> +++ b/drivers/net/ethernet/broadcom/b44.c
> @@ -2126,14 +2126,14 @@ static int b44_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
> if (!netif_running(dev))
> goto out;
>
> - spin_lock_irq(&bp->lock);
[Severity: Medium]
The commit message says:
External PHY register accesses are serialized by the MDIO bus mutex, as
they already are when called from the PHY state machine.
Does that hold for b44? b44_mdio_read_phylib() and
b44_mdio_write_phylib() call __b44_readphy() and __b44_writephy(). Each
of those runs a multi-step sequence on Ethernet core registers:
drivers/net/ethernet/broadcom/b44.c:__b44_readphy() {
bw32(bp, B44_EMAC_ISTAT, EMAC_INT_MII);
bw32(bp, B44_MDIO_DATA, (MDIO_DATA_SB_START |
...
err = b44_wait_bit(bp, B44_EMAC_ISTAT, EMAC_INT_MII, 100, 0);
*val = br32(bp, B44_MDIO_DATA) & MDIO_DATA_DATA;
...
}
Two other paths touch the same hardware while holding only bp->lock,
without the mdio_lock:
b44_chip_reset() calls ssb_device_enable() and
ssb_pcicore_dev_irqvecs_enable(). On older SSB-PCI cores the second call
can switch the BAR0 window to the PCI core. b44_chip_reset() then
rewrites B44_MDIO_CTRL.
b44_setup_phy() calls b44_wap54g10_workaround() before the
B44_FLAG_EXTERNAL_PHY early return. That function does raw
__b44_readphy() and __b44_writephy() calls on PHY 0 and bypasses the
mii_bus.
Both paths can run without rtnl, from b44_tx_timeout() and from the RFO
and ISTAT_ERRORS recovery paths in b44_poll():
b44_tx_timeout()
spin_lock_irq(&bp->lock);
b44_halt(bp);
b44_init_rings(bp);
b44_init_hw(bp, B44_FULL_RESET);
Before this patch, the spin_lock_irq() in b44_ioctl() stopped a
SIOCGMIIREG or SIOCSMIIREG transaction from overlapping these paths.
Now the transaction runs under only rtnl and mdio_lock.
Can a TX timeout or NAPI error recovery interleave with the ioctl's MDIO
sequence? If so, the read could return a wrong value, b44_wait_bit()
could time out, or a SIOCSMIIREG write could be lost while
phy_mii_ioctl() still updates phydev->autoneg and advertising.
Also, ssb_pci_read32() checks bus->mapped_device and then calls
ioread32() with no lock in between. Could a concurrent window switch
send the MDIO register access to the PCI core's registers?
The PHY state machine already has this gap. This patch adds a path that
userspace can trigger. Would it make sense to serialize inside the b44
MDIO accessors instead, for example with a short
spin_lock_irqsave(&bp->lock) around the udelay-only sequence? That would
also mean dropping bp->lock in b44_set_link_ksettings().
> if (bp->flags & B44_FLAG_EXTERNAL_PHY) {
> BUG_ON(!dev->phydev);
> err = phy_mii_ioctl(dev->phydev, ifr, cmd);
[Severity: High]
Is this fix complete? On the external PHY path, b44_set_link_ksettings()
still calls into phylib with bp->lock held and interrupts disabled:
drivers/net/ethernet/broadcom/b44.c:b44_set_link_ksettings() {
...
if (bp->flags & B44_FLAG_EXTERNAL_PHY) {
BUG_ON(!dev->phydev);
spin_lock_irq(&bp->lock);
if (netif_running(dev))
b44_setup_phy(bp);
ret = phy_ethtool_ksettings_set(dev->phydev, cmd);
spin_unlock_irq(&bp->lock);
return ret;
}
...
}
Once its argument checks pass, phy_ethtool_ksettings_set() calls
mutex_lock(&phydev->lock). It then calls phy_trigger_machine() or
_phy_start_aneg(), and the aneg path does MDIO I/O under the bus
mdio_lock.
An ordinary "ethtool -s <dev> speed 100 duplex full autoneg off" on a
b44 with B44_FLAG_EXTERNAL_PHY gets here. ethtool does a get before the
set, and b44_get_link_ksettings() fills phy_address from
phy_ethtool_ksettings_get(), so the phy_address check passes.
Doesn't this hit the same sleeping-in-atomic problem that the commit
message describes for phy_mii_ioctl()?
If phydev->lock is contended, for example by phy_state_machine(), the
task would schedule with bp->lock held and interrupts off. Then
b44_interrupt() or b44_timer() on that CPU could spin on bp->lock
forever.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-submit-phy-mii-reset-v1-v1-0-02a55f352a91%40gmail.com
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net 3/4] net: phy: quiesce the state machine during MII resets
2026-11-13 8:48 ` [PATCH net 3/4] net: phy: quiesce the state machine during MII resets James Hilliard
@ 2026-11-17 9:15 ` netdev-bot+sashiko
0 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 9:15 UTC (permalink / raw)
To: james.hilliard1
Cc: hkallweit1, linux, davem, edumazet, kuba, pabeni, michael.chan,
hauke, andrew, netdev, linux-kernel
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
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] The patch does not fully close the bug it describes.
- [Low] The commit message's only concrete symptom, "A statistics update
in this window can interpret cleared hardware counters as a…
- [Low] The patch carries `Fixes: 00db8189d984` (the original 2005 phylib
commit), so stable will select it for every maintained LTS branch.
--
net: phy: quiesce the state machine during MII resets
This commit sends Clause 22 BMCR_RESET writes from SIOCSMIIREG through a
new helper, phy_mii_ioctl_reset(). The helper disables and drains the PHY
state machine work and waits for BMCR_RESET to clear via phy_poll_reset().
It then calls phy_init_hw() and re-enables and triggers the state machine.
> phy_mii_ioctl() performs a BMCR reset write and calls phy_init_hw() while
> the PHY state machine remains active. The worker can access the PHY after
> reset but before the driver has restored its configuration and software
> state. A statistics update in this window can interpret cleared hardware
> counters as a wraparound.
[Severity: Low]
Which driver does the wraparound case refer to?
The worker only reaches driver statistics code through phy_update_stats()
in _phy_state_machine():
drivers/net/phy/phy.c:_phy_state_machine() {
...
case PHY_NOLINK:
case PHY_RUNNING:
err = phy_check_link_status(phydev);
func = &phy_check_link_status;
if (!err)
err = phy_update_stats(phydev);
break;
...
}
The in-tree .update_stats callbacks either add read-clear counters to a
software total or assign absolute values:
qcom_phy_update_stats(): hw_stats->rx_pkts += cnt;
dp83tg720_update_stats(): priv->stats.tx_pkt_cnt += count;
dp83td510_update_stats(), gpy_update_stats(),
xway_gphy_update_stats(), kszphy_update_stats(): accumulate with +=
lan8842_update_stats(): assigns absolute values
None of them keeps a previous snapshot or computes a delta. It doesn't look
like any of them can mistake a reset for a wrap.
The in-tree effects of the worker running mid-reset look different. One is
a spurious link down/up from reading BMSR during the reset. Another is
possible double counting if the reset clears a read-clear enable that
config_init() restores, for example qcom_phy_counter_config().
The ethtool statistics read path (ETHTOOL_GPHYSTATS) doesn't seem to be a
gap. It and SIOCSMIIREG are both serialized by RTNL or the netdev ops lock.
Could the commit message describe the actual in-tree failure, or name the
driver it refers to? The Fixes: tag will send this to all stable branches.
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index 4ac72a1b4f427..5da8a699446c0 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -297,6 +297,30 @@ void phy_ethtool_ksettings_get(struct phy_device *phydev,
> }
> EXPORT_SYMBOL(phy_ethtool_ksettings_get);
>
> +static int phy_mii_ioctl_reset(struct phy_device *phydev, u16 val)
> +{
> + int ret;
> +
> + /* Keep the worker out until the driver has restored its state. */
> + disable_delayed_work_sync(&phydev->state_queue);
[Severity: Low]
Will this build on the stable trees that the Fixes: tag selects?
The patch carries Fixes: 00db8189d984, the original 2005 phylib commit. That
means it will be picked for every maintained stable branch.
disable_delayed_work_sync() and enable_delayed_work() were added in v6.10
by commit 86898fa6b8cd ("workqueue: Implement disable/enable for (delayed)
work items"). They don't exist in 6.6, 6.1, 5.15 or older trees.
Should there be a stable version limit such as "Cc: stable # 6.10+", a
note about the dependency, or a different quiescing approach for older
trees?
> +
> + ret = phy_write(phydev, MII_BMCR, val);
> + if (ret < 0)
> + goto out;
> +
> + ret = phy_poll_reset(phydev);
> + if (ret)
> + goto out;
> +
> + phydev->autoneg = AUTONEG_ENABLE;
> + ret = phy_init_hw(phydev);
> +out:
> + if (enable_delayed_work(&phydev->state_queue))
> + phy_trigger_machine(phydev);
> +
> + return ret;
> +}
> +
> /**
> * phy_mii_ioctl - generic PHY MII ioctl interface
> * @phydev: the phy_device struct
> @@ -349,6 +373,9 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
> } else {
> prtad = mii_data->phy_id;
> devad = mii_data->reg_num;
> + if (prtad == phydev->mdio.addr &&
> + devad == MII_BMCR && val & BMCR_RESET)
> + return phy_mii_ioctl_reset(phydev, val);
> }
>
> if (mdio_phy_id_is_c45(mii_data->phy_id))
[Severity: Medium]
Can the old reset path at the end of the SIOCSMIIREG case still call
phy_init_hw() while the state machine is active?
The new early return only exists in the Clause 22 else branch. The old
check at the end of phy_mii_ioctl() is still there:
if (prtad == phydev->mdio.addr &&
devad == MII_BMCR &&
val & BMCR_RESET)
return phy_init_hw(phydev);
With a Clause 45 form phy_id, prtad and devad come from
mdio_phy_id_prtad() and mdio_phy_id_devad(). This path is taken when all of
the following hold:
- prtad matches the attached PHY's address
- the MMD is 0, which equals MII_BMCR
- val_in has bit 15 set
- the bus accepts the C45 write
phy_mii_ioctl()
mdiobus_c45_write(...)
case MII_BMCR: phydev->autoneg = AUTONEG_ENABLE;
phy_init_hw(phydev)
None of disable_delayed_work_sync(), phy_poll_reset() or
phy_trigger_machine() runs on this path. phy_init_hw() can also do its own
BMCR reset through drv->soft_reset (for example genphy_soft_reset()) while
the worker is running.
For Clause 22 IDs the tail branch is now dead code. That leaves
phy_mii_ioctl() with two reset paths, one quiesced and one not. Could the
leftover branch be removed, or routed through phy_mii_ioctl_reset()?
The later patch in this series, "net: phy: reinitialize the PHY after an
MII reset", doesn't change phy.c. Its phylink_phy_write() returns early for
C45 IDs, so drivers that use phy_do_ioctl() without phylink still reach
this path.
Could the commit message also say that genuine Clause 45 resets
(MDIO_MMD_PMAPMD / MDIO_CTRL1 with MDIO_CTRL1_RESET) are out of scope? This
patch doesn't intercept them either.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-submit-phy-mii-reset-v1-v1-0-02a55f352a91%40gmail.com
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net 4/4] net: phylink: reinitialize the PHY after an MII reset
2026-11-13 8:48 ` [PATCH net 4/4] net: phylink: reinitialize the PHY after an MII reset James Hilliard
@ 2026-11-17 9:15 ` netdev-bot+sashiko
0 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 9:15 UTC (permalink / raw)
To: james.hilliard1
Cc: hkallweit1, linux, davem, edumazet, kuba, pabeni, michael.chan,
hauke, andrew, netdev, linux-kernel
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 2 · 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] phylink_phy_write() (drivers/net/phy/phylink.c:3614-3616) now
sends a BMCR reset of the attached C22 PHY to phy_mii_ioctl() ->…
- [Medium] phylink chooses the PHY's in-band AN mode (pl->phy_ib_mode:
disable/enable/bypass) and programs it only in phylink_major_config()…
- [Medium] Through phylink, the BMCR reset now goes to
phy_mii_ioctl_reset() (drivers/net/phy/phy.c:300-322).
--
net: phylink: reinitialize the PHY after an MII reset
This patch changes phylink_phy_write() to send BMCR reset writes for the
attached Clause 22 PHY to phy_mii_ioctl(). The phylib reset handling then
runs in place of a raw mdiobus_write(). All other register writes still
use raw MDIO access.
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index e885da1c28311..2f0e3a30615c8 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -3608,6 +3611,10 @@ static int phylink_phy_write(struct phylink *pl, unsigned int phy_id,
> reg, val);
> }
>
> + if (phy_id == phydev->mdio.addr && reg == MII_BMCR &&
> + (val & BMCR_RESET))
> + return phy_mii_ioctl(phydev, ifr, SIOCSMIIREG);
[Severity: High]
Does this path ever write the advertisement back to the PHY after the reset?
phy_mii_ioctl() passes this to phy_mii_ioctl_reset(), which does:
drivers/net/phy/phy.c:phy_mii_ioctl_reset() {
...
phydev->autoneg = AUTONEG_ENABLE;
ret = phy_init_hw(phydev);
out:
if (enable_delayed_work(&phydev->state_queue))
phy_trigger_machine(phydev);
...
}
phy_init_hw() runs soft_reset, the fixups, config_init, config_intr and
the autonomous EEE disable. It does not call config_aneg or
phy_start_aneg().
phydev->state also stays PHY_RUNNING or PHY_NOLINK. In those states,
_phy_state_machine() only calls phy_check_link_status().
_phy_start_aneg() only runs from PHY_UP or after a cable test.
So after the reset, MII_ADVERTISE, MII_CTRL1000 and the EEE advertisement
seem to stay at their hardware defaults. phydev->advertising still holds
the MAC-limited mask that phylink_bringup_phy() set up:
linkmode_copy(phy->advertising, config.advertising);
Take a 10/100-only MAC with a gigabit PHY as an example:
- After the reset, the PHY advertises 1000baseT again and can link at
1000.
- genphy_read_status() works out the speed from the stale
phydev->advertising and lp_advertising, and reports 100.
- phylink calls mac_link_up() at 100 while the PHY runs at 1000.
The commit message says:
The PHY worker continues using the old software state.
After this change, isn't that still true for the advertisement registers?
phy_mii_ioctl_reset() was added earlier in this series, and this patch
relies on it to resynchronize the state. Should phy_init_hw() be followed
by phy_start_aneg() (or config_aneg) on this path?
[Severity: Medium]
Is the PHY in-band AN mode that phylink chose lost here?
phylink only programs pl->phy_ib_mode in phylink_major_config():
err = phy_config_inband(pl->phydev, pl->phy_ib_mode);
phy_init_hw() never calls drv->config_inband. After this return, phylink
also does not set force_major_config or requeue pl->resolve.
The config_init callbacks don't seem to reapply the in-band mode either.
For example, m88e1111_config_inband() writes
MII_M1111_HWCFG_SERIAL_AN_BYPASS and the fibre page BMCR_ANENABLE:
err = phy_modify(phydev, MII_M1111_PHY_EXT_SR,
MII_M1111_HWCFG_SERIAL_AN_BYPASS, extsr);
...
return phy_modify_paged(phydev, MII_MARVELL_FIBER_PAGE, MII_BMCR,
BMCR_ANENABLE, bmcr);
m88e1111_config_init() does not touch those bits. In the same way,
rtl822xb_config_init() leaves RTL822X_VND1_SERDES_ADDR_AUTONEG alone.
Whether a soft reset actually clears these SerDes bits depends on the
PHY. If it does, the PHY's in-band mode no longer matches the pcs_neg_mode
that phylink configured. The copper side can then report link up while
the SGMII or 1000BASE-X link to the MAC is down.
The other phylink paths that run phy_init_hw() (attach or resume, then
phylink_start()) all reach phylink_major_config() afterwards. Should the
reset path also ask phylink to redo the major config?
[Severity: Medium]
Can the reset and phy_init_hw() run at the same time as pl->resolve or
the PHY interrupt thread?
phy_mii_ioctl_reset() only quiesces phydev->state_queue:
disable_delayed_work_sync(&phydev->state_queue);
ret = phy_write(phydev, MII_BMCR, val);
After that, the reset, phy_poll_reset() and phy_init_hw() all run under
RTNL without phydev->lock.
phylink_resolve() runs from a workqueue without RTNL. It takes phy->lock.
When the interface changes, it calls
phylink_major_config()->phy_config_inband(), which writes PHY registers:
mutex_lock(&pl->phydev_mutex);
phy = pl->phydev;
if (phy)
mutex_lock(&phy->lock);
...
phylink_major_config(pl, false, &link_state);
The threaded IRQ handler is also serialized only by phydev->lock:
drivers/net/phy/phy.c:phy_interrupt() {
...
mutex_lock(&phydev->lock);
ret = phydev->drv->handle_interrupt(phydev);
mutex_unlock(&phydev->lock);
...
}
Suppose phylink_phy_change() queued a resolve just before the ioctl, for
example after an SGMII to 2500BASE-X switch on an RTL822x. Could the
config_inband writes interleave with the config_init sequence and leave
the PHY partly configured?
Before this patch, phylink's raw reset never ran phy_init_hw(), so
phylink users did not have this overlap. On the resume path,
phylink_stop() and phylink_suspend() disable and flush pl->resolve before
phy_init_hw() runs.
The commit message says phy_mii_ioctl() "quiesces the PHY worker across
reset completion and driver initialization". For phylink devices, isn't
that only true of phydev->state_queue?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-submit-phy-mii-reset-v1-v1-0-02a55f352a91%40gmail.com
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-11-17 9:15 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-13 8:48 [PATCH net 0/4] net: phy: restore driver state after userspace MII resets James Hilliard
2026-11-13 8:48 ` [PATCH net 1/4] net: b44: keep phylib ioctls outside the spinlock James Hilliard
2026-11-17 9:15 ` netdev-bot+sashiko
2026-11-13 8:48 ` [PATCH net 2/4] net: phy: propagate MII register write errors James Hilliard
2026-11-13 8:48 ` [PATCH net 3/4] net: phy: quiesce the state machine during MII resets James Hilliard
2026-11-17 9:15 ` netdev-bot+sashiko
2026-11-13 8:48 ` [PATCH net 4/4] net: phylink: reinitialize the PHY after an MII reset James Hilliard
2026-11-17 9:15 ` netdev-bot+sashiko
2026-11-13 8:53 ` [PATCH net 0/4] net: phy: restore driver state after userspace MII resets netdev-bot+sinfo
2026-11-13 9:28 ` James Hilliard
2026-11-13 13:33 ` Andrew Lunn
2026-11-13 16:39 ` James Hilliard
2026-11-13 17:50 ` Andrew Lunn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®