25 Aug, 2020

5 commits

  • Remove kcsan_counter_inc/dec() functions, as they perform no other
    logic, and are no longer needed.

    This avoids several calls in kcsan_setup_watchpoint() and
    kcsan_found_watchpoint(), as well as lets the compiler warn us about
    potential out-of-bounds accesses as the array's size is known at all
    usage sites at compile-time.

    Signed-off-by: Marco Elver
    Signed-off-by: Paul E. McKenney

    Marco Elver
     
  • Use the same pr_fmt throughout for consistency. [ The only exception is
    report.c, where the format must be kept precisely as-is. ]

    Signed-off-by: Marco Elver
    Signed-off-by: Paul E. McKenney

    Marco Elver
     
  • Remove the debugfs test command, as it is no longer needed now that we
    have the KUnit+Torture based kcsan-test module. This is to avoid
    confusion around how KCSAN should be tested, as only the kcsan-test
    module is maintained.

    Signed-off-by: Marco Elver
    Signed-off-by: Paul E. McKenney

    Marco Elver
     
  • Simplify checking prefixes and length calculation of constant strings.
    For the former, the kernel provides str_has_prefix(), and the latter we
    should just use strlen("..") because GCC and Clang have optimizations
    that optimize these into constants.

    No functional change intended.

    Signed-off-by: Marco Elver
    Signed-off-by: Paul E. McKenney

    Marco Elver
     
  • Simplify counter ID to name mapping by using an array with designated
    inits. This way, we can turn a run-time BUG() into a compile-time static
    assertion failure if a counter name is missing.

    No functional change intended.

    Signed-off-by: Marco Elver
    Signed-off-by: Paul E. McKenney

    Marco Elver
     

28 Apr, 2020

1 commit


14 Apr, 2020

1 commit

  • Introduce ASSERT_EXCLUSIVE_*_SCOPED(), which provide an intuitive
    interface to use the scoped-access feature, without having to explicitly
    mark the start and end of the desired scope. Basing duration of the
    checks on scope avoids accidental misuse and resulting false positives,
    which may be hard to debug. See added comments for usage.

    The macros are implemented using __attribute__((__cleanup__(func))),
    which is supported by all compilers that currently support KCSAN.

    Suggested-by: Boqun Feng
    Suggested-by: Paul E. McKenney
    Signed-off-by: Marco Elver
    Signed-off-by: Paul E. McKenney

    Marco Elver
     

26 Mar, 2020

1 commit

  • Add volatile current->state to list of implicitly atomic accesses. This
    is in preparation to eventually enable KCSAN on kernel/sched (which
    currently still has KCSAN_SANITIZE := n).

    Since accesses that match the special check in atomic.h are rare, it
    makes more sense to move this check to the slow-path, avoiding the
    additional compare in the fast-path. With the microbenchmark, a speedup
    of ~6% is measured.

    Signed-off-by: Marco Elver
    Signed-off-by: Paul E. McKenney

    Marco Elver
     

21 Mar, 2020

3 commits

  • This introduces ASSERT_EXCLUSIVE_BITS(var, mask).
    ASSERT_EXCLUSIVE_BITS(var, mask) will cause KCSAN to assume that the
    following access is safe w.r.t. data races (however, please see the
    docbook comment for disclaimer here).

    For more context on why this was considered necessary, please see:

    http://lkml.kernel.org/r/1580995070-25139-1-git-send-email-cai@lca.pw

    In particular, before this patch, data races between reads (that use
    @mask bits of an access that should not be modified concurrently) and
    writes (that change ~@mask bits not used by the readers) would have been
    annotated with "data_race()" (or "READ_ONCE()"). However, doing so would
    then hide real problems: we would no longer be able to detect harmful
    races between reads to @mask bits and writes to @mask bits.

    Therefore, by using ASSERT_EXCLUSIVE_BITS(var, mask), we accomplish:

    1. Avoid proliferation of specific macros at the call sites: by
    including a single mask in the argument list, we can use the same
    macro in a wide variety of call sites, regardless of how and which
    bits in a field each call site actually accesses.

    2. The existing code does not need to be modified (although READ_ONCE()
    may still be advisable if we cannot prove that the data race is
    always safe).

    3. We catch bugs where the exclusive bits are modified concurrently.

    4. We document properties of the current code.

    Acked-by: John Hubbard
    Signed-off-by: Marco Elver
    Signed-off-by: Paul E. McKenney
    Signed-off-by: Ingo Molnar
    Cc: David Hildenbrand
    Cc: Jan Kara
    Cc: Qian Cai

    Marco Elver
     
  • Add 'test=' option to KCSAN's debugfs interface to invoke KCSAN
    checks on a dummy variable. By writing 'test=' to the debugfs
    file from multiple tasks, we can generate real conflicts, and trigger
    data race reports.

    Signed-off-by: Marco Elver
    Signed-off-by: Paul E. McKenney
    Signed-off-by: Ingo Molnar

    Marco Elver
     
  • The KCSAN_ACCESS_ASSERT access type may be used to introduce dummy reads
    and writes to assert certain properties of concurrent code, where bugs
    could not be detected as normal data races.

    For example, a variable that is only meant to be written by a single
    CPU, but may be read (without locking) by other CPUs must still be
    marked properly to avoid data races. However, concurrent writes,
    regardless if WRITE_ONCE() or not, would be a bug. Using
    kcsan_check_access(&x, sizeof(x), KCSAN_ACCESS_ASSERT) would allow
    catching such bugs.

    To support KCSAN_ACCESS_ASSERT the following notable changes were made:

    * If an access is of type KCSAN_ASSERT_ACCESS, disable various filters
    that only apply to data races, so that all races that KCSAN observes are
    reported.
    * Bug reports that involve an ASSERT access type will be reported as
    "KCSAN: assert: race in ..." instead of "data-race"; this will help
    more easily distinguish them.
    * Update a few comments to just mention 'races' where we do not always
    mean pure data races.

    Signed-off-by: Marco Elver
    Signed-off-by: Paul E. McKenney
    Signed-off-by: Ingo Molnar

    Marco Elver
     

20 Nov, 2019

1 commit

  • Tidy up a few bits:

    - Fix typos and grammar, improve wording.

    - Remove spurious newlines that are col80 warning artifacts where the
    resulting line-break is worse than the disease it's curing.

    - Use core kernel coding style to improve readability and reduce
    spurious code pattern variations.

    - Use better vertical alignment for structure definitions and initialization
    sequences.

    - Misc other small details.

    No change in functionality intended.

    Cc: linux-kernel@vger.kernel.org
    Cc: Marco Elver
    Cc: Paul E. McKenney
    Cc: Peter Zijlstra
    Cc: Linus Torvalds
    Cc: Andrew Morton
    Cc: Thomas Gleixner
    Cc: Paul E. McKenney
    Cc: Will Deacon
    Signed-off-by: Ingo Molnar

    Ingo Molnar
     

16 Nov, 2019

1 commit

  • Kernel Concurrency Sanitizer (KCSAN) is a dynamic data-race detector for
    kernel space. KCSAN is a sampling watchpoint-based data-race detector.
    See the included Documentation/dev-tools/kcsan.rst for more details.

    This patch adds basic infrastructure, but does not yet enable KCSAN for
    any architecture.

    Signed-off-by: Marco Elver
    Acked-by: Paul E. McKenney
    Signed-off-by: Paul E. McKenney

    Marco Elver