Skip to content

GPU passthrough with VFIO and IOMMU — the working procedure

A complete VFIO/IOMMU passthrough setup — IOMMU enable, IOMMU group inspection, vfio-pci driver bind, and the libvirt XML that gets a GPU into a guest.

PCI passthrough using VFIO and the IOMMU lets a virtual machine take exclusive control of a physical PCI device — most commonly a GPU for ML/render workloads, sometimes an NVMe drive or NIC. This article is the working procedure: enable IOMMU in firmware, isolate the device with vfio-pci, configure the libvirt guest XML, and verify the guest actually sees and uses the device. The trick is the IOMMU groups; everything else is bookkeeping.

How to verify

Confirm the CPU and chipset support IOMMU and that firmware has it enabled. The keywords differ: Intel VT-d, AMD-Vi.

# Is IOMMU active?
sudo dmesg | grep -i -e DMAR -e IOMMU | head
ls /sys/class/iommu/

# IOMMU groups — what's grouped with what
for d in /sys/kernel/iommu_groups/*/devices/*; do
  g=${d%/devices/*}; g=${g##*/}
  printf '%s\t%s\n' "$g" "$(lspci -nns "${d##*/}")"
done | sort -n | head -20

# vfio modules present
lsmod | grep vfio || echo "load via: sudo modprobe vfio_pci"

The IOMMU groups output is the critical check — every device in a group passes through together. A GPU that shares its group with a host-critical NVMe is unusable for passthrough without ACS override patches.

What’s happening

IOMMU (Intel VT-d, AMD-Vi) is the chipset feature that translates device DMA addresses, much like the MMU does for CPU memory access. It lets you safely hand a device to a guest because DMA from that device cannot escape into host memory. The kernel exposes IOMMU groups — sets of devices the IOMMU treats as a single unit. A whole group must be passed through together.

VFIO (Virtual Function I/O) is the kernel framework for userspace drivers. The vfio-pci driver binds to a PCI device, marking it unavailable to other host drivers, and exposes it to QEMU through /dev/vfio/<group>. QEMU’s -device vfio-pci,host=... (or libvirt’s <hostdev>) attaches the device to the guest. The guest sees the device as if it were physically plugged in.

The procedure

  1. Enable IOMMU in firmware and kernel. Reboot into firmware, enable VT-d (Intel) or IOMMU (AMD), and Above 4G Decoding if your GPU needs it. Then pass the kernel command-line flag:

    # /etc/default/grub
    GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt"   # Intel
    # or
    GRUB_CMDLINE_LINUX_DEFAULT="quiet amd_iommu=on iommu=pt"     # AMD
    
    sudo update-grub && sudo reboot
    sudo dmesg | grep -i -e DMAR -e IOMMU | head    # confirm

    iommu=pt is the passthrough mode — devices not assigned to a guest use the host’s normal mappings (negligible perf cost), devices assigned go through full IOMMU.

  2. Inspect IOMMU groups. Find your target GPU and confirm its group is “clean” — i.e., it contains only the GPU (and its audio function, which is normal):

    lspci -nn | grep -E '(VGA|3D|Audio)'
    # 01:00.0 VGA compatible controller [0300]: NVIDIA Corporation ... [10de:1f82]
    # 01:00.1 Audio device [0403]: NVIDIA Corporation ... [10de:10fa]
    
    for d in /sys/kernel/iommu_groups/*/devices/*; do
      g=${d%/devices/*}; g=${g##*/}
      printf 'Group %s\t%s\n' "$g" "$(lspci -nns "${d##*/}")"
    done | grep -E '01:00' 

    If your GPU’s group also contains a PCI root port, USB controller, or NIC — that’s a problem. Some motherboards have an ACS override BIOS update; some need the patched kernel ACS override; sometimes a different PCIe slot helps.

  3. Bind the device to vfio-pci at boot. Use the vendor:device IDs:

    # /etc/modprobe.d/vfio.conf
    options vfio-pci ids=10de:1f82,10de:10fa
    softdep nvidia pre: vfio-pci    # tell nvidia driver to load AFTER vfio binds
    
    # /etc/modules-load.d/vfio.conf
    vfio
    vfio_iommu_type1
    vfio_pci

    Regenerate initramfs and reboot:

    sudo update-initramfs -u -k all && sudo reboot
    lspci -nnk -d 10de:1f82   # Kernel driver in use: vfio-pci
  4. Attach to the libvirt guest. Edit the guest XML; add a <hostdev> for each function in the IOMMU group:

    <hostdev mode='subsystem' type='pci' managed='yes'>
      <source>
        <address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
      </source>
      <rom bar='off'/>
    </hostdev>
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <source>
        <address domain='0x0000' bus='0x01' slot='0x00' function='0x1'/>
      </source>
    </hostdev>

    managed='yes' lets libvirt handle the vfio-pci bind/unbind at guest start/stop. The audio function attaches automatically because they share an IOMMU group.

  5. Boot the guest, install the GPU driver inside. For NVIDIA: install the proprietary driver in the guest exactly as you would on bare metal. The guest sees a real 01:00.0 VGA device. For AMD: amdgpu in the guest. Pass through the audio function too if you want HDMI audio.

  6. Verify usage from inside the guest:

    # Linux guest with NVIDIA
    nvidia-smi
    sudo lspci -nnk | grep -A2 -E '(VGA|3D)'
    # Windows guest: GPU shows in Device Manager

Common pitfalls

  • IOMMU group includes non-target devices — use a different PCIe slot, or accept the trade-offs of pcie_acs_override=multifunction on the kernel command line (with full understanding of the security implications).
  • NVIDIA Code 43 in Windows guests — historically NVIDIA’s consumer drivers detected virtualization and refused to load; the fix was <feature policy='require' name='kvm_hidden'/> plus a <kvm><hidden state='on'/></kvm> block. Modern drivers no longer require this for most consumer cards.
  • A GPU passed through to a guest cannot be used by the host (e.g., as the console framebuffer); pick a host that has a second display option (onboard graphics or a separate IPMI/iLO).
  • Live migration of a guest with a passthrough device is generally not supported — the device’s state cannot be transferred. Design for guest restart, not live move.
  • Power management on a passed-through GPU sometimes leaves the device in a bad state when the guest shuts down — a <rom bar='off'/> workaround helps; sometimes pci=noaer is needed.

Stack Harbor sets up GPU passthrough for ML training rigs and render farms where workloads need direct hardware access — host build, IOMMU group inspection documented, vfio bindings under config management, guest images that include the GPU driver. The point is that a node with a passthrough GPU can be rebuilt from configuration in under an hour. This is part of the operating model under Managed Operations.