aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kcsan.h
diff options
context:
space:
mode:
authorMarco Elver <elver@google.com>2021-08-05 14:57:45 +0200
committerPaul E. McKenney <paulmck@kernel.org>2021-12-09 16:42:26 -0800
commit69562e4983d93e2791c0bf128b07462afbd7f4dc (patch)
tree3f09f093f4aea94918bd1ebb127f61a6f263d15d /include/linux/kcsan.h
parentkcsan: Avoid checking scoped accesses from nested contexts (diff)
downloadlinux-dev-69562e4983d93e2791c0bf128b07462afbd7f4dc.tar.xz
linux-dev-69562e4983d93e2791c0bf128b07462afbd7f4dc.zip
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. Suggested-by: Dmitry Vyukov <dvyukov@google.com> Signed-off-by: Marco Elver <elver@google.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Diffstat (limited to 'include/linux/kcsan.h')
-rw-r--r--include/linux/kcsan.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/include/linux/kcsan.h b/include/linux/kcsan.h
index 13cef3458fed..c07c71f5ba4f 100644
--- a/include/linux/kcsan.h
+++ b/include/linux/kcsan.h
@@ -49,8 +49,16 @@ struct kcsan_ctx {
*/
unsigned long access_mask;
- /* List of scoped accesses. */
+ /* List of scoped accesses; likely to be empty. */
struct list_head scoped_accesses;
+
+#ifdef CONFIG_KCSAN_WEAK_MEMORY
+ /*
+ * Scoped access for modeling access reordering to detect missing memory
+ * barriers; only keep 1 to keep fast-path complexity manageable.
+ */
+ struct kcsan_scoped_access reorder_access;
+#endif
};
/**