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

Submitted by Kirill Tkhai on Dec. 7, 2016, 2:38 p.m.

Details

Message ID 148112144125.6830.13196442269344522252.stgit@localhost.localdomain
State New
Series "sched: Dereference resched_next on next task's stack"
Headers show

Commit Message

Kirill Tkhai Dec. 7, 2016, 2:38 p.m.
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@virtuozzo.com>
---
 kernel/sched/core.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

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())