Monday 19 October 2020

Random GPU passthru notes

Random GPU passthru notes

Setting up rlimits

if qemu says this:

2020-10-20T03:55:36.078813Z qemu-system-x86_64: -device vfio-pci,host=02:00.0,id=hostdev0,bus=pci.0,addr=0x7,multifunction=on,x-vga=on: VFIO_MAP_DMA failed: Cannot allocate memory

dmesg probably says something like this:

[  147.460769] vfio_pin_pages_remote: RLIMIT_MEMLOCK (65536) exceeded

Add this to /etc/security/limits.conf (at least on gentoo):

dave         hard memlock    20000000

dave         soft memlock    20000000

Giving myself permission to use vfio

I've never found a better way to do this, on boot I execute this to give myself permission to use the correct vfio group that my second video card is in:

    chown dave:dave /dev/vfio/31

Keys getting stuck, mouse jumping randomly 

Only seems to happen when the kbd and mouse are used at the same time. Easiest way to test was to move the mouse while typing in nodepad.  The mouse would jump around and sometimes (not often) a key would get stuck. 

Started happening after I did a full emerge -vup world upgrade (the kernel from 4.13.? to 5.9.1, it had been a while).  Even tried using my old kernel, and old qemu (I saved them before upgrading), still broken.

thanks to: https://www.reddit.com/r/VFIO/comments/824cdi/evdev_passthrough_problem_in_games_keys_get_stuck/

My startup script only had the -object input-linux lines for keyboard and mouse, so I guess it was defaulting to PS/2 devices?  Has been working fine for 3 years.  Installed virtio drivers and added these devices and it was all fine again.
-device virtio-keyboard
-device virtio-mouse

Sound needs to be modules

My monitors use the snd-hda sound driver, so does my computer.  That's 3 snd-hda devices.  When I compile the hda intel/realtek driver in the kernel it claims all three devices.  vfio requires all devices in an iommu group be unbound (so to pass the video card to qemu, the sound card must also be passed, not possible when the kernel has claimed the sound device on the monitor).  echoing something to the /unbind thing just waits forever and never returns.
The way around this is to make a modprobe file to claim the gpu and onboard sound for vfio before the kernel driver can get hold of it.
/etc/modprobe.d/vfio.conf:
options vfio-pci ids=10de:1b81,10de:10f0
softdep snd-hda-intel pre: vfio-pci