Skip to content

Commit 8913c61

Browse files
Peng Liutorvalds
authored andcommitted
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/[email protected] Signed-off-by: Peng Liu <[email protected]> Reviewed-by: Marco Elver <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Sumit Semwal <[email protected]> Cc: Christian Knig <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 0764db9 commit 8913c61

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

include/linux/kfence.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <linux/atomic.h>
1818
#include <linux/static_key.h>
1919

20+
extern unsigned long kfence_sample_interval;
21+
2022
/*
2123
* We allocate an even number of pages, as it simplifies calculations to map
2224
* address to metadata indices; effectively, the very first page serves as an

mm/kfence/core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747

4848
static bool kfence_enabled __read_mostly;
4949

50-
static unsigned long kfence_sample_interval __read_mostly = CONFIG_KFENCE_SAMPLE_INTERVAL;
50+
unsigned long kfence_sample_interval __read_mostly = CONFIG_KFENCE_SAMPLE_INTERVAL;
51+
EXPORT_SYMBOL_GPL(kfence_sample_interval); /* Export for test modules. */
5152

5253
#ifdef MODULE_PARAM_PREFIX
5354
#undef MODULE_PARAM_PREFIX

mm/kfence/kfence_test.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,13 @@ static void *test_alloc(struct kunit *test, size_t size, gfp_t gfp, enum allocat
268268
* 100x the sample interval should be more than enough to ensure we get
269269
* a KFENCE allocation eventually.
270270
*/
271-
timeout = jiffies + msecs_to_jiffies(100 * CONFIG_KFENCE_SAMPLE_INTERVAL);
271+
timeout = jiffies + msecs_to_jiffies(100 * kfence_sample_interval);
272272
/*
273273
* Especially for non-preemption kernels, ensure the allocation-gate
274274
* timer can catch up: after @resched_after, every failed allocation
275275
* attempt yields, to ensure the allocation-gate timer is scheduled.
276276
*/
277-
resched_after = jiffies + msecs_to_jiffies(CONFIG_KFENCE_SAMPLE_INTERVAL);
277+
resched_after = jiffies + msecs_to_jiffies(kfence_sample_interval);
278278
do {
279279
if (test_cache)
280280
alloc = kmem_cache_alloc(test_cache, gfp);
@@ -608,7 +608,7 @@ static void test_gfpzero(struct kunit *test)
608608
int i;
609609

610610
/* Skip if we think it'd take too long. */
611-
KFENCE_TEST_REQUIRES(test, CONFIG_KFENCE_SAMPLE_INTERVAL <= 100);
611+
KFENCE_TEST_REQUIRES(test, kfence_sample_interval <= 100);
612612

613613
setup_test_cache(test, size, 0, NULL);
614614
buf1 = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY);
@@ -739,7 +739,7 @@ static void test_memcache_alloc_bulk(struct kunit *test)
739739
* 100x the sample interval should be more than enough to ensure we get
740740
* a KFENCE allocation eventually.
741741
*/
742-
timeout = jiffies + msecs_to_jiffies(100 * CONFIG_KFENCE_SAMPLE_INTERVAL);
742+
timeout = jiffies + msecs_to_jiffies(100 * kfence_sample_interval);
743743
do {
744744
void *objects[100];
745745
int i, num = kmem_cache_alloc_bulk(test_cache, GFP_ATOMIC, ARRAY_SIZE(objects),

0 commit comments

Comments
 (0)