Skip to content

Commit 8cc05c7

Browse files
Tetsuo HandaIngo Molnar
authored andcommitted
locking/lockdep: Move sanity check to inside lockdep_print_held_locks()
Calling lockdep_print_held_locks() on a running thread is considered unsafe. Since all callers should follow that rule and the sanity check is not heavy, this patch moves the sanity check to inside lockdep_print_held_locks(). As a side effect of this patch, the number of locks held by running threads will be printed as well. This change will be preferable when we want to know which threads might be relevant to a problem but are unable to print any clues because that thread is running. Signed-off-by: Tetsuo Handa <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/1523011279-8206-2-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp Signed-off-by: Ingo Molnar <[email protected]>
1 parent 0f736a5 commit 8cc05c7

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

kernel/locking/lockdep.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -561,20 +561,24 @@ static void print_lock(struct held_lock *hlock)
561561
printk(KERN_CONT ", at: %pS\n", (void *)hlock->acquire_ip);
562562
}
563563

564-
static void lockdep_print_held_locks(struct task_struct *curr)
564+
static void lockdep_print_held_locks(struct task_struct *p)
565565
{
566-
int i, depth = curr->lockdep_depth;
566+
int i, depth = READ_ONCE(p->lockdep_depth);
567567

568-
if (!depth) {
569-
printk("no locks held by %s/%d.\n", curr->comm, task_pid_nr(curr));
568+
if (!depth)
569+
printk("no locks held by %s/%d.\n", p->comm, task_pid_nr(p));
570+
else
571+
printk("%d lock%s held by %s/%d:\n", depth,
572+
depth > 1 ? "s" : "", p->comm, task_pid_nr(p));
573+
/*
574+
* It's not reliable to print a task's held locks if it's not sleeping
575+
* and it's not the current task.
576+
*/
577+
if (p->state == TASK_RUNNING && p != current)
570578
return;
571-
}
572-
printk("%d lock%s held by %s/%d:\n",
573-
depth, depth > 1 ? "s" : "", curr->comm, task_pid_nr(curr));
574-
575579
for (i = 0; i < depth; i++) {
576580
printk(" #%d: ", i);
577-
print_lock(curr->held_locks + i);
581+
print_lock(p->held_locks + i);
578582
}
579583
}
580584

@@ -4460,13 +4464,6 @@ void debug_show_all_locks(void)
44604464

44614465
rcu_read_lock();
44624466
for_each_process_thread(g, p) {
4463-
/*
4464-
* It's not reliable to print a task's held locks
4465-
* if it's not sleeping (or if it's not the current
4466-
* task):
4467-
*/
4468-
if (p->state == TASK_RUNNING && p != current)
4469-
continue;
44704467
if (!p->lockdep_depth)
44714468
continue;
44724469
lockdep_print_held_locks(p);

0 commit comments

Comments
 (0)