From: Matthew Wilcox <willy@infradead.org>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@samsung.com>,
"Kees Cook" <keescook@chromium.org>,
"Al Viro" <viro@zeniv.linux.org.uk>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Arve Hjønnevåg" <arve@android.com>,
"Todd Kjos" <tkjos@android.com>,
"Martijn Coenen" <maco@android.com>,
"Joel Fernandes" <joel@joelfernandes.org>,
"Carlos Llamas" <cmllamas@google.com>,
"Suren Baghdasaryan" <surenb@google.com>,
"Arnd Bergmann" <arnd@arndb.de>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
rust-for-linux@vger.kernel.org,
"Christian Brauner" <brauner@kernel.org>
Subject: Re: [PATCH 3/3] rust: add abstraction for `struct page`
Date: Mon, 29 Jan 2024 17:59:53 +0000 [thread overview]
Message-ID: <ZbfnmX1J8iLV8UnO@casper.infradead.org> (raw)
In-Reply-To: <20240124-alice-mm-v1-3-d1abcec83c44@google.com>
On Wed, Jan 24, 2024 at 11:20:23AM +0000, 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.
OK ...
> This patch only adds support for pages of order zero, as that is all
> Rust Binder needs. However, it is written to make it easy to add support
> for higher-order pages in the future. To do that, you would add a const
> generic parameter to `Page` that specifies the order. Most of the
> methods do not need to be adjusted, as the logic for dealing with
> mapping multiple pages at once can be isolated to just the
> `with_pointer_into_page` method. Finally, the struct can be renamed to
> `Pages<ORDER>`, and the type alias `Page = Pages<0>` can be introduced.
This description concerns me because it reads like you're not keeping
up with the current thinking in MM about what pages are and how we're
improving the type hierarchy. As in, we're creating one instead of
allowing the current mish-mash of absolutely everything to continue.
Are you the right person to ask about the operations that Binder does
with a page so we can figure out where it fits in the type hierarchy?
> Rust Binder needs to manage pages directly as that is how transactions
> are delivered: Each process has an mmap'd region for incoming
> transactions. When an incoming transaction arrives, the Binder driver
> will choose a region in the mmap, allocate and map the relevant pages
> manually, and copy the incoming transaction directly into the page. This
> architecture allows the driver to copy transactions directly from the
> address space of one process to another, without an intermediate copy
> to a kernel buffer.
Everything about this says "This is what a first year comp sci student
thinks will be fast". Oh well, the thinking here isn't your fault.
> @@ -127,6 +129,24 @@ int rust_helper_signal_pending(struct task_struct *t)
> }
> EXPORT_SYMBOL_GPL(rust_helper_signal_pending);
>
> +struct page *rust_helper_alloc_pages(gfp_t gfp_mask, unsigned int order)
> +{
> + return alloc_pages(gfp_mask, order);
> +}
> +EXPORT_SYMBOL_GPL(rust_helper_alloc_pages);
> +
> +void *rust_helper_kmap_local_page(struct page *page)
> +{
> + return kmap_local_page(page);
> +}
> +EXPORT_SYMBOL_GPL(rust_helper_kmap_local_page);
> +
> +void rust_helper_kunmap_local(const void *addr)
> +{
> + kunmap_local(addr);
> +}
> +EXPORT_SYMBOL_GPL(rust_helper_kunmap_local);
I remain opposed to all these fidgetty little helpers. Particularly
when they're noops on machines without HIGHMEM, which is ~all of them.
> +/// A bitwise shift for the page size.
> +pub const PAGE_SHIFT: usize = bindings::PAGE_SHIFT as usize;
Does PAGE_SHIFT really need to be as large as 'usize'? If it's more
than 63 by the time I retire, I'll be shocked. If it's more than 127
by the time I die, I'll be even more shocked. And it won't get to 255
by the heat death of the universe.
> +/// The number of bytes in a page.
> +pub const PAGE_SIZE: usize = 1 << PAGE_SHIFT;
This is appropriately usize.
> +/// A bitwise mask for the page size.
> +pub const PAGE_MASK: usize = PAGE_SIZE - 1;
Are you trying to get somebody killed?
include/asm-generic/page.h:#define PAGE_MASK (~(PAGE_SIZE-1))
Defining PAGE_MASK to be the opposite set of bits in C and Rust is
going to bite us all day every day for a decade.
> +impl Page {
> + /// Allocates a new set of contiguous pages.
> + pub fn new() -> Result<Self, AllocError> {
> + // SAFETY: These are the correct arguments to allocate a single page.
> + let page = unsafe {
> + bindings::alloc_pages(
> + bindings::GFP_KERNEL | bindings::__GFP_ZERO | bindings::__GFP_HIGHMEM,
> + 0,
> + )
> + };
This feels too Binder-specific to be 'Page'. Pages are not necessarily
allocated with GFP_HIGHMEM, nor are they necessarily zeroed. Maybe you
want a BinderPage type?
next prev parent reply other threads:[~2024-01-29 18:00 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-24 11:20 [PATCH 0/3] Memory management patches needed by Rust Binder Alice Ryhl
2024-01-24 11:20 ` [PATCH 1/3] rust: add userspace pointers Alice Ryhl
2024-01-24 23:12 ` Valentin Obst
2024-02-08 12:20 ` Alice Ryhl
2024-02-01 4:06 ` Trevor Gross
2024-02-08 12:53 ` Alice Ryhl
2024-02-08 15:35 ` Greg Kroah-Hartman
2024-02-08 15:41 ` Alice Ryhl
2024-02-08 15:59 ` Greg Kroah-Hartman
2024-02-10 6:20 ` Kees Cook
2024-02-10 7:06 ` Trevor Gross
2024-02-10 14:14 ` David Laight
2024-02-12 9:30 ` Alice Ryhl
2024-01-24 11:20 ` [PATCH 2/3] rust: add typed accessors for " Alice Ryhl
2024-01-24 23:46 ` Valentin Obst
2024-01-25 12:40 ` Alice Ryhl
2024-01-25 12:26 ` Arnd Bergmann
2024-01-25 12:37 ` Alice Ryhl
2024-01-25 15:59 ` Arnd Bergmann
2024-01-25 16:15 ` Alice Ryhl
2024-02-01 5:03 ` Trevor Gross
2024-02-08 13:14 ` Alice Ryhl
2024-01-24 11:20 ` [PATCH 3/3] rust: add abstraction for `struct page` Alice Ryhl
2024-01-26 0:46 ` Boqun Feng
2024-01-26 12:33 ` Alice Ryhl
2024-01-26 18:28 ` Boqun Feng
2024-02-01 6:50 ` Trevor Gross
2024-02-05 17:23 ` Boqun Feng
2024-02-08 13:36 ` Alice Ryhl
2024-01-30 9:15 ` Andreas Hindborg (Samsung)
2024-01-29 17:59 ` Matthew Wilcox [this message]
2024-01-29 18:56 ` Carlos Llamas
2024-01-29 20:19 ` Matthew Wilcox
2024-01-29 21:27 ` Alice Ryhl
2024-01-30 9:02 ` Andreas Hindborg
2024-01-30 9:06 ` Alice Ryhl
2024-02-01 6:02 ` Trevor Gross
2024-02-08 13:46 ` Alice Ryhl
2024-02-08 14:02 ` Andreas Hindborg
2024-02-08 14:12 ` Alice Ryhl
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=ZbfnmX1J8iLV8UnO@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).