From: Pekka Enberg Date: Mon, 5 Jul 2010 18:43:17 +0000 (+0300) Subject: kvm: Cleanup kvm__cpu_supports_vm() X-Git-Tag: next-20110824~3^2~528^2~107 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=9856437896be3d391a1e3f2e2a0ff14fffc91a8c;p=karo-tx-linux.git kvm: Cleanup kvm__cpu_supports_vm() This patch cleans up kvm__cpu_supports_vm() by unifying the VMX and SVM paths. Signed-off-by: Pekka Enberg --- diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index 4d1efaa5ab82..78306e7bd9e0 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -137,35 +137,39 @@ void kvm__delete(struct kvm *self) static bool kvm__cpu_supports_vm(void) { struct cpuid_regs regs; - bool ret = false; + uint32_t eax_base; + int feature; regs = (struct cpuid_regs) { - .eax = 0, + .eax = 0x00, }; host_cpuid(®s); switch (regs.ebx) { case CPUID_VENDOR_INTEL_1: - if (regs.eax < 1) - return false; - regs = (struct cpuid_regs) { .eax = 1 }; - host_cpuid(®s); - if (regs.ecx & (1 << KVM__X86_FEATURE_VMX)) - ret = true; + eax_base = 0x00; + feature = KVM__X86_FEATURE_VMX; break; case CPUID_VENDOR_AMD_1: - regs = (struct cpuid_regs) { .eax = 0x80000000 }; - host_cpuid(®s); - if (regs.eax < 0x80000001) - return false; - regs = (struct cpuid_regs) { .eax = 0x80000001 }; - host_cpuid(®s); - if (regs.ecx & (1 << KVM__X86_FEATURE_SVM)) - ret = true; + eax_base = 0x80000000; + feature = KVM__X86_FEATURE_SVM; break; } - return ret; + regs = (struct cpuid_regs) { + .eax = eax_base, + }; + host_cpuid(®s); + + if (regs.eax < eax_base + 0x01) + return false; + + regs = (struct cpuid_regs) { + .eax = eax_base + 0x01 + }; + host_cpuid(®s); + + return regs.ecx & (1 << feature); } struct kvm *kvm__init(const char *kvm_dev)