</>EmbeddedInterview

How are interrupts and timers virtualized on ARM (vGIC and the generic timer)?

HardVirtualization (QEMU & KVM)

Short answer: The GICv2/v3 has hardware virtualization support: the hypervisor writes pending virtual interrupts into List Registers (ICH_LR<n>_EL2), and the guest acknowledges and completes them through the virtual CPU interface without trapping. KVM emulates the distributor and redistributors (the "vGIC") in the kernel. For time, each vCPU uses the virtual timer (CNTV_*), which counts physical time minus a per-VM offset; when it fires, KVM injects the virtual timer interrupt (PPI 27) into the guest.

Interrupt path for an emulated device

  1. A QEMU device raises its IRQ line → QEMU calls KVM_IRQ_LINE (or signals an irqfd, an eventfd the kernel waits on).
  2. The in-kernel vGIC marks the virtual interrupt pending for the target vCPU.
  3. Before entering the guest, KVM writes it into a List Register and kicks the vCPU if it is sleeping in WFI.
  4. The guest takes a normal IRQ exception at EL1, reads ICC_IAR1_EL1 (which the hardware serves from the virtual interface), handles it, writes EOI. No exit is needed for the acknowledge and EOI.

Physical interrupts while the guest runs are routed to EL2 (HCR_EL2.IMO), so the host can always regain the CPU (for its own devices and for scheduling).

Device passthrough: with GICv4/4.1, MSIs from a passed-through PCIe device can be delivered directly to a running vCPU without a hypervisor exit.

Timers

  • The physical timer (CNTP) is used by the host; the virtual timer (CNTV) by the guest. CNTVOFF_EL2 lets each VM have its own time base (useful after migration or pause).
  • KVM saves and restores the guest's timer state on every world switch and uses a host hrtimer to wake a vCPU that is blocked in WFI when its timer is due.

Why it was moved into the kernel: emulating the GIC in QEMU would turn every interrupt acknowledge and EOI into an exit to user space. In-kernel vGIC plus hardware List Registers makes interrupt-heavy workloads practical.

x86 equivalent: APIC virtualization (APICv, AVIC) and posted interrupts.