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 |
| 7 | bool "KCSAN: watchpoint-based dynamic data race detector" |
| 8 | depends on HAVE_ARCH_KCSAN && !KASAN && STACKTRACE |
Marco Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 9 | help |
| 10 | Kernel Concurrency Sanitizer is a dynamic data race detector, which |
| 11 | uses a watchpoint-based sampling approach to detect races. See |
| 12 | <file:Documentation/dev-tools/kcsan.rst> for more details. |
| 13 | |
| 14 | if KCSAN |
| 15 | |
| 16 | config KCSAN_DEBUG |
| 17 | bool "Debugging of KCSAN internals" |
Marco Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 18 | |
| 19 | config KCSAN_SELFTEST |
| 20 | bool "Perform short selftests on boot" |
| 21 | default y |
| 22 | help |
Ingo Molnar | 5cbaefe | 2019-11-20 10:41:43 +0100 | [diff] [blame] | 23 | 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] | 24 | |
| 25 | config KCSAN_EARLY_ENABLE |
| 26 | bool "Early enable during boot" |
| 27 | default y |
| 28 | help |
| 29 | If KCSAN should be enabled globally as soon as possible. KCSAN can |
| 30 | later be enabled/disabled via debugfs. |
| 31 | |
| 32 | config KCSAN_NUM_WATCHPOINTS |
| 33 | int "Number of available watchpoints" |
| 34 | default 64 |
| 35 | help |
| 36 | Total number of available watchpoints. An address range maps into a |
| 37 | specific watchpoint slot as specified in kernel/kcsan/encoding.h. |
| 38 | Although larger number of watchpoints may not be usable due to |
| 39 | limited number of CPUs, a larger value helps to improve performance |
| 40 | due to reducing cache-line contention. The chosen default is a |
| 41 | conservative value; we should almost never observe "no_capacity" |
| 42 | events (see /sys/kernel/debug/kcsan). |
| 43 | |
| 44 | config KCSAN_UDELAY_TASK |
| 45 | int "Delay in microseconds (for tasks)" |
| 46 | default 80 |
| 47 | help |
| 48 | For tasks, the microsecond delay after setting up a watchpoint. |
| 49 | |
| 50 | config KCSAN_UDELAY_INTERRUPT |
| 51 | int "Delay in microseconds (for interrupts)" |
| 52 | default 20 |
| 53 | help |
| 54 | For interrupts, the microsecond delay after setting up a watchpoint. |
| 55 | Interrupts have tighter latency requirements, and their delay should |
| 56 | be lower than for tasks. |
| 57 | |
| 58 | config KCSAN_DELAY_RANDOMIZE |
| 59 | bool "Randomize above delays" |
| 60 | default y |
| 61 | help |
| 62 | If delays should be randomized, where the maximum is KCSAN_UDELAY_*. |
Ingo Molnar | 5cbaefe | 2019-11-20 10:41:43 +0100 | [diff] [blame] | 63 | If false, the chosen delays are always the KCSAN_UDELAY_* values |
| 64 | as defined above. |
Marco Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 65 | |
| 66 | config KCSAN_SKIP_WATCH |
| 67 | int "Skip instructions before setting up watchpoint" |
| 68 | default 4000 |
| 69 | help |
| 70 | The number of per-CPU memory operations to skip, before another |
| 71 | watchpoint is set up, i.e. one in KCSAN_WATCH_SKIP per-CPU |
| 72 | memory operations are used to set up a watchpoint. A smaller value |
| 73 | results in more aggressive race detection, whereas a larger value |
| 74 | improves system performance at the cost of missing some races. |
| 75 | |
| 76 | config KCSAN_SKIP_WATCH_RANDOMIZE |
| 77 | bool "Randomize watchpoint instruction skip count" |
| 78 | default y |
| 79 | help |
| 80 | If instruction skip count should be randomized, where the maximum is |
| 81 | KCSAN_WATCH_SKIP. If false, the chosen value is always |
| 82 | KCSAN_WATCH_SKIP. |
| 83 | |
Marco Elver | 05f9a40 | 2020-01-10 19:48:34 +0100 | [diff] [blame] | 84 | config KCSAN_REPORT_ONCE_IN_MS |
| 85 | int "Duration in milliseconds, in which any given data race is only reported once" |
| 86 | default 3000 |
| 87 | help |
| 88 | Any given data race is only reported once in the defined time window. |
| 89 | Different data races may still generate reports within a duration |
| 90 | that is smaller than the duration defined here. This allows rate |
| 91 | limiting reporting to avoid flooding the console with reports. |
| 92 | Setting this to 0 disables rate limiting. |
| 93 | |
Marco Elver | 1e6ee2f | 2020-02-04 18:21:10 +0100 | [diff] [blame^] | 94 | # The main purpose of the below options is to control reported data races (e.g. |
| 95 | # in fuzzer configs), and are not expected to be switched frequently by other |
| 96 | # users. We could turn some of them into boot parameters, but given they should |
| 97 | # not be switched normally, let's keep them here to simplify configuration. |
| 98 | # |
| 99 | # The defaults below are chosen to be very conservative, and may miss certain |
| 100 | # bugs. |
Marco Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 101 | |
| 102 | config KCSAN_REPORT_RACE_UNKNOWN_ORIGIN |
| 103 | bool "Report races of unknown origin" |
| 104 | default y |
| 105 | help |
| 106 | If KCSAN should report races where only one access is known, and the |
| 107 | conflicting access is of unknown origin. This type of race is |
| 108 | reported if it was only possible to infer a race due to a data value |
| 109 | change while an access is being delayed on a watchpoint. |
| 110 | |
| 111 | config KCSAN_REPORT_VALUE_CHANGE_ONLY |
| 112 | bool "Only report races where watcher observed a data value change" |
| 113 | default y |
| 114 | help |
Ingo Molnar | 5cbaefe | 2019-11-20 10:41:43 +0100 | [diff] [blame] | 115 | If enabled and a conflicting write is observed via a watchpoint, but |
Marco Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 116 | the data value of the memory location was observed to remain |
| 117 | unchanged, do not report the data race. |
| 118 | |
Marco Elver | 1e6ee2f | 2020-02-04 18:21:10 +0100 | [diff] [blame^] | 119 | config KCSAN_ASSUME_PLAIN_WRITES_ATOMIC |
| 120 | bool "Assume that plain aligned writes up to word size are atomic" |
| 121 | default y |
| 122 | help |
| 123 | Assume that plain aligned writes up to word size are atomic by |
| 124 | default, and also not subject to other unsafe compiler optimizations |
| 125 | resulting in data races. This will cause KCSAN to not report data |
| 126 | races due to conflicts where the only plain accesses are aligned |
| 127 | writes up to word size: conflicts between marked reads and plain |
| 128 | aligned writes up to word size will not be reported as data races; |
| 129 | notice that data races between two conflicting plain aligned writes |
| 130 | will also not be reported. |
| 131 | |
Marco Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 132 | config KCSAN_IGNORE_ATOMICS |
| 133 | bool "Do not instrument marked atomic accesses" |
Marco Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 134 | help |
| 135 | If enabled, never instruments marked atomic accesses. This results in |
| 136 | not reporting data races where one access is atomic and the other is |
| 137 | a plain access. |
| 138 | |
| 139 | endif # KCSAN |