History

kcsan: Add core support for a subset of weak memory modeling

Add support for modeling a subset of weak memory, which will enable detection of a subset of data races due to missing memory barriers. KCSAN's approach to detecting missing memory barriers is based on modeling access reordering, and enabled if `CONFIG_KCSAN_WEAK_MEMORY=y`, which depends on `CONFIG_KCSAN_STRICT=y`. The feature can be enabled or disabled at boot and runtime via the `kcsan.weak_memory` boot parameter. Each memory access for which a watchpoint is set up, is also selected for simulated reordering within the scope of its function (at most 1 in-flight access). We are limited to modeling the effects of "buffering" (delaying the access), since the runtime cannot "prefetch" accesses (therefore no acquire modeling). Once an access has been selected for reordering, it is checked along every other access until the end of the function scope. If an appropriate memory barrier is encountered, the access will no longer be considered for reordering. When the result of a memory operation should be ordered by a barrier, KCSAN can then detect data races where the conflict only occurs as a result of a missing barrier due to reordering accesses.

Marco Elver committed 5 years ago

Commit 69562e41 parent 9756f646 files · +235 −19Browse files

Showing the changes to scripts (1 of 6 files). Show all

Unified · Split

scripts/Makefile.kcsan+7−2
@@ -9,7 +9,12 @@ endif · 8 unmodified lines
9 9
10# Keep most options here optional, to allow enabling more compilers if absence10# Keep most options here optional, to allow enabling more compilers if absence
11# of some options does not break KCSAN nor causes false positive reports.11# of some options does not break KCSAN nor causes false positive reports.
12export CFLAGS_KCSAN := -fsanitize=thread \12kcsan-cflags := -fsanitize=thread -fno-optimize-sibling-calls \
13 $(call cc-option,$(call cc-param,tsan-instrument-func-entry-exit=0) -fno-optimize-sibling-calls) \
14 $(call cc-option,$(call cc-param,tsan-compound-read-before-write=1),$(call cc-option,$(call cc-param,tsan-instrument-read-before-write=1))) \13 $(call cc-option,$(call cc-param,tsan-compound-read-before-write=1),$(call cc-option,$(call cc-param,tsan-instrument-read-before-write=1))) \
15 $(call cc-param,tsan-distinguish-volatile=1)14 $(call cc-param,tsan-distinguish-volatile=1)
15
16ifndef CONFIG_KCSAN_WEAK_MEMORY
17kcsan-cflags += $(call cc-option,$(call cc-param,tsan-instrument-func-entry-exit=0))
18endif
19
20export CFLAGS_KCSAN := $(kcsan-cflags)