On 7/30/23 03:29, Boqun Feng wrote:
Currently the rust allocator simply passes the size of the type Layout to krealloc(), and in theory the alignment requirement from the type Layout may be larger than the guarantee provided by SLAB, which means the allocated object is mis-aligned.
Fix this by adjusting the allocation size to the nearest power of two, which SLAB always guarantees a size-aligned allocation. And because Rust guarantees that the original size must be a multiple of alignment and the alignment must be a power of two, then the alignment requirement is satisfied.
Suggested-by: Vlastimil Babka vbabka@suse.cz Co-developed-by: Andreas Hindborg (Samsung) nmi@metaspace.dk Signed-off-by: Andreas Hindborg (Samsung) nmi@metaspace.dk Signed-off-by: Boqun Feng boqun.feng@gmail.com Cc: stable@vger.kernel.org # v6.1+
Acked-by: Vlastimil Babka vbabka@suse.cz