Skip to content

x86 GPU Passthrough with Qemu

  • GPU passthrough allows a virtual machine (VM) to use a dedicated GPU, enabling near-native performance for 3D workloads, media decoding/encoding and other GPU-intensive tasks.
  • QEMU combined with libvirt is a common stack used for this on Linux.

Hardware

  • CPU with IOMMU support:
    • Intel VT-d (Intel IOMMU)
    • AMD-Vi (AMD)
  • Make sure following parameters added to kernel command line.

    Terminal window
    # For Intel CPUs
    "intel_iommu=on"
    # For AMD CPUs
    "amd_iommu=on"
  • List devices

    Terminal window
    lspci -nn
  • Blacklist the GPU driver on the host system so it won’t be used. Example
    Terminal window
    # For Intel GPUs
    "module_blacklist=i915,xe"
  • Bind Devices to VFIO
    Terminal window
    options vfio-pci.ids=<VendorId>:<DeviceId>

On Graphics VM (gui-vm) run the following commands.

  • To verifiy PCI device passthrough:

    Terminal window
    lspci | grep VGA
  • Check the driver:

    Terminal window
    lshw -c display

With GPU passthrough to a specific VM, the GPU cannot be used for other VMs. However, sometimes we may need the GPU to be shared across different VMs, which is not possible with the current implementation.