Skip to content

Commit dacf472

Browse files
braunertehcaster
authored andcommitted
slab: remove rcu_freeptr_offset from struct kmem_cache
Pass down struct kmem_cache_args to calculate_sizes() so we can use args->{use}_freeptr_offset directly. This allows us to remove ->rcu_freeptr_offset from struct kmem_cache. Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Jens Axboe <[email protected]> Reviewed-by: Mike Rapoport (Microsoft) <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Signed-off-by: Christian Brauner <[email protected]> Reviewed-by: Roman Gushchin <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 3dbe2ba commit dacf472

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

mm/slab.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,6 @@ struct kmem_cache {
261261
unsigned int object_size; /* Object size without metadata */
262262
struct reciprocal_value reciprocal_size;
263263
unsigned int offset; /* Free pointer offset */
264-
/* Specific free pointer requested (if not UINT_MAX) */
265-
unsigned int rcu_freeptr_offset;
266264
#ifdef CONFIG_SLUB_CPU_PARTIAL
267265
/* Number of per cpu partial objects to keep around */
268266
unsigned int cpu_partial;

mm/slub.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3916,8 +3916,7 @@ static void *__slab_alloc_node(struct kmem_cache *s,
39163916
* If the object has been wiped upon free, make sure it's fully initialized by
39173917
* zeroing out freelist pointer.
39183918
*
3919-
* Note that we also wipe custom freelist pointers specified via
3920-
* s->rcu_freeptr_offset.
3919+
* Note that we also wipe custom freelist pointers.
39213920
*/
39223921
static __always_inline void maybe_wipe_obj_freeptr(struct kmem_cache *s,
39233922
void *obj)
@@ -5141,17 +5140,11 @@ static void set_cpu_partial(struct kmem_cache *s)
51415140
#endif
51425141
}
51435142

5144-
/* Was a valid freeptr offset requested? */
5145-
static inline bool has_freeptr_offset(const struct kmem_cache *s)
5146-
{
5147-
return s->rcu_freeptr_offset != UINT_MAX;
5148-
}
5149-
51505143
/*
51515144
* calculate_sizes() determines the order and the distribution of data within
51525145
* a slab object.
51535146
*/
5154-
static int calculate_sizes(struct kmem_cache *s)
5147+
static int calculate_sizes(struct kmem_cache_args *args, struct kmem_cache *s)
51555148
{
51565149
slab_flags_t flags = s->flags;
51575150
unsigned int size = s->object_size;
@@ -5192,7 +5185,7 @@ static int calculate_sizes(struct kmem_cache *s)
51925185
*/
51935186
s->inuse = size;
51945187

5195-
if (((flags & SLAB_TYPESAFE_BY_RCU) && !has_freeptr_offset(s)) ||
5188+
if (((flags & SLAB_TYPESAFE_BY_RCU) && !args->use_freeptr_offset) ||
51965189
(flags & SLAB_POISON) || s->ctor ||
51975190
((flags & SLAB_RED_ZONE) &&
51985191
(s->object_size < sizeof(void *) || slub_debug_orig_size(s)))) {
@@ -5214,8 +5207,8 @@ static int calculate_sizes(struct kmem_cache *s)
52145207
*/
52155208
s->offset = size;
52165209
size += sizeof(void *);
5217-
} else if ((flags & SLAB_TYPESAFE_BY_RCU) && has_freeptr_offset(s)) {
5218-
s->offset = s->rcu_freeptr_offset;
5210+
} else if ((flags & SLAB_TYPESAFE_BY_RCU) && args->use_freeptr_offset) {
5211+
s->offset = args->freeptr_offset;
52195212
} else {
52205213
/*
52215214
* Store freelist pointer near middle of object to keep
@@ -5856,18 +5849,14 @@ int do_kmem_cache_create(struct kmem_cache *s, const char *name,
58565849
#ifdef CONFIG_SLAB_FREELIST_HARDENED
58575850
s->random = get_random_long();
58585851
#endif
5859-
if (args->use_freeptr_offset)
5860-
s->rcu_freeptr_offset = args->freeptr_offset;
5861-
else
5862-
s->rcu_freeptr_offset = UINT_MAX;
58635852
s->align = args->align;
58645853
s->ctor = args->ctor;
58655854
#ifdef CONFIG_HARDENED_USERCOPY
58665855
s->useroffset = args->useroffset;
58675856
s->usersize = args->usersize;
58685857
#endif
58695858

5870-
if (!calculate_sizes(s))
5859+
if (!calculate_sizes(args, s))
58715860
goto out;
58725861
if (disable_higher_order_debug) {
58735862
/*
@@ -5877,7 +5866,7 @@ int do_kmem_cache_create(struct kmem_cache *s, const char *name,
58775866
if (get_order(s->size) > get_order(s->object_size)) {
58785867
s->flags &= ~DEBUG_METADATA_FLAGS;
58795868
s->offset = 0;
5880-
if (!calculate_sizes(s))
5869+
if (!calculate_sizes(args, s))
58815870
goto out;
58825871
}
58835872
}

0 commit comments

Comments
 (0)