</>EmbeddedInterview

What is ARM virtualization at EL2?

HardARM Architecture

Short answer: EL2 lets a hypervisor control guest execution and traps. Stage-1 translation maps guest VA to IPA; stage-2 maps IPA to host PA.

Guest VAStage 1IPAStage 2Host PAMemory
MRS X0, VTTBR_EL2 // stage-2 table base

1. Guest stage 1: Guest Linux translates its virtual address using its own page tables to an intermediate physical address (IPA).

2. Hypervisor stage 2: EL2 controls translation from IPA to host physical address. This allows a hypervisor to restrict guest memory without modifying guest page tables.

3. Traps: Selected privileged operations, device accesses or faults can trap to EL2 for handling. Hardware virtualization allows many guest instructions to execute directly.

4. Linux example: KVM on an ARM64 host uses EL2 facilities; QEMU can provide userspace device emulation. An x86 host cannot directly execute ARM guest instructions with KVM and typically needs QEMU TCG for cross-ISA emulation.

Interview takeaway: Stage-2 translation and configurable traps let EL2 isolate and manage guests.

Worked translation and trap example

Guest Linux maps VA 0x40001234 through its stage-1 tables to IPA 0x80000234. The hypervisor maps IPA page 0x80000000 to host physical page 0xA0000000. The resulting host PA is 0xA0000234, assuming 4 KiB pages and permitted accesses.

EL2 register Role
HCR_EL2 Virtualization controls and selected trap routing
VTTBR_EL2 Stage-2 translation root and VMID, as configured
VTCR_EL2 Stage-2 translation parameters
ELR_EL2 / SPSR_EL2 Exception return state
ESR_EL2 Exception syndrome where applicable

If the guest accesses an emulated peripheral that is not backed by ordinary stage-2 RAM, the hypervisor can handle the resulting fault and emulate the register operation. In Linux KVM, some exits are handled in the kernel; selected events such as emulated MMIO can return to QEMU through KVM_RUN. QEMU services the device model and re-enters guest execution.

A combined translation can be cached in the TLB, so two-stage translation does not require two complete walks for every instruction. Guest DMA needs its own device isolation/mapping mechanism. KVM accelerates compatible-ISA guests; TCG dynamically translates guest instructions on a different host architecture.