qemu/KVM PCI passthrough · uwot.eu
another meaningless subtitle

qemu/KVM PCI passthrough

· by fabio · Read in about 2 min · (390 Words)
Fedora Nvidia PCI passthrough GPU passthrough

PCI passthrough is the process of attaching a PCI-E device directly to a VM; CPU support (namely VT-D for Intel and AMD-V for AMD) and motherboard support (IOMMU) are required for PCI passthrough to work properly.
Hardware configuration used:

AMD Ryzen 1700x
Gigabyte X370 K7
Nvidia Geforce GTX260
32 GiB of RAM and a few HDDs
Fedora 29 as host OS

The system only has a single graphic card because it is normally used as headless compute server for which a GPU is not really required; the graphic card is also very very old Nvidia Geforce GTX260 with a standard non UEFI BIOS.
If using an UEFI enabled graphic card it is probably required to install the OS in UEFI mode using a virtual UEFI BIOS.
This guide assumes you already have a working Windows virtual machine and are familiar with libvirt.
First of all, edit GRUB to enable IOMMU and blacklist nouveau kernel module so that the graphic card is not picked up anymore by the host:

$ vi /etc/default/grub2
GRUB_CMDLINE_LINUX=". . . amd_iommu=on modprobe.blacklist=nouveau video=vesafb:off,efifb:off . . ."

$ grub2-mkconfig -o /boot/grub2/grub.cfg

Find out what your graphic card ID is (you might want to replace nvidia with amd if appropriate):

# lspci -nn | grep -i nvidia
07:00.0 VGA compatible controller [0300]: NVIDIA Corporation GT200 [GeForce GTX 260] [10de:05e2] (rev a1)

In my case 10de:05e2 is the ID of the graphic card, bind it to vfio module:

vi /etc/modprobe.d/vfio.conf
options vfio-pci ids=10de:05e2

Before rebooting the machine be sure to have openssh running on the system.
After the reboot ssh into the server and edit the virtual machine config:

virsh edit <virtual_machine_name>
    . . . 
      <vendor_id state='on' value='0123456789ab'/>
      <hidden state='on'/>
    . . .

The lines above are required to trick nvidia drivers into thinking that they are running on bare metal, without it they refuse to work.
At this point the only thing left to do is add the PCI device to the virtual machine in virt-manager.
Don’t forget to also passthrough a mouse and a keyboard and also remove any other spice and virtual video card from the VM configuration.


Reboot the host system and start the vm using virt manager or virsh

$ sudo reboot
. . .
$ virsh start <virtual_machine_name>

gentoo wiki
arch wiki