Merge tag 'kvm-arm-for-4.6-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 1 Apr 2016 10:10:06 +0000 (12:10 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 1 Apr 2016 10:10:06 +0000 (12:10 +0200)
KVM/ARM Fixes for Linux v4.6-rc2.

Fixes a bug that corrupts stage-2 translationson 16-bit VMID equipped systems
and fixes CPU PM and Hotplug after the EL2 init code has been moved to C.

arch/arm/kvm/arm.c
arch/arm64/include/asm/kvm_arm.h
arch/arm64/include/asm/sysreg.h
arch/arm64/kvm/hyp/s2-setup.c

index 6accd66..b538431 100644 (file)
@@ -1061,15 +1061,27 @@ static void cpu_init_hyp_mode(void *dummy)
        kvm_arm_init_debug();
 }
 
+static void cpu_hyp_reinit(void)
+{
+       if (is_kernel_in_hyp_mode()) {
+               /*
+                * cpu_init_stage2() is safe to call even if the PM
+                * event was cancelled before the CPU was reset.
+                */
+               cpu_init_stage2(NULL);
+       } else {
+               if (__hyp_get_vectors() == hyp_default_vectors)
+                       cpu_init_hyp_mode(NULL);
+       }
+}
+
 static int hyp_init_cpu_notify(struct notifier_block *self,
                               unsigned long action, void *cpu)
 {
        switch (action) {
        case CPU_STARTING:
        case CPU_STARTING_FROZEN:
-               if (__hyp_get_vectors() == hyp_default_vectors)
-                       cpu_init_hyp_mode(NULL);
-               break;
+               cpu_hyp_reinit();
        }
 
        return NOTIFY_OK;
@@ -1084,9 +1096,8 @@ static int hyp_init_cpu_pm_notifier(struct notifier_block *self,
                                    unsigned long cmd,
                                    void *v)
 {
-       if (cmd == CPU_PM_EXIT &&
-           __hyp_get_vectors() == hyp_default_vectors) {
-               cpu_init_hyp_mode(NULL);
+       if (cmd == CPU_PM_EXIT) {
+               cpu_hyp_reinit();
                return NOTIFY_OK;
        }
 
@@ -1127,6 +1138,22 @@ static int init_subsystems(void)
 {
        int err;
 
+       /*
+        * Register CPU Hotplug notifier
+        */
+       cpu_notifier_register_begin();
+       err = __register_cpu_notifier(&hyp_init_cpu_nb);
+       cpu_notifier_register_done();
+       if (err) {
+               kvm_err("Cannot register KVM init CPU notifier (%d)\n", err);
+               return err;
+       }
+
+       /*
+        * Register CPU lower-power notifier
+        */
+       hyp_cpu_pm_init();
+
        /*
         * Init HYP view of VGIC
         */
@@ -1270,19 +1297,6 @@ static int init_hyp_mode(void)
        free_boot_hyp_pgd();
 #endif
 
-       cpu_notifier_register_begin();
-
-       err = __register_cpu_notifier(&hyp_init_cpu_nb);
-
-       cpu_notifier_register_done();
-
-       if (err) {
-               kvm_err("Cannot register HYP init CPU notifier (%d)\n", err);
-               goto out_err;
-       }
-
-       hyp_cpu_pm_init();
-
        /* set size of VMID supported by CPU */
        kvm_vmid_bits = kvm_get_vmid_bits();
        kvm_info("%d-bit VMID\n", kvm_vmid_bits);
index 0e391db..4150fd8 100644 (file)
 #define VTCR_EL2_SL0_LVL1      (1 << 6)
 #define VTCR_EL2_T0SZ_MASK     0x3f
 #define VTCR_EL2_T0SZ_40B      24
-#define VTCR_EL2_VS            19
+#define VTCR_EL2_VS_SHIFT      19
+#define VTCR_EL2_VS_8BIT       (0 << VTCR_EL2_VS_SHIFT)
+#define VTCR_EL2_VS_16BIT      (1 << VTCR_EL2_VS_SHIFT)
 
 /*
  * We configure the Stage-2 page tables to always restrict the IPA space to be
index 1a78d6e..1287416 100644 (file)
 #define ID_AA64MMFR1_VMIDBITS_SHIFT    4
 #define ID_AA64MMFR1_HADBS_SHIFT       0
 
+#define ID_AA64MMFR1_VMIDBITS_8                0
+#define ID_AA64MMFR1_VMIDBITS_16       2
+
 /* id_aa64mmfr2 */
 #define ID_AA64MMFR2_UAO_SHIFT         4
 
index bfc54fd..5a9f3bf 100644 (file)
@@ -36,8 +36,10 @@ void __hyp_text __init_stage2_translation(void)
         * Read the VMIDBits bits from ID_AA64MMFR1_EL1 and set the VS
         * bit in VTCR_EL2.
         */
-       tmp = (read_sysreg(id_aa64mmfr1_el1) >> 4) & 0xf;
-       val |= (tmp == 2) ? VTCR_EL2_VS : 0;
+       tmp = (read_sysreg(id_aa64mmfr1_el1) >> ID_AA64MMFR1_VMIDBITS_SHIFT) & 0xf;
+       val |= (tmp == ID_AA64MMFR1_VMIDBITS_16) ?
+                       VTCR_EL2_VS_16BIT :
+                       VTCR_EL2_VS_8BIT;
 
        write_sysreg(val, vtcr_el2);
 }