[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <56169ee4-321c-4546-bb89-2f9530adb01c@ryhl.io>
Date: Mon, 21 Oct 2024 20:32:11 +0200
From: Alice Ryhl <alice@...l.io>
To: John Hubbard <jhubbard@...dia.com>, Miguel Ojeda <ojeda@...nel.org>
Cc: Alex Gaynor <alex.gaynor@...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@...nel.org>, Trevor Gross <tmgross@...ch.edu>,
linux-mm@...ck.org, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org, Alice Ryhl <aliceryhl@...gle.com>,
Andrew Morton <akpm@...ux-foundation.org>,
"Matthew Wilcox (Oracle)" <willy@...radead.org>
Subject: Re: [PATCH v2] rust: page: add Rust version of PAGE_ALIGN
On 10/21/24 8:20 PM, John Hubbard wrote:
> On 10/16/24 4:34 AM, 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`").
>>
>> Reviewed-by: Boqun Feng <boqun.feng@...il.com>
>> Signed-off-by: Alice Ryhl <aliceryhl@...gle.com>
>> ---
>> Changes in v2:
>> - Make the function const.
>> - Address integer overflow in docs.
>> - Link to v1: https://lore.kernel.org/r/20241015-page-align-
>> v1-1-68fbd8b6d10c@...gle.com
>> ---
>> rust/kernel/page.rs | 9 +++++++++
>> 1 file changed, 9 insertions(+)
>>
>> diff --git a/rust/kernel/page.rs b/rust/kernel/page.rs
>> index 208a006d587c..9ef01929e7d0 100644
>> --- a/rust/kernel/page.rs
>> +++ b/rust/kernel/page.rs
>> @@ -20,6 +20,15 @@
>> /// A bitmask that gives the page containing a given address.
>> pub const PAGE_MASK: usize = !(PAGE_SIZE - 1);
>> +/// Round up the given number to the next multiple of `PAGE_SIZE`.
>> +///
>> +/// It is incorrect to pass an address where the next multiple of
>> `PAGE_SIZE` doesn't fit in a
>> +/// `usize`.
>> +pub const fn page_align(addr: usize) -> usize {
>> + // Brackets around PAGE_SIZE-1 to avoid triggering overflow
>> sanitizers in the wrong cases.
>
> Silly nit, but I did start looking for brackets that aren't there, so:
>
> s/Brackets/parentheses/
This isn't a distinction that exists in my vocabulary, shrug.
Miguel, feel free to reword when you pick this.
Alice
Powered by blists - more mailing lists