Skip to content

Commit 0ebba71

Browse files
melverpaulmckrcu
authored andcommitted
build, kcsan: Add KCSAN build exceptions
This blacklists several compilation units from KCSAN. See the respective inline comments for the reasoning. Signed-off-by: Marco Elver <elver@google.com> Acked-by: Paul E. McKenney <paulmck@kernel.org> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent 5f5c971 commit 0ebba71

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎drivers/firmware/efi/libstub/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ KBUILD_CFLAGS := $(cflags-y) -DDISABLE_BRANCH_PROFILING \
3131
-D__DISABLE_EXPORTS
3232

3333
GCOV_PROFILE := n
34+
# Sanitizer runtimes are unavailable and cannot be linked here.
3435
KASAN_SANITIZE := n
36+
KCSAN_SANITIZE := n
3537
UBSAN_SANITIZE := n
3638
OBJECT_FILES_NON_STANDARD := y
3739

‎kernel/Makefile‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ endif
2323
# Prevents flicker of uninteresting __do_softirq()/__local_bh_disable_ip()
2424
# in coverage traces.
2525
KCOV_INSTRUMENT_softirq.o := n
26+
# Avoid KCSAN instrumentation in softirq ("No shared variables, all the data
27+
# are CPU local" => assume no data races), to reduce overhead in interrupts.
28+
KCSAN_SANITIZE_softirq.o = n
2629
# These are called from save_stack_trace() on slub debug path,
2730
# and produce insane amounts of uninteresting coverage.
2831
KCOV_INSTRUMENT_module.o := n
2932
KCOV_INSTRUMENT_extable.o := n
3033
# Don't self-instrument.
3134
KCOV_INSTRUMENT_kcov.o := n
3235
KASAN_SANITIZE_kcov.o := n
36+
KCSAN_SANITIZE_kcov.o := n
3337
CFLAGS_kcov.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
3438

3539
# cond_syscall is currently not LTO compatible
@@ -118,6 +122,7 @@ obj-$(CONFIG_RSEQ) += rseq.o
118122

119123
obj-$(CONFIG_GCC_PLUGIN_STACKLEAK) += stackleak.o
120124
KASAN_SANITIZE_stackleak.o := n
125+
KCSAN_SANITIZE_stackleak.o := n
121126
KCOV_INSTRUMENT_stackleak.o := n
122127

123128
$(obj)/configs.o: $(obj)/config_data.gz

‎kernel/sched/Makefile‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ endif
77
# that is not a function of syscall inputs. E.g. involuntary context switches.
88
KCOV_INSTRUMENT := n
99

10+
# There are numerous races here, however, most of them due to plain accesses.
11+
# This would make it even harder for syzbot to find reproducers, because these
12+
# bugs trigger without specific input. Disable by default, but should re-enable
13+
# eventually.
14+
KCSAN_SANITIZE := n
15+
1016
ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y)
1117
# According to Alan Modra <alan@linuxcare.com.au>, the -fno-omit-frame-pointer is
1218
# needed for x86 only. Why this used to be enabled for all architectures is beyond

‎mm/Makefile‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ KASAN_SANITIZE_slab_common.o := n
77
KASAN_SANITIZE_slab.o := n
88
KASAN_SANITIZE_slub.o := n
99

10+
# These produce frequent data race reports: most of them are due to races on
11+
# the same word but accesses to different bits of that word. Re-enable KCSAN
12+
# for these when we have more consensus on what to do about them.
13+
KCSAN_SANITIZE_slab_common.o := n
14+
KCSAN_SANITIZE_slab.o := n
15+
KCSAN_SANITIZE_slub.o := n
16+
KCSAN_SANITIZE_page_alloc.o := n
17+
1018
# These files are disabled because they produce non-interesting and/or
1119
# flaky coverage that is not a function of syscall inputs. E.g. slab is out of
1220
# free pages, or a task is migrated between nodes.

0 commit comments

Comments
 (0)