Re: [PATCH v2] locking/hung_task: Show all hung tasks before panic
From: Tetsuo Handa
Date: Sat Apr 07 2018 - 08:31:26 EST
Hello.
Can we add lockdep functions which print trace of threads with locks held?
For example,
void debug_show_map_users(struct lockdep_map *map)
{
struct task_struct *g, *p;
struct held_lock *hlock;
int i, depth;
rcu_read_lock();
for_each_process_thread(g, p) {
depth = p->lockdep_depth;
hlock = p->held_locks;
for (i = 0; i < depth; i++)
if (map == hlock[i]->instance) {
touch_nmi_watchdog();
touch_all_softlockup_watchdogs();
sched_show_task(p);
lockdep_print_held_locks(p);
break;
}
}
rcu_read_unlock();
}
is for replacing debug_show_all_locks() in oom_reap_task() because
we are interested in only threads holding specific mm->mmap_sem.
For example
void debug_show_relevant_tasks(struct task_struct *origin)
{
struct task_struct *g, *p;
struct held_lock *i_hlock, *j_hlock;
int i, j, i_depth, j_depth;
rcu_read_lock();
i_depth = origin->lockdep_depth;
i_hlock = origin->held_locks;
for_each_process_thread(g, p) {
j_depth = p->lockdep_depth;
j_hlock = p->held_locks;
for (i = 0; i < i_depth; i++)
for (j = 0; j < j_depth; j++)
if (i_hlock[i]->instance == j_hlock[j]->instance)
goto hit;
continue;
hit:
touch_nmi_watchdog();
touch_all_softlockup_watchdogs();
sched_show_task(p);
lockdep_print_held_locks(p);
}
rcu_read_unlock();
}
or
void debug_show_all_locked_tasks(void)
{
struct task_struct *g, *p;
rcu_read_lock();
for_each_process_thread(g, p) {
if (p->lockdep_depth == 0)
continue;
touch_nmi_watchdog();
touch_all_softlockup_watchdogs();
sched_show_task(p);
lockdep_print_held_locks(p);
}
rcu_read_unlock();
}
are for replacing debug_show_all_locks() in check_hung_task() for cases like
https://syzkaller.appspot.com/bug?id=26aa22915f5e3b7ca2cfca76a939f12c25d624db
because we are interested in only threads holding locks.
SysRq-t is too much but SysRq-w is useless for killable/interruptible threads...