Problems/Solutions - Ubuntu 18.04 - VFIO PCIe Passthrough w/ Looking Glass

Hello everyone. Over the past 3 days, I have gone through the extremely painful process of getting a Windows 10 Virtual Machine with PCIe Passthrough working adequately on a fresh install of Ubuntu 18.04 LTS.

Along the way, I’ve run into problem after problem, many of which were problems that required multiple hours to figure out, so I’m making this thread to put all the problems and solutions I’ve run into in one place. Hopefully, this will make setting something similar to this up on your own machine, much less time consuming.

Without further ado, I used the following guides for various points in the process:
Ubuntu 17.04 – VFIO PCIe Passthrough & Kernel Update (4.14-rc1)
Ubuntu 18.04 – VFIO PCIe Passthrough
Looking Glass Quickstart
Rokups’ Sharing HID devices with KVM virtual machine Guide


NOTE: Apparently New Forum Users can only post 5 links at a time, and huge posts need approval, so this thread is probably gonna be a pain to navigate/missing parts at first.

9 Likes

Problem:
Only IOMMU Group * exists, or no IOMMU Groups exist

Solution:
/etc/default/grub is either missing the needed iommu values, you haven’t run sudo update-grub or sudo update-initramfs -u, or you haven’t rebooted yet.

Also dmesg | grep -E "DMAR|IOMMU" may help you spot issues.


Problem:
IOMMU Groups aren’t specific enough; ex. two GPUs in the same Group

Solution:
As discussed in IOMMU Groups, Inside and Out, the first option would be to simply try moving the GPU to a different slot. If that doesn’t work, another option is Compiling your own Kernel with the ACS Override Patch.

The latter is discouraged, and if you can help it, don’t do it.

But if you do do it, please note that compiling the kernel will take a long time (30+ minutes for me, even with an i7-4790K), and you’d better not delete/remove the stock (4.15.x) kernel(s). You will want to make sure you’re still able to boot using the 4.15.x kernel in case something goes wrong.

You will also probably be missing some packages if you’re using that script, so run this before running the script:
sudo apt-get install bison flex kernel-package libssl-dev

Also remember to add pcie_acs_override=downstream to /etc/default/grub, in the same GRUB_CMDLINE that you added the IOMMU stuff to, and run sudo update-grub once the ACS-patched kernel is installed.


Problem:
The Guest GPU isn’t using the vfio-pci kernel driver

Solution:
Your /etc/initramfs-tools/modules or another VFIO-related config is incorrect, you haven’t run sudo update-initramfs -u, or you haven’t rebooted yet.

Also, if you’re using an NVIDIA GPU as your Guest GPU, you should be using these softdep rules for the relevant configs instead of the amdgpu ones:

softdep nouveau pre: vfio vfio_pci
softdep nvidia pre: vfio vfio_pci
softdep nvidia_drm pre: vfio vfio_pci
softdep nvidia-* pre: vfio vfio_pci

Problem:
"The emulator may not have search permissions for the path …"

Solution:
A read permissions issue with either LibVirt (Virtual Machine Manager) or QEMU. You can either fix these permissions yourself, you can run VirtManager using sudo virt-manager, hit “Yes” when it asks if you want to “correct this now.” You can then use Virtual Machine Manager without sudo again and it’ll probably work fine.


Problem:
Windows Guest VM boots to EFI Shell

Solution:
You either don’t have the Operating System installed yet, have it installed but don’t have the HDD image attached to the machine, don’t have Windows Installation Media attached to the machine, or you aren’t hitting anything when it says something along the lines of “Press any key to boot to CD/DVD.”


Problem:
Windows Guest VM hangs after "Loading Files…"

Solution:
You probably don’t have a Graphical Display attached to your machine (like Spice or VNC), “Video” hardware that can handle what the Display hardware is outputting (like QXL), or options kvm ignore_msrs=1 is missing from /etc/modprobe.d/kvm.conf. If none of these help you, connecting a real physical display to your Guest GPU may help you (at least see what’s going on).


Problem:
No Keyboard/Mouse control of VM

Solution:
Might be Spice related or Guest Drivers/Tools related. I found that after installing the Guest Tools, my Keyboard worked but my Mouse didn’t unless I switched the Display type to VNC. However, this shouldn’t be an issue once you successfully start using Looking Glass or Rokups’ Sharing HID devices with KVM virtual machine Guide (see above).


Problem:
The Looking Glass Client won’t build successfully

Solution:
If you’re using the Git master branch, don’t do that. Use a tagged release instead.

You may be missing required packages, so run this, on top of whatever Looking Glass’s Build Guide tells you to run:

sudo apt-get install git build-essential nettle-dev libspice-protocol-dev

Problem:
The Looking Glass Client can’t stat /dev/shm/looking-glass or otherwise can’t read it

Solution:
Either /dev/shm/looking-glass doesn’t exist (has to be recreated every boot!), or the file permissions are incorrect for the Looking Glass Client to be able to read it.


Problem:
The VM won’t start because QEMU/libvirt can’t stat /dev/shm/looking-glass or otherwise can’t read it

Solution:
Either /dev/shm/looking-glass doesn’t exist (has to be recreated every boot!), file permissions are incorrect for QEMU/libvirt to Read/Write to it, AppArmor is enabled and /etc/apparmor.d/abstractions/libvirt-qemu is missing the /dev/shm/looking-glass rw, rule, or the AppArmor service hasn’t been restarted after adding that rule.


Problem:
The Looking Glass Client won’t start with error "Failed to map the shared memory file"

Solution:
Start the VM. The VM has fill /dev/shm/looking-glass with data first before the Looking Glass Client can read that data (AFAIK?).


Problem:
The VM won’t start because of some other error concerning /dev/shm/looking-glass

Solution:
Try deleting and recreating the file. Make sure the file permissions are correct for QEMU/libvirt to be able to both read AND write. Also see the AppArmor-related solution concerning /dev/shm/looking-glass above.


Problem:
The VM won’t start with error "Requested operation is not valid: network ‘default’ is not active"

Solution:
If you’re using libvirt, run the following commands:

virsh net-start default
virsh net-autostart default

Problem:
The Looking Glass Host (in the Windows Guest VM) won’t start, fails to start with “Failed to create D3D11 device” or “Unable to configure a capture device” or “Access denied” errors, or the Client only shows a Blue Screen

Solution:
First, read all of the Looking Glass Quickstart Guide.

Second, make sure the IVSHMEM driver is installed on your Windows VM.

Third, make sure the latest NVIDIA drivers are installed (NOT the ones from Windows Update!) and you aren’t experiencing the “Code 43” error. Instructions to fix Code 43 are in the original Ubuntu 17.04 VFIO PCIe Passthrough Guide (above).

Fourth, if the Looking Glass Host attempted to start while you were on the Login screen or in any other “Secure Desktop” context, you may have to try restarting it manually.

Fifth, the Blue Screen should only appear on the Client when the Looking Glass Host has not yet started, or…

Sixth, Looking Glass may not work at all if the VM’s GPU doesn’t detect a display is attached, as most GPUs will disable hardware acceleration and other things if they think they’re not needed. You can get around this by buying a “Dummy Plug” (aka “Display Emulator”), or just attaching a real display to it.


Problem:
The Ubuntu Host OS doesn’t show any display output after attaching Display/Display Emulator to Guest GPU

Solution:
This is happening because Ubuntu is attempting to use your Guest GPU for its display device. This doesn’t work because you told VFIO earlier to grab that GPU before the real drivers do while Ubuntu is booting.

Just unplug the Dummy Plug/Display from your Guest GPU while Ubuntu is booting and then reattach it once you’ve logged in.


Problem:
The Mouse is wonky (aka totally sucks) in Looking Glass

Solution:
Consider doing passthrough with a Hardware Mouse using Rokups’ Sharing HID devices with KVM virtual machine Guide (see above). This is the best solution I’ve come across so far, as it allows you to directly interact with your VM without using a separate set of peripherals.

You may also consider using the -s flag for the Looking Glass Client at the same time, if you’re passing through both your Keyboard and Mouse, to prevent Looking Glass from trying to communicate with your VM over Spice.


Problem:
Copy/Paste between Host OS and Guest VM doesn’t work

Solution:
If you’re using Looking Glass, it doesn’t work in any case, I don’t think. Although, theoretically Spice is supposed to support it, when the Guest Tools are installed. Consider using something like Synergy, Microsoft Garage’s “Mouse without Borders” (if it even still works), or some other Clipboard Sharing software.


Problem:
Guest VM Audio stutters/crackles/lags/is terrible

Solution:
Emulated Audio is generally probably going to be terrible. Some solutions are potentially:

  • Try @kriss120 's Audio Tips/Tweaks
  • Use your Guest GPU’s HDMI Audio in some way (capture card? somehow convert it to a 3.5mm headphone output and plug it into your motherboard’s Line In or speakers/headphones? use your display?)
  • Attach a Sound Card or USB Sound Card to your Guest VM and then plug its output into your motherboard’s Line In/some speakers/headphones
  • Somehow stream audio “over the network” from your VM to your Host OS
  • Experiment with the Sound hardware “Model” in your VM settings
  • Ask the Looking Glass guys nicely to add Audio support

Problem:
Leaving the Windows VM running for long enough/shutting the VM down will completely lock up/freeze the Host/make Host unstable

Solution:
For me, the thing that fixed it was that the Guest GPU wasn’t using MSI (Message Signaled Interrupts). You can find a guide on how to fix that here:
Windows: Line-Based vs. Message Signaled-Based Interrupts


Problem:
Binding/Unbinding the Keyboard/Mouse using Rokups’ scripts takes a while, makes Host OS not recognize Hotkeys, or doesn’t always/correctly unbind from Guest VM

Solution:
There’s not much that can be done about it taking a while.

If Hotkeys are broken after Unbinding from the Guest, the thing that fixed it for me was correctly setting up my Keyboard’s backlight button toggling (which didn’t work without running a command in terminal before) and then just, uh, toggling the backlight. If you have a similar setup, you can find instructions for that here:
How to light up back-lit keyboard?

If Keyboard/Mouse aren’t always (correctly) unbinding, it may be your PowerShell Execution Policy, or the detach.ps1 script that Rokups provided. There’s a bug with it where sometimes it’ll dump a bunch of garbage before the vm_name while doing $port.WriteLine. To fix this, simply add an empty detach-device command before the real ones like so (quick/lazy fix, not really actually fixing the code):

detach-device "" # Bogus/Flush
detach-device "vendor:device"
detach-device "vendor:device"

Problem:
Unable to share Folder/Filesystem between Host OS and Guest VM

Solution:
Apparently this is only supported on Linux Guests with QEMU (the “Filesystem” VM hardware/9p virtio), as I can’t find any documentation anywhere that doesn’t involve straight up doing Passthrough with a block device or just using Samba/SMB/CIFS. Somebody please correct me if I’m wrong.

7 Likes

And that’s it! All of the problems I ran into while setting up this thing. It took 3 days of my life, so I hope this helps somebody!

3 Likes

Wow, this is some incredibly detailed information! Welcome to the forum and thank you for sharing this with us!

1 Like

You should be able to post now without issue, I’ve bumped up your trust level temporarily until it naturally catches up.

2 Likes

Very nice! It would be nice if this site had a wiki so this stuff could be indexed/search for easily