Skip to content

Commit 03a9349

Browse files
ramosian-glidertorvalds
authored andcommitted
lib/test_meminit: add a kmem_cache_alloc_bulk() test
Make sure allocations from kmem_cache_alloc_bulk() and kmem_cache_free_bulk() are properly initialized. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Alexander Potapenko <[email protected]> Cc: Kees Cook <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: Laura Abbott <[email protected]> Cc: Thibaut Sautereau <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 0f181f9 commit 03a9349

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lib/test_meminit.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,32 @@ static int __init do_kmem_cache_rcu_persistent(int size, int *total_failures)
297297
return 1;
298298
}
299299

300+
static int __init do_kmem_cache_size_bulk(int size, int *total_failures)
301+
{
302+
struct kmem_cache *c;
303+
int i, iter, maxiter = 1024;
304+
int num, bytes;
305+
bool fail = false;
306+
void *objects[10];
307+
308+
c = kmem_cache_create("test_cache", size, size, 0, NULL);
309+
for (iter = 0; (iter < maxiter) && !fail; iter++) {
310+
num = kmem_cache_alloc_bulk(c, GFP_KERNEL, ARRAY_SIZE(objects),
311+
objects);
312+
for (i = 0; i < num; i++) {
313+
bytes = count_nonzero_bytes(objects[i], size);
314+
if (bytes)
315+
fail = true;
316+
fill_with_garbage(objects[i], size);
317+
}
318+
319+
if (num)
320+
kmem_cache_free_bulk(c, num, objects);
321+
}
322+
*total_failures += fail;
323+
return 1;
324+
}
325+
300326
/*
301327
* Test kmem_cache allocation by creating caches of different sizes, with and
302328
* without constructors, with and without SLAB_TYPESAFE_BY_RCU.
@@ -318,6 +344,7 @@ static int __init test_kmemcache(int *total_failures)
318344
num_tests += do_kmem_cache_size(size, ctor, rcu, zero,
319345
&failures);
320346
}
347+
num_tests += do_kmem_cache_size_bulk(size, &failures);
321348
}
322349
REPORT_FAILURES_IN_FN();
323350
*total_failures += failures;

0 commit comments

Comments
 (0)