Skip to content

Commit 86169b0

Browse files
committed
slab: wrap debug slab validation in validate_slab_ptr()
This will make it clear where we currently cast struct slab to folio only to check the slab type, and allow to change the implementation later with memdesc conversion. For now use a struct page based implementation instead of struct folio to be compatible with further upcoming changes. Reviewed-by: Harry Yoo <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent f4930de commit 86169b0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

mm/slub.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,15 @@ static inline unsigned int get_orig_size(struct kmem_cache *s, void *object)
821821
return *(unsigned int *)p;
822822
}
823823

824+
/*
825+
* For debugging context when we want to check if the struct slab pointer
826+
* appears to be valid.
827+
*/
828+
static inline bool validate_slab_ptr(struct slab *slab)
829+
{
830+
return PageSlab(slab_page(slab));
831+
}
832+
824833
#ifdef CONFIG_SLUB_DEBUG
825834
static unsigned long object_map[BITS_TO_LONGS(MAX_OBJS_PER_PAGE)];
826835
static DEFINE_SPINLOCK(object_map_lock);
@@ -1453,7 +1462,7 @@ static int check_slab(struct kmem_cache *s, struct slab *slab)
14531462
{
14541463
int maxobj;
14551464

1456-
if (!folio_test_slab(slab_folio(slab))) {
1465+
if (!validate_slab_ptr(slab)) {
14571466
slab_err(s, slab, "Not a valid slab page");
14581467
return 0;
14591468
}
@@ -1653,7 +1662,7 @@ static noinline bool alloc_debug_processing(struct kmem_cache *s,
16531662
return true;
16541663

16551664
bad:
1656-
if (folio_test_slab(slab_folio(slab))) {
1665+
if (validate_slab_ptr(slab)) {
16571666
/*
16581667
* If this is a slab page then lets do the best we can
16591668
* to avoid issues in the future. Marking all objects
@@ -2818,7 +2827,7 @@ static void *alloc_single_from_partial(struct kmem_cache *s,
28182827
slab->inuse++;
28192828

28202829
if (!alloc_debug_processing(s, slab, object, orig_size)) {
2821-
if (folio_test_slab(slab_folio(slab)))
2830+
if (validate_slab_ptr(slab))
28222831
remove_partial(n, slab);
28232832
return NULL;
28242833
}

0 commit comments

Comments
 (0)