1 # SPDX-License-Identifier: GPL-2.0-only
7 bool "KCSAN: dynamic data race detector"
8 depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN
11 The Kernel Concurrency Sanitizer (KCSAN) is a dynamic
12 data-race detector that relies on compile-time instrumentation.
13 KCSAN uses a watchpoint-based sampling approach to detect races.
15 While KCSAN's primary purpose is to detect data races, it
16 also provides assertions to check data access constraints.
17 These assertions can expose bugs that do not manifest as
20 See <file:Documentation/dev-tools/kcsan.rst> for more details.
25 bool "Show verbose reports with more information about system state"
26 depends on PROVE_LOCKING
28 If enabled, reports show more information about the system state that
29 may help better analyze and debug races. This includes held locks and
32 While this option should generally be benign, we call into more
33 external functions on report generation; if a race report is
34 generated from any one of them, system stability may suffer due to
35 deadlocks or recursion. If in doubt, say N.
38 bool "Debugging of KCSAN internals"
41 bool "Perform short selftests on boot"
44 Run KCSAN selftests on boot. On test failure, causes the kernel to panic.
46 config KCSAN_EARLY_ENABLE
47 bool "Early enable during boot"
50 If KCSAN should be enabled globally as soon as possible. KCSAN can
51 later be enabled/disabled via debugfs.
53 config KCSAN_NUM_WATCHPOINTS
54 int "Number of available watchpoints"
57 Total number of available watchpoints. An address range maps into a
58 specific watchpoint slot as specified in kernel/kcsan/encoding.h.
59 Although larger number of watchpoints may not be usable due to
60 limited number of CPUs, a larger value helps to improve performance
61 due to reducing cache-line contention. The chosen default is a
62 conservative value; we should almost never observe "no_capacity"
63 events (see /sys/kernel/debug/kcsan).
65 config KCSAN_UDELAY_TASK
66 int "Delay in microseconds (for tasks)"
69 For tasks, the microsecond delay after setting up a watchpoint.
71 config KCSAN_UDELAY_INTERRUPT
72 int "Delay in microseconds (for interrupts)"
75 For interrupts, the microsecond delay after setting up a watchpoint.
76 Interrupts have tighter latency requirements, and their delay should
77 be lower than for tasks.
79 config KCSAN_DELAY_RANDOMIZE
80 bool "Randomize above delays"
83 If delays should be randomized, where the maximum is KCSAN_UDELAY_*.
84 If false, the chosen delays are always the KCSAN_UDELAY_* values
87 config KCSAN_SKIP_WATCH
88 int "Skip instructions before setting up watchpoint"
91 The number of per-CPU memory operations to skip, before another
92 watchpoint is set up, i.e. one in KCSAN_WATCH_SKIP per-CPU
93 memory operations are used to set up a watchpoint. A smaller value
94 results in more aggressive race detection, whereas a larger value
95 improves system performance at the cost of missing some races.
97 config KCSAN_SKIP_WATCH_RANDOMIZE
98 bool "Randomize watchpoint instruction skip count"
101 If instruction skip count should be randomized, where the maximum is
102 KCSAN_WATCH_SKIP. If false, the chosen value is always
105 config KCSAN_INTERRUPT_WATCHER
106 bool "Interruptible watchers"
108 If enabled, a task that set up a watchpoint may be interrupted while
109 delayed. This option will allow KCSAN to detect races between
110 interrupted tasks and other threads of execution on the same CPU.
112 Currently disabled by default, because not all safe per-CPU access
113 primitives and patterns may be accounted for, and therefore could
114 result in false positives.
116 config KCSAN_REPORT_ONCE_IN_MS
117 int "Duration in milliseconds, in which any given race is only reported once"
120 Any given race is only reported once in the defined time window.
121 Different races may still generate reports within a duration that is
122 smaller than the duration defined here. This allows rate limiting
123 reporting to avoid flooding the console with reports. Setting this
124 to 0 disables rate limiting.
126 # The main purpose of the below options is to control reported data races (e.g.
127 # in fuzzer configs), and are not expected to be switched frequently by other
128 # users. We could turn some of them into boot parameters, but given they should
129 # not be switched normally, let's keep them here to simplify configuration.
131 # The defaults below are chosen to be very conservative, and may miss certain
134 config KCSAN_REPORT_RACE_UNKNOWN_ORIGIN
135 bool "Report races of unknown origin"
138 If KCSAN should report races where only one access is known, and the
139 conflicting access is of unknown origin. This type of race is
140 reported if it was only possible to infer a race due to a data value
141 change while an access is being delayed on a watchpoint.
143 config KCSAN_REPORT_VALUE_CHANGE_ONLY
144 bool "Only report races where watcher observed a data value change"
147 If enabled and a conflicting write is observed via a watchpoint, but
148 the data value of the memory location was observed to remain
149 unchanged, do not report the data race.
151 config KCSAN_ASSUME_PLAIN_WRITES_ATOMIC
152 bool "Assume that plain aligned writes up to word size are atomic"
155 Assume that plain aligned writes up to word size are atomic by
156 default, and also not subject to other unsafe compiler optimizations
157 resulting in data races. This will cause KCSAN to not report data
158 races due to conflicts where the only plain accesses are aligned
159 writes up to word size: conflicts between marked reads and plain
160 aligned writes up to word size will not be reported as data races;
161 notice that data races between two conflicting plain aligned writes
162 will also not be reported.
164 config KCSAN_IGNORE_ATOMICS
165 bool "Do not instrument marked atomic accesses"
167 Never instrument marked atomic accesses. This option can be used for
168 additional filtering. Conflicting marked atomic reads and plain
169 writes will never be reported as a data race, however, will cause
170 plain reads and marked writes to result in "unknown origin" reports.
171 If combined with CONFIG_KCSAN_REPORT_RACE_UNKNOWN_ORIGIN=n, data
172 races where at least one access is marked atomic will never be
175 Similar to KCSAN_ASSUME_PLAIN_WRITES_ATOMIC, but including unaligned
176 accesses, conflicting marked atomic reads and plain writes will not
177 be reported as data races; however, unlike that option, data races
178 due to two conflicting plain writes will be reported (aligned and
179 unaligned, if CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC=n).