GPU Passthrough
GPU passthrough allows a virtual machine to have direct access to your dedicated GPU, enabling near-native graphics performance for gaming or GPU-accelerated workloads.
Prerequisites
Section titled “Prerequisites”- Completed KVM Setup
- Two GPUs (integrated + dedicated, or two dedicated)
- VT-d/AMD-Vi and IOMMU enabled in BIOS
- IOMMU groups properly separated
System Verification
Section titled “System Verification”virt-host-validateEnsure QEMU and KVM show PASS. IOMMU warnings are expected if not yet configured.
Step 1: Identify GPU PCI IDs
Section titled “Step 1: Identify GPU PCI IDs”Find your dedicated GPU:
lspci -nn | grep -E "VGA|Audio" | grep -i nvidiaExample output:
01:00.0 VGA compatible controller [0300]: NVIDIA Corporation [...] [10de:2560]01:00.1 Audio device [0403]: NVIDIA Corporation [...] [10de:228e]Note the IDs: 10de:2560 and 10de:228e
Step 2: Configure VFIO
Section titled “Step 2: Configure VFIO”Create /etc/modprobe.d/vfio.conf:
options vfio-pci ids=10de:2560,10de:228esoftdep nvidia pre: vfio-pciCreate /etc/modprobe.d/nvidia.conf to prevent loading:
# Prevent NVIDIA driver from binding to passthrough GPUinstall nvidia /bin/falseinstall nvidia_modeset /bin/falseinstall nvidia_drm /bin/falseStep 3: Update Initramfs
Section titled “Step 3: Update Initramfs”Add VFIO modules to mkinitcpio. Edit /etc/mkinitcpio.conf:
MODULES=(vfio_pci vfio vfio_iommu_type1)Regenerate:
sudo mkinitcpio -PStep 4: Reboot and Verify
Section titled “Step 4: Reboot and Verify”After reboot, verify VFIO is bound to the GPU:
lspci -nnk -d 10de:2560Should show Kernel driver in use: vfio-pci
Step 5: Windows VM Setup
Section titled “Step 5: Windows VM Setup”Required Packages
Section titled “Required Packages”sudo pacman -S --needed qemu-full libvirt virt-install virt-manager \ virt-viewer dnsmasq bridge-utils openbsd-netcat edk2-ovmf swtpm \ iptables-nft libosinfoVirtIO Drivers
Section titled “VirtIO Drivers”paru -S virtio-winThe ISO is placed at /var/lib/libvirt/images/virtio-win.iso
Step 6: VM Configuration
Section titled “Step 6: VM Configuration”When creating the Windows VM in virt-manager:
- Firmware: Select UEFI (OVMF)
- Add Hardware > PCI Host Device: Add your GPU (both VGA and Audio)
- Add VirtIO disk instead of SATA
- Attach VirtIO ISO as CD-ROM for driver installation
XML Tweaks
Section titled “XML Tweaks”Edit the VM XML (virsh edit vmname):
<features> <hyperv> <vendor_id state="on" value="randomid"/> </hyperv> <kvm> <hidden state="on"/> </kvm></features>This hides the hypervisor from the guest (helps with NVIDIA driver detection).
Looking Glass (Optional)
Section titled “Looking Glass (Optional)”For low-latency display without connecting a monitor:
- Install Looking Glass client on host
- Install Looking Glass host application in Windows guest
- Configure shared memory in VM XML
See the Looking Glass documentation for details.
Troubleshooting
Section titled “Troubleshooting”GPU Not Binding to VFIO
Section titled “GPU Not Binding to VFIO”Check IOMMU groups - GPU must be alone or with related devices only:
#!/bin/bashfor d in /sys/kernel/iommu_groups/*/devices/*; do n=$(basename $(dirname $(dirname $d))) echo "IOMMU Group $n: $(lspci -nns ${d##*/})"doneCode 43 in Windows
Section titled “Code 43 in Windows”- Ensure hypervisor is hidden (XML tweaks above)
- Update to latest NVIDIA drivers in guest
- Disable Message-Signaled Interrupts if needed