History

kcsan: Introduce KCSAN_ACCESS_ASSERT access type

The KCSAN_ACCESS_ASSERT access type may be used to introduce dummy reads and writes to assert certain properties of concurrent code, where bugs could not be detected as normal data races. For example, a variable that is only meant to be written by a single CPU, but may be read (without locking) by other CPUs must still be marked properly to avoid data races. However, concurrent writes, regardless if WRITE_ONCE() or not, would be a bug. Using kcsan_check_access(&x, sizeof(x), KCSAN_ACCESS_ASSERT) would allow catching such bugs. To support KCSAN_ACCESS_ASSERT the following notable changes were made: * If an access is of type KCSAN_ASSERT_ACCESS, disable various filters that only apply to data races, so that all races that KCSAN observes are reported. * Bug reports that involve an ASSERT access type will be reported as "KCSAN: assert: race in ..." instead of "data-race"; this will help more easily distinguish them. * Update a few comments to just mention 'races' where we do not always mean pure data races.

Marco Elver committed 6 years ago

Commit d591ec31 parent ed95f956 files · +103 −34Browse files

Showing the changes to include/linux (1 of 6 files). Show all

Unified · Split

include/linux/kcsan-checks.h+12−6
@@ -6,10 +6,16 @@ · 5 unmodified lines
66 #include <linux/types.h>
77
88 /*
9− * Access type modifiers.
9+ * ACCESS TYPE MODIFIERS
10+ *
11+ * <none>: normal read access;
12+ * WRITE : write access;
13+ * ATOMIC: access is atomic;
14+ * ASSERT: access is not a regular access, but an assertion;
1015 */
1116 #define KCSAN_ACCESS_WRITE 0x1
1217 #define KCSAN_ACCESS_ATOMIC 0x2
18+#define KCSAN_ACCESS_ASSERT 0x4
1319
1420 /*
1521 * __kcsan_*: Always calls into the runtime when KCSAN is enabled. This may be used
@@ -18,7 +24,7 @@ · 2 unmodified lines
1824 */
1925 #ifdef CONFIG_KCSAN
2026 /**
21− * __kcsan_check_access - check generic access for data races
27+ * __kcsan_check_access - check generic access for races
2228 *
2329 * @ptr address of access
2430 * @size size of access
@@ -43,7 +49,7 @@ static inline void kcsan_check_access(const volatile void *ptr, size_t size, · 18 unmodified lines
4349 #endif
4450
4551 /**
46− * __kcsan_check_read - check regular read access for data races
52+ * __kcsan_check_read - check regular read access for races
4753 *
4854 * @ptr address of access
4955 * @size size of access
@@ -51,7 +57,7 @@ static inline void kcsan_check_access(const volatile void *ptr, size_t size, · 1 unmodified line
5157 #define __kcsan_check_read(ptr, size) __kcsan_check_access(ptr, size, 0)
5258
5359 /**
54− * __kcsan_check_write - check regular write access for data races
60+ * __kcsan_check_write - check regular write access for races
5561 *
5662 * @ptr address of access
5763 * @size size of access
@@ -60,7 +66,7 @@ static inline void kcsan_check_access(const volatile void *ptr, size_t size, · 2 unmodified lines
6066 __kcsan_check_access(ptr, size, KCSAN_ACCESS_WRITE)
6167
6268 /**
63− * kcsan_check_read - check regular read access for data races
69+ * kcsan_check_read - check regular read access for races
6470 *
6571 * @ptr address of access
6672 * @size size of access
@@ -68,7 +74,7 @@ static inline void kcsan_check_access(const volatile void *ptr, size_t size, · 1 unmodified line
6874 #define kcsan_check_read(ptr, size) kcsan_check_access(ptr, size, 0)
6975
7076 /**
71− * kcsan_check_write - check regular write access for data races
77+ * kcsan_check_write - check regular write access for races
7278 *
7379 * @ptr address of access
7480 * @size size of access