kernel_optimize_test/kernel/kcsan
Marco Elver 7e8cad8788 kcsan: Rewrite kcsan_prandom_u32_max() without prandom_u32_state()
[ Upstream commit 71a076f4a61a6c779794ad286f356b39725edc3b ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-03-04 11:37:37 +01: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-03-04 11:37:37 +01:00
debugfs.c kcsan: Optimize debugfs stats counters 2020-08-24 15:10:23 -07:00
encoding.h kernel/: fix repeated words in comments 2020-10-16 11:11:19 -07: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: Use pr_fmt for consistency 2020-08-24 15:10:23 -07:00