lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240831131606.32427c73.gary@garyguo.net>
Date: Sat, 31 Aug 2024 13:16:06 +0100
From: Gary Guo <gary@...yguo.net>
To: Danilo Krummrich <dakr@...nel.org>
Cc: ojeda@...nel.org, alex.gaynor@...il.com, wedsonaf@...il.com,
 boqun.feng@...il.com, bjorn3_gh@...tonmail.com, benno.lossin@...ton.me,
 a.hindborg@...sung.com, aliceryhl@...gle.com, akpm@...ux-foundation.org,
 daniel.almeida@...labora.com, faith.ekstrand@...labora.com,
 boris.brezillon@...labora.com, lina@...hilina.net, mcanal@...lia.com,
 zhiw@...dia.com, cjia@...dia.com, jhubbard@...dia.com, airlied@...hat.com,
 ajanulgu@...hat.com, lyude@...hat.com, linux-kernel@...r.kernel.org,
 rust-for-linux@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [PATCH v6 02/26] rust: alloc: separate `aligned_size` from
 `krealloc_aligned`

On Fri, 16 Aug 2024 02:10:44 +0200
Danilo Krummrich <dakr@...nel.org> wrote:

> Separate `aligned_size` from `krealloc_aligned`.
> 
> Subsequent patches implement `Allocator` derivates, such as `Kmalloc`,
> that require `aligned_size` and replace the original `krealloc_aligned`.
> 
> Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
> Reviewed-by: Benno Lossin <benno.lossin@...ton.me>
> Signed-off-by: Danilo Krummrich <dakr@...nel.org>

Reviewed-by: Gary Guo <gary@...yguo.net>

> ---
>  rust/kernel/alloc/allocator.rs | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator.rs
> index e6ea601f38c6..c83b6dff896d 100644
> --- a/rust/kernel/alloc/allocator.rs
> +++ b/rust/kernel/alloc/allocator.rs
> @@ -8,6 +8,17 @@
>  
>  struct KernelAllocator;
>  
> +/// Returns a proper size to alloc a new object aligned to `new_layout`'s alignment.
> +fn aligned_size(new_layout: Layout) -> usize {
> +    // Customized layouts from `Layout::from_size_align()` can have size < align, so pad first.
> +    let layout = new_layout.pad_to_align();
> +
> +    // Note that `layout.size()` (after padding) is guaranteed to be a multiple of `layout.align()`
> +    // which together with the slab guarantees means the `krealloc` will return a properly aligned
> +    // object (see comments in `kmalloc()` for more information).
> +    layout.size()
> +}
> +
>  /// Calls `krealloc` with a proper size to alloc a new object aligned to `new_layout`'s alignment.
>  ///
>  /// # Safety
> @@ -15,13 +26,7 @@
>  /// - `ptr` can be either null or a pointer which has been allocated by this allocator.
>  /// - `new_layout` must have a non-zero size.
>  pub(crate) unsafe fn krealloc_aligned(ptr: *mut u8, new_layout: Layout, flags: Flags) -> *mut u8 {
> -    // Customized layouts from `Layout::from_size_align()` can have size < align, so pad first.
> -    let layout = new_layout.pad_to_align();
> -
> -    // Note that `layout.size()` (after padding) is guaranteed to be a multiple of `layout.align()`
> -    // which together with the slab guarantees means the `krealloc` will return a properly aligned
> -    // object (see comments in `kmalloc()` for more information).
> -    let size = layout.size();
> +    let size = aligned_size(new_layout);
>  
>      // SAFETY:
>      // - `ptr` is either null or a pointer returned from a previous `k{re}alloc()` by the


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ