From: Thomas Gleixner <tglx@linutronix.de>
Subject: powerpc: Fix broken cpu_idle_wait() implementation
Git-commit: 9cd75e13de2dcf32ecc21c7f277cff3c0ced059e
Patch-mainline: yes
References: fate#314019,bnc#795230

    commit 771dae818 (powerpc/cpuidle: Add cpu_idle_wait() to allow
    switching of idle routines) implemented cpu_idle_wait() for powerpc.

    The changelog says:
     "The equivalent routine for x86 is in arch/x86/kernel/process.c
      but the powerpc implementation is different.":

    Unfortunately the changelog is completely useless as it does not tell
    _WHY_ it is different.

    Aside of being different the implementation is patently wrong.

    The rescheduling IPI is async. That means that there is no guarantee,
    that the other cores have executed the IPI when cpu_idle_wait()
    returns. But that's the whole purpose of this function: to guarantee
    that no CPU uses the old idle handler anymore.

    Use the smp_functional_call() based implementation, which fulfils the
    requirements.

    [ This code is going to replaced by a core version to remove all the
      pointless copies in arch/*, but this one should go to stable ]

Signed-off-by: Deepthi Dharwar <deepthi@linux.vnet.ibm.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Torsten Duwe <duwe@suse.de>
---

 arch/powerpc/kernel/idle.c |   14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)


diff --git a/arch/powerpc/kernel/idle.c b/arch/powerpc/kernel/idle.c
index 8574b0e..4fc8aa6 100644
--- a/arch/powerpc/kernel/idle.c
+++ b/arch/powerpc/kernel/idle.c
@@ -106,6 +106,9 @@ void cpu_idle(void)
 	}
 }
 
+static void do_nothing(void *unused)
+{
+}
 
 /*
  * cpu_idle_wait - Used to ensure that all the CPUs come out of the old
@@ -116,16 +119,9 @@ void cpu_idle(void)
  */
 void cpu_idle_wait(void)
 {
-	int cpu;
 	smp_mb();
-
-	/* kick all the CPUs so that they exit out of old idle routine */
-	get_online_cpus();
-	for_each_online_cpu(cpu) {
-		if (cpu != smp_processor_id())
-			smp_send_reschedule(cpu);
-	}
-	put_online_cpus();
+	/* kick all the CPUs so that they exit out of pm_idle */
+	smp_call_function(do_nothing, NULL, 1);
 }
 EXPORT_SYMBOL_GPL(cpu_idle_wait);
 
