On Sun, Feb 16, 2025 at 8:39 PM Benno Lossin <benno.lossin@xxxxxxxxx> wrote: > > On 07.02.25 14:58, Tamir Duberstein wrote: > > Allow implementors to specify the foreign pointer type; this exposes > > information about the pointed-to type such as its alignment. > > > > This requires the trait to be `unsafe` since it is now possible for > > implementors to break soundness by returning a misaligned pointer. > > > > Encoding the pointer type in the trait (and avoiding pointer casts) > > allows the compiler to check that implementors return the correct > > pointer type. This is preferable to directly encoding the alignment in > > the trait using a constant as the compiler would be unable to check it. > > > > Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx> > > Reviewed-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx> > > Reviewed-by: Fiona Behrens <me@xxxxxxxxxx> > > Signed-off-by: Tamir Duberstein <tamird@xxxxxxxxx> > > --- > > rust/kernel/alloc/kbox.rs | 38 ++++++++++++++++++++------------------ > > rust/kernel/miscdevice.rs | 7 ++++++- > > rust/kernel/pci.rs | 2 ++ > > rust/kernel/platform.rs | 2 ++ > > rust/kernel/sync/arc.rs | 21 ++++++++++++--------- > > rust/kernel/types.rs | 46 +++++++++++++++++++++++++++++++--------------- > > 6 files changed, 73 insertions(+), 43 deletions(-) > > When compiling this (on top of rust-next), I get the following error: > > error[E0308]: mismatched types > --> rust/kernel/miscdevice.rs:300:62 > | > 300 | let device = unsafe { <T::Ptr as ForeignOwnable>::borrow(private) }; > | ---------------------------------- ^^^^^^^ expected `*mut <<T as MiscDevice>::Ptr as ForeignOwnable>::PointedTo`, found `*mut c_void` > | | > | arguments to this function are incorrect > | > = note: expected raw pointer `*mut <<T as MiscDevice>::Ptr as ForeignOwnable>::PointedTo` > found raw pointer `*mut c_void` > = help: consider constraining the associated type `<<T as MiscDevice>::Ptr as ForeignOwnable>::PointedTo` to `c_void` or calling a method that returns `<<T as MiscDevice>::Ptr as ForeignOwnable>::PointedTo` > = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html > note: associated function defined here > --> rust/kernel/types.rs:98:15 > | > 98 | unsafe fn borrow<'a>(ptr: *mut Self::PointedTo) -> Self::Borrowed<'a>; > | ^^^^^^ > > error: aborting due to 1 previous error > > Can anyone reproduce? > > --- > Cheers, > Benno > Looks like this code is behind #[cfg(CONFIG_COMPAT)] and I missed updating it. It is fixed by diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs index f1a081dd64c7..004dc87f441f 100644 --- a/rust/kernel/miscdevice.rs +++ b/rust/kernel/miscdevice.rs @@ -296,6 +296,7 @@ impl<T: MiscDevice> VtableHelper<T> { ) -> c_long { // SAFETY: The compat ioctl call of a file can access the private data. let private = unsafe { (*file).private_data }; + let private = private.cast(); // SAFETY: Ioctl calls can borrow the private data of the file. let device = unsafe { <T::Ptr as ForeignOwnable>::borrow(private) }; I'll include that in the next version.