From: Alessio Maroni <alessiomaroni0@gmail.com>
To: brauner@kernel.org, viro@zeniv.linux.org.uk, ojeda@kernel.org
Cc: rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org,
Alessio Maroni <alessiomaroni0@gmail.com>
Subject: [PATCH] rust: fs, hrtimer: replace read_volatile workarounds with atomic_load
Date: Sun, 12 Jul 2026 14:14:20 +0200 [thread overview]
Message-ID: <20260712121420.25179-1-alessiomaroni0@gmail.com> (raw)
Remove the temporary FIXME(read_once) comments and replace the
read_volatile implementations with the proper native atomic_load.
The generic `atomic_load` with `Relaxed` ordering maps directly to the
C side `READ_ONCE()` macro, providing the intended behavior and
correct hardware memory guarantees without relying on pure volatile reads.
Signed-off-by: Alessio Maroni <alessiomaroni0@gmail.com>
---
rust/kernel/fs/file.rs | 12 +++++++-----
rust/kernel/time/hrtimer.rs | 7 ++++---
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/rust/kernel/fs/file.rs b/rust/kernel/fs/file.rs
index 23ee689bd..63f309f5c 100644
--- a/rust/kernel/fs/file.rs
+++ b/rust/kernel/fs/file.rs
@@ -335,12 +335,14 @@ pub fn cred(&self) -> &Credential {
/// The flags are a combination of the constants in [`flags`].
#[inline]
pub fn flags(&self) -> u32 {
- // This `read_volatile` is intended to correspond to a READ_ONCE call.
- //
// SAFETY: The file is valid because the shared reference guarantees a nonzero refcount.
- //
- // FIXME(read_once): Replace with `read_once` when available on the Rust side.
- unsafe { core::ptr::addr_of!((*self.as_ptr()).f_flags).read_volatile() }
+ // `atomic_load` safely performs an atomic read equivalent to `READ_ONCE()`.
+ unsafe {
+ crate::sync::atomic::atomic_load(
+ core::ptr::addr_of!((*self.as_ptr()).f_flags).cast_mut(),
+ crate::sync::atomic::ordering::Relaxed,
+ )
+ }
}
}
diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
index 2d7f1131a..cb1b5a2ae 100644
--- a/rust/kernel/time/hrtimer.rs
+++ b/rust/kernel/time/hrtimer.rs
@@ -576,9 +576,10 @@ pub fn expires(&self) -> HrTimerInstant<T>
// - There's no actual locking here, a racy read is fine and expected
unsafe {
Instant::from_ktime(
- // This `read_volatile` is intended to correspond to a READ_ONCE call.
- // FIXME(read_once): Replace with `read_once` when available on the Rust side.
- core::ptr::read_volatile(&raw const ((*c_timer_ptr).node.expires)),
+ crate::sync::atomic::atomic_load(
+ (&raw const ((*c_timer_ptr).node.expires)) as *mut i64,
+ crate::sync::atomic::ordering::Relaxed,
+ )
)
}
}
--
2.55.0
next reply other threads:[~2026-07-12 12:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-12 12:14 Alessio Maroni [this message]
2026-07-12 12:34 ` [PATCH] rust: fs, hrtimer: replace read_volatile workarounds with atomic_load Alessio Maroni
2026-07-12 13:40 ` Gary Guo
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=20260712121420.25179-1-alessiomaroni0@gmail.com \
--to=alessiomaroni0@gmail.com \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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