[Devel] [PATCH RHEL7 COMMIT] ms/sched: Fix schedule_tail() to disable preemption

Konstantin Khorenko khorenko at virtuozzo.com
Tue Sep 1 06:08:00 PDT 2015


The commit is pushed to "branch-rh7-3.10.0-229.7.2-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-229.7.2.vz7.6.5
------>
commit b1d861eea2c7217a8bd6162b93c5a4356d822844
Author: Kirill Tkhai <ktkhai at odin.com>
Date:   Tue Sep 1 17:08:00 2015 +0400

    ms/sched: Fix schedule_tail() to disable preemption
    
    Porting ms commit 1a43a14a5bd9c32dbd7af35e35a5afa703944bcb by Oleg Nesterov:
    
    finish_task_switch() enables preemption, so post_schedule(rq) can be
    called on the wrong (and even dead) CPU. Afaics, nothing really bad
    can happen, but in this case we can wrongly clear rq->post_schedule
    on that CPU. And this simply looks wrong in any case.
    
    Signed-off-by: Oleg Nesterov <oleg at redhat.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz at infradead.org>
    Cc: Steven Rostedt <rostedt at goodmis.org>
    Cc: Kirill Tkhai <tkhai at yandex.ru>
    Cc: Linus Torvalds <torvalds at linux-foundation.org>
    Link: http://lkml.kernel.org/r/20141008193644.GA32055@redhat.com
    Signed-off-by: Ingo Molnar <mingo at kernel.org>
    Signed-off-by: Kirill Tkhai <ktkhai at odin.com>
---
 kernel/sched/core.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index bbb6fc3..30f39a25 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2245,20 +2245,18 @@ static inline void post_schedule(struct rq *rq)
 asmlinkage void schedule_tail(struct task_struct *prev)
 	__releases(rq->lock)
 {
-	struct rq *rq = this_rq();
+	struct rq *rq;
 
+#ifndef __ARCH_WANT_UNLOCKED_CTXSW
+	/* finish_task_switch() drops rq->lock and enables preemtion */
+	preempt_disable();
+#endif
+	rq = this_rq();
 	finish_task_switch(rq, prev);
 
-	/*
-	 * FIXME: do we need to worry about rq being invalidated by the
-	 * task_switch?
-	 */
 	post_schedule(rq);
-
-#ifdef __ARCH_WANT_UNLOCKED_CTXSW
-	/* In this case, finish_task_switch does not reenable preemption */
 	preempt_enable();
-#endif
+
 	if (current->set_child_tid)
 		put_user(task_pid_vnr(current), current->set_child_tid);
 }



More information about the Devel mailing list