Hi,

Please consider the following patch for the v7.3 merge window.

This patch adds a stress-based selftest for kernel locking and atomic
synchronization primitives. The test runs concurrent workers against
an array of counters while maintaining a simple invariant: every
increment is paired with a decrement, so the sum of all counters must
remain zero.

A common test interface allows the same workload to exercise a range
of locking primitives, including spinlocks and rwlocks, as well as
variants using atomic and bit operations without an explicit
lock. After the workers complete, the module checks the invariant and
reports a failure if the resulting sum is nonzero.

The test provides regression coverage for memory-ordering issues that
may otherwise be difficult to reproduce. In particular, it can expose
the regression fixed by commit 415d83249709 ("locking/atomic: Make
test_and_*_bit() ordered on failure") on weakly ordered architectures
such as ARM. It also includes a variant modeling the incorrect
acquire/release ordering formerly used by RDS before commit
1422f28826d2 ("rds: introduce acquire/release ordering in
acquire/release_in_xmit()"). This variant fails on ARM systems.

The patch also adds a kselftest script that:

* first runs an intentionally unsynchronized variant to verify that the
  workload is capable of exposing lost updates;
* obtains the available test variants from the module;
* runs each non-broken variant; and
* supports low, medium, and high effort levels for interactive and CI use.

The module exposes parameters for selecting the test variant, run
duration, number of elements, and data-structure padding. Varying the
padding is useful because the reproducibility of some ordering
failures depends on the relative placement of the tested state in
memory.

A successful run does not prove correctness, but the test provides a
practical way to detect synchronization regressions and reproduce
known classes of ordering bugs under load.

If this commit gets accepted, I have the intention, subject to other
work priorities, to expand on the locking primitives, and in
particular add a double set of ww_mutexes for each counter and attempt
to acquire both in a random order. Using both the Wound-Wait and
Wait-Die variants.


Thxs, Håkon


Håkon Bugge (1):
  kernel/locking: Add mutual exclusion self-test

 kernel/locking/Makefile                    |   1 +
 kernel/locking/mx_test.c                   | 707 +++++++++++++++++++++
 lib/Kconfig.debug                          |   9 +
 tools/testing/selftests/locking/Makefile   |   2 +-
 tools/testing/selftests/locking/mx_test.sh | 181 ++++++
 5 files changed, 899 insertions(+), 1 deletion(-)
 create mode 100644 kernel/locking/mx_test.c
 create mode 100755 tools/testing/selftests/locking/mx_test.sh

--
2.43.5


Reply via email to