context_tracking: Restore preempted context state after preempt_schedule_irq()
authorFrederic Weisbecker <[email protected]>
Sun, 24 Feb 2013 11:59:30 +0000 (12:59 +0100)
committerFrederic Weisbecker <[email protected]>
Thu, 7 Mar 2013 16:10:21 +0000 (17:10 +0100)
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 <[email protected]>
Cc: Li Zhong <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc: Mats Liljegren <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Paul E. McKenney <[email protected]>
kernel/sched/core.c

index 7f12624a393c3100506e5a3eaf588b5f463332ee..af7a8c84b797c535a3be96e36e61c73e4c0addc5 100644 (file)
@@ -3082,11 +3082,13 @@ EXPORT_SYMBOL(preempt_schedule);
 asmlinkage void __sched preempt_schedule_irq(void)
 {
        struct thread_info *ti = current_thread_info();
+       enum ctx_state prev_state;
 
        /* Catch callers which need to be fixed */
        BUG_ON(ti->preempt_count || !irqs_disabled());
 
-       user_exit();
+       prev_state = exception_enter();
+
        do {
                add_preempt_count(PREEMPT_ACTIVE);
                local_irq_enable();
@@ -3100,6 +3102,8 @@ asmlinkage void __sched preempt_schedule_irq(void)
                 */
                barrier();
        } while (need_resched());
+
+       exception_exit(prev_state);
 }
 
 #endif /* CONFIG_PREEMPT */