GPU Passthrough

Recording a log of my efforts to have proper GPU performance in a windows VM.

Fist, enable some iommu on kernel. Given I use syslinux, I added intel_iommu=on:

LABEL arch-lts
    MENU LABEL Arch Linux LTS Kernel OPTI
    LINUX ../vmlinuz-linux-lts
    APPEND root=UUID=xxx rw intel_iommu=on
    INITRD ../intel-ucode.img,../initramfs-linux-lts.img

Also I plugged in my radeon card and started the computer:

Then I listed the IOMMU groups with the script from arch linux manual:

IOMMU Group 1 00:01.0 PCI bridge [0604]: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor PCI Express x16 Controller [8086:0c01] (rev 06)
IOMMU Group 1 01:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Oland XT [Radeon HD 8670 / R7 250/350] [1002:6610] (rev 81)
IOMMU Group 1 01:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Cape Verde/Pitcairn HDMI Audio [Radeon HD 7700/7800 Series] [1002:aab0]
IOMMU Group 2 00:02.0 VGA compatible controller [0300]: Intel Corporation ...

Nice. Let's add vfio it. Given that I'm on kernel 4.14 I need to load the modules:

# cat /etc/modprobe.d/vfio.conf
options vfio-pci ids=1002:6610,1002:aab0

Modify initial ramfs:

# grep vfio /etc/mkinitcpio.conf
MODULES="vfio_pci vfio vfio_iommu_type1 vfio_virqfd xhci-hcd i915"

I made sure modconf is added as a hook:

# grep modconf /etc/mkinitcpio.conf
HOOKS="base udev autodetect modconf block filesystems keyboard fsck"

And re-generated the initramfs:

# mkinitcpio -p linux-lts

and rebooted...

Verifying that the configuration worked

# dmesg | grep -i vfio
[    0.681607] VFIO - User Level meta-driver version: 0.3
[    0.683310] vfio-pci 0000:01:00.0: vgaarb: changed VGA decodes: olddecodes=io+mem,decodes=io+mem:owns=none
[    0.710059] vfio_pci: add [1002:6610[ffff:ffff]] class 0x000000/00000000
[    0.740110] vfio_pci: add [1002:aab0[ffff:ffff]] class 0x000000/00000000
[    0.797346] vfio-pci 0000:01:00.0: vgaarb: changed VGA decodes: olddecodes=io+mem,decodes=io+mem:owns=none

Then gave it to my virtual machine, and everything worked as expected.

Links

<qemu:arg value='-cpu'/>
<qemu:arg value='host,hv_time,kvm=off'/>