arm: kvm: implement CPU PM notifier
authorLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Mon, 5 Aug 2013 14:04:46 +0000 (15:04 +0100)
committerLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Mon, 16 Dec 2013 17:17:33 +0000 (17:17 +0000)
Upon CPU shutdown and consequent warm-reboot, the hypervisor CPU state
must be re-initialized. This patch implements a CPU PM notifier that
upon warm-boot calls a KVM hook to reinitialize properly the hypervisor
state so that the CPU can be safely resumed.

Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Acked-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
arch/arm/kvm/arm.c

index 2a700e00528d0a3cc9d78a58f7d38dddf2297611..b18165ca1d387b9cf30c9f2896d53c79e5453fa1 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include <linux/cpu.h>
+#include <linux/cpu_pm.h>
 #include <linux/errno.h>
 #include <linux/err.h>
 #include <linux/kvm_host.h>
@@ -853,6 +854,33 @@ static struct notifier_block hyp_init_cpu_nb = {
        .notifier_call = hyp_init_cpu_notify,
 };
 
+#ifdef CONFIG_CPU_PM
+static int hyp_init_cpu_pm_notifier(struct notifier_block *self,
+                                   unsigned long cmd,
+                                   void *v)
+{
+       if (cmd == CPU_PM_EXIT) {
+               cpu_init_hyp_mode(NULL);
+               return NOTIFY_OK;
+       }
+
+       return NOTIFY_DONE;
+}
+
+static struct notifier_block hyp_init_cpu_pm_nb = {
+       .notifier_call = hyp_init_cpu_pm_notifier,
+};
+
+static void __init hyp_cpu_pm_init(void)
+{
+       cpu_pm_register_notifier(&hyp_init_cpu_pm_nb);
+}
+#else
+static inline void hyp_cpu_pm_init(void)
+{
+}
+#endif
+
 /**
  * Inits Hyp-mode on all online CPUs
  */
@@ -1013,6 +1041,8 @@ int kvm_arch_init(void *opaque)
                goto out_err;
        }
 
+       hyp_cpu_pm_init();
+
        kvm_coproc_table_init();
        return 0;
 out_err: