[Devel] [PATCH] sched: Dereference resched_next on next task's stack

Kirill Tkhai ktkhai at virtuozzo.com
Wed Dec 7 06:38:09 PST 2016


When we dereference it before context switch, the read value
just caches in prev task's stack. Later, the prev task may
wake up in any cpu, so the value became useless.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 kernel/sched/core.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ccc826a..384373c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3443,9 +3443,6 @@ static void __sched __schedule(void)
 	clear_tsk_need_resched(prev);
 	rq->skip_clock_update = 0;
 
-	resched_next = rq->resched_next;
-	rq->resched_next = 0;
-
 	if (likely(prev != next)) {
 		rq->nr_switches++;
 		rq->curr = next;
@@ -3465,8 +3462,11 @@ static void __sched __schedule(void)
 
 	post_schedule(rq);
 
-	if (resched_next)
+	resched_next = READ_ONCE(rq->resched_next);
+	if (resched_next) {
 		set_tsk_need_resched(current);
+		rq->resched_next = 0;
+	}
 
 	sched_preempt_enable_no_resched();
 	if (!resched_next && need_resched())



More information about the Devel mailing list