diff options
| author | John Stultz <[email protected]> | 2023-02-21 19:02:36 +0000 |
|---|---|---|
| committer | Paul E. McKenney <[email protected]> | 2023-03-07 10:13:57 -0800 |
| commit | 3e5aeaf53422bdd79fecf89aa160f048114e013c (patch) | |
| tree | fb89ae31fdc4c7aa34f81dc9ec7d9229e661125b /kernel/locking | |
| parent | b63343207da21179d82df933f42a1725a53b9a63 (diff) | |
locktorture: Add nested locking to mutex torture tests
This patch adds randomized nested locking to the mutex torture
tests, as well as new LOCK08 config files for testing mutexes
with nested locking
Cc: Davidlohr Bueso <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Cc: Josh Triplett <[email protected]>
Cc: Joel Fernandes <[email protected]>
Cc: Juri Lelli <[email protected]>
Cc: Valentin Schneider <[email protected]>
Cc: Dietmar Eggemann <[email protected]>
Cc: [email protected]
Reviewed-by: Davidlohr Bueso <[email protected]>
Co-developed-by: Connor O'Brien <[email protected]>
Signed-off-by: Connor O'Brien <[email protected]>
Signed-off-by: John Stultz <[email protected]>
Signed-off-by: Paul E. McKenney <[email protected]>
Diffstat (limited to 'kernel/locking')
| -rw-r--r-- | kernel/locking/locktorture.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index a8519af25ece..a4d15a9a9d7f 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -370,6 +370,28 @@ static struct lock_torture_ops rw_lock_irq_ops = { }; static DEFINE_MUTEX(torture_mutex); +static struct mutex torture_nested_mutexes[MAX_NESTED_LOCKS]; +static struct lock_class_key nested_mutex_keys[MAX_NESTED_LOCKS]; + +static void torture_mutex_init(void) +{ + int i; + + for (i = 0; i < MAX_NESTED_LOCKS; i++) + __mutex_init(&torture_nested_mutexes[i], __func__, + &nested_mutex_keys[i]); +} + +static int torture_mutex_nested_lock(int tid __maybe_unused, + u32 lockset) +{ + int i; + + for (i = 0; i < nested_locks; i++) + if (lockset & (1 << i)) + mutex_lock(&torture_nested_mutexes[i]); + return 0; +} static int torture_mutex_lock(int tid __maybe_unused) __acquires(torture_mutex) @@ -398,11 +420,24 @@ __releases(torture_mutex) mutex_unlock(&torture_mutex); } +static void torture_mutex_nested_unlock(int tid __maybe_unused, + u32 lockset) +{ + int i; + + for (i = nested_locks - 1; i >= 0; i--) + if (lockset & (1 << i)) + mutex_unlock(&torture_nested_mutexes[i]); +} + static struct lock_torture_ops mutex_lock_ops = { + .init = torture_mutex_init, + .nested_lock = torture_mutex_nested_lock, .writelock = torture_mutex_lock, .write_delay = torture_mutex_delay, .task_boost = torture_rt_boost, .writeunlock = torture_mutex_unlock, + .nested_unlock = torture_mutex_nested_unlock, .readlock = NULL, .read_delay = NULL, .readunlock = NULL, |