linux/kernel/kcsan
Marco Elver a70d36e6a0 kcsan: Make barrier tests compatible with lockdep
The barrier tests in selftest and the kcsan_test module only need the
spinlock and mutex to test correct barrier instrumentation. Therefore,
these were initially placed on the stack.

However, lockdep asserts that locks are in static storage, and will
generate this warning:

 | INFO: trying to register non-static key.
 | The code is fine but needs lockdep annotation, or maybe
 | you didn't initialize this object before use?
 | turning off the locking correctness validator.
 | CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.16.0-rc1+ #3208
 | Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-1ubuntu1.1 04/01/2014
 | Call Trace:
 |  <TASK>
 |  dump_stack_lvl+0x88/0xd8
 |  dump_stack+0x15/0x1b
 |  register_lock_class+0x6b3/0x840
 |  ...
 |  test_barrier+0x490/0x14c7
 |  kcsan_selftest+0x47/0xa0
 |  ...

To fix, move the test locks into static storage.

Fixing the above also revealed that lock operations are strengthened on
first use with lockdep enabled, due to lockdep calling out into
non-instrumented files (recall that kernel/locking/lockdep.c is not
instrumented with KCSAN).

Only kcsan_test checks for over-instrumentation of *_lock() operations,
where we can simply "warm up" the test locks to avoid the test case
failing with lockdep.

Reported-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
2021-12-09 16:42:28 -08:00
..
core.c kcsan: Add core memory barrier instrumentation functions 2021-12-09 16:42:26 -08:00
debugfs.c kcsan: use u64 instead of cycles_t 2021-07-30 17:09:02 +02:00
encoding.h
kcsan_test.c kcsan: Make barrier tests compatible with lockdep 2021-12-09 16:42:28 -08:00
kcsan.h kcsan: Add ability to pass instruction pointer of access to reporting 2021-09-13 16:41:19 -07:00
Makefile kcsan: selftest: Add test case to check memory barrier instrumentation 2021-12-09 16:42:27 -08:00
permissive.h kcsan: permissive: Ignore data-racy 1-bit value changes 2021-07-20 13:49:44 -07:00
report.c kcsan: Show location access was reordered to 2021-12-09 16:42:27 -08:00
selftest.c kcsan: Make barrier tests compatible with lockdep 2021-12-09 16:42:28 -08:00