[PATCH net-next v3 0/4] net: mdio: support dynamic OF device changes
From: James Hilliard
Date: Wed Aug 05 2026 - 13:49:31 EST
MDIO buses enumerate firmware children only when the bus is registered. A
later devicetree overlay or status transition is ignored, unlike on I2C and
SPI buses. Supporting live reconfiguration also means that population and
removal can race address scanning, PHY attachment and bus teardown.
This is generic OF_DYNAMIC support for MDIO buses. It contains no
Allwinner H616 or X-Powers AC200/AC300-specific behavior and does not
depend on either platform; H616 hardware was used only as the runtime
test platform.
Patch 1 fixes an existing lifetime bug exposed while auditing those races:
PHY attach and detach paths cache the MDIO bus but read its owner after
dropping their PHY device reference. Cache the owner before that lifetime
boundary.
Patch 2 factors fixed-address child registration and legacy PHY scanning
into helpers shared by initial and dynamic population.
Patch 3 serializes MDIO device-map changes, reserves addresses while
registration is in progress, publishes devices only after registration
completes, routes lockless map readers through the ordered accessor, and
coordinates scans, attachment, removal and bus teardown. Firmware removal
is exclusive with registration, scanning and other firmware changes.
Dynamically removed PHY devices remain pinned until bus teardown,
preserving the borrowed-pointer convention of mdiobus_get_phy(); generic
MDIO devices can be released normally because their lookup API takes a
reference.
Patch 4 adds the OF reconfiguration notifier. It supports fixed-address
PHYs and generic MDIO devices, scanned PHY addresses, and Ethernet PHY
packages. It preflights overlay removal before firmware nodes disappear
and refuses removal of attached or in-flight PHYs, including while another
MDIO map operation is still completing.
Build-tested on net-next under W=1 with arm64 defconfig, x86_64
allmodconfig under GCC and Clang, and minimal arm64 configurations covering
CONFIG_OF_DYNAMIC=n and CONFIG_OF_DYNAMIC=y with CONFIG_OF_OVERLAY=n. No
warning was emitted from a changed file. Runtime-tested on Allwinner H616
hardware from SD with 100 notifier-driven add/remove cycles for a
fixed-address generic MDIO device; rejection of an out-of-range fixed
address without device creation; 20 complete MAC/MDIO teardown and
recreation cycles with link recovery; another 50 notifier-driven cycles
after bus recreation; successful removal of an unrelated non-MDIO overlay;
and successful link traffic after testing.
Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
---
Changes in v3:
- add a preparatory fix for MDIO bus-owner lifetime handling
- make teardown take a device reference and honor removal ownership
- use one checked callback for normal and dynamic internal removal
- publish map entries only after device registration completes
- route the remaining direct map reader through mdiobus_get_phy()
- retire only PHY devices which have a borrowed-pointer lookup API
- make firmware removal exclusive with registration, scanning and other
firmware changes
- preserve existing error handling while propagating package population
conflicts
- allow global overlay removal to ignore unrelated nodes and absent MDIO
buses
- annotate the recursive notifier lock owner accesses for KCSAN
- avoid an OF/MDIO lock inversion during overlay preflight
- refuse overlay removal while another MDIO map change is active
- propagate removal-transaction conflicts from the OF notifier
- do not treat malformed fixed addresses as addressless PHYs
- rebase onto current net-next
- Link to v2: https://patch.msgid.link/20260803-submit-mdio-of-dynamic-v2-v2-0-f8841f3124d7@xxxxxxxxx
Changes in v2:
- split the generic MDIO work from the ACx00 series
- rebase onto current net-next
- move touched declarations to function scope for netdev style
- Link to v1: https://patch.msgid.link/20260802-submit-acx00-of-dynamic-v1-v1-0-0a53cd9e21cc@xxxxxxxxx
To: Andrew Lunn <andrew@xxxxxxx>
To: Heiner Kallweit <hkallweit1@xxxxxxxxx>
To: Russell King <linux@xxxxxxxxxxxxxxx>
To: "David S. Miller" <davem@xxxxxxxxxxxxx>
To: Eric Dumazet <edumazet@xxxxxxxxxx>
To: Jakub Kicinski <kuba@xxxxxxxxxx>
To: Paolo Abeni <pabeni@xxxxxxxxxx>
To: Florian Fainelli <f.fainelli@xxxxxxxxx>
To: Richard Cochran <richardcochran@xxxxxxxxx>
To: Rob Herring <robh@xxxxxxxxxx>
To: Saravana Kannan <saravanak@xxxxxxxxxx>
Cc: netdev@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: devicetree@xxxxxxxxxxxxxxx
---
James Hilliard (4):
net: phy: cache MDIO bus owner before dropping PHY reference
net: mdio: factor out OF child registration helpers
net: mdio: make device map changes hotplug-safe
net: mdio: support dynamic OF device changes
drivers/net/mdio/of_mdio.c | 514 +++++++++++++++++++++++++++++++++---
drivers/net/phy/mdio_bus.c | 14 +-
drivers/net/phy/mdio_bus_provider.c | 147 ++++++++---
drivers/net/phy/mdio_device.c | 236 +++++++++++++++--
drivers/net/phy/mscc/mscc_ptp.c | 6 +-
drivers/net/phy/phy_device.c | 118 ++++++---
drivers/net/phy/phylib-internal.h | 4 +-
include/linux/mdio.h | 4 +-
include/linux/phy.h | 20 ++
9 files changed, 923 insertions(+), 140 deletions(-)
---
base-commit: a23b36233d4103def55dc8cf65698106d0bd1e62
change-id: 20260803-submit-mdio-of-dynamic-v2-90560ca159b9
Best regards,
--
James Hilliard <james.hilliard1@xxxxxxxxx>