* Re: [PATCH 5/5] rust: fs: use READ_ONCE instead of read_volatile
[not found] ` <20251231-rwonce-v1-5-702a10b85278@google.com>
@ 2026-01-21 0:47 ` Boqun Feng
0 siblings, 0 replies; only message in thread
From: Boqun Feng @ 2026-01-21 0:47 UTC (permalink / raw)
To: Alice Ryhl
Cc: Will Deacon, Peter Zijlstra, Richard Henderson, Matt Turner,
Magnus Lindholm, Catalin Marinas, Miguel Ojeda, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Danilo Krummrich, Mark Rutland, FUJITA Tomonori,
Frederic Weisbecker, Lyude Paul, Thomas Gleixner,
Anna-Maria Behnsen, John Stultz, Stephen Boyd, Alexander Viro,
Christian Brauner, Jan Kara, linux-kernel, linux-alpha,
linux-arm-kernel, rust-for-linux, linux-fsdevel
On Wed, Dec 31, 2025 at 12:22:29PM +0000, Alice Ryhl wrote:
> Using `READ_ONCE` is the correct way to read the `f_flags` field.
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
> rust/kernel/fs/file.rs | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/rust/kernel/fs/file.rs b/rust/kernel/fs/file.rs
> index 23ee689bd2400565223181645157d832a836589f..6b07f08e7012f512e53743266096ce0076d29e1c 100644
> --- a/rust/kernel/fs/file.rs
> +++ b/rust/kernel/fs/file.rs
> @@ -335,12 +335,8 @@ 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() }
> + // SAFETY: The `f_flags` field of `struct file` is readable with `READ_ONCE`.
> + unsafe { kernel::sync::READ_ONCE(&raw const (*self.as_ptr()).f_flags) }
Not a question directly to this patch, but for FS folks: I see we read
and write `f_flags` normally (i.e. without *_ONCE() or any atomic), and
I don't see any synchronization between these read and write (maybe I'm
missing something?), if read and write can happen at the same time, it's
data race. So I assume we must have some assumption on the atomicity of
these accesses to `f_flags`, could you may share or confirm this? Thanks
Regards,
Boqun
> }
> }
>
>
> --
> 2.52.0.351.gbe84eed79e-goog
>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-01-21 2:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20251231-rwonce-v1-0-702a10b85278@google.com>
[not found] ` <20251231-rwonce-v1-5-702a10b85278@google.com>
2026-01-21 0:47 ` [PATCH 5/5] rust: fs: use READ_ONCE instead of read_volatile Boqun Feng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox