Marco Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0-only |
| 2 | |
| 3 | config HAVE_ARCH_KCSAN |
| 4 | bool |
| 5 | |
| 6 | menuconfig KCSAN |
Marco Elver | d591ec3 | 2020-02-06 16:46:24 +0100 | [diff] [blame] | 7 | bool "KCSAN: dynamic race detector" |
Marco Elver | 8cfbb04 | 2020-02-04 18:21:12 +0100 | [diff] [blame] | 8 | depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN |
| 9 | select STACKTRACE |
Marco Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 10 | help |
Marco Elver | d591ec3 | 2020-02-06 16:46:24 +0100 | [diff] [blame] | 11 | 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 Elver | 8cfbb04 | 2020-02-04 18:21:12 +0100 | [diff] [blame] | 18 | |
| 19 | See <file:Documentation/dev-tools/kcsan.rst> for more details. |
Marco Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 20 | |
| 21 | if KCSAN |
| 22 | |
Marco Elver | 2402d0e | 2020-02-22 00:10:27 +0100 | [diff] [blame^] | 23 | config 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 Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 36 | config KCSAN_DEBUG |
| 37 | bool "Debugging of KCSAN internals" |
Marco Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 38 | |
| 39 | config KCSAN_SELFTEST |
| 40 | bool "Perform short selftests on boot" |
| 41 | default y |
| 42 | help |
Ingo Molnar | 5cbaefe | 2019-11-20 10:41:43 +0100 | [diff] [blame] | 43 | Run KCSAN selftests on boot. On test failure, causes the kernel to panic. |
Marco Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 44 | |
| 45 | config 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 | |
| 52 | config 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 | |
| 64 | config 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 | |
| 70 | config 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 | |
| 78 | config 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 Molnar | 5cbaefe | 2019-11-20 10:41:43 +0100 | [diff] [blame] | 83 | If false, the chosen delays are always the KCSAN_UDELAY_* values |
| 84 | as defined above. |
Marco Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 85 | |
| 86 | config 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 | |
| 96 | config 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 Elver | 48b1fc1 | 2020-02-21 23:02:09 +0100 | [diff] [blame] | 104 | config 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 Elver | 05f9a40 | 2020-01-10 19:48:34 +0100 | [diff] [blame] | 115 | config KCSAN_REPORT_ONCE_IN_MS |
Marco Elver | d591ec3 | 2020-02-06 16:46:24 +0100 | [diff] [blame] | 116 | int "Duration in milliseconds, in which any given race is only reported once" |
Marco Elver | 05f9a40 | 2020-01-10 19:48:34 +0100 | [diff] [blame] | 117 | default 3000 |
| 118 | help |
Marco Elver | d591ec3 | 2020-02-06 16:46:24 +0100 | [diff] [blame] | 119 | 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 Elver | 05f9a40 | 2020-01-10 19:48:34 +0100 | [diff] [blame] | 124 | |
Marco Elver | 1e6ee2f | 2020-02-04 18:21:10 +0100 | [diff] [blame] | 125 | # 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 Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 132 | |
| 133 | config 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 | |
| 142 | config KCSAN_REPORT_VALUE_CHANGE_ONLY |
| 143 | bool "Only report races where watcher observed a data value change" |
| 144 | default y |
| 145 | help |
Ingo Molnar | 5cbaefe | 2019-11-20 10:41:43 +0100 | [diff] [blame] | 146 | If enabled and a conflicting write is observed via a watchpoint, but |
Marco Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 147 | the data value of the memory location was observed to remain |
| 148 | unchanged, do not report the data race. |
| 149 | |
Marco Elver | 1e6ee2f | 2020-02-04 18:21:10 +0100 | [diff] [blame] | 150 | config 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 Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 163 | config KCSAN_IGNORE_ATOMICS |
| 164 | bool "Do not instrument marked atomic accesses" |
Marco Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 165 | help |
Marco Elver | a249a73 | 2020-02-04 18:21:11 +0100 | [diff] [blame] | 166 | 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 Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 179 | |
| 180 | endif # KCSAN |