From 4bff7fad95840f604564d91a40902d7c637874f4 Mon Sep 17 00:00:00 2001 From: Neel Natu Date: Wed, 25 Jul 2012 00:21:16 +0000 Subject: [PATCH] Verify that VMX operation has been enabled by BIOS before executing the VMXON instruction. Reported by "s vas" on freebsd-virtualization@ --- sys/amd64/vmm/intel/vmx.c | 12 +++++++++++- sys/x86/include/specialreg.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/sys/amd64/vmm/intel/vmx.c b/sys/amd64/vmm/intel/vmx.c index 4bbcea8dca5a..df28fe950b69 100644 --- a/sys/amd64/vmm/intel/vmx.c +++ b/sys/amd64/vmm/intel/vmx.c @@ -427,7 +427,7 @@ static int vmx_init(void) { int error; - uint64_t fixed0, fixed1; + uint64_t fixed0, fixed1, feature_control; uint32_t tmp; /* CPUID.1:ECX[bit 5] must be 1 for processor to support VMX */ @@ -436,6 +436,16 @@ vmx_init(void) return (ENXIO); } + /* + * Verify that MSR_IA32_FEATURE_CONTROL lock and VMXON enable bits + * are set (bits 0 and 2 respectively). + */ + feature_control = rdmsr(MSR_IA32_FEATURE_CONTROL); + if ((feature_control & 0x5) != 0x5) { + printf("vmx_init: VMX operation disabled by BIOS\n"); + return (ENXIO); + } + /* Check support for primary processor-based VM-execution controls */ error = vmx_set_ctlreg(MSR_VMX_PROCBASED_CTLS, MSR_VMX_TRUE_PROCBASED_CTLS, diff --git a/sys/x86/include/specialreg.h b/sys/x86/include/specialreg.h index ff6a7771c5fa..9f83f141cc00 100644 --- a/sys/x86/include/specialreg.h +++ b/sys/x86/include/specialreg.h @@ -294,6 +294,7 @@ #define MSR_APICBASE 0x01b #define MSR_EBL_CR_POWERON 0x02a #define MSR_TEST_CTL 0x033 +#define MSR_IA32_FEATURE_CONTROL 0x03a #define MSR_BIOS_UPDT_TRIG 0x079 #define MSR_BBL_CR_D0 0x088 #define MSR_BBL_CR_D1 0x089