[PATCH net-next v4 0/4] net: mdio: support dynamic OF device changes
James Hilliard <[email protected]> Thu, 06 Aug 2026 21:54:19 -0600
| Newsgroups | org.kernel.vger.linux-usb,dev.linux.lists.imx,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-kernel,org.kernel.vger.linux-omap,org.kernel.vger.linux-pm,org.kernel.vger.netdev |
|---|---|
| Message-ID | <[email protected]> |
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, and coordinates scans, attachment, removal and bus teardown. Firmware removal is exclusive with registration, scanning and other firmware changes. Map readers use RCU to acquire device references; mdiobus_get_phy() and the PHY iterators now return referenced PHYs, and all in-tree callers release or retain those references explicitly. Removed PHY generations can therefore be reclaimed when their actual users finish, without removing dynamic PHY deletion or accumulating retired objects until bus teardown. Attachment waits for another task's pending publication and defers same-task recursive attachment. 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. Strict checkpatch reports only its expected MAINTAINERS warning for the two required lookup-ownership updates in the obsolete AX88796 driver. Changed objects were build-tested with W=1 using x86_64 allmodconfig under GCC, arm64 defconfig under LLVM, native MIPS and SPARC configurations for architecture-specific callers, and minimal arm64 configurations covering CONFIG_OF_DYNAMIC=n and CONFIG_OF_DYNAMIC=y with CONFIG_OF_OVERLAY=n. No new compiler warning was emitted. Runtime testing used an Allwinner H616 board with AC300, booted from SD. A forced-ID test PHY completed 700 notifier-driven add/remove/re-add cycles. Every cycle raced standalone attachment against the interval between device_add() visibility and MDIO-map publication, held a referenced lookup across removal, verified that no core reference remained, released the last reference and re-added the same address. A generic MDIO device completed 150 add/remove cycles. Removal of the attached AC300 PHY was rejected while its driver, carrier and traffic remained active. Testing also covered rejection of an out-of-range fixed address, removal of an unrelated non-MDIO overlay, 20 complete MAC/MDIO teardown and recreation cycles, another PHY and generic MDIO stress run after bus recreation, and bidirectional link traffic. No refcount, RCU, use-after-free or lock warning occurred. Signed-off-by: James Hilliard <[email protected]> --- Changes in v4: - make PHY map lookups reference-counted and RCU-protected - update every in-tree mdiobus_get_phy() and PHY iterator caller for the referenced lookup contract - reclaim dynamically removed PHY generations after their users release them instead of retaining every generation until bus teardown - wait for concurrent map publication before attaching a PHY and defer same-task recursive attachment - handle a missing VSC8584 base PHY without dereferencing NULL - use RCU-safe map access while checking a dynamic removal scope - Link to v3: https://patch.msgid.link/[email protected] 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/[email protected] 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/[email protected] To: Andrew Lunn <[email protected]> To: Heiner Kallweit <[email protected]> To: Russell King <[email protected]> To: "David S. Miller" <[email protected]> To: Eric Dumazet <[email protected]> To: Jakub Kicinski <[email protected]> To: Paolo Abeni <[email protected]> To: Florian Fainelli <[email protected]> To: Richard Cochran <[email protected]> To: Rob Herring <[email protected]> To: Saravana Kannan <[email protected]> To: Florian Fainelli <[email protected]> To: Jonas Gorski <[email protected]> To: Vladimir Oltean <[email protected]> To: Ciprian Regus <[email protected]> To: Andreas Larsson <[email protected]> To: Mark Einon <[email protected]> To: Iyappan Subramanian <[email protected]> To: Keyur Chudgar <[email protected]> To: Michael Chan <[email protected]> To: Rafał Miłecki <[email protected]> To: Broadcom internal kernel review list <[email protected]> To: Doug Berger <[email protected]> To: Pavan Chebbi <[email protected]> To: Théo Lebrun <[email protected]> To: Conor Dooley <[email protected]> To: Wei Fang <[email protected]> To: Frank Li <[email protected]> To: Shenwei Wang <[email protected]> To: Jijie Shao <[email protected]> To: Jian Shen <[email protected]> To: Bryan Whitehead <[email protected]> To: [email protected] To: Vladimir Zapolskiy <[email protected]> To: Piotr Wojtaszczyk <[email protected]> To: Parthiban Veerasooran <[email protected]> To: Timur Tabi <[email protected]> To: [email protected] To: Byungho An <[email protected]> To: Steve Glendinning <[email protected]> To: Maxime Chevallier <[email protected]> To: Maxime Coquelin <[email protected]> To: Alexandre Torgue <[email protected]> To: FUJITA Tomonori <[email protected]> To: Siddharth Vadapalli <[email protected]> To: Roger Quadros <[email protected]> To: Jiawen Wu <[email protected]> To: Mengyuan Lou <[email protected]> To: Thangaraj Samynathan <[email protected]> To: Sebastian Reichel <[email protected]> To: Simon Horman <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] --- 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/dsa/b53/b53_common.c | 9 +- drivers/net/ethernet/8390/ax88796.c | 2 + drivers/net/ethernet/adi/adin1140.c | 6 +- drivers/net/ethernet/aeroflex/greth.c | 2 + drivers/net/ethernet/agere/et131x.c | 10 +- drivers/net/ethernet/amd/au1000_eth.c | 27 +- drivers/net/ethernet/apm/xgene-v2/mdio.c | 8 +- drivers/net/ethernet/broadcom/b44.c | 6 + drivers/net/ethernet/broadcom/bgmac-bcma.c | 1 + drivers/net/ethernet/broadcom/genet/bcmmii.c | 4 + drivers/net/ethernet/broadcom/sb1250-mac.c | 8 +- drivers/net/ethernet/broadcom/tg3.c | 32 +- drivers/net/ethernet/broadcom/tg3.h | 1 + drivers/net/ethernet/cadence/macb_main.c | 1 + drivers/net/ethernet/engleder/tsnep_main.c | 4 + drivers/net/ethernet/ethoc.c | 14 +- drivers/net/ethernet/faraday/ftgmac100.c | 8 +- drivers/net/ethernet/freescale/fec_main.c | 14 +- drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.c | 8 + .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 10 +- drivers/net/ethernet/lantiq_etop.c | 8 +- .../ethernet/mellanox/mlxbf_gige/mlxbf_gige_main.c | 2 + drivers/net/ethernet/microchip/lan743x_main.c | 1 + drivers/net/ethernet/nxp/lpc_eth.c | 10 +- drivers/net/ethernet/oa_tc6.c | 3 + drivers/net/ethernet/qualcomm/emac/emac-phy.c | 7 - drivers/net/ethernet/rdc/r6040.c | 10 +- drivers/net/ethernet/realtek/r8169_main.c | 15 +- drivers/net/ethernet/samsung/sxgbe/sxgbe_mdio.c | 1 + drivers/net/ethernet/smsc/smsc911x.c | 6 +- drivers/net/ethernet/smsc/smsc9420.c | 10 +- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 1 + drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 2 + drivers/net/ethernet/tehuti/tn40_phy.c | 5 +- drivers/net/ethernet/ti/davinci_emac.c | 20 +- drivers/net/ethernet/toshiba/tc35815.c | 8 +- drivers/net/ethernet/wangxun/ngbe/ngbe_mdio.c | 8 + drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c | 8 + drivers/net/mdio/of_mdio.c | 514 +++++++++++++++++++-- drivers/net/phy/mdio_bus.c | 46 +- drivers/net/phy/mdio_bus_provider.c | 141 ++++-- drivers/net/phy/mdio_device.c | 238 +++++++++- drivers/net/phy/mscc/mscc_ptp.c | 50 +- drivers/net/phy/phy_device.c | 151 ++++-- drivers/net/phy/phylib-internal.h | 4 +- drivers/net/usb/asix_devices.c | 4 + drivers/net/usb/lan78xx.c | 7 +- drivers/net/usb/smsc95xx.c | 2 + drivers/power/reset/linkstation-poweroff.c | 1 + include/linux/mdio.h | 4 +- include/linux/phy.h | 34 +- net/dsa/user.c | 12 +- 52 files changed, 1239 insertions(+), 269 deletions(-) --- base-commit: a23b36233d4103def55dc8cf65698106d0bd1e62 change-id: 20260803-submit-mdio-of-dynamic-v2-90560ca159b9 Best regards, -- James Hilliard <[email protected]>