[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <873514qxd2.fsf@metaspace.dk>
Date: Mon, 31 Jul 2023 10:48:57 +0200
From: "Andreas Hindborg (Samsung)" <nmi@...aspace.dk>
To: Boqun Feng <boqun.feng@...il.com>
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-mm@...ck.org, Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Wedson Almeida Filho <wedsonaf@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Martin Rodriguez Reboredo <yakoyoku@...il.com>,
Alice Ryhl <aliceryhl@...gle.com>,
Dariusz Sosnowski <dsosnowski@...snowski.pl>,
Geoffrey Thomas <geofft@...reload.com>,
Fox Chen <foxhlchen@...il.com>,
John Baublitz <john.m.baublitz@...il.com>,
Christoph Lameter <cl@...ux.com>,
Pekka Enberg <penberg@...nel.org>,
David Rientjes <rientjes@...gle.com>,
Joonsoo Kim <iamjoonsoo.kim@....com>,
Andrew Morton <akpm@...ux-foundation.org>,
Vlastimil Babka <vbabka@...e.cz>,
Roman Gushchin <roman.gushchin@...ux.dev>,
Hyeonggon Yoo <42.hyeyoo@...il.com>,
Kees Cook <keescook@...omium.org>, stable@...r.kernel.org
Subject: Re: [PATCH 2/3] rust: allocator: Use krealloc_aligned() in
KernelAllocator::alloc
Boqun Feng <boqun.feng@...il.com> writes:
> This fixes the potential issue that when KernelAllocator is used, the
> allocation may be mis-aligned due to SLAB's alignment guarantee.
>
> Signed-off-by: Boqun Feng <boqun.feng@...il.com>
> ---
> rust/kernel/allocator.rs | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/rust/kernel/allocator.rs b/rust/kernel/allocator.rs
> index fae11d1fdba7..1aec688cf0e0 100644
> --- a/rust/kernel/allocator.rs
> +++ b/rust/kernel/allocator.rs
> @@ -41,9 +41,9 @@ unsafe fn krealloc_aligned(ptr: *mut u8, new_layout: Layout, flags: bindings::gf
>
> unsafe impl GlobalAlloc for KernelAllocator {
> unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
> - // `krealloc()` is used instead of `kmalloc()` because the latter is
> - // an inline function and cannot be bound to as a result.
> - unsafe { bindings::krealloc(ptr::null(), layout.size(), bindings::GFP_KERNEL) as *mut u8 }
> + // SAFETY: `ptr::null_mut()` is null and `layout` has a non-zero size by the function safety
> + // requirement.
> + unsafe { krealloc_aligned(ptr::null_mut(), layout, bindings::GFP_KERNEL) }
> }
>
> unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
Reviewed-by: Andreas Hindborg <a.hindborg@...sung.com>
Powered by blists - more mailing lists