KVM: PPC: Book3S HV: Allow HV module to load without hypervisor mode
authorPaul Mackerras <paulus@ozlabs.org>
Mon, 8 Oct 2018 05:31:16 +0000 (16:31 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 9 Oct 2018 05:04:27 +0000 (16:04 +1100)
With this, the KVM-HV module can be loaded in a guest running under
KVM-HV, and if the hypervisor supports nested virtualization, this
guest can now act as a nested hypervisor and run nested guests.

This also adds some checks to inform userspace that HPT guests are not
supported by nested hypervisors (by returning false for the
KVM_CAP_PPC_MMU_HASH_V3 capability), and to prevent userspace from
configuring a guest to use HPT mode.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/kvm/book3s_hv.c
arch/powerpc/kvm/powerpc.c

index 8458bbe..e1ac69e 100644 (file)
@@ -4811,11 +4811,15 @@ static int kvmppc_core_emulate_mfspr_hv(struct kvm_vcpu *vcpu, int sprn,
 
 static int kvmppc_core_check_processor_compat_hv(void)
 {
-       if (!cpu_has_feature(CPU_FTR_HVMODE) ||
-           !cpu_has_feature(CPU_FTR_ARCH_206))
-               return -EIO;
+       if (cpu_has_feature(CPU_FTR_HVMODE) &&
+           cpu_has_feature(CPU_FTR_ARCH_206))
+               return 0;
 
-       return 0;
+       /* POWER9 in radix mode is capable of being a nested hypervisor. */
+       if (cpu_has_feature(CPU_FTR_ARCH_300) && radix_enabled())
+               return 0;
+
+       return -EIO;
 }
 
 #ifdef CONFIG_KVM_XICS
@@ -5133,6 +5137,10 @@ static int kvmhv_configure_mmu(struct kvm *kvm, struct kvm_ppc_mmuv3_cfg *cfg)
        if (radix && !radix_enabled())
                return -EINVAL;
 
+       /* If we're a nested hypervisor, we currently only support radix */
+       if (kvmhv_on_pseries() && !radix)
+               return -EINVAL;
+
        mutex_lock(&kvm->lock);
        if (radix != kvm_is_radix(kvm)) {
                if (kvm->arch.mmu_ready) {
index eba5756..1f4b128 100644 (file)
@@ -594,7 +594,8 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
                r = !!(hv_enabled && radix_enabled());
                break;
        case KVM_CAP_PPC_MMU_HASH_V3:
-               r = !!(hv_enabled && cpu_has_feature(CPU_FTR_ARCH_300));
+               r = !!(hv_enabled && cpu_has_feature(CPU_FTR_ARCH_300) &&
+                      cpu_has_feature(CPU_FTR_HVMODE));
                break;
 #endif
        case KVM_CAP_SYNC_MMU: