linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] rust: file: mark `LocalFile` as `repr(transparent)`
@ 2025-05-27 20:48 Pekka Ristola
  2025-05-27 20:48 ` [PATCH 2/2] rust: file: improve safety comments Pekka Ristola
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Pekka Ristola @ 2025-05-27 20:48 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Miguel Ojeda, Alex Gaynor
  Cc: Jan Kara, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, linux-fsdevel, rust-for-linux, linux-kernel,
	Pekka Ristola

Unsafe code in `LocalFile`'s methods assumes that the type has the same
layout as the inner `bindings::file`. This is not guaranteed by the default
struct representation in Rust, but requires specifying the `transparent`
representation.

The `File` struct (which also wraps `bindings::file`) is already marked as
`repr(transparent)`, so this change makes their layouts equivalent.

Fixes: 851849824bb5 ("rust: file: add Rust abstraction for `struct file`")
Closes: https://github.com/Rust-for-Linux/linux/issues/1165
Signed-off-by: Pekka Ristola <pekkarr@protonmail.com>
---
 rust/kernel/fs/file.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/rust/kernel/fs/file.rs b/rust/kernel/fs/file.rs
index 13a0e44cd1aa..138693bdeb3f 100644
--- a/rust/kernel/fs/file.rs
+++ b/rust/kernel/fs/file.rs
@@ -219,6 +219,7 @@ unsafe fn dec_ref(obj: ptr::NonNull<File>) {
 ///   must be on the same thread as this file.
 ///
 /// [`assume_no_fdget_pos`]: LocalFile::assume_no_fdget_pos
+#[repr(transparent)]
 pub struct LocalFile {
     inner: Opaque<bindings::file>,
 }
-- 
2.49.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-05-30  5:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-27 20:48 [PATCH 1/2] rust: file: mark `LocalFile` as `repr(transparent)` Pekka Ristola
2025-05-27 20:48 ` [PATCH 2/2] rust: file: improve safety comments Pekka Ristola
2025-05-28 10:20   ` Alice Ryhl
2025-05-28 15:30   ` Benno Lossin
2025-05-28 10:19 ` [PATCH 1/2] rust: file: mark `LocalFile` as `repr(transparent)` Alice Ryhl
2025-05-28 10:51 ` Miguel Ojeda
2025-05-28 12:18   ` Pekka Ristola
2025-05-28 15:29 ` Benno Lossin
2025-05-30  5:12 ` Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).