mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH urgent v2] sched: Add missing rcu protection to wake_up_all_idle_cpus
@ 2014-11-29 16:13 Andy Lutomirski
  2014-12-01  3:13 ` Liu, Chuansheng
  2014-12-09 10:17 ` [tip:sched/core] " tip-bot for Andy Lutomirski
  0 siblings, 2 replies; 3+ messages in thread
From: Andy Lutomirski @ 2014-11-29 16:13 UTC (permalink / raw)
  To: Ingo Molnar, Thomas Gleixner, linux-kernel
  Cc: Peter Zijlstra, Andy Lutomirski, Chuansheng Liu

Locklessly doing is_idle_task(rq->curr) is only okay because of RCU
protection.  The older variant of the broken code checked
rq->curr == rq->idle instead and therefore didn't need RCU.

Fixes: f6be8af1c95d sched: Add new API wake_up_if_idle() to wake up the idle cpu
Cc: Chuansheng Liu <chuansheng.liu@intel.com>
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
---

This fixes a 3.18 regression, I think.  This code seems to only be called
inside preempt_disable, so I think it's unlikely to be a problem in practice.

Compile-tested only, although the kbuild bot is chewing on it.

Changes from v1:
 - Cc the right people (whoops)
 - Add rcu_read_lock and rcu_read_unlock.

 kernel/sched/core.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 240157c13ddc..b7937512965f 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1623,8 +1623,10 @@ void wake_up_if_idle(int cpu)
 	struct rq *rq = cpu_rq(cpu);
 	unsigned long flags;
 
-	if (!is_idle_task(rq->curr))
-		return;
+	rcu_read_lock();
+
+	if (!is_idle_task(rcu_dereference(rq->curr)))
+		goto out;
 
 	if (set_nr_if_polling(rq->idle)) {
 		trace_sched_wake_idle_without_ipi(cpu);
@@ -1635,6 +1637,9 @@ void wake_up_if_idle(int cpu)
 		/* Else cpu is not in idle, do nothing here */
 		raw_spin_unlock_irqrestore(&rq->lock, flags);
 	}
+
+out:
+	rcu_read_unlock();
 }
 
 bool cpus_share_cache(int this_cpu, int that_cpu)
-- 
1.9.3


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-12-09 10:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-29 16:13 [PATCH urgent v2] sched: Add missing rcu protection to wake_up_all_idle_cpus Andy Lutomirski
2014-12-01  3:13 ` Liu, Chuansheng
2014-12-09 10:17 ` [tip:sched/core] " tip-bot for Andy Lutomirski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome