]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
KVM: x86: Warn if guest virtual address space is not 48-bits
authorNadav Amit <namit@cs.technion.ac.il>
Tue, 16 Sep 2014 12:10:03 +0000 (15:10 +0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 24 Sep 2014 12:07:48 +0000 (14:07 +0200)
The KVM emulator code assumes that the guest virtual address space (in 64-bit)
is 48-bits wide.  Fail the KVM_SET_CPUID and KVM_SET_CPUID2 ioctl if
userspace tries to create a guest that does not obey this restriction.

Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/cpuid.c
arch/x86/kvm/cpuid.h

index f4bad87ef256533473650a57b250d0d1924ee164..e28d798f72777e7f17fd0b8e474b73b7d11d199d 100644 (file)
@@ -53,14 +53,14 @@ u64 kvm_supported_xcr0(void)
        return xcr0;
 }
 
-void kvm_update_cpuid(struct kvm_vcpu *vcpu)
+int kvm_update_cpuid(struct kvm_vcpu *vcpu)
 {
        struct kvm_cpuid_entry2 *best;
        struct kvm_lapic *apic = vcpu->arch.apic;
 
        best = kvm_find_cpuid_entry(vcpu, 1, 0);
        if (!best)
-               return;
+               return 0;
 
        /* Update OSXSAVE bit */
        if (cpu_has_xsave && best->function == 0x1) {
@@ -88,7 +88,17 @@ void kvm_update_cpuid(struct kvm_vcpu *vcpu)
                        xstate_required_size(vcpu->arch.xcr0);
        }
 
+       /*
+        * The existing code assumes virtual address is 48-bit in the canonical
+        * address checks; exit if it is ever changed.
+        */
+       best = kvm_find_cpuid_entry(vcpu, 0x80000008, 0);
+       if (best && ((best->eax & 0xff00) >> 8) != 48 &&
+               ((best->eax & 0xff00) >> 8) != 0)
+               return -EINVAL;
+
        kvm_pmu_cpuid_update(vcpu);
+       return 0;
 }
 
 static int is_efer_nx(void)
@@ -151,10 +161,9 @@ int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
        }
        vcpu->arch.cpuid_nent = cpuid->nent;
        cpuid_fix_nx_cap(vcpu);
-       r = 0;
        kvm_apic_set_version(vcpu);
        kvm_x86_ops->cpuid_update(vcpu);
-       kvm_update_cpuid(vcpu);
+       r = kvm_update_cpuid(vcpu);
 
 out_free:
        vfree(cpuid_entries);
@@ -178,9 +187,7 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
        vcpu->arch.cpuid_nent = cpuid->nent;
        kvm_apic_set_version(vcpu);
        kvm_x86_ops->cpuid_update(vcpu);
-       kvm_update_cpuid(vcpu);
-       return 0;
-
+       r = kvm_update_cpuid(vcpu);
 out:
        return r;
 }
index 43b33e301e6851819fbc7e8b4a4942c248299e22..4452eedfaedd0a4849b54d4137edd5e85b24ae46 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "x86.h"
 
-void kvm_update_cpuid(struct kvm_vcpu *vcpu);
+int kvm_update_cpuid(struct kvm_vcpu *vcpu);
 struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
                                              u32 function, u32 index);
 int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,