Skip to content

Commit f5d2313

Browse files
melverIngo Molnar
authored andcommitted
kcsan, trace: Make KCSAN compatible with tracing
Previously the system would lock up if ftrace was enabled together with KCSAN. This is due to recursion on reporting if the tracer code is instrumented with KCSAN. To avoid this for all types of tracing, disable KCSAN instrumentation for all of kernel/trace. Furthermore, since KCSAN relies on udelay() to introduce delay, we have to disable ftrace for udelay() (currently done for x86) in case KCSAN is used together with lockdep and ftrace. The reason is that it may corrupt lockdep IRQ flags tracing state due to a peculiar case of recursion (details in Makefile comment). Reported-by: Qian Cai <[email protected]> Tested-by: Qian Cai <[email protected]> Acked-by: Steven Rostedt (VMware) <[email protected]> Signed-off-by: Marco Elver <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent 703b321 commit f5d2313

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

arch/x86/lib/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ KCOV_INSTRUMENT_delay.o := n
88

99
# KCSAN uses udelay for introducing watchpoint delay; avoid recursion.
1010
KCSAN_SANITIZE_delay.o := n
11+
ifdef CONFIG_KCSAN
12+
# In case KCSAN+lockdep+ftrace are enabled, disable ftrace for delay.o to avoid
13+
# lockdep -> [other libs] -> KCSAN -> udelay -> ftrace -> lockdep recursion.
14+
CFLAGS_REMOVE_delay.o = $(CC_FLAGS_FTRACE)
15+
endif
1116

1217
# Early boot use of cmdline; don't instrument it
1318
ifdef CONFIG_AMD_MEM_ENCRYPT

kernel/kcsan/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ KCOV_INSTRUMENT := n
44
UBSAN_SANITIZE := n
55

66
CFLAGS_REMOVE_core.o = $(CC_FLAGS_FTRACE)
7+
CFLAGS_REMOVE_debugfs.o = $(CC_FLAGS_FTRACE)
8+
CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE)
79

810
CFLAGS_core.o := $(call cc-option,-fno-conserve-stack,) \
911
$(call cc-option,-fno-stack-protector,)

kernel/trace/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ ifdef CONFIG_FUNCTION_TRACER
66
ORIG_CFLAGS := $(KBUILD_CFLAGS)
77
KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
88

9+
# Avoid recursion due to instrumentation.
10+
KCSAN_SANITIZE := n
11+
912
ifdef CONFIG_FTRACE_SELFTEST
1013
# selftest needs instrumentation
1114
CFLAGS_trace_selftest_dynamic.o = $(CC_FLAGS_FTRACE)

0 commit comments

Comments
 (0)