mm/slab.h | 28 +++++----------------------- mm/slab_common.c | 12 ------------ 2 files changed, 5 insertions(+), 35 deletions(-)
SLUB is the only remaining allocator. We can therefore get rid of
the logic for allocator-specific flags:
* Merge SLAB_CACHE_FLAGS into SLAB_CORE_FLAGS.
* Remove SLAB_FLAGS_PERMITTED (effectively the same as
CACHE_CREATE_MASK aside from debug flags being unconditionally
included).
While at it also remove misleading comments that suggest that
multiple allocators are available.
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
---
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>
---
mm/slab.h | 28 +++++-----------------------
mm/slab_common.c | 12 ------------
2 files changed, 5 insertions(+), 35 deletions(-)
diff --git a/mm/slab.h b/mm/slab.h
index 632fedd71fea..392f4763dee8 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -457,10 +457,12 @@ static inline bool is_kmalloc_normal(struct kmem_cache *s)
return !(s->flags & (SLAB_CACHE_DMA|SLAB_ACCOUNT|SLAB_RECLAIM_ACCOUNT));
}
-/* Legal flag mask for kmem_cache_create(), for various configurations */
#define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | \
SLAB_CACHE_DMA32 | SLAB_PANIC | \
- SLAB_TYPESAFE_BY_RCU | SLAB_DEBUG_OBJECTS )
+ SLAB_TYPESAFE_BY_RCU | SLAB_DEBUG_OBJECTS | \
+ SLAB_NOLEAKTRACE | SLAB_RECLAIM_ACCOUNT | \
+ SLAB_TEMPORARY | SLAB_ACCOUNT | \
+ SLAB_NO_USER_FLAGS | SLAB_KMALLOC | SLAB_NO_MERGE)
#ifdef CONFIG_SLUB_DEBUG
#define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \
@@ -469,27 +471,7 @@ static inline bool is_kmalloc_normal(struct kmem_cache *s)
#define SLAB_DEBUG_FLAGS (0)
#endif
-#define SLAB_CACHE_FLAGS (SLAB_NOLEAKTRACE | SLAB_RECLAIM_ACCOUNT | \
- SLAB_TEMPORARY | SLAB_ACCOUNT | \
- SLAB_NO_USER_FLAGS | SLAB_KMALLOC | SLAB_NO_MERGE)
-
-/* Common flags available with current configuration */
-#define CACHE_CREATE_MASK (SLAB_CORE_FLAGS | SLAB_DEBUG_FLAGS | SLAB_CACHE_FLAGS)
-
-/* Common flags permitted for kmem_cache_create */
-#define SLAB_FLAGS_PERMITTED (SLAB_CORE_FLAGS | \
- SLAB_RED_ZONE | \
- SLAB_POISON | \
- SLAB_STORE_USER | \
- SLAB_TRACE | \
- SLAB_CONSISTENCY_CHECKS | \
- SLAB_NOLEAKTRACE | \
- SLAB_RECLAIM_ACCOUNT | \
- SLAB_TEMPORARY | \
- SLAB_ACCOUNT | \
- SLAB_KMALLOC | \
- SLAB_NO_MERGE | \
- SLAB_NO_USER_FLAGS)
+#define CACHE_CREATE_MASK (SLAB_CORE_FLAGS | SLAB_DEBUG_FLAGS)
bool __kmem_cache_empty(struct kmem_cache *);
int __kmem_cache_shutdown(struct kmem_cache *);
diff --git a/mm/slab_common.c b/mm/slab_common.c
index a29457bef626..3b07cdaac3ae 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -305,18 +305,6 @@ struct kmem_cache *__kmem_cache_create_args(const char *name,
goto out_unlock;
}
- /* Refuse requests with allocator specific flags */
- if (flags & ~SLAB_FLAGS_PERMITTED) {
- err = -EINVAL;
- goto out_unlock;
- }
-
- /*
- * Some allocators will constraint the set of valid flags to a subset
- * of all flags. We expect them to define CACHE_CREATE_MASK in this
- * case, and we'll just provide them with a sanitized version of the
- * passed flags.
- */
flags &= CACHE_CREATE_MASK;
/* Fail closed on bad usersize of useroffset values. */
base-commit: 9bffa1ad25b8b3b95d8f463e5c24dabe3c87d54d
--
2.47.0
On Fri, 17 Jan 2025, Kevin Brodsky wrote:
> index a29457bef626..3b07cdaac3ae 100644
> --- a/mm/slab_common.c
> +++ b/mm/slab_common.c
> @@ -305,18 +305,6 @@ struct kmem_cache *__kmem_cache_create_args(const char *name,
> goto out_unlock;
> }
>
> - /* Refuse requests with allocator specific flags */
> - if (flags & ~SLAB_FLAGS_PERMITTED) {
> - err = -EINVAL;
> - goto out_unlock;
> - }
I think we should keep checking for invalid flags.
-
> - /*
> - * Some allocators will constraint the set of valid flags to a subset
> - * of all flags. We expect them to define CACHE_CREATE_MASK in this
> - * case, and we'll just provide them with a sanitized version of the
> - * passed flags.
> - */
> flags &= CACHE_CREATE_MASK;
This would silently clear some flags instead of creating an error.
On 17/01/2025 23:13, Christoph Lameter (Ampere) wrote:
> On Fri, 17 Jan 2025, Kevin Brodsky wrote:
>
>> index a29457bef626..3b07cdaac3ae 100644
>> --- a/mm/slab_common.c
>> +++ b/mm/slab_common.c
>> @@ -305,18 +305,6 @@ struct kmem_cache *__kmem_cache_create_args(const char *name,
>> goto out_unlock;
>> }
>>
>> - /* Refuse requests with allocator specific flags */
>> - if (flags & ~SLAB_FLAGS_PERMITTED) {
>> - err = -EINVAL;
>> - goto out_unlock;
>> - }
> I think we should keep checking for invalid flags.
The commit that introduced this check [1] aimed to ensure that no
allocator-specific flag is passed to kmem_cache_create(), so it seemed
to me it was no longer needed now that allocator-specific flags are gone.
Having said that, we could keep it in order to reject flags that are not
supposed to be passed to kmem_cache_create() (e.g. SLAB_SKIP_KFENCE).
With that approach we'd just need to clear SLAB_DEBUG_FLAGS below if
!CONFIG_SLUB_DEBUG (and get rid of CACHE_CREATE_MASK).
- Kevin
[1]
https://lore.kernel.org/all/1478553075-120242-2-git-send-email-thgarnie@google.com/
>> - /*
>> - * Some allocators will constraint the set of valid flags to a subset
>> - * of all flags. We expect them to define CACHE_CREATE_MASK in this
>> - * case, and we'll just provide them with a sanitized version of the
>> - * passed flags.
>> - */
>> flags &= CACHE_CREATE_MASK;
> This would silently clear some flags instead of creating an error.
On 1/21/25 11:46, Kevin Brodsky wrote:
> On 17/01/2025 23:13, Christoph Lameter (Ampere) wrote:
>> On Fri, 17 Jan 2025, Kevin Brodsky wrote:
>>
>>> index a29457bef626..3b07cdaac3ae 100644
>>> --- a/mm/slab_common.c
>>> +++ b/mm/slab_common.c
>>> @@ -305,18 +305,6 @@ struct kmem_cache *__kmem_cache_create_args(const char *name,
>>> goto out_unlock;
>>> }
>>>
>>> - /* Refuse requests with allocator specific flags */
>>> - if (flags & ~SLAB_FLAGS_PERMITTED) {
>>> - err = -EINVAL;
>>> - goto out_unlock;
>>> - }
>> I think we should keep checking for invalid flags.
>
> The commit that introduced this check [1] aimed to ensure that no
> allocator-specific flag is passed to kmem_cache_create(), so it seemed
> to me it was no longer needed now that allocator-specific flags are gone.
>
> Having said that, we could keep it in order to reject flags that are not
> supposed to be passed to kmem_cache_create() (e.g. SLAB_SKIP_KFENCE).
> With that approach we'd just need to clear SLAB_DEBUG_FLAGS below if
> !CONFIG_SLUB_DEBUG (and get rid of CACHE_CREATE_MASK).
Sounds like a good plan to me, thanks!
> - Kevin
>
> [1]
> https://lore.kernel.org/all/1478553075-120242-2-git-send-email-thgarnie@google.com/
>
>>> - /*
>>> - * Some allocators will constraint the set of valid flags to a subset
>>> - * of all flags. We expect them to define CACHE_CREATE_MASK in this
>>> - * case, and we'll just provide them with a sanitized version of the
>>> - * passed flags.
>>> - */
>>> flags &= CACHE_CREATE_MASK;
>> This would silently clear some flags instead of creating an error.
>
>
>
© 2016 - 2026 Red Hat, Inc.