kvm, cpuid: Fix XSTOR and VMX compatibility in cpuid

Under virtual environment we don't support XSTOR and VMX features.

Reported-by: Asias He <asias.hejun.hj@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov
2015-06-01 16:39:39 +01:00
committed by Will Deacon
parent 79241bb628
commit d845784715
2 changed files with 37 additions and 0 deletions
+22
View File
@@ -1,5 +1,6 @@
#include "kvm/kvm.h"
#include "kvm/cpufeature.h"
#include "kvm/util.h"
#include <sys/ioctl.h>
@@ -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(&regs);
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;
+15
View File
@@ -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 */