Intel 64 and IA-32 Architectures Software Developers Manual Volume 3B, System Programming Guide Part 2

Table Of Contents
Vol. 3 26-5
VIRTUAL-MACHINE MONITOR PROGRAMMING CONSIDERATIONS
26.4 USING VMX INSTRUCTIONS
VMX instructions are allowed only in VMX root operation. An attempt to execute a
VMX instruction in VMX non-root operation causes a VM exit.
Processors perform various checks while executing any VMX instruction. They follow
well-defined error handling on failures. VMX instruction execution failures detected
before loading of a guest state are handled by the processor as follows:
If the working-VMCS is not valid, the instruction fails by setting RFLAGS.CF = 1.
If the working-VMCS pointer is valid, RFLAGS.ZF is set to value 1 and the proper
error-code is saved in the VM-instruction error field of the working-VMCS.
Software is required to check RFLAGS.CF and RFLAGS.ZF to determine the success or
failure of VMX instruction executions.
After a VM-entry instruction (VMRESUME or VMLAUNCH) successfully completes the
general checks and checks on VMX controls and the host-state area (see Section
22.2), any errors encountered while loading of guest-state (due to bad guest-state or
bad MSR loading) causes the processor to load state from the host-state area of the
working VMCS as if a VM exit had occurred (see Section 26.7).
This failure behavior differs from that of VM exits in that no guest-state is saved to
the guest-state area. A VMM can detect its VM-exit handler was invoked by such a
failure by checking bit 31 (for 1) in the exit reason field of the working VMCS and
further identify the failure by using the exit qualification field.
26.5 VMM SETUP & TEAR DOWN
VMMs need to ensure that the processor is running in protected mode with paging
before entering VMX operation. The following list describes the minimal steps
required to enter VMX root operation with a VMM running at CPL = 0.
Check VMX support in processor using CPUID.
Determine the VMX capabilities supported by the processor through the VMX
capability MSRs. See Section 26.5.1 and Appendix G.
Create a VMXON region in non-pageable memory of a size specified by
IA32_VMX_BASIC MSR and aligned to a 4-KByte boundary. Software should read
the capability MSRs to determine width of the physical addresses that may be
used for the VMXON region and ensure the entire VMXON region can be
addressed by addresses with that width. Also, software must ensure that the
VMXON region is hosted in cache-coherent memory.
Initialize the version identifier in the VMXON region (the first 32 bits) with the
VMCS revision identifier reported by capability MSRs.
Ensure the current processor operating mode meets the required CR0 fixed bits
(CR0.PE = 1, CR0.PG = 1). Other required CR0 fixed bits can be detected
through the IA32_VMX_CR0_FIXED0 and IA32_VMX_CR0_FIXED1 MSRs.