Skip to contentSkip to conversation

kcsan, trace: Make KCSAN compatible with tracing

PATCH Superseded Marco Elver 2 participants 3 messages Feb 14, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Marco Elver

author maintainer
#0 lore raw

PATCH 1/1 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.

Cc Paul E. McKenney <[email protected]>
Cc Steven Rostedt <[email protected]>
---
 kernel/kcsan/Makefile | 2 ++
 kernel/trace/Makefile | 3 +++
 2 files changed, 5 insertions(+)
kernel/kcsan/Makefile +2 -0
index df6b7799e4927..d4999b38d1be5 100644
@@ -4,6 +4,8 @@ KCOV_INSTRUMENT := n
 UBSAN_SANITIZE := n
 
 CFLAGS_REMOVE_core.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_debugfs.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE)
 
 CFLAGS_core.o := $(call cc-option,-fno-conserve-stack,) \
 	$(call cc-option,-fno-stack-protector,)
kernel/trace/Makefile +3 -0
index f9dcd19165fa2..6b601d88bf71e 100644
@@ -6,6 +6,9 @@ ifdef CONFIG_FUNCTION_TRACER
 ORIG_CFLAGS := $(KBUILD_CFLAGS)
 KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
 
+# Avoid recursion due to instrumentation.
+KCSAN_SANITIZE := n
+
 ifdef CONFIG_FTRACE_SELFTEST
 # selftest needs instrumentation
 CFLAGS_trace_selftest_dynamic.o = $(CC_FLAGS_FTRACE)
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
Tested-by on v1 1/1
#1 lore raw
Quoted 6 lines · Marco Elver

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.

I remembered that KCSAN + ftrace was working last week, but I probably had a bad memory. Anyway, this patch works fine. Feel free to add,

Quoted 37 lines
Cc Paul E. McKenney <[email protected]>
Cc Steven Rostedt <[email protected]>
---
 kernel/kcsan/Makefile | 2 ++
 kernel/trace/Makefile | 3 +++
 2 files changed, 5 insertions(+)
kernel/kcsan/Makefile +2 -0
index df6b7799e4927..d4999b38d1be5 100644
@@ -4,6 +4,8 @@ KCOV_INSTRUMENT := n
 UBSAN_SANITIZE := n
 
 CFLAGS_REMOVE_core.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_debugfs.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE)
 
 CFLAGS_core.o := $(call cc-option,-fno-conserve-stack,) \
 	$(call cc-option,-fno-stack-protector,)
kernel/trace/Makefile +3 -0
index f9dcd19165fa2..6b601d88bf71e 100644
@@ -6,6 +6,9 @@ ifdef CONFIG_FUNCTION_TRACER
 ORIG_CFLAGS := $(KBUILD_CFLAGS)
 KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
 
+# Avoid recursion due to instrumentation.
+KCSAN_SANITIZE := n
+
 ifdef CONFIG_FTRACE_SELFTEST
 # selftest needs instrumentation
 CFLAGS_trace_selftest_dynamic.o = $(CC_FLAGS_FTRACE)
author maintainer
#2 lore raw
Quoted 6 lines · Qian Cai
Quoted 4 lines · Marco Elver

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.

Quoted 7 lines
Quoted 2 lines

To avoid this for all types of tracing, disable KCSAN instrumentation for all of kernel/trace.

I remembered that KCSAN + ftrace was working last week, but I probably had a bad memory. Anyway, this patch works fine. Feel free to add,

Based your further feedback I've sent v2:
http://lkml.kernel.org/r/[email protected]

Thanks,
-- Marco

Quoted 37 lines
Quoted 37 lines
Cc Paul E. McKenney <[email protected]>
Cc Steven Rostedt <[email protected]>
---
 kernel/kcsan/Makefile | 2 ++
 kernel/trace/Makefile | 3 +++
 2 files changed, 5 insertions(+)
kernel/kcsan/Makefile +2 -0
index df6b7799e4927..d4999b38d1be5 100644
@@ -4,6 +4,8 @@ KCOV_INSTRUMENT := n
 UBSAN_SANITIZE := n
 
 CFLAGS_REMOVE_core.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_debugfs.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE)
 
 CFLAGS_core.o := $(call cc-option,-fno-conserve-stack,) \
      $(call cc-option,-fno-stack-protector,)
kernel/trace/Makefile +3 -0
index f9dcd19165fa2..6b601d88bf71e 100644
@@ -6,6 +6,9 @@ ifdef CONFIG_FUNCTION_TRACER
 ORIG_CFLAGS := $(KBUILD_CFLAGS)
 KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
 
+# Avoid recursion due to instrumentation.
+KCSAN_SANITIZE := n
+
 ifdef CONFIG_FTRACE_SELFTEST
 # selftest needs instrumentation
 CFLAGS_trace_selftest_dynamic.o = $(CC_FLAGS_FTRACE)