From d845784715f4feda1ace8f4e8427daf30217e014 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Sat, 3 Jul 2010 19:21:33 +0400 Subject: [PATCH] kvm, cpuid: Fix XSTOR and VMX compatibility in cpuid Under virtual environment we don't support XSTOR and VMX features. Reported-by: Asias He Signed-off-by: Cyrill Gorcunov --- cpuid.c | 22 ++++++++++++++++++++++ include/kvm/cpufeature.h | 15 +++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 include/kvm/cpufeature.h diff --git a/cpuid.c b/cpuid.c index f03ef80..4b47eee 100644 --- a/cpuid.c +++ b/cpuid.c @@ -1,5 +1,6 @@ #include "kvm/kvm.h" +#include "kvm/cpufeature.h" #include "kvm/util.h" #include @@ -92,6 +93,27 @@ void kvm__setup_cpuid(struct kvm *self) * Linux kernel is not interested in them during boot up. */ switch (function) { + case 0x01: { /* Feature Information */ + struct cpuid_regs regs; + + regs = (struct cpuid_regs) { + .eax = function, + }; + cpuid(®s); + + kvm_cpuid->entries[ndx++] = (struct kvm_cpuid_entry2) { + .function = function, + .index = 0, + .flags = 0, + .eax = regs.eax, + .ebx = regs.ebx, + .ecx = + cpu_feature_disable(regs.ecx, KVM__X86_FEATURE_XSAVE) | + cpu_feature_disable(regs.ecx, KVM__X86_FEATURE_VMX), + .edx = regs.edx, + }; + break; + } case 0x02: { /* Processor configuration descriptor */ struct cpuid_regs regs; uint32_t times; diff --git a/include/kvm/cpufeature.h b/include/kvm/cpufeature.h new file mode 100644 index 0000000..83373b4 --- /dev/null +++ b/include/kvm/cpufeature.h @@ -0,0 +1,15 @@ +#ifndef KVM__CPUFEATURE_H +#define KVM__CPUFEATURE_H + +/* + * CPUID flags we need to deal with + */ +#define KVM__X86_FEATURE_VMX 5 /* Hardware virtualization */ +#define KVM__X86_FEATURE_XSAVE 26 /* XSAVE/XRSTOR/XSETBV/XGETBV */ + +#define cpu_feature_disable(reg, feature) \ + ((reg) & ~(1 << (feature))) +#define cpu_feature_enable(reg, feature) \ + ((reg) | (1 << (feature))) + +#endif /* KVM__CPUFEATURE_H */