Commit 1a2ea802 authored by Peng Liu's avatar Peng Liu Committed by Zheng Zengkai
Browse files

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

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I4V388


CVE: NA

--------------------------------

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.

Signed-off-by: default avatarPeng Liu <liupeng256@huawei.com>
Reviewed-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 901b983c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
#include <linux/atomic.h>
#include <linux/static_key.h>

extern unsigned long kfence_sample_interval;

#ifdef CONFIG_KFENCE_DYNAMIC_OBJECTS
extern unsigned long kfence_num_objects;
#define KFENCE_NR_OBJECTS kfence_num_objects
+2 −1
Original line number Diff line number Diff line
@@ -47,7 +47,8 @@

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
#undef MODULE_PARAM_PREFIX
+4 −4
Original line number Diff line number Diff line
@@ -263,13 +263,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
	 * 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
	 * timer can catch up: after @resched_after, every failed allocation
	 * 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 {
		if (test_cache)
			alloc = kmem_cache_alloc(test_cache, gfp);
@@ -603,7 +603,7 @@ static void test_gfpzero(struct kunit *test)
	char *buf1, *buf2;
	int i;

	if (CONFIG_KFENCE_SAMPLE_INTERVAL > 100) {
	if (kfence_sample_interval > 100) {
		kunit_warn(test, "skipping ... would take too long\n");
		return;
	}
@@ -737,7 +737,7 @@ static void test_memcache_alloc_bulk(struct kunit *test)
	 * 100x the sample interval should be more than enough to ensure we get
	 * a KFENCE allocation eventually.
	 */
	timeout = jiffies + msecs_to_jiffies(100 * CONFIG_KFENCE_SAMPLE_INTERVAL);
	timeout = jiffies + msecs_to_jiffies(100 * kfence_sample_interval);
	do {
		void *objects[100];
		int i, num = kmem_cache_alloc_bulk(test_cache, GFP_ATOMIC, ARRAY_SIZE(objects),