</>EmbeddedInterview

What is device passthrough (VFIO) and when would you use it?

HardVirtualization (QEMU & KVM)

Short answer: Passthrough gives a VM direct, exclusive access to a real hardware device (a PCIe NIC, GPU or an SoC peripheral). The host's VFIO framework hands the device's registers and interrupts to user space (QEMU), which maps them into the guest, and the IOMMU/SMMU restricts the device's DMA to that guest's memory. The guest's normal driver then talks to the hardware at near-native speed.

How it works

  1. Unbind the device from its host driver and bind it to vfio-pci (or vfio-platform for SoC devices).
  2. QEMU opens the device's VFIO group/container (or the newer iommufd), maps the device's BARs (registers) into guest physical space so accesses do not exit, and programs the IOMMU so the device's DMA addresses are the guest's physical addresses.
  3. Device interrupts (MSI/MSI-X) are delivered to the guest through irqfd, or directly with GICv4 / posted interrupts.
qemu-system-aarch64 ... -device vfio-pci,host=0000:01:00.0

Requirements: an IOMMU/SMMU, and devices that can be isolated in their own IOMMU group (devices behind the same PCIe bridge without ACS may have to be passed through together).

Trade-offs

Passthrough virtio / emulated
Performance near native good (virtio) to slow (emulated)
Sharing one VM owns the device (unless SR-IOV) many VMs share
Live migration hard (device state is in hardware) supported
Isolation depends on IOMMU and device reset quality hypervisor controls everything

SR-IOV: a PCIe device presents several virtual functions (VFs), each passed through to a different VM, which gives near-native I/O with sharing (common for NICs in cloud servers).

Embedded use: on automotive SoCs, a display controller, camera or CAN controller is often passed through to the VM that owns it (e.g. the safety cluster VM gets the display it must drive), while less critical devices are shared with virtio.