x86 GPU Passthrough with Qemu
Overview
Section titled “Overview”- 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.
1. Requirements
Section titled “1. Requirements”Hardware
- CPU with IOMMU support:
- Intel VT-d (Intel IOMMU)
- AMD-Vi (AMD)
2. Enable IOMMU in the Bootloader
Section titled “2. Enable IOMMU in the Bootloader”-
Make sure following parameters added to kernel command line.
Terminal window # For Intel CPUs"intel_iommu=on"# For AMD CPUs"amd_iommu=on"
3. Identify the GPU
Section titled “3. Identify the GPU”-
List devices
Terminal window lspci -nn
4. Isolate GPU with VFIO
Section titled “4. Isolate GPU with VFIO”- 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>
5. Verify GPU Passthrough Works in QEMU
Section titled “5. Verify GPU Passthrough Works in QEMU”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
Limitation
Section titled “Limitation”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.