Skip to content

Commit 80d4c47

Browse files
melverIngo Molnar
authored andcommitted
kcsan: Expose core configuration parameters as module params
This adds early_boot, udelay_{task,interrupt}, and skip_watch as module params. The latter parameters are useful to modify at runtime to tune KCSAN's performance on new systems. This will also permit auto-tuning these parameters to maximize overall system performance and KCSAN's race detection ability. None of the parameters are used in the fast-path and referring to them via static variables instead of CONFIG constants will not affect performance. Signed-off-by: Marco Elver <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Qian Cai <[email protected]>
1 parent a312013 commit 80d4c47

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

kernel/kcsan/core.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/export.h>
77
#include <linux/init.h>
88
#include <linux/kernel.h>
9+
#include <linux/moduleparam.h>
910
#include <linux/percpu.h>
1011
#include <linux/preempt.h>
1112
#include <linux/random.h>
@@ -16,6 +17,20 @@
1617
#include "encoding.h"
1718
#include "kcsan.h"
1819

20+
static bool kcsan_early_enable = IS_ENABLED(CONFIG_KCSAN_EARLY_ENABLE);
21+
static unsigned int kcsan_udelay_task = CONFIG_KCSAN_UDELAY_TASK;
22+
static unsigned int kcsan_udelay_interrupt = CONFIG_KCSAN_UDELAY_INTERRUPT;
23+
static long kcsan_skip_watch = CONFIG_KCSAN_SKIP_WATCH;
24+
25+
#ifdef MODULE_PARAM_PREFIX
26+
#undef MODULE_PARAM_PREFIX
27+
#endif
28+
#define MODULE_PARAM_PREFIX "kcsan."
29+
module_param_named(early_enable, kcsan_early_enable, bool, 0);
30+
module_param_named(udelay_task, kcsan_udelay_task, uint, 0644);
31+
module_param_named(udelay_interrupt, kcsan_udelay_interrupt, uint, 0644);
32+
module_param_named(skip_watch, kcsan_skip_watch, long, 0644);
33+
1934
bool kcsan_enabled;
2035

2136
/* Per-CPU kcsan_ctx for interrupts */
@@ -239,9 +254,9 @@ should_watch(const volatile void *ptr, size_t size, int type)
239254

240255
static inline void reset_kcsan_skip(void)
241256
{
242-
long skip_count = CONFIG_KCSAN_SKIP_WATCH -
257+
long skip_count = kcsan_skip_watch -
243258
(IS_ENABLED(CONFIG_KCSAN_SKIP_WATCH_RANDOMIZE) ?
244-
prandom_u32_max(CONFIG_KCSAN_SKIP_WATCH) :
259+
prandom_u32_max(kcsan_skip_watch) :
245260
0);
246261
this_cpu_write(kcsan_skip, skip_count);
247262
}
@@ -253,8 +268,7 @@ static __always_inline bool kcsan_is_enabled(void)
253268

254269
static inline unsigned int get_delay(void)
255270
{
256-
unsigned int delay = in_task() ? CONFIG_KCSAN_UDELAY_TASK :
257-
CONFIG_KCSAN_UDELAY_INTERRUPT;
271+
unsigned int delay = in_task() ? kcsan_udelay_task : kcsan_udelay_interrupt;
258272
return delay - (IS_ENABLED(CONFIG_KCSAN_DELAY_RANDOMIZE) ?
259273
prandom_u32_max(delay) :
260274
0);
@@ -527,7 +541,7 @@ void __init kcsan_init(void)
527541
* We are in the init task, and no other tasks should be running;
528542
* WRITE_ONCE without memory barrier is sufficient.
529543
*/
530-
if (IS_ENABLED(CONFIG_KCSAN_EARLY_ENABLE))
544+
if (kcsan_early_enable)
531545
WRITE_ONCE(kcsan_enabled, true);
532546
}
533547

0 commit comments

Comments
 (0)