What is two-stage address translation (stage 2, IPA)?
Short answer: With virtualization there are two page-table walks. Stage 1 is owned by the guest OS and translates guest virtual addresses (VA) to intermediate physical addresses (IPA), which the guest thinks are physical. Stage 2 is owned by the hypervisor and translates IPAs to real physical addresses (PA). The guest cannot see or change stage 2, so it can only reach memory the hypervisor has given it.
guest VA --(stage 1, guest's TTBR0/1_EL1)--> IPA --(stage 2, VTTBR_EL2)--> PA
Why it matters
- Isolation: each VM has its own stage-2 tables, so one guest cannot address another guest's or the host's memory.
- Unmodified guests: the guest manages its own page tables normally, with no hypervisor calls; on x86 this is EPT (Intel) or NPT/RVI (AMD).
- Trapping MMIO: leaving device addresses unmapped in stage 2 makes every access fault to the hypervisor, which then emulates the device.
- Memory over-commit and migration: the hypervisor can unmap, swap, share (KSM) or write-protect guest pages to track dirty pages during live migration.
Cost of a TLB miss: each step of the guest's stage-1 walk itself needs a stage-2 translation. With 4-level tables at both stages, a miss can cost up to 24 memory accesses instead of 4. TLBs cache the combined VA→PA result, tagged with the VMID (and ASID), so switching between VMs does not require flushing the whole TLB. Large pages at stage 2 (2 MB/1 GB, via hugepages for guest RAM) reduce the cost a lot.
Related hardware: the SMMU (Arm's IOMMU) also has stage-1 and stage-2 translation, so a device passed through to a guest can only DMA into that guest's memory.
Interview check question: "Who handles a page fault on a guest virtual address that is not in the guest's page tables?" The guest kernel: it is a stage-1 fault, delivered to EL1 as normal. Only stage-2 faults go to the hypervisor.