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
6#include <linux/types.h>6#include <linux/types.h>
7 7
8/*8/*
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;
10 */15 */
11#define KCSAN_ACCESS_WRITE 0x116#define KCSAN_ACCESS_WRITE 0x1
12#define KCSAN_ACCESS_ATOMIC 0x217#define KCSAN_ACCESS_ATOMIC 0x2
18#define KCSAN_ACCESS_ASSERT 0x4
13 19
14/*20/*
15 * __kcsan_*: Always calls into the runtime when KCSAN is enabled. This may be used21 * __kcsan_*: Always calls into the runtime when KCSAN is enabled. This may be used
@@ -18,7 +24,7 @@ · 2 unmodified lines
18 */24 */
19#ifdef CONFIG_KCSAN25#ifdef CONFIG_KCSAN
20/**26/**
21 * __kcsan_check_access - check generic access for data races27 * __kcsan_check_access - check generic access for races
22 *28 *
23 * @ptr address of access29 * @ptr address of access
24 * @size size of access30 * @size size of access
@@ -43,7 +49,7 @@ static inline void kcsan_check_access(const volatile void *ptr, size_t size, · 18 unmodified lines
43#endif49#endif
44 50
45/**51/**
46 * __kcsan_check_read - check regular read access for data races52 * __kcsan_check_read - check regular read access for races
47 *53 *
48 * @ptr address of access54 * @ptr address of access
49 * @size size of access55 * @size size of access
@@ -51,7 +57,7 @@ static inline void kcsan_check_access(const volatile void *ptr, size_t size, · 1 unmodified line
51#define __kcsan_check_read(ptr, size) __kcsan_check_access(ptr, size, 0)57#define __kcsan_check_read(ptr, size) __kcsan_check_access(ptr, size, 0)
52 58
53/**59/**
54 * __kcsan_check_write - check regular write access for data races60 * __kcsan_check_write - check regular write access for races
55 *61 *
56 * @ptr address of access62 * @ptr address of access
57 * @size size of access63 * @size size of access
@@ -60,7 +66,7 @@ static inline void kcsan_check_access(const volatile void *ptr, size_t size, · 2 unmodified lines
60 __kcsan_check_access(ptr, size, KCSAN_ACCESS_WRITE)66 __kcsan_check_access(ptr, size, KCSAN_ACCESS_WRITE)
61 67
62/**68/**
63 * kcsan_check_read - check regular read access for data races69 * kcsan_check_read - check regular read access for races
64 *70 *
65 * @ptr address of access71 * @ptr address of access
66 * @size size of access72 * @size size of access
@@ -68,7 +74,7 @@ static inline void kcsan_check_access(const volatile void *ptr, size_t size, · 1 unmodified line
68#define kcsan_check_read(ptr, size) kcsan_check_access(ptr, size, 0)74#define kcsan_check_read(ptr, size) kcsan_check_access(ptr, size, 0)
69 75
70/**76/**
71 * kcsan_check_write - check regular write access for data races77 * kcsan_check_write - check regular write access for races
72 *78 *
73 * @ptr address of access79 * @ptr address of access
74 * @size size of access80 * @size size of access