PCI Passthrough
KVM
Inital Setup
Your motherboard must support Intel VT-D or AMD IOMMU and it needs to be enabled in the bios.
Consult KVM/libvirt documentation to make sure you have the appropriate features enabled in your kernel.
For device assignment, you must enable vfio-pci in your kernel. KVM legacy PCI device assignment is no longer supported.
Device Drivers ---> <*> VFIO Non-Privileged userspace driver framework ---> <*> VFIO support for PCI devices
Using virt-manager
Create a new virtual machine, then go to the "Show virtual hardware details" tab (button with lightbulb icon) and click on the "Add Hardware" button on the bottom right. This will bring up the "Add New Virtual Hardware" window.
On the "Add New Virtual Hardware" window click on "PCI Host Device" from the list on the left hand side of the window and then select the GPU device you want to use in your VM. When you are done click "Finish"
By default virt-manager adds the new device to bus 0, but we need to change this to bus 1, because the radeon driver expects there to be a parent PCI device. To do this run:
sudo virsh edit your-vm-name
Then update the hostdev tag assign it to bus number 1:
<hostdev mode='subsystem' type='pci' managed='yes'> <source> <address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> </source> UPDATED LINE -> <address type='pci' domain='0x0000' bus='0x01' slot='0x08' function='0x0'/> </hostdev>
It is recommended that you set the default video device to 'VGA'. Some of the video devices like QXL and Cirrus are virtual drm devices, so if you try to use them you will end up with 2 video cards on your system, which can make configuring X slightly more work.