Vol. 3C 31-1
CHAPTER 31
VIRTUAL-MACHINE MONITOR PROGRAMMING CONSIDERATIONS
31.1
VMX SYSTEM PROGRAMMING OVERVIEW
The Virtual Machine Monitor (VMM) is a software class used to manage virtual machines (VM). This chapter
describes programming considerations for VMMs.
Each VM behaves like a complete physical machine and can run operating system (OS) and applications. The VMM
software layer runs at the most privileged level and has complete ownership of the underlying system hardware.
The VMM controls creation of a VM, transfers control to a VM, and manages situations that can cause transitions
between the guest VMs and host VMM. The VMM allows the VMs to share the underlying hardware and yet provides
isolation between the VMs. The guest software executing in a VM is unaware of any transitions that might have
occurred between the VM and its host.
31.2
SUPPORTING PROCESSOR OPERATING MODES IN GUEST ENVIRONMENTS
Typically, VMMs transfer control to a VM using VMX transitions referred to as VM entries. The boundary conditions
that define what a VM is allowed to execute in isolation are specified in a virtual-machine control structure (VMCS).
As noted in Section 23.8, processors may fix certain bits in CR0 and CR4 to specific values and not support other
values. The first processors to support VMX operation require that CR0.PE and CR0.PG be 1 in VMX operation. Thus,
a VM entry is allowed only to guests with paging enabled that are in protected mode or in virtual-8086 mode. Guest
execution in other processor operating modes need to be specially handled by the VMM.
One example of such a condition is guest execution in real-mode. A VMM could support guest real-mode execution
using at least two approaches:
•
By using a fast instruction set emulator in the VMM.
•
By using the similarity between real-mode and virtual-8086 mode to support real-mode guest execution in a
virtual-8086 container. The virtual-8086 container may be implemented as a virtual-8086 container task within
a monitor that emulates real-mode guest state and instructions, or by running the guest VM as the virtual-8086
container (by entering the guest with RFLAGS.VM
1
set). Attempts by real-mode code to access privileged state
outside the virtual-8086 container would trap to the VMM and would also need to be emulated.
Another example of such a condition is guest execution in protected mode with paging disabled. A VMM could
support such guest execution by using “identity” page tables to emulate unpaged protected mode.
31.2.1
Using Unrestricted Guest Mode
Processors which support the “unrestricted guest” VM-execution control allow VM software to run in real-address
mode and unpaged protected mode. Since these modes do not use paging, VMM software must virtualize guest
memory using EPT.
Special notes for 64-bit VMM software using the 1-setting of the “unrestricted guest” VM-execution control:
•
It is recommended that 64-bit VMM software use the 1-settings of the "load IA32_EFER" VM entry control and
the "save IA32_EFER" VM-exit control. If VM entry is establishing CR0.PG=0 and if the "IA-32e mode guest"
and "load IA32_EFER" VM entry controls are both 0, VM entry leaves IA32_EFER.LME unmodified (i.e., the host
value will persist in the guest).
•
It is not necessary for VMM software to track guest transitions into and out of IA-32e mode for the purpose of
maintaining the correct setting of the "IA-32e mode guest" VM entry control. This is because VM exits on
1. This chapter uses the notation RAX, RIP, RSP, RFLAGS, etc. for processor registers because most processors that support VMX oper-
ation also support Intel 64 architecture. For processors that do not support Intel 64 architecture, this notation refers to the 32-bit
forms of those registers (EAX, EIP, ESP, EFLAGS, etc.).