Re: [PATCH net-next v3 0/3] rust: net: phy: suspend may run without phy_device->lock

From: FUJITA Tomonori

Date: Wed Nov 25 2026 - 18:12:16 EST


On Wed, 25 Nov 2026 18:40:32 +0900
SeungJong Ha <engineer.jjhama@xxxxxxxxx> wrote:

> On Tue, 24 Nov 2026 21:57:47 +0900 (JST), FUJITA Tomonori wrote:
>>
>> On Tue, 17 Nov 2026 19:36:18 +0900
>> SeungJong Ha <engineer.jjhama@xxxxxxxxx> wrote:
>>
>> > Patch 1 drops `read_mmd`, `write_mmd` and `match_phy_device`, which make
>> > the same claim but are called under other conditions, and have no users.
>> > Patch 2 makes `Device` generic over a lock context and documents when
>> > the `Locked` callbacks run without the lock, and patch 3 gives `suspend`
>> > the `MaybeLocked` one.
>>
>> Can we use &Device and &mut Device instead of the new context types?
> [...]
>
> Yes, that is simpler. I will do that in v4. Two things to check first:
>
> - genphy_soft_reset() reads autoneg and writes suspended, so I would keep
> it on &mut self. soft_reset gets &mut Device, and the SAFETY comment
> says that the phy_mii_ioctl() path is outside the guarantee.

Agreed.

> - read() and write() take the MDIO bus lock, and &Device cannot say
> more than that the phy_device->lock state is off limits.
>
> In read_mmd and write_mmd the bus lock is already held, so they
> deadlock. A test driver whose read_mmd calls dev.read() hangs as soon
> as the PHY binds, and lockdep reports recursive locking on
> bus->mdio_lock. The path is phy_probe() -> genphy_read_abilities() ->
> genphy_c45_read_eee_abilities() -> phy_read_mmd().
>
> In match_phy_device they reach a device that may be bound to another
> driver, which the netdev AI review pointed out on v1 [1].
>
> Do you still want to keep these callbacks with &Device and document
> this, or wait until they can get accessors that fit their context?

Yes, please keep them with &Device and document it. The deadlock is not
a soundness problem. I will add accessors for the bus-locked context,
with a guard or a context type, as a follow-up.

For match_phy_device, &Device fixes both problems in [1]: read_paged()
needs &mut self, and read_mmd no longer gets &mut Device.

> [1] https://lore.kernel.org/r/179454612500.2199510.688554972467066283@xxxxxxxxxx