Commit b99def8b authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

sched/core: Rework TASK_DEAD preemption exception

TASK_DEAD is special in that the final schedule call from do_exit()
must be done with preemption disabled.

This means we end up scheduling with a preempt_count() higher than
usual (3 instead of the 'expected' 2).

Since future patches will want to rely on an invariant
preempt_count() value during schedule, fix this up.
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
Reviewed-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 87dcbc06
...@@ -2949,12 +2949,8 @@ static inline void schedule_debug(struct task_struct *prev) ...@@ -2949,12 +2949,8 @@ static inline void schedule_debug(struct task_struct *prev)
#ifdef CONFIG_SCHED_STACK_END_CHECK #ifdef CONFIG_SCHED_STACK_END_CHECK
BUG_ON(unlikely(task_stack_end_corrupted(prev))); BUG_ON(unlikely(task_stack_end_corrupted(prev)));
#endif #endif
/*
* Test if we are atomic. Since do_exit() needs to call into if (unlikely(in_atomic_preempt_off()))
* schedule() atomically, we ignore that path. Otherwise whine
* if we are scheduling when we should not.
*/
if (unlikely(in_atomic_preempt_off() && prev->state != TASK_DEAD))
__schedule_bug(prev); __schedule_bug(prev);
rcu_sleep_check(); rcu_sleep_check();
...@@ -3053,6 +3049,17 @@ static void __sched __schedule(void) ...@@ -3053,6 +3049,17 @@ static void __sched __schedule(void)
rcu_note_context_switch(); rcu_note_context_switch();
prev = rq->curr; prev = rq->curr;
/*
* do_exit() calls schedule() with preemption disabled as an exception;
* however we must fix that up, otherwise the next task will see an
* inconsistent (higher) preempt count.
*
* It also avoids the below schedule_debug() test from complaining
* about this.
*/
if (unlikely(prev->state == TASK_DEAD))
preempt_enable_no_resched_notrace();
schedule_debug(prev); schedule_debug(prev);
if (sched_feat(HRTICK)) if (sched_feat(HRTICK))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment