GPU pass-through with QEMU

This is assuming AMD graphics (pci ids 1002:67df & 1002:aaf0) on AMD Ryzen platform.

Host motherboard UEFI config:

  • enable iommu

Host kernel parameters to add:

iommu=pt vfio-pci.ids=1002:67df,1002:aaf0

Host configuration:

  • add your user to kvm group
  • /etc/security/limits.d/90-vfio.conf
@kvm hard memlock 20485760
@kvm soft memlock 20485760
  • cat /etc/udev/rules.d/51-vfio.rules
SUBSYSTEM=="vfio", OWNER="root", GROUP="kvm", MODE="0660"
KERNEL=="vfio", SUBSYSTEM=="vfio", OWNER="root", GROUP="kvm"
  • /etc/modprobe.d/vfio.conf
softdep drm pre: vfio-pci
options vfio-pci ids=1002:67df,1002:aaf0

QEMU script:

#!/bin/bash
NAME=vm_name
BASE="/path/to/vm"

qemu-system-x86_64 \
	-name "$NAME" \
	-M q35,accel=kvm,kernel_irqchip=on \
	-cpu host,kvm=off,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vapic,hv_vendor_id=xyz,topoext \
	-smp 4,sockets=1,cores=2,threads=2 \
	-m 16G \
	-nographic \
	-vga none \
	-display none \
	-rtc clock=host,base=localtime \
	-drive if=pflash,file="$BASE/OVMF.4m.fd",format=raw \
	-drive if=virtio,file="$BASE/$NAME.qcow2",id=hd0,format=qcow2 \
	-netdev bridge,id=net0,br=br0 \
	-device virtio-net-pci,netdev=net0 \
	-device virtio-serial-pci \
	-serial none \
	-device pcie-root-port,chassis=0,port=0 \
	-device pcie-root-port,chassis=1,port=1 \
	-spice unix=on,addr=/tmp/.$NAME.sock,disable-ticketing=on \
	-device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
	-chardev spicevmc,id=spicechannel0,name=vdagent \
	-audiodev spice,id=snd0 \
	-device ich9-intel-hda \
	-device hda-output,audiodev=snd0 \
	-device pci-bridge,chassis_nr=1,id=pcibr0 \
	-device vfio-pci,host=07:00.0,multifunction=on,x-vga=on,id=vfio0,bus=pcie.1,romfile="$BASE/Ellesmere.rom" \
	-device vfio-pci,host=07:00.1,bus=pcie.1 \
	
#add the following for looking glass
#	-device ivshmem-plain,memdev=ivshmem,bus=pcie.0 \
#	-object memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=32M \

Posted

in

,

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *