All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Oleg Nesterov <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, tkhai@yandex.ru,
	rostedt@goodmis.org, torvalds@linux-foundation.org,
	mingo@kernel.org, hpa@zytor.com, peterz@infradead.org,
	tglx@linutronix.de, oleg@redhat.com
Subject: [tip:sched/core] sched: Fix schedule_tail() to disable preemption
Date: Tue, 28 Oct 2014 04:06:00 -0700	[thread overview]
Message-ID: <tip-1a43a14a5bd9c32dbd7af35e35a5afa703944bcb@git.kernel.org> (raw)
In-Reply-To: <20141008193644.GA32055@redhat.com>

Commit-ID:  1a43a14a5bd9c32dbd7af35e35a5afa703944bcb
Gitweb:     http://git.kernel.org/tip/1a43a14a5bd9c32dbd7af35e35a5afa703944bcb
Author:     Oleg Nesterov <oleg@redhat.com>
AuthorDate: Wed, 8 Oct 2014 21:36:44 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 28 Oct 2014 10:47:54 +0100

sched: Fix schedule_tail() to disable preemption

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@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Kirill Tkhai <tkhai@yandex.ru>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/20141008193644.GA32055@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/core.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index cde8481..b493560 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2309,15 +2309,14 @@ static inline void post_schedule(struct rq *rq)
 asmlinkage __visible void schedule_tail(struct task_struct *prev)
 	__releases(rq->lock)
 {
-	struct rq *rq = this_rq();
+	struct rq *rq;
 
+	/* finish_task_switch() drops rq->lock and enables preemtion */
+	preempt_disable();
+	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);
+	preempt_enable();
 
 	if (current->set_child_tid)
 		put_user(task_pid_vnr(current), current->set_child_tid);

  parent reply	other threads:[~2014-10-28 11:06 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-07 19:50 [PATCH 0/1] sched: fix the PREEMPT_ACTIVE check in __trace_sched_switch_state() Oleg Nesterov
2014-10-07 19:51 ` [PATCH 1/1] " Oleg Nesterov
2014-10-10  9:54   ` Peter Zijlstra
2014-10-10  9:56     ` Peter Zijlstra
2014-10-28 11:05   ` [tip:sched/core] sched: Fix " tip-bot for Oleg Nesterov
2014-10-08  8:00 ` [PATCH 0/1] sched: fix " Peter Zijlstra
2014-10-08 18:33   ` [PATCH 0/2] (Was: sched: fix the PREEMPT_ACTIVE check in __trace_sched_switch_state()) Oleg Nesterov
2014-10-08 18:33     ` [PATCH 1/2] sched: schedule_tail() should disable preemption Oleg Nesterov
2014-10-08 19:36       ` [PATCH v2 " Oleg Nesterov
2014-10-08 21:37         ` Kirill Tkhai
2014-10-09 14:57           ` Oleg Nesterov
2014-10-09 15:17             ` Peter Zijlstra
2014-10-09 16:57               ` Oleg Nesterov
2014-10-09 17:28                 ` Peter Zijlstra
2014-10-09 17:32                   ` Peter Zijlstra
2014-10-09 17:55                     ` Oleg Nesterov
2014-10-28 11:06         ` tip-bot for Oleg Nesterov [this message]
2014-10-08 18:33     ` [PATCH 2/2] sched: kill task_preempt_count() Oleg Nesterov
2014-10-28 11:06       ` [tip:sched/core] sched: Kill task_preempt_count() tip-bot for Oleg Nesterov
2014-10-09 19:32 ` [PATCH 0/1] sched: make finish_task_switch() return struct rq * Oleg Nesterov
2014-10-09 19:32   ` [PATCH 1/1] " Oleg Nesterov
2014-10-10 10:06     ` Peter Zijlstra
2014-10-10 17:06       ` Oleg Nesterov
2014-10-10 20:32         ` Peter Zijlstra
2014-10-14 17:57           ` Oleg Nesterov
2014-10-28 11:06     ` [tip:sched/core] sched: Make finish_task_switch() return ' struct rq *' tip-bot for Oleg Nesterov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-1a43a14a5bd9c32dbd7af35e35a5afa703944bcb@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=tkhai@yandex.ru \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.