]> git.baikalelectronics.ru Git - kernel.git/commitdiff
kcsan: Pass option tsan-instrument-read-before-write to Clang
authorMarco Elver <elver@google.com>
Thu, 21 May 2020 14:20:40 +0000 (16:20 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Thu, 11 Jun 2020 18:04:01 +0000 (20:04 +0200)
Clang (unlike GCC) removes reads before writes with matching addresses
in the same basic block. This is an optimization for TSAN, since writes
will always cause conflict if the preceding read would have.

However, for KCSAN we cannot rely on this option, because we apply
several special rules to writes, in particular when the
KCSAN_ASSUME_PLAIN_WRITES_ATOMIC option is selected. To avoid missing
potential data races, pass the -tsan-instrument-read-before-write option
to Clang if it is available [1].

[1] https://github.com/llvm/llvm-project/commit/151ed6aa38a3ec6c01973b35f684586b6e1c0f7e

Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Will Deacon <will@kernel.org>
Link: https://lkml.kernel.org/r/20200521142047.169334-5-elver@google.com
scripts/Makefile.kcsan

index 75d2942b9437dc90d815052765a3093509481292..bd4da1af59532c96ebfab47b193c17908bdec740 100644 (file)
@@ -13,6 +13,7 @@ endif
 # of some options does not break KCSAN nor causes false positive reports.
 CFLAGS_KCSAN := -fsanitize=thread \
        $(call cc-option,$(call cc-param,tsan-instrument-func-entry-exit=0) -fno-optimize-sibling-calls) \
+       $(call cc-option,$(call cc-param,tsan-instrument-read-before-write=1)) \
        $(call cc-param,tsan-distinguish-volatile=1)
 
 endif # CONFIG_KCSAN