GPU passthrough is probably is the coolest thing I’ve stumbled across lately, and it’s all made possible with vfio-pci. However, vfio is in its infancy, and binding your GPU with vfio-pci can be confusing. This step presents a significant barrier to entry for newcomers. Enter vfioselect, our new tool for automatic device binding.



Read also: VFIO Guide to Audio Hardware

Introduction

One of the biggest issues I see people face when setting up GPU passthrough is creating their modprobe rules. I can understand the confusion, as it is far deeper into the system than most people mess with. In an effort to make the binding process faster and easier, I’ve created vfioselect. Vfioselect is written in bash to show a menu, then it makes the new config, and binds the devices without the need to reboot.

If you’re new to linux, only have one GPU, or are nervous about messing with modprobe, you can still easily set up a GPU passthrough system. Vfioselect displays an easy to use menu to select the target for vfio-pci. After confirming, vfioselect then creates rules and binds the card without the need to reboot. Below is a screenshot showing the menu, with some targets selected for binding:



Installation

Before you install vfioselect, you will need to install it’s dependency, dialog. Dialog is usually in your distro’s default repositories, but if not, you might have to hunt for it, but installing dialog is beyond the scope of this article.

Once you have dialog installed, you’re ready to move on to vfioselect, so run the following two commands:

wget 'https://raw.githubusercontent.com/PassthroughPOST/VFIO-Tools/master/vfioselect/vfioselect' chmod +x vfioselect

Then, ensure that you have iommu enabled:

printf "IOMMU Status: ";\ if cat /proc/cmdline|grep -i iommu; then printf "enabled

";else printf "disabled

";fi

If the command returned “IOMMU Status: disabled”, you will need to enable it in your kernel parameters before you continue.

Usage

Vfioselect assumes that it is the only thing handling the config file. If you already have rules set up, I recommend moving the config file to /etc/modprobe.d/vfioselect.conf . When vfioselect runs, it reads the config file, and uses it to determine which devices are bound with vfio-pci. If you run vfioselect with the -h flag, you’re given the following:

Usage: vfioselect [<arguments>] -t,--tmpfile <path> Specify path to temporary file -g,--genfile <path> Specify path to modprobe rule -o,--online Attempt to bind/unbind without the need to reboot -h,--help Display this help dialogue

To break down everything:

The temporary file simply acts as a temporary file, and has the default location randomized

genfile specifies where it makes the rule, by default the location is /etc/modprobe.d/vfioselect.conf

The online option will try to bind the device to vfio-pci while the system is running. Make sure that you have a hook setup to switch inputs if you go this route.

Navigating the menu is easy, using the arrow keys, spacebar, and enter. Since everything is command line based, you can run the program in ssh, to fix anything that you might have broken.

Next steps

If you haven’t finished setting up GPU passthrough, then you’re at the last step: Adding the modules to your initramfs. From here the sky is the limit, swapping your GPU between host and guest is as simple as it gets, and you truly never have to reboot now!

I can’t wait to see what you come up with, so be sure to find us in our discord, or follow us on github for more tools. We plan to fully automate the GPU passthrough set up process, but that takes a lot of time and effort. Consider supporting us on Patreon if you’d like to see it happen too.