Skip to content

Commit e4e38e1

Browse files
mingqiangchilijinxia
authored andcommitted
hv:Check if VMX capability is locked with incorrect value
Check if the VMX capability is locked with incorrect value, at the time when HV do the hardware capability detect. Tracked-On: #861 Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com> Reviewed-by: Junjie Mao <junjie.mao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 6593080 commit e4e38e1

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ static int hardware_detect_support(void)
252252
return -ENODEV;
253253
}
254254

255+
if (is_vmx_disabled()) {
256+
pr_fatal("%s, VMX can not be enabled\n", __func__);
257+
return -ENODEV;
258+
}
259+
255260
ret = check_vmx_mmu_cap();
256261
if (ret != 0) {
257262
return ret;

hypervisor/arch/x86/vmx.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ static uint64_t cr4_host_mask;
2626
static uint64_t cr4_always_on_mask;
2727
static uint64_t cr4_always_off_mask;
2828

29+
bool is_vmx_disabled(void)
30+
{
31+
uint64_t msr_val;
32+
33+
/* Read Feature ControL MSR */
34+
msr_val = msr_read(MSR_IA32_FEATURE_CONTROL);
35+
36+
/* Check if feature control is locked and vmx cannot be enabled */
37+
if ((msr_val & MSR_IA32_FEATURE_CONTROL_LOCK) != 0U &&
38+
(msr_val & MSR_IA32_FEATURE_CONTROL_VMX_NO_SMX) == 0U) {
39+
return true;
40+
}
41+
return false;
42+
}
43+
2944
static inline int exec_vmxon(void *addr)
3045
{
3146
uint64_t rflags;
@@ -41,14 +56,7 @@ static inline int exec_vmxon(void *addr)
4156
tmp64 = msr_read(MSR_IA32_FEATURE_CONTROL);
4257

4358
/* Determine if feature control is locked */
44-
if ((tmp64 & MSR_IA32_FEATURE_CONTROL_LOCK) != 0U) {
45-
/* See if VMX enabled */
46-
if ((tmp64 & MSR_IA32_FEATURE_CONTROL_VMX_NO_SMX) == 0U) {
47-
/* Return error - VMX can't be enabled */
48-
pr_err("%s, VMX can't be enabled\n", __func__);
49-
status = -EINVAL;
50-
}
51-
} else {
59+
if ((tmp64 & MSR_IA32_FEATURE_CONTROL_LOCK) == 0U) {
5260
/* Lock and enable VMX support */
5361
tmp64 |= (MSR_IA32_FEATURE_CONTROL_LOCK |
5462
MSR_IA32_FEATURE_CONTROL_VMX_NO_SMX);

hypervisor/include/arch/x86/vmx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ int vmx_wrmsr_pat(struct vcpu *vcpu, uint64_t value);
448448

449449
void vmx_write_cr0(struct vcpu *vcpu, uint64_t cr0);
450450
void vmx_write_cr4(struct vcpu *vcpu, uint64_t cr4);
451+
bool is_vmx_disabled(void);
451452

452453
static inline enum vm_cpu_mode get_vcpu_mode(const struct vcpu *vcpu)
453454
{

0 commit comments

Comments
 (0)