Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4dcb4075 authored by Laura Abbott's avatar Laura Abbott Committed by Alexander Potapenko
Browse files

UPSTREAM: lib/test_meminit.c: add bulk alloc/free tests

Upstream commit dc5c5ad79f0c ("lib/test_meminit.c: add bulk alloc/free
tests").

kmem_cache_alloc_bulk/kmem_cache_free_bulk are used to make multiple
allocations of the same size to avoid the overhead of multiple
kmalloc/kfree calls.  Extend the kmem_cache tests to make some calls to
these APIs.

Link: http://lkml.kernel.org/r/20191107191447.23058-1-labbott@redhat.com


Signed-off-by: default avatarLaura Abbott <labbott@redhat.com>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Tested-by: default avatarAlexander Potapenko <glider@google.com>
Cc: Laura Abbott <labbott@redhat.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Kostya Serebryany <kcc@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Sandeep Patil <sspatil@android.com>
Cc: Jann Horn <jannh@google.com>
Cc: Marco Elver <elver@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>

Bug: 138435492
Test: Boot an ARM64 mobile device with and without init_on_alloc=1
Change-Id: I78e767949384359a00c9aaf893d725649bd1732c
Signed-off-by: default avatarAlexander Potapenko <glider@google.com>
parent 2689307b
Loading
Loading
Loading
Loading
+19 −1
Original line number Original line Diff line number Diff line
@@ -183,6 +183,9 @@ static bool __init check_buf(void *buf, int size, bool want_ctor,
	return fail;
	return fail;
}
}


#define BULK_SIZE 100
static void *bulk_array[BULK_SIZE];

/*
/*
 * Test kmem_cache with given parameters:
 * Test kmem_cache with given parameters:
 *  want_ctor - use a constructor;
 *  want_ctor - use a constructor;
@@ -203,9 +206,24 @@ static int __init do_kmem_cache_size(size_t size, bool want_ctor,
			      want_rcu ? SLAB_TYPESAFE_BY_RCU : 0,
			      want_rcu ? SLAB_TYPESAFE_BY_RCU : 0,
			      want_ctor ? test_ctor : NULL);
			      want_ctor ? test_ctor : NULL);
	for (iter = 0; iter < 10; iter++) {
	for (iter = 0; iter < 10; iter++) {
		/* Do a test of bulk allocations */
		if (!want_rcu && !want_ctor) {
			int ret;

			ret = kmem_cache_alloc_bulk(c, alloc_mask, BULK_SIZE, bulk_array);
			if (!ret) {
				fail = true;
			} else {
				int i;
				for (i = 0; i < ret; i++)
					fail |= check_buf(bulk_array[i], size, want_ctor, want_rcu, want_zero);
				kmem_cache_free_bulk(c, ret, bulk_array);
			}
		}

		buf = kmem_cache_alloc(c, alloc_mask);
		buf = kmem_cache_alloc(c, alloc_mask);
		/* Check that buf is zeroed, if it must be. */
		/* Check that buf is zeroed, if it must be. */
		fail = check_buf(buf, size, want_ctor, want_rcu, want_zero);
		fail |= check_buf(buf, size, want_ctor, want_rcu, want_zero);
		fill_with_garbage_skip(buf, size, want_ctor ? CTOR_BYTES : 0);
		fill_with_garbage_skip(buf, size, want_ctor ? CTOR_BYTES : 0);


		if (!want_rcu) {
		if (!want_rcu) {