sched: Debug nested sleeps
Validate we call might_sleep() with TASK_RUNNING, which catches places where we nest blocking primitives, eg. mutex usage in a wait loop. Since all blocking is arranged through task_struct::state, nesting this will cause the inner primitive to set TASK_RUNNING and the outer will thus not block. Another observed problem is calling a blocking function from schedule()->sched_submit_work()->blk_schedule_flush_plug() which will then destroy the task state for the actual __schedule() call that comes after it. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: tglx@linutronix.de Cc: ilya.dryomov@inktank.com Cc: umgwanakikbuti@gmail.com Cc: oleg@redhat.com Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: http://lkml.kernel.org/r/20140924082242.591637616@infradead.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:

committed by
Ingo Molnar

parent
26cabd3125
commit
8eb23b9f35
@@ -7298,6 +7298,19 @@ void __might_sleep(const char *file, int line, int preempt_offset)
|
||||
{
|
||||
static unsigned long prev_jiffy; /* ratelimiting */
|
||||
|
||||
/*
|
||||
* Blocking primitives will set (and therefore destroy) current->state,
|
||||
* since we will exit with TASK_RUNNING make sure we enter with it,
|
||||
* otherwise we will destroy state.
|
||||
*/
|
||||
if (WARN(current->state != TASK_RUNNING,
|
||||
"do not call blocking ops when !TASK_RUNNING; "
|
||||
"state=%lx set at [<%p>] %pS\n",
|
||||
current->state,
|
||||
(void *)current->task_state_change,
|
||||
(void *)current->task_state_change))
|
||||
__set_current_state(TASK_RUNNING);
|
||||
|
||||
rcu_sleep_check(); /* WARN_ON_ONCE() by default, no rate limit reqd. */
|
||||
if ((preempt_count_equals(preempt_offset) && !irqs_disabled() &&
|
||||
!is_idle_task(current)) ||
|
||||
|
Reference in New Issue
Block a user