linux/kernel/kcsan
Marco Elver 71a076f4a6 kcsan: Rewrite kcsan_prandom_u32_max() without prandom_u32_state()
Rewrite kcsan_prandom_u32_max() to not depend on code that might be
instrumented, removing any dependency on lib/random32.c. The rewrite
implements a simple linear congruential generator, that is sufficient
for our purposes (for udelay() and skip_watch counter randomness).

The initial motivation for this was to allow enabling KCSAN for
kernel/sched (remove KCSAN_SANITIZE := n from kernel/sched/Makefile),
with CONFIG_DEBUG_PREEMPT=y. Without this change, we could observe
recursion:

	check_access() [via instrumentation]
	  kcsan_setup_watchpoint()
	    reset_kcsan_skip()
	      kcsan_prandom_u32_max()
	        get_cpu_var()
		  preempt_disable()
		    preempt_count_add() [in kernel/sched/core.c]
		      check_access() [via instrumentation]

Note, while this currently does not affect an unmodified kernel, it'd be
good to keep a KCSAN kernel working when KCSAN_SANITIZE := n is removed
from kernel/sched/Makefile to permit testing scheduler code with KCSAN
if desired.

Fixes: cd290ec246 ("kcsan: Use tracing-safe version of prandom")
Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
2021-01-04 14:39:07 -08:00
..
atomic.h kcsan: Remove existing special atomic rules 2020-06-29 12:04:48 -07:00
core.c kcsan: Rewrite kcsan_prandom_u32_max() without prandom_u32_state() 2021-01-04 14:39:07 -08:00
debugfs.c kcsan: Optimize debugfs stats counters 2020-08-24 15:10:23 -07:00
encoding.h kcsan: Fix encoding masks and regain address bit 2020-11-06 17:19:26 -08:00
kcsan-test.c kcsan: Test support for compound instrumentation 2020-08-24 15:09:58 -07:00
kcsan.h kcsan: Optimize debugfs stats counters 2020-08-24 15:10:23 -07:00
Makefile kcsan: Disable branch tracing in core runtime 2020-06-29 12:04:48 -07:00
report.c kcsan: Optimize debugfs stats counters 2020-08-24 15:10:23 -07:00
selftest.c kcsan: selftest: Ensure that address is at least PAGE_SIZE 2020-11-02 17:08:50 -08:00