From: sashiko-bot@kernel.org
To: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>,
"Harry Yoo" <harry@kernel.org>
Cc: "Chris Down" <chris@chrisdown.name>,
"Kees Cook" <kees@kernel.org>, "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
Subject: Re: [PATCH v2 2/3] mm/slab: add own entry points for kmem_buckets_alloc() family
Date: Thu, 03 Dec 2026 14:42:57 +0000 [thread overview]
Message-ID: <sashiko-outbox-247997@kernel.org> (raw)
In-Reply-To: <20261203-kmalloc-entry-rework-v2-2-d718dc4fd906@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mm: missing EXPORT_SYMBOL for new kmem_buckets allocation
entry points
- [Medium] mm: __assume_kmalloc_alignment on kmem_buckets allocators
exceeds cache align
--
commit 090eb1fb34ca44eca95fa86e7bfc2e6da9eb1e43
Author: Vlastimil Babka (SUSE) <vbabka@kernel.org>
mm/slab: add own entry points for kmem_buckets_alloc() family
This commit adds dedicated __kmem_buckets_alloc_noprof(),
__kmem_buckets_alloc_node_track_caller_noprof(), and
__kmem_buckets_valloc_noprof() entry points for the kmem_buckets
allocation macros instead of routing them through the kmalloc entry
points. It also factors out __kvmalloc_fallback() to share the vmalloc
fallback path with __kvmalloc_node_noprof().
> diff --git a/include/linux/slab.h b/include/linux/slab.h
> index cda126def67af..d9592e700d03f 100644
> --- a/include/linux/slab.h
> +++ b/include/linux/slab.h
> @@ -1175,11 +1175,22 @@ void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node);
> #define kvzalloc_flex(P, FAM, COUNT, ...) \
> __alloc_flex(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), FAM, COUNT)
>
> -#define kmem_buckets_alloc(_b, _size, _flags) \
> - alloc_hooks(__kmalloc_node_noprof(PASS_KMALLOC_PARAMS(_size, _b, __kmalloc_token(_size)), _flags, NUMA_NO_NODE))
> +void *__kmem_buckets_alloc_noprof(kmem_buckets *b,
> + DECL_TOKEN_PARAMS(size, token), gfp_t flags)
> + __assume_kmalloc_alignment __alloc_size(2);
>
> -#define kmem_buckets_alloc_node_track_caller(_b, _size, _flags, _node) \
> - alloc_hooks(__kmalloc_node_track_caller_noprof(PASS_KMALLOC_PARAMS(_size, _b, __kmalloc_token(_size)), _flags, _node, _RET_IP_))
> +void *__kmem_buckets_alloc_node_track_caller_noprof(kmem_buckets *b,
> + DECL_TOKEN_PARAMS(size, token), gfp_t flags, int node, unsigned long caller)
> + __assume_kmalloc_alignment __alloc_size(2);
[Severity: Medium]
Do caches created by kmem_buckets_create() actually guarantee
__assume_kmalloc_alignment?
kmem_buckets_create() passes align = 0 to kmem_cache_create_usercopy(),
so calculate_alignment() only clamps s->align to arch_slab_minalign().
When ARCH_KMALLOC_MINALIGN exceeds ARCH_SLAB_MINALIGN (e.g., ARM or
PowerPC), calculate_sizes() aligns s->red_left_pad and the object stride
only to s->align, so returned pointers can violate ARCH_KMALLOC_MINALIGN
under slab debug, KASAN, or a ctor.
Previously __kmalloc_node_track_caller_noprof() lacked this attribute, so
this adds the false assumption to the track_caller path, risking
miscompilation or alignment faults.
Should these prototypes use __assume_slab_alignment instead, or should
kmem_buckets_create() enforce ARCH_KMALLOC_MINALIGN?
[ ... ]
> diff --git a/mm/slub.c b/mm/slub.c
> index ff69988204c13..17199fef1a2d1 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
[ ... ]
> EXPORT_SYMBOL(__kvmalloc_node_noprof);
>
> +void *__kmem_buckets_valloc_noprof(kmem_buckets *b, DECL_TOKEN_PARAMS(size, token),
> + unsigned long align, gfp_t flags, int node)
> +{
> + void *ret;
> + const struct slab_alloc_context ac = {
> + .caller_addr = _RET_IP_,
> + .orig_size = size,
> + .alloc_flags = SLAB_ALLOC_DEFAULT,
> + };
> +
> + if (!IS_ENABLED(CONFIG_SLAB_BUCKETS))
> + b = NULL;
> +
> + /*
> + * It doesn't really make sense to fallback to vmalloc for sub page
> + * requests
> + */
> + ret = __do_kmalloc_node(b, kmalloc_gfp_adjust(flags, size),
> + node, PASS_TOKEN_PARAM(token), &ac);
> + if (ret || size <= PAGE_SIZE)
> + return ret;
> +
> + return __kvmalloc_fallback(size, align, flags, node,
> + __builtin_return_address(0));
> +}
[Severity: Medium]
As reported by Hao Li on v1 [1], should __kmem_buckets_alloc_noprof(),
__kmem_buckets_alloc_node_track_caller_noprof(), and
__kmem_buckets_valloc_noprof() be exported with EXPORT_SYMBOL()?
kmem_buckets_create() is exported via EXPORT_SYMBOL(), and these macros
previously expanded to exported kmalloc/kvmalloc symbols. Without
exporting the new entry points (or unexporting kmem_buckets_create()),
modules can create buckets but will fail to link when allocating from them.
[1] https://lore.kernel.org/r/aw1ciiXYI06gegvd@fedora
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-kmalloc-entry-rework-v2-0-d718dc4fd906@kernel.org?part=2
next prev parent reply other threads:[~2026-12-03 14:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 13:42 [PATCH v2 0/3] kmem_buckets entry point rework Vlastimil Babka (SUSE)
2026-12-03 13:42 ` [PATCH v2 1/3] mm/slab: add ___do_kmalloc_node() to deduplicate code Vlastimil Babka (SUSE)
2026-12-03 13:42 ` [PATCH v2 2/3] mm/slab: add own entry points for kmem_buckets_alloc() family Vlastimil Babka (SUSE)
2026-12-03 14:42 ` sashiko-bot [this message]
2026-12-03 13:42 ` [PATCH v2 3/3] mm/slab: drop BUCKET_PARAMS and KMALLOC_PARAMS macros Vlastimil Babka (SUSE)
2026-12-03 14:42 ` sashiko-bot
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=sashiko-outbox-247997@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=chris@chrisdown.name \
--cc=cl@gentwo.org \
--cc=hao.li@linux.dev \
--cc=harry@kernel.org \
--cc=kees@kernel.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=sashiko-reviews@lists.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