Skip to content

Instantly share code, notes, and snippets.

@heppu
Last active October 8, 2021 20:46
Show Gist options
  • Save heppu/e09e622c25c90b366ab7 to your computer and use it in GitHub Desktop.
Save heppu/e09e622c25c90b366ab7 to your computer and use it in GitHub Desktop.
Arch GPU passthrough

Install rpmextract

sudo pacman -Suy rpmextract

Get lates edk2.git-ovmf-x64

wget https://www.kraxel.org/repos/jenkins/edk2/edk2.git-ovmf-x64-XXXXXX.noarch.rpm

Extract edk2

rpmextract.sh edk2.git-ovmf-x64-0-20160306.b1588.g7e869ee.noarch.rpm

Copy files

sudo cp -R ./usr/share/* /usr/share

Enable iommu

sudo nano /etc/default/grub
	GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on"
sudo grub-mkconfig -o /boot/grub/grub.cfg
sudo reboot

Cheak that iommu is enabled

dmesg|grep -e DMAR -e IOMMU
	[    0.000000] DMAR: IOMMU enabled

Print GPU ID(10de:0a65]) and location(11:0.1)

lspci -nn
	11:00.0 VGA compatible controller [0300]: NVIDIA Corporation GT218 [GeForce 210] [10de:0a65] (rev a2)
	11:00.1 Audio device [0403]: NVIDIA Corporation High Definition Audio Controller [10de:0be3] (rev a1)

Find vfio group for that device

find /sys/kernel/iommu_groups/ -type
	/sys/kernel/iommu_groups/18/devices/0000:05:00.0
	/sys/kernel/iommu_groups/19/devices/0000:11:00.0
	/sys/kernel/iommu_groups/19/devices/0000:11:00.1
	/sys/kernel/iommu_groups/20/devices/0000:3e:00.0
	/sys/kernel/iommu_groups/20/devices/0000:3e:00.1

Create udev rules to give user-access to devices (hdd and gpu)

sudo nano /etc/udev/rules.d/10-qemu-hw-users.rules
	KERNEL=="sda[3-6]", OWNER="YOUR_USER", GROUP="YOUR_GROUP"
	KERNEL=="YOUR_VFIO_GROUPS", SUBSYSTEM=="vfio", OWNER="YOUR_USER", GROUP="YOUR_USER"

Check that you have vfio-pci module (no output from command)

sudo modprobe vfio-pci

Isolate GPU

sudo nano /etc/modprobe.d/vfio.conf
	options vfio-pci ids=10de:0a65

Enable module on boot

sudo nano /etc/mkinitcpio.conf
	MODULES="vfio vfio_iommu_type1 vfio_pci vfio_virqfd"

Save changes

sudo mkinitcpio -p linux
sudo reboot

Check dmesg outupt

dmesg | grep -i vfio
	[    0.972556] VFIO - User Level meta-driver version: 0.3
	[    1.004515] vfio_pci: add [10de:0a65[ffff:ffff]] class 0x000000/00000000
	[    1.017910] vfio_pci: add [10de:0be3[ffff:ffff]] class 0x000000/00000000

Give QEMU access to hardware

sudo nano /etc/libvirt/qemu.conf
	user = "root"
	group = "root"
	clear_emulator_capabilities = 0

QEMU also needs acces to VFIO files. Include every numbered file in /dev/vfio

ls -1 /dev/vfio
	19
	vfio
sudo nano /etc/libvirt/qemu.conf
	cgroup_device_acl = [
    	"/dev/vfio/vfio",
    	"/dev/vfio/19"
	]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment