From: SeungJong Ha <engineer.jjhama@gmail.com>
To: "FUJITA Tomonori" <fujita.tomonori@gmail.com>,
"Trevor Gross" <tmgross@umich.edu>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@kernel.org>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>, "Andrew Lunn" <andrew@lunn.ch>,
"Heiner Kallweit" <hkallweit1@gmail.com>,
"Russell King" <linux@armlinux.org.uk>
Cc: netdev@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org,
SeungJong Ha <engineer.jjhama@gmail.com>
Subject: [PATCH net-next v3 3/3] rust: net: phy: pass a MaybeLocked device to suspend
Date: Tue, 17 Nov 2026 19:36:21 +0900 [thread overview]
Message-ID: <20261117-exp-phy-rs-maybelocked-v3-3-4e183a7366a7@gmail.com> (raw)
In-Reply-To: <20261117-exp-phy-rs-maybelocked-v3-0-4e183a7366a7@gmail.com>
phy_suspend() calls `suspend` without `phy_device->lock`, also right
after the state machine drops it, so another path may hold the lock
meanwhile. Yet the callback gets a `Locked` device, and can call methods
such as set_speed() that rely on the lock.
Pass a `&mut Device<MaybeLocked>` and correct the SAFETY comment. Update
ax88796b_rust, the only user; it only calls genphy_suspend().
Signed-off-by: SeungJong Ha <engineer.jjhama@gmail.com>
---
drivers/net/phy/ax88796b_rust.rs | 4 ++--
rust/kernel/net/phy.rs | 9 ++++-----
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/net/phy/ax88796b_rust.rs b/drivers/net/phy/ax88796b_rust.rs
index 2d24628a4e58..498704f1ef9d 100644
--- a/drivers/net/phy/ax88796b_rust.rs
+++ b/drivers/net/phy/ax88796b_rust.rs
@@ -77,7 +77,7 @@ fn read_status(dev: &mut phy::Device) -> Result<u16> {
Ok(0)
}
- fn suspend(dev: &mut phy::Device) -> Result {
+ fn suspend(dev: &mut phy::Device<phy::MaybeLocked>) -> Result {
dev.genphy_suspend()
}
@@ -107,7 +107,7 @@ impl Driver for PhyAX88772C {
const NAME: &'static CStr = c"Asix Electronics AX88772C";
const PHY_DEVICE_ID: DeviceId = DeviceId::new_with_exact_mask(0x003b1881);
- fn suspend(dev: &mut phy::Device) -> Result {
+ fn suspend(dev: &mut phy::Device<phy::MaybeLocked>) -> Result {
dev.genphy_suspend()
}
diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
index 8cbb4c19dac1..4b7b3ad09059 100644
--- a/rust/kernel/net/phy.rs
+++ b/rust/kernel/net/phy.rs
@@ -395,10 +395,9 @@ impl<T: Driver> Adapter<T> {
/// `phydev` must be passed by the corresponding callback in `phy_driver`.
unsafe extern "C" fn suspend_callback(phydev: *mut bindings::phy_device) -> c_int {
from_result(|| {
- // SAFETY: The C core code ensures that the accessors on
- // `Device` are okay to call even though `phy_device->lock`
- // might not be held.
- let dev = unsafe { Device::from_raw(phydev) };
+ // SAFETY: `phy_suspend()` does not take `phy_device->lock`, and `phy_state_machine()`
+ // calls it right after dropping the lock. This is the `MaybeLocked` context.
+ let dev = unsafe { Device::<MaybeLocked>::from_raw(phydev) };
T::suspend(dev)?;
Ok(0)
})
@@ -572,7 +571,7 @@ fn read_status(_dev: &mut Device) -> Result<u16> {
}
/// Suspends the hardware, saving state if needed.
- fn suspend(_dev: &mut Device) -> Result {
+ fn suspend(_dev: &mut Device<MaybeLocked>) -> Result {
build_error!(VTABLE_DEFAULT_ERROR)
}
--
2.54.0
prev parent reply other threads:[~2026-11-17 10:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 10:36 [PATCH net-next v3 0/3] rust: net: phy: suspend may run without phy_device->lock SeungJong Ha
2026-11-17 10:36 ` [PATCH net-next v3 1/3] rust: net: phy: drop unused read_mmd, write_mmd and match_phy_device SeungJong Ha
2026-11-17 10:36 ` [PATCH net-next v3 2/3] rust: net: phy: make Device generic over a lock context SeungJong Ha
2026-11-17 10:36 ` SeungJong Ha [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261117-exp-phy-rs-maybelocked-v3-3-4e183a7366a7@gmail.com \
--to=engineer.jjhama@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=andrew@lunn.ch \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=lossin@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=pabeni@redhat.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®