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