blob: 0f1447ff8f5582c2c85b587117beecb342a3ff7c [file] [log] [blame]
Marco Elverdfd402a2019-11-14 19:02:54 +01001# SPDX-License-Identifier: GPL-2.0-only
2
3config HAVE_ARCH_KCSAN
4 bool
5
6menuconfig KCSAN
Marco Elverd591ec32020-02-06 16:46:24 +01007 bool "KCSAN: dynamic race detector"
Marco Elver8cfbb042020-02-04 18:21:12 +01008 depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN
9 select STACKTRACE
Marco Elverdfd402a2019-11-14 19:02:54 +010010 help
Marco Elverd591ec32020-02-06 16:46:24 +010011 The Kernel Concurrency Sanitizer (KCSAN) is a dynamic race detector,
12 which relies on compile-time instrumentation, and uses a
13 watchpoint-based sampling approach to detect races.
14
15 KCSAN's primary purpose is to detect data races. KCSAN can also be
16 used to check properties, with the help of provided assertions, of
17 concurrent code where bugs do not manifest as data races.
Marco Elver8cfbb042020-02-04 18:21:12 +010018
19 See <file:Documentation/dev-tools/kcsan.rst> for more details.
Marco Elverdfd402a2019-11-14 19:02:54 +010020
21if KCSAN
22
Marco Elver2402d0e2020-02-22 00:10:27 +010023config KCSAN_VERBOSE
24 bool "Show verbose reports with more information about system state"
25 depends on PROVE_LOCKING
26 help
27 If enabled, reports show more information about the system state that
28 may help better analyze and debug races. This includes held locks and
29 IRQ trace events.
30
31 While this option should generally be benign, we call into more
32 external functions on report generation; if a race report is
33 generated from any one of them, system stability may suffer due to
34 deadlocks or recursion. If in doubt, say N.
35
Marco Elverdfd402a2019-11-14 19:02:54 +010036config KCSAN_DEBUG
37 bool "Debugging of KCSAN internals"
Marco Elverdfd402a2019-11-14 19:02:54 +010038
39config KCSAN_SELFTEST
40 bool "Perform short selftests on boot"
41 default y
42 help
Ingo Molnar5cbaefe2019-11-20 10:41:43 +010043 Run KCSAN selftests on boot. On test failure, causes the kernel to panic.
Marco Elverdfd402a2019-11-14 19:02:54 +010044
45config KCSAN_EARLY_ENABLE
46 bool "Early enable during boot"
47 default y
48 help
49 If KCSAN should be enabled globally as soon as possible. KCSAN can
50 later be enabled/disabled via debugfs.
51
52config KCSAN_NUM_WATCHPOINTS
53 int "Number of available watchpoints"
54 default 64
55 help
56 Total number of available watchpoints. An address range maps into a
57 specific watchpoint slot as specified in kernel/kcsan/encoding.h.
58 Although larger number of watchpoints may not be usable due to
59 limited number of CPUs, a larger value helps to improve performance
60 due to reducing cache-line contention. The chosen default is a
61 conservative value; we should almost never observe "no_capacity"
62 events (see /sys/kernel/debug/kcsan).
63
64config KCSAN_UDELAY_TASK
65 int "Delay in microseconds (for tasks)"
66 default 80
67 help
68 For tasks, the microsecond delay after setting up a watchpoint.
69
70config KCSAN_UDELAY_INTERRUPT
71 int "Delay in microseconds (for interrupts)"
72 default 20
73 help
74 For interrupts, the microsecond delay after setting up a watchpoint.
75 Interrupts have tighter latency requirements, and their delay should
76 be lower than for tasks.
77
78config KCSAN_DELAY_RANDOMIZE
79 bool "Randomize above delays"
80 default y
81 help
82 If delays should be randomized, where the maximum is KCSAN_UDELAY_*.
Ingo Molnar5cbaefe2019-11-20 10:41:43 +010083 If false, the chosen delays are always the KCSAN_UDELAY_* values
84 as defined above.
Marco Elverdfd402a2019-11-14 19:02:54 +010085
86config KCSAN_SKIP_WATCH
87 int "Skip instructions before setting up watchpoint"
88 default 4000
89 help
90 The number of per-CPU memory operations to skip, before another
91 watchpoint is set up, i.e. one in KCSAN_WATCH_SKIP per-CPU
92 memory operations are used to set up a watchpoint. A smaller value
93 results in more aggressive race detection, whereas a larger value
94 improves system performance at the cost of missing some races.
95
96config KCSAN_SKIP_WATCH_RANDOMIZE
97 bool "Randomize watchpoint instruction skip count"
98 default y
99 help
100 If instruction skip count should be randomized, where the maximum is
101 KCSAN_WATCH_SKIP. If false, the chosen value is always
102 KCSAN_WATCH_SKIP.
103
Marco Elver48b1fc12020-02-21 23:02:09 +0100104config KCSAN_INTERRUPT_WATCHER
105 bool "Interruptible watchers"
106 help
107 If enabled, a task that set up a watchpoint may be interrupted while
108 delayed. This option will allow KCSAN to detect races between
109 interrupted tasks and other threads of execution on the same CPU.
110
111 Currently disabled by default, because not all safe per-CPU access
112 primitives and patterns may be accounted for, and therefore could
113 result in false positives.
114
Marco Elver05f9a402020-01-10 19:48:34 +0100115config KCSAN_REPORT_ONCE_IN_MS
Marco Elverd591ec32020-02-06 16:46:24 +0100116 int "Duration in milliseconds, in which any given race is only reported once"
Marco Elver05f9a402020-01-10 19:48:34 +0100117 default 3000
118 help
Marco Elverd591ec32020-02-06 16:46:24 +0100119 Any given race is only reported once in the defined time window.
120 Different races may still generate reports within a duration that is
121 smaller than the duration defined here. This allows rate limiting
122 reporting to avoid flooding the console with reports. Setting this
123 to 0 disables rate limiting.
Marco Elver05f9a402020-01-10 19:48:34 +0100124
Marco Elver1e6ee2f2020-02-04 18:21:10 +0100125# The main purpose of the below options is to control reported data races (e.g.
126# in fuzzer configs), and are not expected to be switched frequently by other
127# users. We could turn some of them into boot parameters, but given they should
128# not be switched normally, let's keep them here to simplify configuration.
129#
130# The defaults below are chosen to be very conservative, and may miss certain
131# bugs.
Marco Elverdfd402a2019-11-14 19:02:54 +0100132
133config KCSAN_REPORT_RACE_UNKNOWN_ORIGIN
134 bool "Report races of unknown origin"
135 default y
136 help
137 If KCSAN should report races where only one access is known, and the
138 conflicting access is of unknown origin. This type of race is
139 reported if it was only possible to infer a race due to a data value
140 change while an access is being delayed on a watchpoint.
141
142config KCSAN_REPORT_VALUE_CHANGE_ONLY
143 bool "Only report races where watcher observed a data value change"
144 default y
145 help
Ingo Molnar5cbaefe2019-11-20 10:41:43 +0100146 If enabled and a conflicting write is observed via a watchpoint, but
Marco Elverdfd402a2019-11-14 19:02:54 +0100147 the data value of the memory location was observed to remain
148 unchanged, do not report the data race.
149
Marco Elver1e6ee2f2020-02-04 18:21:10 +0100150config KCSAN_ASSUME_PLAIN_WRITES_ATOMIC
151 bool "Assume that plain aligned writes up to word size are atomic"
152 default y
153 help
154 Assume that plain aligned writes up to word size are atomic by
155 default, and also not subject to other unsafe compiler optimizations
156 resulting in data races. This will cause KCSAN to not report data
157 races due to conflicts where the only plain accesses are aligned
158 writes up to word size: conflicts between marked reads and plain
159 aligned writes up to word size will not be reported as data races;
160 notice that data races between two conflicting plain aligned writes
161 will also not be reported.
162
Marco Elverdfd402a2019-11-14 19:02:54 +0100163config KCSAN_IGNORE_ATOMICS
164 bool "Do not instrument marked atomic accesses"
Marco Elverdfd402a2019-11-14 19:02:54 +0100165 help
Marco Elvera249a732020-02-04 18:21:11 +0100166 Never instrument marked atomic accesses. This option can be used for
167 additional filtering. Conflicting marked atomic reads and plain
168 writes will never be reported as a data race, however, will cause
169 plain reads and marked writes to result in "unknown origin" reports.
170 If combined with CONFIG_KCSAN_REPORT_RACE_UNKNOWN_ORIGIN=n, data
171 races where at least one access is marked atomic will never be
172 reported.
173
174 Similar to KCSAN_ASSUME_PLAIN_WRITES_ATOMIC, but including unaligned
175 accesses, conflicting marked atomic reads and plain writes will not
176 be reported as data races; however, unlike that option, data races
177 due to two conflicting plain writes will be reported (aligned and
178 unaligned, if CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC=n).
Marco Elverdfd402a2019-11-14 19:02:54 +0100179
180endif # KCSAN