Reviewed-by: Nikita Leshenko <nikita.leshchenko@xxxxxxxxxx> Reviewed-by: Joao Martins <joao.m.martins@xxxxxxxxxx> Signed-off-by: Liran Alon <liran.alon@xxxxxxxxxx> --- x86/vmx.c | 22 ++++++++++++++-------- x86/vmx.h | 1 + 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/x86/vmx.c b/x86/vmx.c index 146734d334a1..b9328d9ca75c 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -1247,6 +1247,19 @@ static int init_vmcs(struct vmcs **vmcs) return 0; } +void enable_vmx(void) +{ + bool vmx_enabled = + rdmsr(MSR_IA32_FEATURE_CONTROL) & + FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX; + + if (!vmx_enabled) { + wrmsr(MSR_IA32_FEATURE_CONTROL, + FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX | + FEATURE_CONTROL_LOCKED); + } +} + static void init_vmx_caps(void) { basic.val = rdmsr(MSR_IA32_VMX_BASIC); @@ -1932,7 +1945,6 @@ test_wanted(const char *name, const char *filters[], int filter_count) int main(int argc, const char *argv[]) { int i = 0; - bool vmx_enabled; setup_vm(); smp_init(); @@ -1954,13 +1966,7 @@ int main(int argc, const char *argv[]) if (test_vmx_feature_control() != 0) goto exit; } else { - vmx_enabled = rdmsr(MSR_IA32_FEATURE_CONTROL) & - FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX; - if (!vmx_enabled) { - wrmsr(MSR_IA32_FEATURE_CONTROL, - FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX | - FEATURE_CONTROL_LOCKED); - } + enable_vmx(); } if (test_wanted("test_vmxon", argv, argc)) { diff --git a/x86/vmx.h b/x86/vmx.h index fdc6f7171826..e47134e29e83 100644 --- a/x86/vmx.h +++ b/x86/vmx.h @@ -790,6 +790,7 @@ static inline bool invvpid(unsigned long type, u64 vpid, u64 gla) return ret; } +void enable_vmx(void); void init_vmx(u64 *vmxon_region); const char *exit_reason_description(u64 reason); -- 2.20.1