From 417cff5049e0000705b898c8371b686434c57e6f Mon Sep 17 00:00:00 2001 From: Binbin Wu Date: Tue, 22 May 2018 13:59:06 +0800 Subject: [PATCH] hv: check vmx unrestricted guest capability Signed-off-by: Binbin Wu Reviewed-by: Kevin Tian Acked-by: Xu, Anthony --- hypervisor/arch/x86/cpu.c | 5 +++++ hypervisor/include/arch/x86/vmx.h | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index 63aa1a991..2f076d12c 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -211,6 +211,11 @@ static int hardware_detect_support(void) return -ENODEV; } + if (!cpu_has_vmx_unrestricted_guest_cap()) { + pr_fatal("%s, unrestricted guest not supported\n", __func__); + return -ENODEV; + } + ret = check_vmx_mmu_cap(); if (ret) return ret; diff --git a/hypervisor/include/arch/x86/vmx.h b/hypervisor/include/arch/x86/vmx.h index 27987f502..7d3749257 100644 --- a/hypervisor/include/arch/x86/vmx.h +++ b/hypervisor/include/arch/x86/vmx.h @@ -390,6 +390,8 @@ /* CR4 bits hv want to trap to track status change */ #define CR4_TRAP_MASK (CR4_PSE | CR4_PAE) +#define VMX_SUPPORT_UNRESTRICTED_GUEST (1<<5) + /* External Interfaces */ int exec_vmxon_instr(void); uint64_t exec_vmread(uint32_t field); @@ -410,11 +412,15 @@ static inline uint8_t get_vcpu_mode(struct vcpu *vcpu) return vcpu->arch_vcpu.cpu_mode; } +static inline bool cpu_has_vmx_unrestricted_guest_cap(void) +{ + return !!(msr_read(MSR_IA32_VMX_MISC) & VMX_SUPPORT_UNRESTRICTED_GUEST); +} + typedef struct _descriptor_table_{ uint16_t limit; uint64_t base; }__attribute__((packed)) descriptor_table; - #endif /* ASSEMBLER */ #endif /* VMX_H_ */