Commit | Line | Data |
---|---|---|
dfd402a4 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
bd0ccc4a ME |
2 | /* |
3 | * The Kernel Concurrency Sanitizer (KCSAN) infrastructure. Public interface and | |
4 | * data structures to set up runtime. See kcsan-checks.h for explicit checks and | |
5 | * modifiers. For more info please see Documentation/dev-tools/kcsan.rst. | |
6 | * | |
7 | * Copyright (C) 2019, Google LLC. | |
8 | */ | |
dfd402a4 ME |
9 | |
10 | #ifndef _LINUX_KCSAN_H | |
11 | #define _LINUX_KCSAN_H | |
12 | ||
13 | #include <linux/kcsan-checks.h> | |
14 | #include <linux/types.h> | |
15 | ||
16 | #ifdef CONFIG_KCSAN | |
17 | ||
18 | /* | |
19 | * Context for each thread of execution: for tasks, this is stored in | |
20 | * task_struct, and interrupts access internal per-CPU storage. | |
21 | */ | |
22 | struct kcsan_ctx { | |
23 | int disable_count; /* disable counter */ | |
9756f64c | 24 | int disable_scoped; /* disable scoped access counter */ |
dfd402a4 ME |
25 | int atomic_next; /* number of following atomic ops */ |
26 | ||
27 | /* | |
28 | * We distinguish between: (a) nestable atomic regions that may contain | |
29 | * other nestable regions; and (b) flat atomic regions that do not keep | |
30 | * track of nesting. Both (a) and (b) are entirely independent of each | |
31 | * other, and a flat region may be started in a nestable region or | |
32 | * vice-versa. | |
33 | * | |
34 | * This is required because, for example, in the annotations for | |
35 | * seqlocks, we declare seqlock writer critical sections as (a) nestable | |
36 | * atomic regions, but reader critical sections as (b) flat atomic | |
37 | * regions, but have encountered cases where seqlock reader critical | |
38 | * sections are contained within writer critical sections (the opposite | |
39 | * may be possible, too). | |
40 | * | |
41 | * To support these cases, we independently track the depth of nesting | |
42 | * for (a), and whether the leaf level is flat for (b). | |
43 | */ | |
44 | int atomic_nest_count; | |
45 | bool in_flat_atomic; | |
81af89e1 ME |
46 | |
47 | /* | |
48 | * Access mask for all accesses if non-zero. | |
49 | */ | |
50 | unsigned long access_mask; | |
757a4cef | 51 | |
69562e49 | 52 | /* List of scoped accesses; likely to be empty. */ |
757a4cef | 53 | struct list_head scoped_accesses; |
69562e49 ME |
54 | |
55 | #ifdef CONFIG_KCSAN_WEAK_MEMORY | |
56 | /* | |
57 | * Scoped access for modeling access reordering to detect missing memory | |
58 | * barriers; only keep 1 to keep fast-path complexity manageable. | |
59 | */ | |
60 | struct kcsan_scoped_access reorder_access; | |
61 | #endif | |
dfd402a4 ME |
62 | }; |
63 | ||
64 | /** | |
65 | * kcsan_init - initialize KCSAN runtime | |
66 | */ | |
67 | void kcsan_init(void); | |
68 | ||
dfd402a4 ME |
69 | #else /* CONFIG_KCSAN */ |
70 | ||
5cbaefe9 | 71 | static inline void kcsan_init(void) { } |
dfd402a4 ME |
72 | |
73 | #endif /* CONFIG_KCSAN */ | |
74 | ||
75 | #endif /* _LINUX_KCSAN_H */ |