slab: pass struct kmem_cache_args to create_cache()

Pass struct kmem_cache_args to create_cache() so that we can later
simplify further helpers.

Reviewed-by: Kees Cook <kees@kernel.org>
Reviewed-by: Jens Axboe <axboe@kernel.dk>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
This commit is contained in:
Christian Brauner 2024-09-05 09:56:49 +02:00 committed by Vlastimil Babka
parent 1d3d7645d7
commit 34410a9060

View File

@ -202,22 +202,22 @@ struct kmem_cache *find_mergeable(unsigned int size, unsigned int align,
} }
static struct kmem_cache *create_cache(const char *name, static struct kmem_cache *create_cache(const char *name,
unsigned int object_size, unsigned int freeptr_offset, unsigned int object_size,
unsigned int align, slab_flags_t flags, struct kmem_cache_args *args,
unsigned int useroffset, unsigned int usersize, slab_flags_t flags)
void (*ctor)(void *))
{ {
struct kmem_cache *s; struct kmem_cache *s;
int err; int err;
if (WARN_ON(useroffset + usersize > object_size)) if (WARN_ON(args->useroffset + args->usersize > object_size))
useroffset = usersize = 0; args->useroffset = args->usersize = 0;
/* If a custom freelist pointer is requested make sure it's sane. */ /* If a custom freelist pointer is requested make sure it's sane. */
err = -EINVAL; err = -EINVAL;
if (freeptr_offset != UINT_MAX && if (args->use_freeptr_offset &&
(freeptr_offset >= object_size || !(flags & SLAB_TYPESAFE_BY_RCU) || (args->freeptr_offset >= object_size ||
!IS_ALIGNED(freeptr_offset, sizeof(freeptr_t)))) !(flags & SLAB_TYPESAFE_BY_RCU) ||
!IS_ALIGNED(args->freeptr_offset, sizeof(freeptr_t))))
goto out; goto out;
err = -ENOMEM; err = -ENOMEM;
@ -227,12 +227,15 @@ static struct kmem_cache *create_cache(const char *name,
s->name = name; s->name = name;
s->size = s->object_size = object_size; s->size = s->object_size = object_size;
s->rcu_freeptr_offset = freeptr_offset; if (args->use_freeptr_offset)
s->align = align; s->rcu_freeptr_offset = args->freeptr_offset;
s->ctor = ctor; else
s->rcu_freeptr_offset = UINT_MAX;
s->align = args->align;
s->ctor = args->ctor;
#ifdef CONFIG_HARDENED_USERCOPY #ifdef CONFIG_HARDENED_USERCOPY
s->useroffset = useroffset; s->useroffset = args->useroffset;
s->usersize = usersize; s->usersize = args->usersize;
#endif #endif
err = do_kmem_cache_create(s, flags); err = do_kmem_cache_create(s, flags);
if (err) if (err)
@ -265,7 +268,6 @@ struct kmem_cache *__kmem_cache_create_args(const char *name,
slab_flags_t flags) slab_flags_t flags)
{ {
struct kmem_cache *s = NULL; struct kmem_cache *s = NULL;
unsigned int freeptr_offset = UINT_MAX;
const char *cache_name; const char *cache_name;
int err; int err;
@ -323,11 +325,8 @@ struct kmem_cache *__kmem_cache_create_args(const char *name,
goto out_unlock; goto out_unlock;
} }
if (args->use_freeptr_offset) args->align = calculate_alignment(flags, args->align, object_size);
freeptr_offset = args->freeptr_offset; s = create_cache(cache_name, object_size, args, flags);
s = create_cache(cache_name, object_size, freeptr_offset,
calculate_alignment(flags, args->align, object_size),
flags, args->useroffset, args->usersize, args->ctor);
if (IS_ERR(s)) { if (IS_ERR(s)) {
err = PTR_ERR(s); err = PTR_ERR(s);
kfree_const(cache_name); kfree_const(cache_name);