]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blobdiff - lib/Kconfig.kcsan
Merge tag 'regulator-fix-v5.8-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mirror_ubuntu-hirsute-kernel.git] / lib / Kconfig.kcsan
index 5dd464e52ab4329a27470a5b6bc399d12dccda47..5ee88e5119c2815ffaf91fa9ba1f89d3dbd9371e 100644 (file)
@@ -3,26 +3,63 @@
 config HAVE_ARCH_KCSAN
        bool
 
 config HAVE_ARCH_KCSAN
        bool
 
+config HAVE_KCSAN_COMPILER
+       def_bool CC_IS_CLANG && $(cc-option,-fsanitize=thread -mllvm -tsan-distinguish-volatile=1)
+       help
+         For the list of compilers that support KCSAN, please see
+         <file:Documentation/dev-tools/kcsan.rst>.
+
+config KCSAN_KCOV_BROKEN
+       def_bool KCOV && CC_HAS_SANCOV_TRACE_PC
+       depends on CC_IS_CLANG
+       depends on !$(cc-option,-Werror=unused-command-line-argument -fsanitize=thread -fsanitize-coverage=trace-pc)
+       help
+         Some versions of clang support either KCSAN and KCOV but not the
+         combination of the two.
+         See https://bugs.llvm.org/show_bug.cgi?id=45831 for the status
+         in newer releases.
+
 menuconfig KCSAN
 menuconfig KCSAN
-       bool "KCSAN: watchpoint-based dynamic data race detector"
-       depends on HAVE_ARCH_KCSAN && !KASAN && STACKTRACE
-       default n
+       bool "KCSAN: dynamic data race detector"
+       depends on HAVE_ARCH_KCSAN && HAVE_KCSAN_COMPILER
+       depends on DEBUG_KERNEL && !KASAN
+       depends on !KCSAN_KCOV_BROKEN
+       select STACKTRACE
        help
        help
-         Kernel Concurrency Sanitizer is a dynamic data race detector, which
-         uses a watchpoint-based sampling approach to detect races. See
-         <file:Documentation/dev-tools/kcsan.rst> for more details.
+         The Kernel Concurrency Sanitizer (KCSAN) is a dynamic
+         data-race detector that relies on compile-time instrumentation.
+         KCSAN uses a watchpoint-based sampling approach to detect races.
+
+         While KCSAN's primary purpose is to detect data races, it
+         also provides assertions to check data access constraints.
+         These assertions can expose bugs that do not manifest as
+         data races.
+
+         See <file:Documentation/dev-tools/kcsan.rst> for more details.
 
 if KCSAN
 
 
 if KCSAN
 
+config KCSAN_VERBOSE
+       bool "Show verbose reports with more information about system state"
+       depends on PROVE_LOCKING
+       help
+         If enabled, reports show more information about the system state that
+         may help better analyze and debug races. This includes held locks and
+         IRQ trace events.
+
+         While this option should generally be benign, we call into more
+         external functions on report generation; if a race report is
+         generated from any one of them, system stability may suffer due to
+         deadlocks or recursion.  If in doubt, say N.
+
 config KCSAN_DEBUG
        bool "Debugging of KCSAN internals"
 config KCSAN_DEBUG
        bool "Debugging of KCSAN internals"
-       default n
 
 config KCSAN_SELFTEST
        bool "Perform short selftests on boot"
        default y
        help
 
 config KCSAN_SELFTEST
        bool "Perform short selftests on boot"
        default y
        help
-         Run KCSAN selftests on boot. On test failure, causes kernel to panic.
+         Run KCSAN selftests on boot. On test failure, causes the kernel to panic.
 
 config KCSAN_EARLY_ENABLE
        bool "Early enable during boot"
 
 config KCSAN_EARLY_ENABLE
        bool "Early enable during boot"
@@ -62,7 +99,8 @@ config KCSAN_DELAY_RANDOMIZE
        default y
        help
          If delays should be randomized, where the maximum is KCSAN_UDELAY_*.
        default y
        help
          If delays should be randomized, where the maximum is KCSAN_UDELAY_*.
-         If false, the chosen delays are always KCSAN_UDELAY_* defined above.
+         If false, the chosen delays are always the KCSAN_UDELAY_* values
+         as defined above.
 
 config KCSAN_SKIP_WATCH
        int "Skip instructions before setting up watchpoint"
 
 config KCSAN_SKIP_WATCH
        int "Skip instructions before setting up watchpoint"
@@ -82,13 +120,34 @@ config KCSAN_SKIP_WATCH_RANDOMIZE
          KCSAN_WATCH_SKIP. If false, the chosen value is always
          KCSAN_WATCH_SKIP.
 
          KCSAN_WATCH_SKIP. If false, the chosen value is always
          KCSAN_WATCH_SKIP.
 
-# Note that, while some of the below options could be turned into boot
-# parameters, to optimize for the common use-case, we avoid this because: (a)
-# it would impact performance (and we want to avoid static branch for all
-# {READ,WRITE}_ONCE, atomic_*, bitops, etc.), and (b) complicate the design
-# without real benefit. The main purpose of the below options are for use in
-# fuzzer configs to control reported data races, and are not expected to be
-# switched frequently by a user.
+config KCSAN_INTERRUPT_WATCHER
+       bool "Interruptible watchers"
+       help
+         If enabled, a task that set up a watchpoint may be interrupted while
+         delayed. This option will allow KCSAN to detect races between
+         interrupted tasks and other threads of execution on the same CPU.
+
+         Currently disabled by default, because not all safe per-CPU access
+         primitives and patterns may be accounted for, and therefore could
+         result in false positives.
+
+config KCSAN_REPORT_ONCE_IN_MS
+       int "Duration in milliseconds, in which any given race is only reported once"
+       default 3000
+       help
+         Any given race is only reported once in the defined time window.
+         Different races may still generate reports within a duration that is
+         smaller than the duration defined here. This allows rate limiting
+         reporting to avoid flooding the console with reports.  Setting this
+         to 0 disables rate limiting.
+
+# The main purpose of the below options is to control reported data races (e.g.
+# in fuzzer configs), and are not expected to be switched frequently by other
+# users. We could turn some of them into boot parameters, but given they should
+# not be switched normally, let's keep them here to simplify configuration.
+#
+# The defaults below are chosen to be very conservative, and may miss certain
+# bugs.
 
 config KCSAN_REPORT_RACE_UNKNOWN_ORIGIN
        bool "Report races of unknown origin"
 
 config KCSAN_REPORT_RACE_UNKNOWN_ORIGIN
        bool "Report races of unknown origin"
@@ -103,16 +162,38 @@ config KCSAN_REPORT_VALUE_CHANGE_ONLY
        bool "Only report races where watcher observed a data value change"
        default y
        help
        bool "Only report races where watcher observed a data value change"
        default y
        help
-         If enabled and a conflicting write is observed via watchpoint, but
+         If enabled and a conflicting write is observed via watchpoint, but
          the data value of the memory location was observed to remain
          unchanged, do not report the data race.
 
          the data value of the memory location was observed to remain
          unchanged, do not report the data race.
 
+config KCSAN_ASSUME_PLAIN_WRITES_ATOMIC
+       bool "Assume that plain aligned writes up to word size are atomic"
+       default y
+       help
+         Assume that plain aligned writes up to word size are atomic by
+         default, and also not subject to other unsafe compiler optimizations
+         resulting in data races. This will cause KCSAN to not report data
+         races due to conflicts where the only plain accesses are aligned
+         writes up to word size: conflicts between marked reads and plain
+         aligned writes up to word size will not be reported as data races;
+         notice that data races between two conflicting plain aligned writes
+         will also not be reported.
+
 config KCSAN_IGNORE_ATOMICS
        bool "Do not instrument marked atomic accesses"
 config KCSAN_IGNORE_ATOMICS
        bool "Do not instrument marked atomic accesses"
-       default n
        help
        help
-         If enabled, never instruments marked atomic accesses. This results in
-         not reporting data races where one access is atomic and the other is
-         a plain access.
+         Never instrument marked atomic accesses. This option can be used for
+         additional filtering. Conflicting marked atomic reads and plain
+         writes will never be reported as a data race, however, will cause
+         plain reads and marked writes to result in "unknown origin" reports.
+         If combined with CONFIG_KCSAN_REPORT_RACE_UNKNOWN_ORIGIN=n, data
+         races where at least one access is marked atomic will never be
+         reported.
+
+         Similar to KCSAN_ASSUME_PLAIN_WRITES_ATOMIC, but including unaligned
+         accesses, conflicting marked atomic reads and plain writes will not
+         be reported as data races; however, unlike that option, data races
+         due to two conflicting plain writes will be reported (aligned and
+         unaligned, if CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC=n).
 
 endif # KCSAN
 
 endif # KCSAN