mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Byungchul Park <byungchul.park@lge.com>
To: stable@vger.kernel.org
Cc: peterz@infradead.org, linux-kernel@vger.kernel.org,
	ktkhai@parallels.com, rostedt@goodmis.org, juri.lelli@gmail.com,
	pang.xunlei@linaro.org, oleg@redhat.com,
	wanpeng.li@linux.intel.com, Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH for v3.14.58 3/7] sched: Allow balance callbacks for check_class_changed()
Date: Tue,  5 Jan 2016 18:16:24 +0900	[thread overview]
Message-ID: <1451985388-19492-3-git-send-email-byungchul.park@lge.com> (raw)
In-Reply-To: <1451985388-19492-1-git-send-email-byungchul.park@lge.com>

From: Peter Zijlstra <peterz@infradead.org>

In order to remove dropping rq->lock from the
switched_{to,from}()/prio_changed() sched_class methods, run the
balance callbacks after it.

We need to remove dropping rq->lock because its buggy,
suppose using sched_setattr()/sched_setscheduler() to change a running
task from FIFO to OTHER.

By the time we get to switched_from_rt() the task is already enqueued
on the cfs runqueues. If switched_from_rt() does pull_rt_task() and
drops rq->lock, load-balancing can come in and move our task @p to
another rq.

The subsequent switched_to_fair() still assumes @p is on @rq and bad
things will happen.

By using balance callbacks we delay the load-balancing operations
{rt,dl}x{push,pull} until we've done all the important work and the
task is fully set up.

Furthermore, the balance callbacks do not know about @p, therefore
they cannot get confused like this.

Reported-by: Mike Galbraith <umgwanakikbuti@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: ktkhai@parallels.com
Cc: rostedt@goodmis.org
Cc: juri.lelli@gmail.com
Cc: pang.xunlei@linaro.org
Cc: oleg@redhat.com
Cc: wanpeng.li@linux.intel.com
Link: http://lkml.kernel.org/r/20150611124742.615343911@infradead.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Byungchul Park <byungchul.park@lge.com>

Conflicts:
	kernel/sched/core.c
---
 kernel/sched/core.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index cc1be56..459cc86 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -937,6 +937,13 @@ inline int task_curr(const struct task_struct *p)
 	return cpu_curr(task_cpu(p)) == p;
 }
 
+/*
+ * switched_from, switched_to and prio_changed must _NOT_ drop rq->lock,
+ * use the balance_callback list if you want balancing.
+ *
+ * this means any call to check_class_changed() must be followed by a call to
+ * balance_callback().
+ */
 static inline void check_class_changed(struct rq *rq, struct task_struct *p,
 				       const struct sched_class *prev_class,
 				       int oldprio)
@@ -1423,8 +1430,12 @@ ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)
 
 	p->state = TASK_RUNNING;
 #ifdef CONFIG_SMP
-	if (p->sched_class->task_woken)
+	if (p->sched_class->task_woken) {
+		/*
+		 * XXX can drop rq->lock; most likely ok.
+		 */
 		p->sched_class->task_woken(rq, p);
+	}
 
 	if (rq->idle_stamp) {
 		u64 delta = rq_clock(rq) - rq->idle_stamp;
@@ -3006,7 +3017,11 @@ void rt_mutex_setprio(struct task_struct *p, int prio)
 
 	check_class_changed(rq, p, prev_class, oldprio);
 out_unlock:
+	preempt_disable(); /* avoid rq from going away on us */
 	__task_rq_unlock(rq);
+
+	balance_callback(rq);
+	preempt_enable();
 }
 #endif
 
@@ -3512,10 +3527,17 @@ change:
 		enqueue_task(rq, p, 0);
 
 	check_class_changed(rq, p, prev_class, oldprio);
+	preempt_disable(); /* avoid rq from going away on us */
 	task_rq_unlock(rq, p, &flags);
 
 	rt_mutex_adjust_pi(p);
 
+	/*
+	 * Run balance callbacks after we've adjusted the PI chain.
+	 */
+	balance_callback(rq);
+	preempt_enable();
+
 	return 0;
 }
 
-- 
1.9.1


  parent reply	other threads:[~2016-01-05  9:17 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-05  8:52 [STABLE] kernel oops which can be fixed by peterz's patches Byungchul Park
2016-01-05  9:14 ` Peter Zijlstra
2016-01-12  8:47   ` Byungchul Park
2016-01-12 10:21   ` Willy Tarreau
2016-01-25  7:25   ` Byungchul Park
2016-02-16  7:08     ` Byungchul Park
2016-02-16  8:44       ` Peter Zijlstra
2016-02-16 17:42         ` Greg KH
2016-02-17  0:11           ` Byungchul Park
2016-02-17  0:41             ` Greg KH
2016-02-17  2:00               ` Byungchul Park
2016-02-17  3:01                 ` Greg KH
2016-02-17  3:02                 ` Mike Galbraith
2016-02-23 21:05                   ` Ben Hutchings
2016-02-23 21:06                   ` Ben Hutchings
2016-01-05  9:16 ` [PATCH for v3.14.58 1/7] sched: Clean up idle task SMP logic Byungchul Park
2016-01-05  9:16   ` [PATCH for v3.14.58 2/7] sched: Replace post_schedule with a balance callback list Byungchul Park
2016-01-05  9:16   ` Byungchul Park [this message]
2016-01-05  9:16   ` [PATCH for v3.14.58 4/7] sched,rt: Remove return value from pull_rt_task() Byungchul Park
2016-01-05  9:16   ` [PATCH for v3.14.58 5/7] sched, rt: Convert switched_{from, to}_rt() / prio_changed_rt() to balance callbacks Byungchul Park
2016-01-05  9:16   ` [PATCH for v3.14.58 6/7] sched,dl: Remove return value from pull_dl_task() Byungchul Park
2016-01-05  9:16   ` [PATCH for v3.14.58 7/7] sched, dl: Convert switched_{from, to}_dl() / prio_changed_dl() to balance callbacks Byungchul Park
2016-01-05  9:24 ` [PATCH for v3.18.25 1/6] sched: Replace post_schedule with a balance callback list Byungchul Park
2016-01-05  9:24   ` [PATCH for v3.18.25 2/6] sched: Allow balance callbacks for check_class_changed() Byungchul Park
2016-01-05  9:24   ` [PATCH for v3.18.25 3/6] sched,rt: Remove return value from pull_rt_task() Byungchul Park
2016-01-05  9:24   ` [PATCH for v3.18.25 4/6] sched, rt: Convert switched_{from, to}_rt() / prio_changed_rt() to balance callbacks Byungchul Park
2016-01-05  9:24   ` [PATCH for v3.18.25 5/6] sched,dl: Remove return value from pull_dl_task() Byungchul Park
2016-01-05  9:24   ` [PATCH for v3.18.25 6/6] sched, dl: Convert switched_{from, to}_dl() / prio_changed_dl() to balance callbacks Byungchul Park
2016-03-01  8:15 ` [STABLE] kernel oops which can be fixed by peterz's patches Greg KH
2016-07-18  6:31   ` Byungchul Park
2016-07-18 12:09     ` Greg KH
2016-07-18 23:59       ` Byungchul Park
2016-06-13 18:31 ` Ben Hutchings

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=1451985388-19492-3-git-send-email-byungchul.park@lge.com \
    --to=byungchul.park@lge.com \
    --cc=juri.lelli@gmail.com \
    --cc=ktkhai@parallels.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=pang.xunlei@linaro.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=wanpeng.li@linux.intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®