Thread (7 messages) 7 messages, 3 authors, 2025-08-24

Re: [PATCH] rust: alloc: add missing trait item MIN_ALIGN to Cmalloc

From: "Danilo Krummrich" <dakr@kernel.org>
Date: 2025-08-24 13:18:34
Also in: linux-mm

On Sun Aug 24, 2025 at 3:04 PM CEST, Danilo Krummrich wrote:
On Sun Aug 24, 2025 at 2:36 PM CEST, Alice Ryhl wrote:
quoted
On Sun, Aug 24, 2025 at 2:07 PM Danilo Krummrich [off-list ref] wrote:
quoted
+    const MIN_ALIGN: usize = bindings::ARCH_KMALLOC_MINALIGN;
Is this the right value for normal malloc?
Heh! ARCH_KMALLOC_MINALIGN should be correct, because the Cmalloc implementation
should (ideally) enforce a minimum alignment of ARCH_KMALLOC_MINALIGN for
compatibility reasons.

However, double checking the existing code, it doesn't. Hence, the correct value
must either be

	const MIN_ALIGN: usize = align_of::<crate::ffi::c_ulonglong>();

instead. Or, we have to actually enforce ARCH_KMALLOC_MINALIGN.

Given that this fix is only for within the -rc cycles, i.e. we will remove
allocator_test.rs before the MIN_ALIGN stuff ever hits an actual release, just
using align_of::<crate::ffi::c_ulonglong>() should be fine.
Just for completeness, allocator_test.rs is also broken for the assumption that
Vmalloc allocated memory is always PAGE_SIZE aligned.

Vmalloc::MIN_ALIGN, of course, does not report PAGE_SIZE in the case of
allocator_test.rs being in charge, but it's an assumption that people might
rightfully rely on in their (unsafe) code.

In the end, just another argument for getting rid of allocator_test.rs. :)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help