KVM guest: make kvm_para_available() check hypervisor bit reading cpuid leaf
authorGleb Natapov <gleb@redhat.com>
Mon, 30 Apr 2012 11:45:49 +0000 (14:45 +0300)
committerAvi Kivity <avi@redhat.com>
Sun, 6 May 2012 12:59:49 +0000 (15:59 +0300)
This cpuid range does not exist on real HW and Intel spec says that
"Information returned for highest basic information leaf" will be
returned. Not very well defined.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
arch/x86/include/asm/kvm_para.h

index 99c4bbe0cca266a1a3ae8efd451b13b677336a71..a7a7a94b94ce9e69e135b15b8ad5d324178bfb40 100644 (file)
@@ -178,14 +178,16 @@ static inline int kvm_para_available(void)
        unsigned int eax, ebx, ecx, edx;
        char signature[13];
 
-       cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
-       memcpy(signature + 0, &ebx, 4);
-       memcpy(signature + 4, &ecx, 4);
-       memcpy(signature + 8, &edx, 4);
-       signature[12] = 0;
-
-       if (strcmp(signature, "KVMKVMKVM") == 0)
-               return 1;
+       if (cpu_has_hypervisor) {
+               cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
+               memcpy(signature + 0, &ebx, 4);
+               memcpy(signature + 4, &ecx, 4);
+               memcpy(signature + 8, &edx, 4);
+               signature[12] = 0;
+
+               if (strcmp(signature, "KVMKVMKVM") == 0)
+                       return 1;
+       }
 
        return 0;
 }