Re: [PATCH 1/3] rust: page: replace the page pointer wrapper with Opaque
From: Alice Ryhl
Date: Tue Oct 15 2024 - 09:26:11 EST
On Fri, Oct 11, 2024 at 1:07 PM Fiona Behrens <me@xxxxxxxxxx> wrote:
>
>
>
> On 7 Oct 2024, at 22:27, Abdiel Janulgue wrote:
>
> > Replace NonNull with Opaque to make it possible to cast to a Page pointer
> > from a raw struct page pointer.
> >
> > Signed-off-by: Abdiel Janulgue <abdiel.janulgue@xxxxxxxxx>
> > ---
> > rust/kernel/page.rs | 19 +++++++++++++------
> > 1 file changed, 13 insertions(+), 6 deletions(-)
> >
> > diff --git a/rust/kernel/page.rs b/rust/kernel/page.rs
> > index 208a006d587c..08ff09a25223 100644
> > --- a/rust/kernel/page.rs
> > +++ b/rust/kernel/page.rs
> > @@ -8,8 +8,9 @@
> > error::code::*,
> > error::Result,
> > uaccess::UserSliceReader,
> > + types::Opaque,
> > };
> > -use core::ptr::{self, NonNull};
> > +use core::ptr::{self};
> >
> > /// A bitwise shift for the page size.
> > pub const PAGE_SHIFT: usize = bindings::PAGE_SHIFT as usize;
> > @@ -25,8 +26,9 @@
> > /// # Invariants
> > ///
> > /// The pointer is valid, and has ownership over the page.
> > +#[repr(transparent)]
> > pub struct Page {
> > - page: NonNull<bindings::page>,
> > + page: Opaque<bindings::page>,
>
> Still not to sure where to encode pinning in the type api. Looking into the C struct I see a union that sometimes holds a list head, should this then be a pinned thing in this type?
As long as you only hand out immutable references to it, nothing
further is necessary.
Alice