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

From: SeungJong Ha

Date: Tue Nov 17 2026 - 05:36:52 EST


The Rust PHY abstraction tells every driver callback that PHYLIB holds
`phy_device->lock`, but phy_suspend() calls `suspend` without it, also
right after the state machine drops the lock. This was found while
auditing the SAFETY comments of Rust abstractions against their C
callers, and confirmed with Clang's context analysis [1].

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.

No in-tree driver is affected, so if this is not worth doing before
there is a real user, I am happy to drop it.

The audit, the patches and their changelogs were done with an AI coding
assistant (Claude Code, Claude Opus 5.5) and reviewed line by line by
me. Compile-tested only.

[1] https://docs.kernel.org/dev-tools/context-analysis.html

---
Changes in v3:
- Give `suspend` the `MaybeLocked` context, and make `genphy_suspend()`
available in both contexts (netdev AI review)
- Move `soft_reset` and `genphy_soft_reset()` back to `Locked`, since
`genphy_soft_reset()` in `MaybeLocked` could race with lock holders
in `suspend`, and document phy_mii_ioctl() as an existing PHYLIB race
instead (netdev AI review)
- Drop `match_phy_device` as well (netdev AI review)
- Fix the `get_features`, `soft_reset`, `read_status` and `resume`
SAFETY comments, and name the context at each `from_raw()` call
- List the exceptions in the `Locked` documentation, including MAC
drivers that call phy_init_hw() or phy_read_status() directly
- Link to v2: https://lore.kernel.org/r/20261115-exp-phy-rs-maybelocked-v2-0-8fa7897a0352@xxxxxxxxx

Changes in v2:
- Keep `&mut self` on the moved methods, so that `match_phy_device` does
not gain register access (netdev AI review)
- Give only `soft_reset` the `MaybeLocked` context
- Drop `read_mmd` and `write_mmd` instead of leaving them `Locked`
- Document how PHYLIB calls the `Locked` callbacks, and fix the
`from_raw()`, `phy_id()` and `genphy_soft_reset()` SAFETY comments
- Link to v1: https://lore.kernel.org/r/20261110-exp-phy-rs-maybelocked-v1-0-3023cc9055e9@xxxxxxxxx

---
SeungJong Ha (3):
rust: net: phy: drop unused read_mmd, write_mmd and match_phy_device
rust: net: phy: make Device generic over a lock context
rust: net: phy: pass a MaybeLocked device to suspend

drivers/net/phy/ax88796b_rust.rs | 4 +-
rust/kernel/net/phy.rs | 299 +++++++++++++++++----------------------
rust/kernel/net/phy/reg.rs | 17 ++-
3 files changed, 139 insertions(+), 181 deletions(-)
---
base-commit: 7ccc5e05043b1bb84326b19a2b05938d8f7a2ae6
change-id: 20261110-exp-phy-rs-maybelocked-ddc59993efba

Best regards,
--
SeungJong Ha <engineer.jjhama@xxxxxxxxx>