Skip to content

Commit cae2ed9

Browse files
Ingo MolnarLinus Torvalds
Ingo Molnar
authored and
Linus Torvalds
committed
[PATCH] lockdep: locking API self tests
Introduce DEBUG_LOCKING_API_SELFTESTS, which uses the generic lock debugging code's silent-failure feature to run a matrix of testcases. There are 210 testcases currently: +----------------------- | Locking API testsuite: +------------------------------+------+------+------+------+------+------+ | spin |wlock |rlock |mutex | wsem | rsem | -------------------------------+------+------+------+------+------+------+ A-A deadlock: ok | ok | ok | ok | ok | ok | A-B-B-A deadlock: ok | ok | ok | ok | ok | ok | A-B-B-C-C-A deadlock: ok | ok | ok | ok | ok | ok | A-B-C-A-B-C deadlock: ok | ok | ok | ok | ok | ok | A-B-B-C-C-D-D-A deadlock: ok | ok | ok | ok | ok | ok | A-B-C-D-B-D-D-A deadlock: ok | ok | ok | ok | ok | ok | A-B-C-D-B-C-D-A deadlock: ok | ok | ok | ok | ok | ok | double unlock: ok | ok | ok | ok | ok | ok | bad unlock order: ok | ok | ok | ok | ok | ok | --------------------------------------+------+------+------+------+------+ recursive read-lock: | ok | | ok | --------------------------------------+------+------+------+------+------+ non-nested unlock: ok | ok | ok | ok | --------------------------------------+------+------+------+ hard-irqs-on + irq-safe-A/12: ok | ok | ok | soft-irqs-on + irq-safe-A/12: ok | ok | ok | hard-irqs-on + irq-safe-A/21: ok | ok | ok | soft-irqs-on + irq-safe-A/21: ok | ok | ok | sirq-safe-A => hirqs-on/12: ok | ok | ok | sirq-safe-A => hirqs-on/21: ok | ok | ok | hard-safe-A + irqs-on/12: ok | ok | ok | soft-safe-A + irqs-on/12: ok | ok | ok | hard-safe-A + irqs-on/21: ok | ok | ok | soft-safe-A + irqs-on/21: ok | ok | ok | hard-safe-A + unsafe-B #1/123: ok | ok | ok | soft-safe-A + unsafe-B #1/123: ok | ok | ok | hard-safe-A + unsafe-B #1/132: ok | ok | ok | soft-safe-A + unsafe-B #1/132: ok | ok | ok | hard-safe-A + unsafe-B #1/213: ok | ok | ok | soft-safe-A + unsafe-B #1/213: ok | ok | ok | hard-safe-A + unsafe-B #1/231: ok | ok | ok | soft-safe-A + unsafe-B #1/231: ok | ok | ok | hard-safe-A + unsafe-B #1/312: ok | ok | ok | soft-safe-A + unsafe-B #1/312: ok | ok | ok | hard-safe-A + unsafe-B #1/321: ok | ok | ok | soft-safe-A + unsafe-B #1/321: ok | ok | ok | hard-safe-A + unsafe-B #2/123: ok | ok | ok | soft-safe-A + unsafe-B #2/123: ok | ok | ok | hard-safe-A + unsafe-B #2/132: ok | ok | ok | soft-safe-A + unsafe-B #2/132: ok | ok | ok | hard-safe-A + unsafe-B #2/213: ok | ok | ok | soft-safe-A + unsafe-B #2/213: ok | ok | ok | hard-safe-A + unsafe-B #2/231: ok | ok | ok | soft-safe-A + unsafe-B #2/231: ok | ok | ok | hard-safe-A + unsafe-B #2/312: ok | ok | ok | soft-safe-A + unsafe-B #2/312: ok | ok | ok | hard-safe-A + unsafe-B #2/321: ok | ok | ok | soft-safe-A + unsafe-B #2/321: ok | ok | ok | hard-irq lock-inversion/123: ok | ok | ok | soft-irq lock-inversion/123: ok | ok | ok | hard-irq lock-inversion/132: ok | ok | ok | soft-irq lock-inversion/132: ok | ok | ok | hard-irq lock-inversion/213: ok | ok | ok | soft-irq lock-inversion/213: ok | ok | ok | hard-irq lock-inversion/231: ok | ok | ok | soft-irq lock-inversion/231: ok | ok | ok | hard-irq lock-inversion/312: ok | ok | ok | soft-irq lock-inversion/312: ok | ok | ok | hard-irq lock-inversion/321: ok | ok | ok | soft-irq lock-inversion/321: ok | ok | ok | hard-irq read-recursion/123: ok | soft-irq read-recursion/123: ok | hard-irq read-recursion/132: ok | soft-irq read-recursion/132: ok | hard-irq read-recursion/213: ok | soft-irq read-recursion/213: ok | hard-irq read-recursion/231: ok | soft-irq read-recursion/231: ok | hard-irq read-recursion/312: ok | soft-irq read-recursion/312: ok | hard-irq read-recursion/321: ok | soft-irq read-recursion/321: ok | --------------------------------+-----+---------------- Good, all 210 testcases passed! | --------------------------------+ Signed-off-by: Ingo Molnar <[email protected]> Signed-off-by: Arjan van de Ven <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1f194a4 commit cae2ed9

18 files changed

+1347
-0
lines changed

Documentation/kernel-parameters.txt

+9
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,15 @@ running once the system is up.
435435

436436
debug [KNL] Enable kernel debugging (events log level).
437437

438+
debug_locks_verbose=
439+
[KNL] verbose self-tests
440+
Format=<0|1>
441+
Print debugging info while doing the locking API
442+
self-tests.
443+
We default to 0 (no extra messages), setting it to
444+
1 will print _a lot_ more information - normally
445+
only useful to kernel developers.
446+
438447
decnet= [HW,NET]
439448
Format: <area>[,<node>]
440449
See also Documentation/networking/decnet.txt.

lib/Kconfig.debug

+11
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ config DEBUG_SPINLOCK_SLEEP
149149
If you say Y here, various routines which may sleep will become very
150150
noisy if they are called with a spinlock held.
151151

152+
config DEBUG_LOCKING_API_SELFTESTS
153+
bool "Locking API boot-time self-tests"
154+
depends on DEBUG_KERNEL
155+
help
156+
Say Y here if you want the kernel to run a short self-test during
157+
bootup. The self-test checks whether common types of locking bugs
158+
are detected by debugging mechanisms or not. (if you disable
159+
lock debugging then those bugs wont be detected of course.)
160+
The following locking APIs are covered: spinlocks, rwlocks,
161+
mutexes and rwsems.
162+
152163
config STACKTRACE
153164
bool
154165
depends on STACKTRACE_SUPPORT

lib/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ CFLAGS_kobject.o += -DDEBUG
1818
CFLAGS_kobject_uevent.o += -DDEBUG
1919
endif
2020

21+
obj-$(CONFIG_DEBUG_LOCKING_API_SELFTESTS) += locking-selftest.o
2122
obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o
2223
lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
2324
lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o

lib/locking-selftest-hardirq.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#undef IRQ_DISABLE
2+
#undef IRQ_ENABLE
3+
#undef IRQ_ENTER
4+
#undef IRQ_EXIT
5+
6+
#define IRQ_ENABLE HARDIRQ_ENABLE
7+
#define IRQ_DISABLE HARDIRQ_DISABLE
8+
#define IRQ_ENTER HARDIRQ_ENTER
9+
#define IRQ_EXIT HARDIRQ_EXIT

lib/locking-selftest-mutex.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#undef LOCK
2+
#define LOCK ML
3+
4+
#undef UNLOCK
5+
#define UNLOCK MU
6+
7+
#undef RLOCK
8+
#undef WLOCK
9+
10+
#undef INIT
11+
#define INIT MI

lib/locking-selftest-rlock-hardirq.h

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "locking-selftest-rlock.h"
2+
#include "locking-selftest-hardirq.h"

lib/locking-selftest-rlock-softirq.h

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "locking-selftest-rlock.h"
2+
#include "locking-selftest-softirq.h"

lib/locking-selftest-rlock.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#undef LOCK
2+
#define LOCK RL
3+
4+
#undef UNLOCK
5+
#define UNLOCK RU
6+
7+
#undef RLOCK
8+
#define RLOCK RL
9+
10+
#undef WLOCK
11+
#define WLOCK WL
12+
13+
#undef INIT
14+
#define INIT RWI

lib/locking-selftest-rsem.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#undef LOCK
2+
#define LOCK RSL
3+
4+
#undef UNLOCK
5+
#define UNLOCK RSU
6+
7+
#undef RLOCK
8+
#define RLOCK RSL
9+
10+
#undef WLOCK
11+
#define WLOCK WSL
12+
13+
#undef INIT
14+
#define INIT RWSI

lib/locking-selftest-softirq.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#undef IRQ_DISABLE
2+
#undef IRQ_ENABLE
3+
#undef IRQ_ENTER
4+
#undef IRQ_EXIT
5+
6+
#define IRQ_DISABLE SOFTIRQ_DISABLE
7+
#define IRQ_ENABLE SOFTIRQ_ENABLE
8+
#define IRQ_ENTER SOFTIRQ_ENTER
9+
#define IRQ_EXIT SOFTIRQ_EXIT

lib/locking-selftest-spin-hardirq.h

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "locking-selftest-spin.h"
2+
#include "locking-selftest-hardirq.h"

lib/locking-selftest-spin-softirq.h

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "locking-selftest-spin.h"
2+
#include "locking-selftest-softirq.h"

lib/locking-selftest-spin.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#undef LOCK
2+
#define LOCK L
3+
4+
#undef UNLOCK
5+
#define UNLOCK U
6+
7+
#undef RLOCK
8+
#undef WLOCK
9+
10+
#undef INIT
11+
#define INIT SI

lib/locking-selftest-wlock-hardirq.h

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "locking-selftest-wlock.h"
2+
#include "locking-selftest-hardirq.h"

lib/locking-selftest-wlock-softirq.h

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "locking-selftest-wlock.h"
2+
#include "locking-selftest-softirq.h"

lib/locking-selftest-wlock.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#undef LOCK
2+
#define LOCK WL
3+
4+
#undef UNLOCK
5+
#define UNLOCK WU
6+
7+
#undef RLOCK
8+
#define RLOCK RL
9+
10+
#undef WLOCK
11+
#define WLOCK WL
12+
13+
#undef INIT
14+
#define INIT RWI

lib/locking-selftest-wsem.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#undef LOCK
2+
#define LOCK WSL
3+
4+
#undef UNLOCK
5+
#define UNLOCK WSU
6+
7+
#undef RLOCK
8+
#define RLOCK RSL
9+
10+
#undef WLOCK
11+
#define WLOCK WSL
12+
13+
#undef INIT
14+
#define INIT RWSI

0 commit comments

Comments
 (0)