From: Boqun Feng <boqun.feng@gmail.com>
To: Alice Ryhl <alice@ryhl.io>
Cc: "Alice Ryhl" <aliceryhl@google.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
"Alex Gaynor" <alex.gaynor@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@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
linux-mm@kvack.org, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: page: add Rust version of PAGE_ALIGN
Date: Tue, 15 Oct 2024 11:43:08 -0700 [thread overview]
Message-ID: <Zw63vD879qeHUA_b@boqun-archlinux> (raw)
In-Reply-To: <3ea20eb4-2a88-40bd-a453-bf2ff5d52d03@ryhl.io>
On Tue, Oct 15, 2024 at 08:44:22PM +0200, Alice Ryhl wrote:
> On 10/15/24 8:33 PM, Boqun Feng wrote:
> > On Tue, Oct 15, 2024 at 02:28:28PM +0000, Alice Ryhl wrote:
> > > This is a useful for helper for working with indices into buffers that
> > > consist of several pages. I forgot to include it when I added PAGE_SIZE
> > > and PAGE_MASK for the same purpose in commit fc6e66f4696b ("rust: add
> > > abstraction for `struct page`").
> > >
> > > Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> > > ---
> > > rust/kernel/page.rs | 5 +++++
> > > 1 file changed, 5 insertions(+)
> > >
> > > diff --git a/rust/kernel/page.rs b/rust/kernel/page.rs
> > > index 208a006d587c..90846e3fe829 100644
> > > --- a/rust/kernel/page.rs
> > > +++ b/rust/kernel/page.rs
> > > @@ -20,6 +20,11 @@
> > > /// A bitmask that gives the page containing a given address.
> > > pub const PAGE_MASK: usize = !(PAGE_SIZE - 1);
> > > +/// Round up the given number to a multiple of `PAGE_SIZE`.
> > > +pub fn page_align(addr: usize) -> usize {
> >
> > Make it a `const` function? For example, there is a VMBUS_RING_SIZE()
> > macro in C that calculates a const number for a vmbus ringbuffer size,
> > so it will be useful.
>
> Good idea.
>
> > > + (addr + (PAGE_SIZE - 1)) & PAGE_MASK
> >
> > I guess overflows are unexpected, i.e. the users should not pass a
> > `addr` that `> usize::MAX - PAGE_SIZE + 1`?
> Correct. If this wraps around to zero, that's incorrect. Note that the minus
> one is in brackets to only trigger overflow detection in the right cases.
>
Make senses, with the const change and some docs on the overflow case,
feel free to add:
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Regards,
Boqun
> I can mention this in the docs.
>
> Alice
prev parent reply other threads:[~2024-10-15 18:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-15 14:28 Alice Ryhl
2024-10-15 18:33 ` Boqun Feng
2024-10-15 18:44 ` Alice Ryhl
2024-10-15 18:43 ` Boqun Feng [this message]
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=Zw63vD879qeHUA_b@boqun-archlinux \
--to=boqun.feng@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alex.gaynor@gmail.com \
--cc=alice@ryhl.io \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=willy@infradead.org \
/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