Skip to content

Commit b22366c

Browse files
committed
context_tracking: Restore preempted context state after preempt_schedule_irq()
From the context tracking POV, preempt_schedule_irq() behaves pretty much like an exception: It can be called anytime and schedule another task. But currently it doesn't restore the context tracking state of the preempted code on preempt_schedule_irq() return. As a result, if preempt_schedule_irq() is called in the tiny frame between user_enter() and the actual return to userspace, we resume userspace with the wrong context tracking state. Fix this by using exception_enter/exit() which are a perfect fit for this kind of issue. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Li Zhong <zhong@linux.vnet.ibm.com> Cc: Kevin Hilman <khilman@linaro.org> Cc: Mats Liljegren <mats.liljegren@enea.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Namhyung Kim <namhyung.kim@lge.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent 6c1e025 commit b22366c

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎kernel/sched/core.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3082,11 +3082,13 @@ EXPORT_SYMBOL(preempt_schedule);
30823082
asmlinkage void __sched preempt_schedule_irq(void)
30833083
{
30843084
struct thread_info *ti = current_thread_info();
3085+
enum ctx_state prev_state;
30853086

30863087
/* Catch callers which need to be fixed */
30873088
BUG_ON(ti->preempt_count || !irqs_disabled());
30883089

3089-
user_exit();
3090+
prev_state = exception_enter();
3091+
30903092
do {
30913093
add_preempt_count(PREEMPT_ACTIVE);
30923094
local_irq_enable();
@@ -3100,6 +3102,8 @@ asmlinkage void __sched preempt_schedule_irq(void)
31003102
*/
31013103
barrier();
31023104
} while (need_resched());
3105+
3106+
exception_exit(prev_state);
31033107
}
31043108

31053109
#endif /* CONFIG_PREEMPT */

0 commit comments

Comments
 (0)