Skip to content

Commit 74e2bfc

Browse files
lifeixjren1
authored andcommitted
Simple get_vmx_cap()
Don't check MSR Control Features in get_vmx_cap Signed-off-by: Li, Fei1 <fei1.li@intel.com>
1 parent 7e4b4c2 commit 74e2bfc

File tree

3 files changed

+5
-28
lines changed

3 files changed

+5
-28
lines changed

hypervisor/arch/x86/vmx.c

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -94,38 +94,15 @@ static inline int exec_vmxon(void *addr)
9494
return status;
9595
}
9696

97-
int check_vmx_support(void)
97+
bool get_vmx_cap(void)
9898
{
9999
uint32_t eax, ebx, ecx, edx;
100-
int ret_val = 0;
101-
uint64_t tmp64;
102100

103101
/* Run CPUID to determine if VTX support available */
104102
cpuid(CPUID_FEATURES, &eax, &ebx, &ecx, &edx);
105103

106104
/* See if VMX feature bit is set in ECX */
107-
if (!(ecx & CPUID_ECX_VMX)) {
108-
/* Log and return error */
109-
pr_fatal("VMX not supported by CPU");
110-
ret_val = -EINVAL;
111-
} else {
112-
/* Read feature control MSR */
113-
tmp64 = msr_read(MSR_IA32_FEATURE_CONTROL);
114-
115-
/* See if feature control MSR is locked and VMX not enabled
116-
* appropriately
117-
*/
118-
if ((tmp64 & MSR_IA32_FEATURE_CONTROL_LOCK) &&
119-
(!(tmp64 & MSR_IA32_FEATURE_CONTROL_VMX_NO_SMX))) {
120-
/* Log and return error */
121-
pr_fatal("MSR_IA32_FEATURE_CONTROL: Lock bit is on and VMXON bit is off");
122-
pr_fatal(" Cannot do vmxon");
123-
ret_val = -EINVAL;
124-
}
125-
}
126-
127-
/* Return status to caller */
128-
return ret_val;
105+
return !!(ecx & CPUID_ECX_VMX);
129106
}
130107

131108
int exec_vmxon_instr(void)

hypervisor/common/hv_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ int hv_main(int cpu_id)
152152
"cpu_id/tsc_aux mismatch");
153153

154154
/* Check if virtualization extensions are supported */
155-
ret = check_vmx_support();
156-
ASSERT(ret == 0, "VMX not supported!");
155+
ret = get_vmx_cap();
156+
ASSERT(ret == 1, "VMX not supported!");
157157

158158
/* Enable virtualization extensions */
159159
ret = exec_vmxon_instr();

hypervisor/include/arch/x86/vmx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@
413413
#define PAGE_PROTECTED_MODE 2
414414

415415
/* External Interfaces */
416-
int check_vmx_support(void);
416+
bool get_vmx_cap(void);
417417
int exec_vmxon_instr(void);
418418
uint64_t exec_vmread(uint32_t field);
419419
uint64_t exec_vmread64(uint32_t field_full);

0 commit comments

Comments
 (0)