kvm: Check for SVM extension being supported for AMD cpus

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov
2010-07-05 21:10:48 +04:00
committed by Will Deacon
parent c78b871349
commit ae87afbf83
2 changed files with 25 additions and 2 deletions
+1
View File
@@ -13,6 +13,7 @@
* CPUID flags we need to deal with
*/
#define KVM__X86_FEATURE_VMX 5 /* Hardware virtualization */
#define KVM__X86_FEATURE_SVM 2 /* Secure virtual machine */
#define KVM__X86_FEATURE_XSAVE 26 /* XSAVE/XRSTOR/XSETBV/XGETBV */
#define cpu_feature_disable(reg, feature) \
+24 -2
View File
@@ -137,13 +137,35 @@ void kvm__delete(struct kvm *self)
static bool kvm__cpu_supports_vm(void)
{
struct cpuid_regs regs;
bool ret = false;
regs = (struct cpuid_regs) {
.eax = 1,
.eax = 0,
};
host_cpuid(&regs);
return regs.ecx & (1 << KVM__X86_FEATURE_VMX);
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;
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;
break;
}
return ret;
}
struct kvm *kvm__init(const char *kvm_dev)