Skip to content

Commit

Permalink
Revert "evl/thread: remove useless dynamic lock key"
Browse files Browse the repository at this point in the history
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 <rpm@xenomai.org>
  • Loading branch information
pgerum committed May 14, 2024
1 parent 8ec85c0 commit 6305af2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/evl/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct evl_init_thread_attr {

struct evl_thread {
hard_spinlock_t lock;
struct lock_class_key lock_key; /* lockdep disambiguation */

/*
* Shared thread-specific data, covered by ->lock.
Expand Down
16 changes: 15 additions & 1 deletion kernel/evl/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ int evl_init_thread(struct evl_thread *thread,
INIT_LIST_HEAD(&thread->boosters);
INIT_LIST_HEAD(&thread->owned_mutexes);
raw_spin_lock_init(&thread->lock);
might_hard_lock(&thread->lock);
init_completion(&thread->exited);
INIT_LIST_HEAD(&thread->ptsync_next);
thread->oob_mm = NULL;
Expand All @@ -247,6 +246,18 @@ int evl_init_thread(struct evl_thread *thread,
if (ret)
goto err_out;

#ifdef CONFIG_LOCKDEP
if (state & EVL_T_ROOT) {
lockdep_set_class_and_name(&thread->lock, &rq->root_lock_key,
thread->name);
} else {
lockdep_register_key(&thread->lock_key);
lockdep_set_class_and_name(&thread->lock, &thread->lock_key,
thread->name);
}
might_hard_lock(&thread->lock);
#endif

trace_evl_init_thread(thread, iattr, ret);

return 0;
Expand Down Expand Up @@ -282,6 +293,9 @@ static void uninit_thread(struct evl_thread *thread)
evl_forget_thread(thread);
evl_put_thread_rq(thread, rq, flags);

if (!(thread->state & EVL_T_ROOT))
lockdep_unregister_key(&thread->lock_key);

kfree(thread->name);
}

Expand Down

0 comments on commit 6305af2

Please sign in to comment.