It’s no secret that a seamless VFIO experience used to be hard to come by. Things have changed recently with the release of looking glass, but that’s not an option for everyone, and newcomers can’t be expected to navigate every corner case that may arise when integrating something like it into their systems.
Whether it’s evdev passthrough, some voodoo with steam home streaming, or kludged together Spice/VNC with synergy, trying to put together a “seamless experience” in software can quickly turn into an exercise in frustration. The exact methods are poorly documented in some cases, outdated in others, and too high latency for twitch gaming in a lot of cases.
Luckily, there’s purpose built hardware that can make switching from VM to host as easy as pressing a button, and I think it’s hardware that newcomers should budget for when putting together a new VFIO system. For the cost of a single retail game, you can go out, get a USB host bus adapter and a USB switch, plug them in, pass them through, and have one button input switching. Here’s our recommended products and how to put them to use:
USB PCI Express Card – Silverstone Tek PCI-e USB HBA – $29.99
A USB PCI Express Card doesn’t exactly do anything special, it’s a PCI-e card that gives you extra USB ports. With this in mind, you can pass it through to the guest just as you would a GPU. This will give the guest full control over the devices that are connected to it.
There may be some cheaper cards you can use for this, but I’m recommending this one for two reasons. First, I’ve personally used it and can confirm that it works. Second, It has the ability for you to plug in your case’s USB ports. If you want to use a flash drive you can just plug it in. You won’t have to fool around with the host doing redirects or trying to pass through another controller.
USB Switch – IOGEAR USB 2.0 Peripheral Sharing Switch – $29.95
A basic USB switch allows you to switch what computer your USB devices are connected to with the flick of a switch. The way these work is they have some USB inputs and 2 USB outputs.
The devices that you plug into the inputs, like a keyboard and mouse, will easily be able to switch what outputs they go to by pressing a button. I recommend this one because it’s simple. It has 4 inputs and two outputs, which gives you some flexibility with your switching. (this technically is only a “KM” switch, as it has no video ports, but for the price, switching video source manually is more than enough to justify going for the less expensive model)
Once you have your HBA and switch, just plug the HBA into a free PCI-e slot that either has it’s own IOMMU group or shares one with your GPU (sometimes this is the only option on badly isolated motherboards.)
If you’re stuck with putting it in the same IOMMU as your GPU, then run lspci -nn to find the cards device and vendor ID (two 4 digit strings separated by a colon at the end of the output for it) and add the value to your sudo nano /etc/modprobe.d/vfio.conf file after your GPU’s values in ids=, separating them by commas
Once that’s done, just add the USB PCI-e device in virt-manager, or in your XML, plug one set of USB leads from the input switcher into the motherboard, and the other into the passed through PCI-e card.
Then plug all the devices (keyboard, mouse, mic, webcam, etc.) that you want to be able to switch into the ports at the front. Position the button somewhere convenient, boot your VM, and enjoy low latency input, with convenient one button switching from guest to host.
Some Stuff Should Just Be Done In Hardware
These two devices together are pretty amazing. The quality of life improvement you experience with this setup over software switching cannot be understated. Once you’ve started your virtual machine, all you have to do is click a button and any devices plugged into the switch will now be used solely by the guest.
Notably, with a USB headset you won’t have to fool around with getting sound to pass-through because the headset will work as if it were bare metal. If you need to do something in the host you can just click the button on your USB switch and all your devices are swapped back over.
Join our Discord server and discuss our content with the community!
Image courtesy pixabay