[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH5fLgjrt0Ohj1qBv=GrqZumBTMQ1jbsKakChmxmG2JYDJEM8w@mail.gmail.com>
Date: Tue, 11 Jun 2024 10:51:19 +0200
From: Alice Ryhl <aliceryhl@...gle.com>
To: Abdiel Janulgue <abdiel@...hat.com>
Cc: Miguel Ojeda <ojeda@...nel.org>, Matthew Wilcox <willy@...radead.org>,
Al Viro <viro@...iv.linux.org.uk>, Andrew Morton <akpm@...ux-foundation.org>,
Kees Cook <keescook@...omium.org>, Alex Gaynor <alex.gaynor@...il.com>,
Wedson Almeida Filho <wedsonaf@...il.com>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>, Andreas Hindborg <a.hindborg@...sung.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>, Arve Hjønnevåg <arve@...roid.com>,
Todd Kjos <tkjos@...roid.com>, Martijn Coenen <maco@...roid.com>,
Joel Fernandes <joel@...lfernandes.org>, Carlos Llamas <cmllamas@...gle.com>,
Suren Baghdasaryan <surenb@...gle.com>, Arnd Bergmann <arnd@...db.de>, Trevor Gross <tmgross@...ch.edu>,
linux-mm@...ck.org, linux-kernel@...r.kernel.org,
rust-for-linux@...r.kernel.org, Christian Brauner <brauner@...nel.org>,
Danilo Krummrich <dakr@...hat.com>
Subject: Re: [PATCH v7 4/4] rust: add abstraction for `struct page`
On Mon, Jun 10, 2024 at 10:47 PM Abdiel Janulgue <abdiel@...hat.com> wrote:
>
> Hi,
>
> On 28/05/2024 17:58, Alice Ryhl wrote:
> > Adds a new struct called `Page` that wraps a pointer to `struct page`.
> > This struct is assumed to hold ownership over the page, so that Rust
> > code can allocate and manage pages directly.
> >
> > +
> > +impl Drop for Page {
> > + fn drop(&mut self) {
> > + // SAFETY: By the type invariants, we have ownership of the page and can free it.
> > + unsafe { bindings::__free_pages(self.page.as_ptr(), 0) };
> > + }
> > +}
> >
>
> What about cases where the struct page pointer is not owned or allocated
> by this wrapper? For example, pages returned vmalloc_to_page()?
> Any thoughts about exposing a provision to avoid freeing those pages
> during Drop?
>
> We've been experimenting in adapting this Page wrapper in advance for
> page management within the Nova DRM driver.
That would make a lot of sense, but this Page wrapper doesn't support
it. You are very welcome to extend it.
There are essentially two ways to go about it:
1. Change the Page struct to be a `Opaque<bindings::page>` and use the
types &Page and BoxLikeType<Page> for these two purposes. Here,
BoxLikeType would be a new type that is to Box in the same way as how
ARef is to Arc.
2. Introduce a new PageRef<'a> type that's like a reference to a page.
You can have Page deref to PageRef so that they share methods.
The second solution is easiest right now. The first solution is
probably what we want long-term.
Alice
Powered by blists - more mailing lists