Skip to content

Commit 12f4888

Browse files
kevin-brodsky-armtehcaster
authored andcommitted
mm/slab: simplify SLAB_* flag handling
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 CACHE_CREATE_MASK and instead mask out SLAB_DEBUG_FLAGS if !CONFIG_SLUB_DEBUG. SLAB_DEBUG_FLAGS is now defined unconditionally (no impact on existing code, which ignores it if !CONFIG_SLUB_DEBUG). * Define SLAB_FLAGS_PERMITTED in terms of SLAB_CORE_FLAGS and SLAB_DEBUG_FLAGS (no functional change). While at it also remove misleading comments that suggest that multiple allocators are available. Signed-off-by: Kevin Brodsky <[email protected]> Reviewed-by: Hyeonggon Yoo <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent dfd3df3 commit 12f4888

File tree

2 files changed

+7
-36
lines changed

2 files changed

+7
-36
lines changed

mm/slab.h

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -457,39 +457,17 @@ static inline bool is_kmalloc_normal(struct kmem_cache *s)
457457
return !(s->flags & (SLAB_CACHE_DMA|SLAB_ACCOUNT|SLAB_RECLAIM_ACCOUNT));
458458
}
459459

460-
/* Legal flag mask for kmem_cache_create(), for various configurations */
461460
#define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | \
462461
SLAB_CACHE_DMA32 | SLAB_PANIC | \
463-
SLAB_TYPESAFE_BY_RCU | SLAB_DEBUG_OBJECTS )
462+
SLAB_TYPESAFE_BY_RCU | SLAB_DEBUG_OBJECTS | \
463+
SLAB_NOLEAKTRACE | SLAB_RECLAIM_ACCOUNT | \
464+
SLAB_TEMPORARY | SLAB_ACCOUNT | \
465+
SLAB_NO_USER_FLAGS | SLAB_KMALLOC | SLAB_NO_MERGE)
464466

465-
#ifdef CONFIG_SLUB_DEBUG
466467
#define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \
467468
SLAB_TRACE | SLAB_CONSISTENCY_CHECKS)
468-
#else
469-
#define SLAB_DEBUG_FLAGS (0)
470-
#endif
471469

472-
#define SLAB_CACHE_FLAGS (SLAB_NOLEAKTRACE | SLAB_RECLAIM_ACCOUNT | \
473-
SLAB_TEMPORARY | SLAB_ACCOUNT | \
474-
SLAB_NO_USER_FLAGS | SLAB_KMALLOC | SLAB_NO_MERGE)
475-
476-
/* Common flags available with current configuration */
477-
#define CACHE_CREATE_MASK (SLAB_CORE_FLAGS | SLAB_DEBUG_FLAGS | SLAB_CACHE_FLAGS)
478-
479-
/* Common flags permitted for kmem_cache_create */
480-
#define SLAB_FLAGS_PERMITTED (SLAB_CORE_FLAGS | \
481-
SLAB_RED_ZONE | \
482-
SLAB_POISON | \
483-
SLAB_STORE_USER | \
484-
SLAB_TRACE | \
485-
SLAB_CONSISTENCY_CHECKS | \
486-
SLAB_NOLEAKTRACE | \
487-
SLAB_RECLAIM_ACCOUNT | \
488-
SLAB_TEMPORARY | \
489-
SLAB_ACCOUNT | \
490-
SLAB_KMALLOC | \
491-
SLAB_NO_MERGE | \
492-
SLAB_NO_USER_FLAGS)
470+
#define SLAB_FLAGS_PERMITTED (SLAB_CORE_FLAGS | SLAB_DEBUG_FLAGS)
493471

494472
bool __kmem_cache_empty(struct kmem_cache *);
495473
int __kmem_cache_shutdown(struct kmem_cache *);

mm/slab_common.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ struct kmem_cache *__kmem_cache_create_args(const char *name,
298298
static_branch_enable(&slub_debug_enabled);
299299
if (flags & SLAB_STORE_USER)
300300
stack_depot_init();
301+
#else
302+
flags &= ~SLAB_DEBUG_FLAGS;
301303
#endif
302304

303305
mutex_lock(&slab_mutex);
@@ -307,20 +309,11 @@ struct kmem_cache *__kmem_cache_create_args(const char *name,
307309
goto out_unlock;
308310
}
309311

310-
/* Refuse requests with allocator specific flags */
311312
if (flags & ~SLAB_FLAGS_PERMITTED) {
312313
err = -EINVAL;
313314
goto out_unlock;
314315
}
315316

316-
/*
317-
* Some allocators will constraint the set of valid flags to a subset
318-
* of all flags. We expect them to define CACHE_CREATE_MASK in this
319-
* case, and we'll just provide them with a sanitized version of the
320-
* passed flags.
321-
*/
322-
flags &= CACHE_CREATE_MASK;
323-
324317
/* Fail closed on bad usersize of useroffset values. */
325318
if (!IS_ENABLED(CONFIG_HARDENED_USERCOPY) ||
326319
WARN_ON(!args->usersize && args->useroffset) ||

0 commit comments

Comments
 (0)