Skip to content

Commit 417cff5

Browse files
binbinwu1lijinxia
authored andcommitted
hv: check vmx unrestricted guest capability
Signed-off-by: Binbin Wu <binbin.wu@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Acked-by: Xu, Anthony <anthony.xu@intel.com>
1 parent 37db817 commit 417cff5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ static int hardware_detect_support(void)
211211
return -ENODEV;
212212
}
213213

214+
if (!cpu_has_vmx_unrestricted_guest_cap()) {
215+
pr_fatal("%s, unrestricted guest not supported\n", __func__);
216+
return -ENODEV;
217+
}
218+
214219
ret = check_vmx_mmu_cap();
215220
if (ret)
216221
return ret;

hypervisor/include/arch/x86/vmx.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@
390390
/* CR4 bits hv want to trap to track status change */
391391
#define CR4_TRAP_MASK (CR4_PSE | CR4_PAE)
392392

393+
#define VMX_SUPPORT_UNRESTRICTED_GUEST (1<<5)
394+
393395
/* External Interfaces */
394396
int exec_vmxon_instr(void);
395397
uint64_t exec_vmread(uint32_t field);
@@ -410,11 +412,15 @@ static inline uint8_t get_vcpu_mode(struct vcpu *vcpu)
410412
return vcpu->arch_vcpu.cpu_mode;
411413
}
412414

415+
static inline bool cpu_has_vmx_unrestricted_guest_cap(void)
416+
{
417+
return !!(msr_read(MSR_IA32_VMX_MISC) & VMX_SUPPORT_UNRESTRICTED_GUEST);
418+
}
419+
413420
typedef struct _descriptor_table_{
414421
uint16_t limit;
415422
uint64_t base;
416423
}__attribute__((packed)) descriptor_table;
417-
418424
#endif /* ASSEMBLER */
419425

420426
#endif /* VMX_H_ */

0 commit comments

Comments
 (0)