Skip to content
Snippets Groups Projects
  1. Dec 10, 2021
    • Marco Elver's avatar
      kcsan: Ignore GCC 11+ warnings about TSan runtime support · 116af35e
      Marco Elver authored
      GCC 11 has introduced a new warning option, -Wtsan [1], to warn about
      unsupported operations in the TSan runtime. But KCSAN != TSan runtime,
      so none of the warnings apply.
      
      [1] https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/Warning-Options.html
      
      
      
      Ignore the warnings.
      
      Currently the warning only fires in the test for __atomic_thread_fence():
      
      kernel/kcsan/kcsan_test.c: In function ‘test_atomic_builtins’:
      kernel/kcsan/kcsan_test.c:1234:17: warning: ‘atomic_thread_fence’ is not supported with ‘-fsanitize=thread’ [-Wtsan]
       1234 |                 __atomic_thread_fence(__ATOMIC_SEQ_CST);
            |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      which exists to ensure the KCSAN runtime keeps supporting the builtin
      instrumentation.
      
      Signed-off-by: default avatarMarco Elver <elver@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      116af35e
    • Marco Elver's avatar
      kcsan: Add core support for a subset of weak memory modeling · 69562e49
      Marco Elver authored
      
      Add support for modeling a subset of weak memory, which will enable
      detection of a subset of data races due to missing memory barriers.
      
      KCSAN's approach to detecting missing memory barriers is based on
      modeling access reordering, and enabled if `CONFIG_KCSAN_WEAK_MEMORY=y`,
      which depends on `CONFIG_KCSAN_STRICT=y`. The feature can be enabled or
      disabled at boot and runtime via the `kcsan.weak_memory` boot parameter.
      
      Each memory access for which a watchpoint is set up, is also selected
      for simulated reordering within the scope of its function (at most 1
      in-flight access).
      
      We are limited to modeling the effects of "buffering" (delaying the
      access), since the runtime cannot "prefetch" accesses (therefore no
      acquire modeling). Once an access has been selected for reordering, it
      is checked along every other access until the end of the function scope.
      If an appropriate memory barrier is encountered, the access will no
      longer be considered for reordering.
      
      When the result of a memory operation should be ordered by a barrier,
      KCSAN can then detect data races where the conflict only occurs as a
      result of a missing barrier due to reordering accesses.
      
      Suggested-by: default avatarDmitry Vyukov <dvyukov@google.com>
      Signed-off-by: default avatarMarco Elver <elver@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      69562e49
  2. Sep 24, 2020
    • Masahiro Yamada's avatar
      kbuild: move CFLAGS_{KASAN,UBSAN,KCSAN} exports to relevant Makefiles · bb273211
      Masahiro Yamada authored
      
      Move CFLAGS_KASAN*, CFLAGS_UBSAN, CFLAGS_KCSAN to Makefile.kasan,
      Makefile.ubsan, Makefile.kcsan, respectively.
      
      This commit also avoids the same -fsanitize=* flags being added to
      CFLAGS_UBSAN multiple times.
      
      Prior to this commit, the ubsan flags were appended by the '+='
      operator, without any initialization. Some build targets such as
      'make bindeb-pkg' recurses to the top Makefile, and ended up with
      adding the same flags to CFLAGS_UBSAN twice.
      
      Clear CFLAGS_UBSAN with ':=' to make it a simply expanded variable.
      This is better than a recursively expanded variable, which evaluates
      $(call cc-option, ...) multiple times before Kbuild starts descending
      to subdirectories.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Acked-by: default avatarMarco Elver <elver@google.com>
      bb273211
  3. Aug 24, 2020
    • Marco Elver's avatar
      kcsan: Support compounded read-write instrumentation · 14e2ac8d
      Marco Elver authored
      Add support for compounded read-write instrumentation if supported by
      the compiler. Adds the necessary instrumentation functions, and a new
      type which is used to generate a more descriptive report.
      
      Furthermore, such compounded memory access instrumentation is excluded
      from the "assume aligned writes up to word size are atomic" rule,
      because we cannot assume that the compiler emits code that is atomic for
      compound ops.
      
      LLVM/Clang added support for the feature in:
      https://github.com/llvm/llvm-project/commit/785d41a261d136b64ab6c15c5d35f2adc5ad53e3
      
      
      
      The new instrumentation is emitted for sets of memory accesses in the
      same basic block to the same address with at least one read appearing
      before a write. These typically result from compound operations such as
      ++, --, +=, -=, |=, &=, etc. but also equivalent forms such as "var =
      var + 1". Where the compiler determines that it is equivalent to emit a
      call to a single __tsan_read_write instead of separate __tsan_read and
      __tsan_write, we can then benefit from improved performance and better
      reporting for such access patterns.
      
      The new reports now show that the ops are both reads and writes, for
      example:
      
      	read-write to 0xffffffff90548a38 of 8 bytes by task 143 on cpu 3:
      	 test_kernel_rmw_array+0x45/0xa0
      	 access_thread+0x71/0xb0
      	 kthread+0x21e/0x240
      	 ret_from_fork+0x22/0x30
      
      	read-write to 0xffffffff90548a38 of 8 bytes by task 144 on cpu 2:
      	 test_kernel_rmw_array+0x45/0xa0
      	 access_thread+0x71/0xb0
      	 kthread+0x21e/0x240
      	 ret_from_fork+0x22/0x30
      
      Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarMarco Elver <elver@google.com>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      14e2ac8d
  4. Aug 09, 2020
  5. Jun 29, 2020
  6. Jun 11, 2020
  7. Nov 16, 2019
Loading