lib/locking-selftest.c
Source file repositories/reference/linux-study-clean/lib/locking-selftest.c
File Facts
- System
- Linux kernel
- Corpus path
lib/locking-selftest.c- Extension
.c- Size
- 67169 bytes
- Lines
- 2989
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/rwsem.hlinux/mutex.hlinux/ww_mutex.hlinux/sched.hlinux/sched/mm.hlinux/delay.hlinux/lockdep.hlinux/spinlock.hlinux/kallsyms.hlinux/interrupt.hlinux/debug_locks.hlinux/irqflags.hlinux/rtmutex.hlinux/local_lock.hlocking-selftest-spin.hlocking-selftest-wlock.hlocking-selftest-rlock.hlocking-selftest-mutex.hlocking-selftest-wsem.hlocking-selftest-rsem.hlocking-selftest-rtmutex.h
Detected Declarations
function setup_debug_locks_verbosefunction init_shared_classesfunction namefunction rlock_AA1function rlock_AA1Bfunction rsem_AA1function rsem_AA1Bfunction rlock_AA2function rsem_AA2function rlock_AA3function rsem_AA3function read_lockfunction rwsem_ABBA1function rlock_chaincache_ABBA1function read_lockfunction rwsem_ABBA2function write_lockfunction rwsem_ABBA3function reset_locksfunction dotestfunction print_testnamefunction ww_test_fail_acquirefunction ww_test_normalfunction ww_test_two_contextsfunction ww_test_diff_classfunction ww_test_context_done_twicefunction ww_test_context_unlock_twicefunction ww_test_context_fini_earlyfunction ww_test_context_lock_after_donefunction ww_test_object_unlock_twicefunction ww_test_object_lock_unbalancedfunction ww_test_object_lock_stale_contextfunction ww_test_edeadlk_normalfunction ww_test_edeadlk_normal_slowfunction ww_test_edeadlk_no_unlockfunction ww_test_edeadlk_no_unlock_slowfunction ww_test_edeadlk_acquire_morefunction ww_test_edeadlk_acquire_more_slowfunction ww_test_edeadlk_acquire_more_edeadlkfunction ww_test_edeadlk_acquire_more_edeadlk_slowfunction ww_test_edeadlk_acquire_wrongfunction ww_test_edeadlk_acquire_wrong_slowfunction ww_test_spin_nest_unlockedfunction ww_test_spin_nest_lockfunction ww_test_unneeded_slowfunction ww_test_context_blockfunction ww_test_context_tryfunction ww_test_context_context
Annotated Snippet
static void name(void) { E(); }
#define GENERATE_PERMUTATIONS_2_EVENTS(name) \
\
static void name##_12(void) { E1(); E2(); } \
static void name##_21(void) { E2(); E1(); }
#define GENERATE_PERMUTATIONS_3_EVENTS(name) \
\
static void name##_123(void) { E1(); E2(); E3(); } \
static void name##_132(void) { E1(); E3(); E2(); } \
static void name##_213(void) { E2(); E1(); E3(); } \
static void name##_231(void) { E2(); E3(); E1(); } \
static void name##_312(void) { E3(); E1(); E2(); } \
static void name##_321(void) { E3(); E2(); E1(); }
/*
* AA deadlock:
*/
#define E() \
\
LOCK(X1); \
LOCK(X2); /* this one should fail */
/*
* 6 testcases:
*/
#include "locking-selftest-spin.h"
GENERATE_TESTCASE(AA_spin)
#include "locking-selftest-wlock.h"
GENERATE_TESTCASE(AA_wlock)
#include "locking-selftest-rlock.h"
GENERATE_TESTCASE(AA_rlock)
#include "locking-selftest-mutex.h"
GENERATE_TESTCASE(AA_mutex)
#include "locking-selftest-wsem.h"
GENERATE_TESTCASE(AA_wsem)
#include "locking-selftest-rsem.h"
GENERATE_TESTCASE(AA_rsem)
#ifdef CONFIG_RT_MUTEXES
#include "locking-selftest-rtmutex.h"
GENERATE_TESTCASE(AA_rtmutex);
#endif
#undef E
/*
* Special-case for read-locking, they are
* allowed to recurse on the same lock class:
*/
static void rlock_AA1(void)
{
RL(X1);
RL(X1); // this one should NOT fail
}
static void rlock_AA1B(void)
{
RL(X1);
RL(X2); // this one should NOT fail
}
static void rsem_AA1(void)
{
RSL(X1);
RSL(X1); // this one should fail
}
static void rsem_AA1B(void)
{
RSL(X1);
RSL(X2); // this one should fail
}
/*
* The mixing of read and write locks is not allowed:
*/
static void rlock_AA2(void)
{
RL(X1);
WL(X2); // this one should fail
}
static void rsem_AA2(void)
{
RSL(X1);
WSL(X2); // this one should fail
}
Annotation
- Immediate include surface: `linux/rwsem.h`, `linux/mutex.h`, `linux/ww_mutex.h`, `linux/sched.h`, `linux/sched/mm.h`, `linux/delay.h`, `linux/lockdep.h`, `linux/spinlock.h`.
- Detected declarations: `function setup_debug_locks_verbose`, `function init_shared_classes`, `function name`, `function rlock_AA1`, `function rlock_AA1B`, `function rsem_AA1`, `function rsem_AA1B`, `function rlock_AA2`, `function rsem_AA2`, `function rlock_AA3`.
- Atlas domain: Kernel Services / lib.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.