summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Potapenko <glider@google.com>2019-10-14 17:12:00 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-10-14 18:04:01 -0400
commit03a9349ac0e095dea6ef8b5b7b14f9c23e5fabe6 (patch)
tree9bbea792d10ecc834bfa9a1efd8d94bc5a764c8f
parent0f181f9fbea8bc7ea2f7e13ae7f8c256b39e254c (diff)
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/20191007091605.30530-2-glider@google.com Signed-off-by: Alexander Potapenko <glider@google.com> Cc: Kees Cook <keescook@chromium.org> Cc: Christoph Lameter <cl@linux.com> Cc: Laura Abbott <labbott@redhat.com> Cc: Thibaut Sautereau <thibaut@sautereau.fr> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--lib/test_meminit.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/test_meminit.c b/lib/test_meminit.c
index 9729f271d150..9742e5cb853a 100644
--- a/lib/test_meminit.c
+++ b/lib/test_meminit.c
@@ -297,6 +297,32 @@ out:
297 return 1; 297 return 1;
298} 298}
299 299
300static 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
300/* 326/*
301 * Test kmem_cache allocation by creating caches of different sizes, with and 327 * Test kmem_cache allocation by creating caches of different sizes, with and
302 * without constructors, with and without SLAB_TYPESAFE_BY_RCU. 328 * without constructors, with and without SLAB_TYPESAFE_BY_RCU.
@@ -318,6 +344,7 @@ static int __init test_kmemcache(int *total_failures)
318 num_tests += do_kmem_cache_size(size, ctor, rcu, zero, 344 num_tests += do_kmem_cache_size(size, ctor, rcu, zero,
319 &failures); 345 &failures);
320 } 346 }
347 num_tests += do_kmem_cache_size_bulk(size, &failures);
321 } 348 }
322 REPORT_FAILURES_IN_FN(); 349 REPORT_FAILURES_IN_FN();
323 *total_failures += failures; 350 *total_failures += failures;