[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200515150338.190344-5-elver@google.com>
Date: Fri, 15 May 2020 17:03:32 +0200
From: Marco Elver <elver@...gle.com>
To: elver@...gle.com
Cc: paulmck@...nel.org, dvyukov@...gle.com, glider@...gle.com,
andreyknvl@...gle.com, kasan-dev@...glegroups.com,
linux-kernel@...r.kernel.org, tglx@...utronix.de, mingo@...nel.org,
peterz@...radead.org, will@...nel.org,
clang-built-linux@...glegroups.com
Subject: [PATCH -tip 04/10] kcsan: Pass option tsan-instrument-read-before-write
to Clang
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@...gle.com>
---
scripts/Makefile.kcsan | 1 +
1 file changed, 1 insertion(+)
diff --git a/scripts/Makefile.kcsan b/scripts/Makefile.kcsan
index c02662b30a7c..ea4a6301633e 100644
--- a/scripts/Makefile.kcsan
+++ b/scripts/Makefile.kcsan
@@ -13,6 +13,7 @@ endif
# if the absence of some options still allows us to use KCSAN in most cases.
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
--
2.26.2.761.g0e0b3e54be-goog
Powered by blists - more mailing lists