diff options
author | Asias He <asias.hejun@gmail.com> | 2010-07-05 14:01:11 +0800 |
---|---|---|
committer | Will Deacon <will.deacon@arm.com> | 2015-06-01 16:39:40 +0100 |
commit | c78b871349ac96c12311c72f4730bb116d44faf1 (patch) | |
tree | 99e9d7136b2c6f78c40c134471fa2186623b21bd /kvm.c | |
parent | 6d7c36ceeafa0dd4c7ea917b14a2b688891e178c (diff) | |
download | kvmtool-c78b871349ac96c12311c72f4730bb116d44faf1.tar.gz |
kvm: Check vmx capability using cpuid
[ penberg@cs.helsinki.fi: use host_cpuid(), cleanups ]
Reported-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
Diffstat (limited to 'kvm.c')
-rw-r--r-- | kvm.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -1,6 +1,7 @@ #include "kvm/kvm.h" #include "kvm/interrupt.h" +#include "kvm/cpufeature.h" #include "kvm/util.h" #include <linux/kvm.h> @@ -133,6 +134,18 @@ void kvm__delete(struct kvm *self) free(self); } +static bool kvm__cpu_supports_vm(void) +{ + struct cpuid_regs regs; + + regs = (struct cpuid_regs) { + .eax = 1, + }; + host_cpuid(®s); + + return regs.ecx & (1 << KVM__X86_FEATURE_VMX); +} + struct kvm *kvm__init(const char *kvm_dev) { struct kvm_userspace_memory_region mem; @@ -142,6 +155,9 @@ struct kvm *kvm__init(const char *kvm_dev) int mmap_size; int ret; + if (!kvm__cpu_supports_vm()) + die("Your CPU does not support hardware virtualization"); + self = kvm__new(); self->sys_fd = open(kvm_dev, O_RDWR); |