]> git.baikalelectronics.ru Git - kernel.git/commit
kcsan: Add support for scoped accesses
authorMarco Elver <elver@google.com>
Wed, 25 Mar 2020 16:41:56 +0000 (17:41 +0100)
committerPaul E. McKenney <paulmck@kernel.org>
Tue, 14 Apr 2020 00:18:11 +0000 (17:18 -0700)
commite79ea68a5e34684f6828a5ca478d0697db077282
tree977a8e0f86eb623366b89e15d298aa492dd28f46
parentdb2fb519fa5b51e5d75d238e75b76b2f82f99aa1
kcsan: Add support for scoped accesses

This adds support for scoped accesses, where the memory range is checked
for the duration of the scope. The feature is implemented by inserting
the relevant access information into a list of scoped accesses for
the current execution context, which are then checked (until removed)
on every call (through instrumentation) into the KCSAN runtime.

An alternative, more complex, implementation could set up a watchpoint for
the scoped access, and keep the watchpoint set up. This, however, would
require first exposing a handle to the watchpoint, as well as dealing
with cases such as accesses by the same thread while the watchpoint is
still set up (and several more cases). It is also doubtful if this would
provide any benefit, since the majority of delay where the watchpoint
is set up is likely due to the injected delays by KCSAN.  Therefore,
the implementation in this patch is simpler and avoids hurting KCSAN's
main use-case (normal data race detection); it also implicitly increases
scoped-access race-detection-ability due to increased probability of
setting up watchpoints by repeatedly calling __kcsan_check_access()
throughout the scope of the access.

The implementation required adding an additional conditional branch to
the fast-path. However, the microbenchmark showed a *speedup* of ~5%
on the fast-path. This appears to be due to subtly improved codegen by
GCC from moving get_ctx() and associated load of preempt_count earlier.

Suggested-by: Boqun Feng <boqun.feng@gmail.com>
Suggested-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
include/linux/kcsan-checks.h
include/linux/kcsan.h
init/init_task.c
kernel/kcsan/core.c
kernel/kcsan/report.c