Commit 170f69f4cf0ef0431d52288644108fe09f68e3b8

Authored by Andy Lutomirski
Committed by Greg Kroah-Hartman
1 parent f88708af7a

sched: Add missing rcu protection to wake_up_all_idle_cpus

commit fd7de1e8d5b2b2b35e71332fafb899f584597150 upstream.

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")
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Reviewed-by: Chuansheng Liu <chuansheng.liu@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/729365dddca178506dfd0a9451006344cd6808bc.1417277372.git.luto@amacapital.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 7 additions and 2 deletions Side-by-side Diff

... ... @@ -1623,9 +1623,11 @@
1623 1623 struct rq *rq = cpu_rq(cpu);
1624 1624 unsigned long flags;
1625 1625  
1626   - if (!is_idle_task(rq->curr))
1627   - return;
  1626 + rcu_read_lock();
1628 1627  
  1628 + if (!is_idle_task(rcu_dereference(rq->curr)))
  1629 + goto out;
  1630 +
1629 1631 if (set_nr_if_polling(rq->idle)) {
1630 1632 trace_sched_wake_idle_without_ipi(cpu);
1631 1633 } else {
... ... @@ -1635,6 +1637,9 @@
1635 1637 /* Else cpu is not in idle, do nothing here */
1636 1638 raw_spin_unlock_irqrestore(&rq->lock, flags);
1637 1639 }
  1640 +
  1641 +out:
  1642 + rcu_read_unlock();
1638 1643 }
1639 1644  
1640 1645 bool cpus_share_cache(int this_cpu, int that_cpu)