Re: [PATCH net] net: phy: don't require RTNL to detach a PHY from an unregistered netdev

From: Kory Maincent

Date: Fri Oct 30 2026 - 05:45:27 EST




On 10/29/26 15:24, Nguyen Ngoc Thang wrote:
phy_detach_internal() reads dev->hwprov with rtnl_dereference(), but
MAC drivers commonly attach and detach PHYs while their net_device is
not registered, without holding RTNL. Before register_netdev(), a failed
phylink_connect_phy() or phy_attach_direct() unwinds through
phy_detach_internal(). After unregister_netdev(), a driver's remove path
may call phy_disconnect(). Both trip lockdep:

WARNING: suspicious RCU usage
drivers/net/phy/phy_device.c:1831 suspicious rcu_dereference_protected() usage!
phy_detach_internal+0x6a5/0x830 drivers/net/phy/phy_device.c:1831
phylink_connect_phy+0x22e/0x2b0 drivers/net/phy/phylink.c:2452
ax88772_bind+0xbb1/0x1520 drivers/net/usb/asix_devices.c:925
usbnet_probe+0xbb3/0x27e0 drivers/net/usb/usbnet.c:1812

syzbot hits this with an emulated asix device. phy_eee_rx_clock_stop()
fails on a USB MDIO error, so phylink_bringup_phy() fails and the PHY is
detached from inside usbnet_probe(), before the netdev is registered.

hwprov is only set through ethtool, under RTNL, on a registered device.
reg_state also changes only under RTNL. So if the device is not
registered, no one else can reach hwprov, and RTNL is not needed. Tell
lockdep that. A detach from a registered device without RTNL still
warns.

Reviewed-by: Kory Maincent <kory.maincent@xxxxxxxxxxx>

Thank you!
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com