/* * Wrapper function for kmem_cache_create(), which reduces 2 parameters: * 'align' and 'ctor', and sets SLAB_SKIP_KFENCE flag to avoid getting an * object from kfence pool, where the operation could be caught by both * our test and kfence sanity check.
*/ staticstruct kmem_cache *test_kmem_cache_create(constchar *name, unsignedint size, slab_flags_t flags)
{ struct kmem_cache *s = kmem_cache_create(name, size, 0,
(flags | SLAB_NO_USER_FLAGS), NULL);
s->flags |= SLAB_SKIP_KFENCE; return s;
}
/* * Expecting three errors. * One for the corrupted freechain and the other one for the wrong * count of objects in use. The third error is fixing broken cache.
*/
validate_slab_cache(s);
KUNIT_EXPECT_EQ(test, 3, slab_errors);
/* * Try to repair corrupted freepointer. * Still expecting two errors. The first for the wrong count * of objects in use. * The second error is for fixing broken cache.
*/
*ptr_addr = tmp;
slab_errors = 0;
/* * Previous validation repaired the count of objects in use. * Now expecting no error.
*/
slab_errors = 0;
validate_slab_cache(s);
KUNIT_EXPECT_EQ(test, 0, slab_errors);
for (i = 0; i < KMEM_CACHE_DESTROY_NR; i++) {
s = test_kmem_cache_create("TestSlub_kfree_rcu_wq_destroy", sizeof(struct test_kfree_rcu_struct),
SLAB_NO_MERGE);
if (!s)
kunit_skip(test, "failed to create cache");
delay = get_random_u8();
p = kmem_cache_alloc(s, GFP_KERNEL);
kfree_rcu(p, rcu);
p = alloc_hooks(__kmalloc_cache_noprof(s, GFP_KERNEL, 48));
memset(p, 0xff, 48);
kasan_disable_current();
OPTIMIZER_HIDE_VAR(p);
/* Test shrink */
p = krealloc(p, 40, GFP_KERNEL | __GFP_ZERO); for (i = 40; i < 64; i++)
KUNIT_EXPECT_EQ(test, p[i], SLUB_RED_ACTIVE);
/* Test grow within the same 64B kmalloc object */
p = krealloc(p, 56, GFP_KERNEL | __GFP_ZERO); for (i = 40; i < 56; i++)
KUNIT_EXPECT_EQ(test, p[i], 0); for (i = 56; i < 64; i++)
KUNIT_EXPECT_EQ(test, p[i], SLUB_RED_ACTIVE);
memset(p, 0xff, 56); /* Test grow with allocating a bigger 128B object */
p = krealloc(p, 112, GFP_KERNEL | __GFP_ZERO); for (i = 0; i < 56; i++)
KUNIT_EXPECT_EQ(test, p[i], 0xff); for (i = 56; i < 112; i++)
KUNIT_EXPECT_EQ(test, p[i], 0);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.