From: Catalin Marinas <catalin.marinas@arm.com>
To: Karl Mehltretter <kmehltretter@gmail.com>
Cc: Vlastimil Babka <vbabka@kernel.org>, Harry Yoo <harry@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Hao Li <hao.li@linux.dev>, Christoph Lameter <cl@gentwo.org>,
David Rientjes <rientjes@google.com>,
Roman Gushchin <roman.gushchin@linux.dev>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev
Subject: Re: [PATCH] slab: align ZERO_SIZE_PTR to ARCH_KMALLOC_MINALIGN
Date: Mon, 10 Aug 2026 15:26:37 +0100 [thread overview]
Message-ID: <annfnXskDJuyzMKD@arm.com> (raw)
In-Reply-To: <20260808105622.62026-1-kmehltretter@gmail.com>
On Sat, Aug 08, 2026 at 12:56:22PM +0200, Karl Mehltretter wrote:
> diff --git a/include/linux/slab.h b/include/linux/slab.h
> index 32c9f8ed7ae20..0798a714da87f 100644
> --- a/include/linux/slab.h
> +++ b/include/linux/slab.h
> @@ -259,13 +259,16 @@ enum _slab_flag_bits {
>
> /*
> * ZERO_SIZE_PTR will be returned for zero sized kmalloc requests.
> + * It satisfies the alignment promised by __assume_kmalloc_alignment
> + * and keeps the historic value 16 where that is already aligned.
> *
> * Dereferencing ZERO_SIZE_PTR will lead to a distinct access fault.
> *
> * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
> * Both make kfree a no-op.
> */
> -#define ZERO_SIZE_PTR ((void *)16)
> +#define ZERO_SIZE_PTR ((void *)(ARCH_KMALLOC_MINALIGN > 16 ? \
> + ARCH_KMALLOC_MINALIGN : 16))
>
> #define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
> (unsigned long)ZERO_SIZE_PTR)
> @@ -622,6 +625,12 @@ static inline bool kmem_dump_obj(void *object) { return false; }
> #define KMALLOC_SHIFT_LOW ilog2(KMALLOC_MIN_SIZE)
> #endif
>
> +/*
> + * Keep ZERO_SIZE_PTR below PAGE_SIZE and the low pointer poison values.
> + * 128 is the largest in-tree ARCH_KMALLOC_MINALIGN.
> + */
> +static_assert(ARCH_KMALLOC_MINALIGN <= 128);
I'm not sure we should bother with this, or at least make it strictly
less than PAGE_SIZE since 128 doesn't have any meaning for the slab
allocator.
Otherwise,
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
next prev parent reply other threads:[~2026-08-10 14:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-08 10:56 [PATCH] slab: align ZERO_SIZE_PTR to ARCH_KMALLOC_MINALIGN Karl Mehltretter
2026-08-10 14:26 ` Catalin Marinas [this message]
2026-08-11 5:43 ` Karl Mehltretter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=annfnXskDJuyzMKD@arm.com \
--to=catalin.marinas@arm.com \
--cc=akpm@linux-foundation.org \
--cc=cl@gentwo.org \
--cc=hao.li@linux.dev \
--cc=harry@kernel.org \
--cc=kmehltretter@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux@rasmusvillemoes.dk \
--cc=llvm@lists.linux.dev \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=vbabka@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox