Skip to content

Commit 00c5403

Browse files
committed
Revert "evl/thread: remove useless dynamic lock key"
This reverts commit 5ae263a6ca027c4b79c4dfacfcf4eca8209eefd0, because disambiguating the per-thread lock is not as useless as it seemed at first. Fixes this regression when CONFIG_DEBUG_HARD_SPINLOCKS is on: [ 52.090120] [ 52.090129] ============================================ [ 52.090134] WARNING: possible recursive locking detected [ 52.090139] 5.10.199-00830-g18654c202dd6 torvalds#118 Not tainted [ 52.090143] -------------------------------------------- [ 52.090147] monitor-dlk-A:4/493 is trying to acquire lock: [ 52.090152] c34a7010 (__RAWLOCK(&thread->lock)){-.-.}-{0:0}, at: evl_lock_mutex_timeout+0x4e0/0x870 [ 52.090169] [ 52.090173] but task is already holding lock: [ 52.090176] c34a5810 (__RAWLOCK(&thread->lock)){-.-.}-{0:0}, at: evl_lock_mutex_timeout+0x4e0/0x870 [ 52.090192] [ 52.090195] other info that might help us debug this: [ 52.090199] Possible unsafe locking scenario: [ 52.090202] [ 52.090205] CPU0 [ 52.090208] ---- [ 52.090211] lock(__RAWLOCK(&thread->lock)); [ 52.090221] lock(__RAWLOCK(&thread->lock)); [ 52.090229] [ 52.090233] *** DEADLOCK *** [ 52.090235] [ 52.090239] May be due to missing lock nesting notation [ 52.090242] [ 52.090246] 2 locks held by monitor-dlk-A:4/493: [ 52.090249] #0: c2d030d4 (&mon->mutex){....}-{0:0}, at: evl_lock_mutex_timeout+0x104/0x870 [ 52.090267] #1: c34a5810 (__RAWLOCK(&thread->lock)){-.-.}-{0:0}, at: evl_lock_mutex_timeout+0x4e0/0x870 Signed-off-by: Philippe Gerum <[email protected]>
1 parent 388ec9a commit 00c5403

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

include/evl/thread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct evl_init_thread_attr {
6363

6464
struct evl_thread {
6565
hard_spinlock_t lock;
66+
struct lock_class_key lock_key; /* lockdep disambiguation */
6667

6768
/*
6869
* Shared thread-specific data, covered by ->lock.

kernel/evl/thread.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ int evl_init_thread(struct evl_thread *thread,
224224
INIT_LIST_HEAD(&thread->boosters);
225225
INIT_LIST_HEAD(&thread->owned_mutexes);
226226
raw_spin_lock_init(&thread->lock);
227-
might_hard_lock(&thread->lock);
228227
init_completion(&thread->exited);
229228
INIT_LIST_HEAD(&thread->ptsync_next);
230229
thread->oob_mm = NULL;
@@ -247,6 +246,18 @@ int evl_init_thread(struct evl_thread *thread,
247246
if (ret)
248247
goto err_out;
249248

249+
#ifdef CONFIG_LOCKDEP
250+
if (state & EVL_T_ROOT) {
251+
lockdep_set_class_and_name(&thread->lock, &rq->root_lock_key,
252+
thread->name);
253+
} else {
254+
lockdep_register_key(&thread->lock_key);
255+
lockdep_set_class_and_name(&thread->lock, &thread->lock_key,
256+
thread->name);
257+
}
258+
might_hard_lock(&thread->lock);
259+
#endif
260+
250261
trace_evl_init_thread(thread, iattr, ret);
251262

252263
return 0;
@@ -282,6 +293,9 @@ static void uninit_thread(struct evl_thread *thread)
282293
evl_forget_thread(thread);
283294
evl_put_thread_rq(thread, rq, flags);
284295

296+
if (!(thread->state & EVL_T_ROOT))
297+
lockdep_unregister_key(&thread->lock_key);
298+
285299
kfree(thread->name);
286300
}
287301

0 commit comments

Comments
 (0)