aboutsummaryrefslogtreecommitdiffstats
path: root/lib/test_meminit.c
diff options
context:
space:
mode:
authorAlexander Potapenko <[email protected]>2019-10-14 21:12:00 +0000
committerLinus Torvalds <[email protected]>2019-10-14 22:04:01 +0000
commit03a9349ac0e095dea6ef8b5b7b14f9c23e5fabe6 (patch)
tree9bbea792d10ecc834bfa9a1efd8d94bc5a764c8f /lib/test_meminit.c
parentmm/slub.c: init_on_free=1 should wipe freelist ptr for bulk allocations (diff)
downloadkernel-03a9349ac0e095dea6ef8b5b7b14f9c23e5fabe6.tar.gz
kernel-03a9349ac0e095dea6ef8b5b7b14f9c23e5fabe6.zip
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]>
Diffstat (limited to 'lib/test_meminit.c')
-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:
return 1;
}
+static int __init do_kmem_cache_size_bulk(int size, int *total_failures)
+{
+ struct kmem_cache *c;
+ int i, iter, maxiter = 1024;
+ int num, bytes;
+ bool fail = false;
+ void *objects[10];
+
+ c = kmem_cache_create("test_cache", size, size, 0, NULL);
+ for (iter = 0; (iter < maxiter) && !fail; iter++) {
+ num = kmem_cache_alloc_bulk(c, GFP_KERNEL, ARRAY_SIZE(objects),
+ objects);
+ for (i = 0; i < num; i++) {
+ bytes = count_nonzero_bytes(objects[i], size);
+ if (bytes)
+ fail = true;
+ fill_with_garbage(objects[i], size);
+ }
+
+ if (num)
+ kmem_cache_free_bulk(c, num, objects);
+ }
+ *total_failures += fail;
+ return 1;
+}
+
/*
* Test kmem_cache allocation by creating caches of different sizes, with and
* without constructors, with and without SLAB_TYPESAFE_BY_RCU.
@@ -318,6 +344,7 @@ static int __init test_kmemcache(int *total_failures)
num_tests += do_kmem_cache_size(size, ctor, rcu, zero,
&failures);
}
+ num_tests += do_kmem_cache_size_bulk(size, &failures);
}
REPORT_FAILURES_IN_FN();
*total_failures += failures;