Skip to content

Commit 3fb7b75

Browse files
lifeixlijinxia
authored andcommitted
hv: execute vmxon instruction fail don't panic system
Don't panic system when execute vmxon instruction failed. And let's follow that only print error info when error return from library function. Signed-off-by: Li, Fei1 <fei1.li@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com>
1 parent fe4484f commit 3fb7b75

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

hypervisor/arch/x86/vmx.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ static inline int exec_vmxon(void *addr)
4949
uint64_t tmp64;
5050
int status = 0;
5151

52-
if (addr == NULL)
53-
status = -EINVAL;
54-
ASSERT(status == 0, "Incorrect arguments");
52+
if (addr == NULL) {
53+
pr_err("%s, Incorrect arguments\n", __func__);
54+
return -EINVAL;
55+
}
5556

5657
/* Read Feature ControL MSR */
5758
tmp64 = msr_read(MSR_IA32_FEATURE_CONTROL);
@@ -61,6 +62,7 @@ static inline int exec_vmxon(void *addr)
6162
/* See if VMX enabled */
6263
if (!(tmp64 & MSR_IA32_FEATURE_CONTROL_VMX_NO_SMX)) {
6364
/* Return error - VMX can't be enabled */
65+
pr_err("%s, VMX can't be enabled\n", __func__);
6466
status = -EINVAL;
6567
}
6668
} else {
@@ -81,8 +83,10 @@ static inline int exec_vmxon(void *addr)
8183
: "%rax", "cc", "memory");
8284

8385
/* if carry and zero flags are clear operation success */
84-
if (rflags & (RFLAGS_C | RFLAGS_Z))
86+
if (rflags & (RFLAGS_C | RFLAGS_Z)) {
87+
pr_err("%s, Turn VMX on failed\n", __func__);
8588
status = -EINVAL;
89+
}
8690
}
8791

8892
/* Return result to caller */
@@ -93,7 +97,7 @@ int exec_vmxon_instr(void)
9397
{
9498
uint64_t tmp64;
9599
uint32_t tmp32;
96-
int ret_val = -EINVAL;
100+
int ret = -ENOMEM;
97101
void *vmxon_region_va;
98102
uint64_t vmxon_region_pa;
99103

@@ -115,10 +119,12 @@ int exec_vmxon_instr(void)
115119

116120
/* Turn ON VMX */
117121
vmxon_region_pa = HVA2HPA(vmxon_region_va);
118-
ret_val = exec_vmxon(&vmxon_region_pa);
119-
}
122+
ret = exec_vmxon(&vmxon_region_pa);
123+
} else
124+
pr_err("%s, alloc memory for VMXON region failed\n",
125+
__func__);
120126

121-
return ret_val;
127+
return ret;
122128
}
123129

124130
int exec_vmclear(void *addr)

hypervisor/common/hv_main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,8 @@ int hv_main(int cpu_id)
156156

157157
/* Enable virtualization extensions */
158158
ret = exec_vmxon_instr();
159-
if (ret != 0) {
160-
pr_err("%s, Unable to enable VMX!\n", __func__);
159+
if (ret != 0)
161160
return ret;
162-
}
163161

164162
/* X2APIC mode is disabled by default. */
165163
x2apic_enabled = false;

0 commit comments

Comments
 (0)