From: Matthew Wilcox <willy@infradead.org>
To: Alice Ryhl <aliceryhl@google.com>
Cc: Andreas Hindborg <a.hindborg@samsung.com>,
akpm@linux-foundation.org, alex.gaynor@gmail.com, arnd@arndb.de,
arve@android.com, benno.lossin@proton.me,
bjorn3_gh@protonmail.com, boqun.feng@gmail.com,
brauner@kernel.org, cmllamas@google.com, gary@garyguo.net,
gregkh@linuxfoundation.org, joel@joelfernandes.org,
keescook@chromium.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, maco@android.com, ojeda@kernel.org,
rust-for-linux@vger.kernel.org, surenb@google.com,
tkjos@android.com, viro@zeniv.linux.org.uk, wedsonaf@gmail.com
Subject: Re: [PATCH v3 4/4] rust: add abstraction for `struct page`
Date: Sat, 16 Mar 2024 15:30:47 +0000 [thread overview]
Message-ID: <ZfW7J2uS28hlFWcd@casper.infradead.org> (raw)
In-Reply-To: <20240311105056.122734-1-aliceryhl@google.com>
On Mon, Mar 11, 2024 at 10:50:56AM +0000, Alice Ryhl wrote:
> Alice Ryhl <aliceryhl@google.com> writes:
> > +/// Flags for the "get free page" function that underlies all memory allocations.
> > +pub mod flags {
> > + pub type gfp_t = bindings::gfp_t;
> > +
> > + /// `GFP_KERNEL` is typical for kernel-internal allocations. The caller requires `ZONE_NORMAL`
> > + /// or a lower zone for direct access but can direct reclaim.
> > + pub const GFP_KERNEL: gfp_t = bindings::GFP_KERNEL;
> > + /// `GFP_ZERO` returns a zeroed page on success.
> > + pub const __GFP_ZERO: gfp_t = bindings::__GFP_ZERO;
> > + /// `GFP_HIGHMEM` indicates that the allocated memory may be located in high memory.
> > + pub const __GFP_HIGHMEM: gfp_t = bindings::__GFP_HIGHMEM;
> > +}
> >
> > [...]
> >
> > +impl Page {
> > + /// Allocates a new page.
> > + pub fn alloc_page(gfp_flags: flags::gfp_t) -> Result<Self, AllocError> {
> > + // SAFETY: The specified order is zero and we want one page.
> > + let page = unsafe { bindings::alloc_pages(gfp_flags, 0) };
> > + let page = NonNull::new(page).ok_or(AllocError)?;
> > + // INVARIANT: We checked that the allocation succeeded.
> > + Ok(Self { page })
> > + }
>
> Matthew Wilcox: You suggested on a previous version that I use gfp flags
> here, or that I rename it to e.g. BinderPage to make it clear that this
> is specific to the kind of pages that Binder needs.
I think what you have here is good.
> In this version I added some gfp flags, but I'm not actually sure that
> the Page abstraction works for all combinations of gfp flags. For
> example, I use kmap_local_page when accessing the page, but is that
> correct if there's a user that doesn't pass GFP_HIGHMEM?
Yes, kmap_local_page() works for non-highmem pages (it's essentially a
no-op)
next prev parent reply other threads:[~2024-03-16 15:31 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-11 10:47 [PATCH v3 0/4] Memory management patches needed by Rust Binder Alice Ryhl
2024-03-11 10:47 ` [PATCH v3 1/4] rust: uaccess: add userspace pointers Alice Ryhl
2024-03-16 14:16 ` Benno Lossin
2024-03-18 18:59 ` Boqun Feng
2024-03-18 19:12 ` Alice Ryhl
2024-03-18 19:33 ` Boqun Feng
2024-03-18 20:10 ` Alice Ryhl
2024-03-18 21:07 ` Boqun Feng
2024-03-20 2:27 ` Boqun Feng
2024-03-20 18:39 ` Boqun Feng
2024-03-11 10:47 ` [PATCH v3 2/4] uaccess: always export _copy_[from|to]_user with CONFIG_RUST Alice Ryhl
2024-03-18 21:16 ` Boqun Feng
2024-03-11 10:47 ` [PATCH v3 3/4] rust: uaccess: add typed accessors for userspace pointers Alice Ryhl
2024-03-16 14:56 ` Benno Lossin
2024-03-19 19:32 ` Boqun Feng
2024-03-11 10:47 ` [PATCH v3 4/4] rust: add abstraction for `struct page` Alice Ryhl
2024-03-11 10:50 ` Alice Ryhl
2024-03-15 8:16 ` Andreas Hindborg
2024-03-16 15:30 ` Matthew Wilcox [this message]
2024-03-16 20:39 ` Benno Lossin
2024-03-20 8:46 ` Alice Ryhl
2024-03-21 13:15 ` Benno Lossin
2024-03-21 13:42 ` Alice Ryhl
2024-03-21 13:56 ` Benno Lossin
2024-03-21 14:11 ` Alice Ryhl
2024-03-21 14:16 ` Alice Ryhl
2024-03-21 14:19 ` Benno Lossin
2024-03-19 22:16 ` Boqun Feng
2024-03-19 22:28 ` Benno Lossin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZfW7J2uS28hlFWcd@casper.infradead.org \
--to=willy@infradead.org \
--cc=a.hindborg@samsung.com \
--cc=akpm@linux-foundation.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=arnd@arndb.de \
--cc=arve@android.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=brauner@kernel.org \
--cc=cmllamas@google.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=joel@joelfernandes.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=maco@android.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=surenb@google.com \
--cc=tkjos@android.com \
--cc=viro@zeniv.linux.org.uk \
--cc=wedsonaf@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).