How Hardware Virtualization Works: Intel VT-x and AMD-V
How VMX and SVM add a guest mode to x86 processors, what the VMCS and VMCB hold, why VM exits happen and how nested paging removes shadow page tables.

Before 2005, running an unmodified operating system under a hypervisor on x86 meant rewriting its code on the fly. Intel's VT-x and AMD's AMD-V removed that need by adding a second execution context to the processor itself, so that a guest kernel can run its privileged instructions natively and still be fenced in. This post explains how that context works: the two modes, the control structure that describes a guest, the events that force a return to the hypervisor, and the memory translation that makes it fast. It uses Intel's terms with AMD's in brackets, Linux 6.12 as the host kernel, and assumes you know what a page table and a privilege ring are. The overview is in the complete guide to virtualization for systems programmers.
The problem in one paragraph
A kernel expects ring 0, where it can load the page-table base in CR3, mask interrupts, access I/O ports and program the interrupt controller. A hypervisor must stop a guest kernel from doing those things to the real machine. If the guest kernel runs at ring 3 so that its privileged instructions fault, the hypervisor can emulate them. That fails on early x86, where some sensitive instructions do not fault. Hardware virtualization sidesteps the ring game completely: the guest runs at ring 0 in its own mode and the processor itself decides which operations leave that mode.
Two modes: root and non-root
Intel names them VMX root operation and VMX non-root operation. AMD calls the guest state "guest mode" and the hypervisor "host mode". Each has the full set of four rings. The hypervisor runs in root mode. When it wants to run a guest it executes a VM entry instruction, and the processor switches to non-root mode, loads the guest's state and starts executing guest code. Certain events cause a VM exit, which saves the guest's state, loads the hypervisor's and resumes in root mode right after the entry instruction.
The instructions differ by vendor. On Intel, VMXON enables VMX operation on a core, VMLAUNCH and VMRESUME perform VM entry, and VMCALL is how a guest calls the hypervisor on purpose. On AMD, VMRUN performs the entry and VMMCALL is the guest's explicit call. Both are privileged, which is why only the kernel can use them and why user space reaches the feature through the KVM interface.
The control structure
The state of a guest is not kept in a dozen scattered registers. It lives in one block of memory that the processor reads and writes. Intel calls it the VMCS, virtual machine control structure, and you access it with VMREAD and VMWRITE instructions, because the layout is deliberately opaque. AMD calls it the VMCB, virtual machine control block, a documented page-sized structure the hypervisor reads and writes with ordinary memory instructions.
Both contain four kinds of information:
| Area | What it holds |
|---|---|
| Guest state | Registers, segment state, control registers, the instruction pointer and flags at the time of exit |
| Host state | What to restore into the processor on VM exit so the hypervisor continues |
| Execution controls | Which events cause exits: interrupts, specific instructions, I/O, MSR access |
| Exit and entry information | The reason for the last exit, and events to inject on the next entry |
The controls are the interesting part. The hypervisor chooses how much of the machine it wants to intercept. If it clears the control for HLT exiting, a guest HLT stops the core for real. If it sets it, the guest halts into the hypervisor instead. The Intel Software Developer's Manual, volume 3, chapters on VMX, lists every control bit, and the AMD64 Architecture Programmer's Manual volume 2 does the same for the VMCB.
What causes an exit
Some events always exit, because they would let a guest learn or change something the hypervisor must own. CPUID always exits on Intel, which is how the hypervisor controls which features the guest sees. The instructions that enter or leave VMX operation exit, as does the one that loads extended control registers. Many others are configurable.
The common exit reasons you will meet when you profile a guest are:
I/O instruction: the guest executed
INorOUT. KVM reports this to user space asKVM_EXIT_IO.EPT violation: the guest touched a guest-physical address with no valid mapping in the second-level table, or violated its permissions. Memory-mapped device registers are caught this way and reported as
KVM_EXIT_MMIO.External interrupt: a host interrupt arrived while the guest ran, so the processor leaves guest mode and the host handles it.
HLT: the guest has nothing to do.
MSR access:
RDMSRorWRMSRon a register the hypervisor intercepts.Control register access: moves to
CR0orCR4that need validation.
Every one of those is a round trip: the processor saves guest state, the hypervisor runs, and the processor restores state on entry. Making a guest fast is mostly the work of eliminating exits that did not need to happen, by letting the hardware handle more on its own.
A sketch of the entry and exit cycle
You will not write VMLAUNCH in application code, but reading a simplified form helps. This pseudocode in C style shows the loop that every hypervisor runs on every virtual CPU. The function names are illustrative, not a real API:
for (;;) {
load_guest_state(vcpu); /* fill the VMCS or VMCB from software state */
enter_guest(vcpu); /* VMLAUNCH, VMRESUME or VMRUN */
/* execution resumes here after a VM exit */
save_guest_state(vcpu);
reason = read_exit_reason(vcpu); /* from the VMCS or VMCB */
if (!handle_in_kernel(vcpu, reason)) {
return_to_user_space(vcpu, reason); /* KVM_RUN returns */
}
}In Linux this loop is vcpu_enter_guest() in arch/x86/kvm/x86.c, which calls the vendor-specific code in vmx/vmx.c or svm/svm.c. Exits that the kernel can resolve alone, such as a fault on memory it can allocate, never reach user space. The rest return from the KVM_RUN ioctl so QEMU can emulate a device. The two outcomes correspond to the fast path and the slow path of every VM, and the ratio between them is the most useful number in virtualization performance work.
Memory: from shadow tables to nested paging
The first generation of VT-x had no help for address translation. The guest kernel manages its own page tables, mapping guest virtual addresses to what it believes is physical memory. But those guest-physical addresses are not real. The hypervisor had to maintain shadow page tables: a combined mapping from guest virtual to host physical, kept in sync with the guest's own tables by write-protecting them and trapping every edit. That was correct and very costly for any workload that creates processes or maps memory often.
Nested paging moved the combination into hardware. Intel's version is EPT (extended page tables) and AMD's is NPT (nested page tables). The processor keeps two page-table walks: the guest's tables translate a guest virtual address to a guest-physical address, and a second set of tables owned by the hypervisor translates guest-physical to host-physical. The guest can edit its own tables freely with no exit. The hypervisor only gets involved when the second-level table lacks an entry, which Intel reports as an EPT violation.
The cost of the second walk is real. A TLB miss in a guest can require walking both levels, and a four-level guest table over a four-level second-level table has many memory references on the worst path. The practical consequences are that TLB size and huge pages matter more in a VM than on bare metal, and that backing guest RAM with 2 MiB pages on the host shortens the second walk. The Linux KVM documentation describes the memory slot interface that feeds the second-level tables, which the post on mapping guest memory covers.
Interrupts and the APIC
Interrupts move in two directions. A device interrupt for the host arrives while a guest runs: the control bit for external-interrupt exiting makes the processor leave guest mode so the host's handler runs. An interrupt for the guest, such as a virtual disk completing, has to be injected: the hypervisor writes an event into the control structure and the processor delivers it to the guest on the next entry as if it came from hardware.
Early on, every access the guest made to its local APIC registers was an exit. Newer hardware adds APIC virtualization, called APICv on Intel and AVIC on AMD. The processor keeps a virtual APIC page for the guest, handles many register reads and writes without exiting, and supports posted interrupts, where a device or another core writes into a descriptor and the processor delivers the interrupt to a running guest vCPU with no exit. The effect is fewer exits for inter-processor interrupts and timers, which matters when a guest has many vCPUs.
Checking it on a real machine
You can see which of these features your host offers from the flags the kernel reports. These lines list the virtualization-related ones on an Intel machine:
grep -o -w -E 'vmx|ept|vpid|flexpriority|tpr_shadow|apicv|vnmi' /proc/cpuinfo | sort -uapicv
ept
flexpriority
tpr_shadow
vmx
vnmi
vpidThe exact list depends on the processor and the kernel version, since some of these flags only appear in recent kernels. vpid is virtual processor identifiers, which tag TLB entries by guest so a VM entry does not flush the whole TLB. On AMD hosts the matching names are svm, npt, avic and flushbyasid. KVM also reports what it enabled through module parameters, readable without any special tool:
cat /sys/module/kvm_intel/parameters/eptYA Y here means the kernel is using EPT. If it prints N, the kernel runs with shadow paging, which is a sign something is wrong in firmware or a module parameter.
What hardware virtualization does not do
It does not virtualize devices. A guest still needs disks, network cards and timers, and every one of them is software, either emulated, paravirtual or passed through. It does not make an exit free: each one is a state switch on the order of the processor's save and restore, plus the hypervisor's work. And it does not give you confidentiality from the host. A hypervisor can read every guest register and page, which is the gap that AMD SEV-SNP and Intel TDX address and that the post on confidential VMs covers. It also does not hide that you are in a VM: a guest can see the hypervisor-present bit and can time instructions that exit, so software that needs to detect virtualization can do so.
When to read the manuals
For application work you never need the details of the VMCS. For kernel and hypervisor work, the primary sources are the Intel Software Developer's Manual, volume 3C, which defines the VMCS fields and exit reasons, and the AMD64 Architecture Programmer's Manual, volume 2, which defines the VMCB layout and VMRUN behavior. The Linux kernel documentation for KVM covers the interface that sits above them. If you plan to write a hypervisor, the post on writing a minimal hypervisor with the KVM API shows how little of this you must handle yourself, because the kernel does the VMCS work for you.


