]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm: Cleanup kvm__cpu_supports_vm()
authorPekka Enberg <penberg@cs.helsinki.fi>
Mon, 5 Jul 2010 18:43:17 +0000 (21:43 +0300)
committerPekka Enberg <penberg@cs.helsinki.fi>
Mon, 5 Jul 2010 18:43:17 +0000 (21:43 +0300)
This patch cleans up kvm__cpu_supports_vm() by unifying the VMX and SVM paths.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
tools/kvm/kvm.c

index 4d1efaa5ab824f7f6d4f04e71bc7bcb0bbbb1f4d..78306e7bd9e0ca63ee3cb3d711f10403c5bc18ff 100644 (file)
@@ -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(&regs);
 
        switch (regs.ebx) {
        case CPUID_VENDOR_INTEL_1:
-               if (regs.eax < 1)
-                       return false;
-               regs = (struct cpuid_regs) { .eax = 1 };
-               host_cpuid(&regs);
-               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(&regs);
-               if (regs.eax < 0x80000001)
-                       return false;
-               regs = (struct cpuid_regs) { .eax = 0x80000001 };
-               host_cpuid(&regs);
-               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(&regs);
+
+       if (regs.eax < eax_base + 0x01)
+               return false;
+
+       regs    = (struct cpuid_regs) {
+               .eax            = eax_base + 0x01
+       };
+       host_cpuid(&regs);
+
+       return regs.ecx & (1 << feature);
 }
 
 struct kvm *kvm__init(const char *kvm_dev)