Skip to content

Commit

Permalink
KVM guest: make kvm_para_available() check hypervisor bit reading cpu…
Browse files Browse the repository at this point in the history
…id leaf

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>
  • Loading branch information
Gleb Natapov authored and Avi Kivity committed May 6, 2012
1 parent 57c22e5 commit 9b72d3b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions arch/x86/include/asm/kvm_para.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 9b72d3b

Please sign in to comment.