Skip to content

Commit 3f1dd33

Browse files
committed
mm, slab: suppress warnings in test_leak_destroy kunit test
The test_leak_destroy kunit test intends to test the detection of stray objects in kmem_cache_destroy(), which normally produces a warning. The other slab kunit tests suppress the warnings in the kunit test context, so suppress warnings and related printk output in this test as well. Automated test running environments then don't need to learn to filter the warnings. Also rename the test's kmem_cache, the name was wrongly copy-pasted from test_kfree_rcu. Fixes: 4e1c44b ("kunit, slub: add test_kfree_rcu() and test_leak_destroy()") Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-lkp/[email protected] Reported-by: Hyeonggon Yoo <[email protected]> Closes: https://lore.kernel.org/all/CAB=+i9RHHbfSkmUuLshXGY_ifEZg9vCZi3fqr99+kmmnpDus7Q@mail.gmail.com/ Reported-by: Guenter Roeck <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Tested-by: Guenter Roeck <[email protected]> Reviewed-by: Hyeonggon Yoo <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 3c5d61a commit 3f1dd33

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

lib/slub_kunit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ static void test_kfree_rcu(struct kunit *test)
177177

178178
static void test_leak_destroy(struct kunit *test)
179179
{
180-
struct kmem_cache *s = test_kmem_cache_create("TestSlub_kfree_rcu",
180+
struct kmem_cache *s = test_kmem_cache_create("TestSlub_leak_destroy",
181181
64, SLAB_NO_MERGE);
182182
kmem_cache_alloc(s, GFP_KERNEL);
183183

184184
kmem_cache_destroy(s);
185185

186-
KUNIT_EXPECT_EQ(test, 1, slab_errors);
186+
KUNIT_EXPECT_EQ(test, 2, slab_errors);
187187
}
188188

189189
static int test_init(struct kunit *test)

mm/slab.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,12 @@ static inline bool kmem_cache_debug_flags(struct kmem_cache *s, slab_flags_t fla
546546
return false;
547547
}
548548

549+
#if IS_ENABLED(CONFIG_SLUB_DEBUG) && IS_ENABLED(CONFIG_KUNIT)
550+
bool slab_in_kunit_test(void);
551+
#else
552+
static inline bool slab_in_kunit_test(void) { return false; }
553+
#endif
554+
549555
#ifdef CONFIG_SLAB_OBJ_EXT
550556

551557
/*

mm/slab_common.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,9 @@ void kmem_cache_destroy(struct kmem_cache *s)
508508
kasan_cache_shutdown(s);
509509

510510
err = __kmem_cache_shutdown(s);
511-
WARN(err, "%s %s: Slab cache still has objects when called from %pS",
512-
__func__, s->name, (void *)_RET_IP_);
511+
if (!slab_in_kunit_test())
512+
WARN(err, "%s %s: Slab cache still has objects when called from %pS",
513+
__func__, s->name, (void *)_RET_IP_);
513514

514515
list_del(&s->list);
515516

mm/slub.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ static bool slab_add_kunit_errors(void)
827827
return true;
828828
}
829829

830-
static bool slab_in_kunit_test(void)
830+
bool slab_in_kunit_test(void)
831831
{
832832
struct kunit_resource *resource;
833833

@@ -843,7 +843,6 @@ static bool slab_in_kunit_test(void)
843843
}
844844
#else
845845
static inline bool slab_add_kunit_errors(void) { return false; }
846-
static inline bool slab_in_kunit_test(void) { return false; }
847846
#endif
848847

849848
static inline unsigned int size_from_object(struct kmem_cache *s)
@@ -5436,6 +5435,8 @@ static void list_slab_objects(struct kmem_cache *s, struct slab *slab,
54365435
for_each_object(p, s, addr, slab->objects) {
54375436

54385437
if (!test_bit(__obj_to_index(s, addr, p), object_map)) {
5438+
if (slab_add_kunit_errors())
5439+
continue;
54395440
pr_err("Object 0x%p @offset=%tu\n", p, p - addr);
54405441
print_tracking(s, p);
54415442
}

0 commit comments

Comments
 (0)