Commit 8913c610 authored by Peng Liu's avatar Peng Liu Committed by Linus Torvalds

kfence: make test case compatible with run time set sample interval

The parameter kfence_sample_interval can be set via boot parameter and
late shell command, which is convenient for automated tests and KFENCE
parameter optimization.  However, KFENCE test case just uses
compile-time CONFIG_KFENCE_SAMPLE_INTERVAL, which will make KFENCE test
case not run as users desired.  Export kfence_sample_interval, so that
KFENCE test case can use run-time-set sample interval.

Link: https://lkml.kernel.org/r/20220207034432.185532-1-liupeng256@huawei.comSigned-off-by: default avatarPeng Liu <liupeng256@huawei.com>
Reviewed-by: default avatarMarco Elver <elver@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: Christian Knig <christian.koenig@amd.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 0764db9b
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <linux/atomic.h> #include <linux/atomic.h>
#include <linux/static_key.h> #include <linux/static_key.h>
extern unsigned long kfence_sample_interval;
/* /*
* We allocate an even number of pages, as it simplifies calculations to map * We allocate an even number of pages, as it simplifies calculations to map
* address to metadata indices; effectively, the very first page serves as an * address to metadata indices; effectively, the very first page serves as an
......
...@@ -47,7 +47,8 @@ ...@@ -47,7 +47,8 @@
static bool kfence_enabled __read_mostly; static bool kfence_enabled __read_mostly;
static unsigned long kfence_sample_interval __read_mostly = CONFIG_KFENCE_SAMPLE_INTERVAL; unsigned long kfence_sample_interval __read_mostly = CONFIG_KFENCE_SAMPLE_INTERVAL;
EXPORT_SYMBOL_GPL(kfence_sample_interval); /* Export for test modules. */
#ifdef MODULE_PARAM_PREFIX #ifdef MODULE_PARAM_PREFIX
#undef MODULE_PARAM_PREFIX #undef MODULE_PARAM_PREFIX
......
...@@ -268,13 +268,13 @@ static void *test_alloc(struct kunit *test, size_t size, gfp_t gfp, enum allocat ...@@ -268,13 +268,13 @@ static void *test_alloc(struct kunit *test, size_t size, gfp_t gfp, enum allocat
* 100x the sample interval should be more than enough to ensure we get * 100x the sample interval should be more than enough to ensure we get
* a KFENCE allocation eventually. * a KFENCE allocation eventually.
*/ */
timeout = jiffies + msecs_to_jiffies(100 * CONFIG_KFENCE_SAMPLE_INTERVAL); timeout = jiffies + msecs_to_jiffies(100 * kfence_sample_interval);
/* /*
* Especially for non-preemption kernels, ensure the allocation-gate * Especially for non-preemption kernels, ensure the allocation-gate
* timer can catch up: after @resched_after, every failed allocation * timer can catch up: after @resched_after, every failed allocation
* attempt yields, to ensure the allocation-gate timer is scheduled. * attempt yields, to ensure the allocation-gate timer is scheduled.
*/ */
resched_after = jiffies + msecs_to_jiffies(CONFIG_KFENCE_SAMPLE_INTERVAL); resched_after = jiffies + msecs_to_jiffies(kfence_sample_interval);
do { do {
if (test_cache) if (test_cache)
alloc = kmem_cache_alloc(test_cache, gfp); alloc = kmem_cache_alloc(test_cache, gfp);
...@@ -608,7 +608,7 @@ static void test_gfpzero(struct kunit *test) ...@@ -608,7 +608,7 @@ static void test_gfpzero(struct kunit *test)
int i; int i;
/* Skip if we think it'd take too long. */ /* Skip if we think it'd take too long. */
KFENCE_TEST_REQUIRES(test, CONFIG_KFENCE_SAMPLE_INTERVAL <= 100); KFENCE_TEST_REQUIRES(test, kfence_sample_interval <= 100);
setup_test_cache(test, size, 0, NULL); setup_test_cache(test, size, 0, NULL);
buf1 = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); buf1 = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY);
...@@ -739,7 +739,7 @@ static void test_memcache_alloc_bulk(struct kunit *test) ...@@ -739,7 +739,7 @@ static void test_memcache_alloc_bulk(struct kunit *test)
* 100x the sample interval should be more than enough to ensure we get * 100x the sample interval should be more than enough to ensure we get
* a KFENCE allocation eventually. * a KFENCE allocation eventually.
*/ */
timeout = jiffies + msecs_to_jiffies(100 * CONFIG_KFENCE_SAMPLE_INTERVAL); timeout = jiffies + msecs_to_jiffies(100 * kfence_sample_interval);
do { do {
void *objects[100]; void *objects[100];
int i, num = kmem_cache_alloc_bulk(test_cache, GFP_ATOMIC, ARRAY_SIZE(objects), int i, num = kmem_cache_alloc_bulk(test_cache, GFP_ATOMIC, ARRAY_SIZE(objects),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment