Linux, AMD Ryzen 3900X, X570, NVIDIA GTX 1060, AMD 5700XT, Looking Glass, PCI Passthrough and Windows 10

Contents

Now that the Windows VM is running fine with the passed through NVIDIA graphics card, spare keyboard and mouse we still have to switch between monitor inputs if we want to work with Windows or Linux. We can’t use both at the same time. That’s were Looking Glass kicks in. The Looking Glass homepage states: Looking Glass is an open source application that allows the use of a KVM (Kernel-based Virtual Machine) configured for VGA PCI Pass-through without an attached physical monitor, keyboard or mouse. This is the final step required to move away from dual booting with other operating systems for legacy programs that require high performance graphics.

Looking glass works by creating a shared memory buffer between a host and a guest. This is a lot faster than streaming frames via localhost, but requires additional setup. We already installed Looking Glass on the Linux side in part 2 of this blog series.

So for my computer I did the following setup:

To change the configuration of your Windows VM run sudo virsh edit [vmname] (again replace [vmname] with your virtual machine name). Before we can add the necessary configuration we need to do a little math ;-) We need the size of the shared memory segment that Looking Glass uses to copy the screen output of the Windows VM to the Linux host and the size depends on the screen size. Here is the formula:

plain

width x height x 4 x 2 = total bytes
total bytes / 1024 / 1024 = total mebibytes + 2

My Windows VM has a default screen size of 3840x1080. It’s a little bit unusual but I’ve a UltraWide screen. For gaming FullHD with 1920x1080 may be better as most games are optimized for this screen size and in my case the NVIDIA GTX1060 should be able to handle this very well. But I’ll keep the 3840x1080 for my daily doing. The result must be rounded up to the nearest power of two.

plain

3840 x 1080 x 4 x 2 = 33177600 bytes
33177600 bytes / 1024 / 1024 = 31.640625 MB + 2

This gives us round about 33.64 MB. So this bigger then 32 MB and therefore we choose 64 MB. Now search for the <devices> section in the XML configuration. In my case I’ve to add this:

xml

<shmem name='looking-glass'>
  <model type='ivshmem-plain'/>
  <size unit='M'>64</size>
</shmem>

In the VM XML config it looks like this now (if you view it in virt-manager): image57

Next we create a configuration file that creates the shared memory file on boot. If not existent create the directory /etc/tmpfiles.d first. Then open /etc/tmpfiles.d/10-looking-glass.conf with your favorite editor and add this configuration (replace user with your username of course!):

bash

f       /dev/shm/looking-glass  0660    user  kvm     -

Ask systemd-tmpfiles to create the shared memory file now without waiting to next boot by running

bash

systemd-tmpfiles --create /etc/tmpfiles.d/10-looking-glass.conf

Next start the Windows VM. After logging in start your favorite browser and download and install Microsoft Visual C++ Redistributable for Visual Studio from Microsoft. It’s located here. Scroll until the end of the page and open Other Tools and Frameworks.

image60

Next we need a driver for the IVSHMEM device (which is basically a driver for the shared memory segment we already talked about above). You can find it here: virtio-win10-prewhql.

image61

Extract the content of the ZIP file somewhere:

image63

Now lets open the Device Manager. In System devices you should see a device called PCI standard RAM Controller:

image62

So right click on the PCI standard RAM Controller device, select Update driver and select the folder you just created by extracting the ZIP file. Make sure that Include subfolders is also selected:

image64

If Windows asks you if you want to install the driver just press Install:

image65

Finally you should see the IVSHMEM Device driver installed:

image66

Next we need to download Looking Glass client for Windows. You can download it here (make sure that you install the same version as you installed for Linux!):

image67

Again extract the ZIP file content somewhere. Change to the new folder and execute looking-glass-host.exe:

image68

Windows will complain about running this app but in that case just click Run anyway:

image69

Switch back to Linux and enter a shell. Now we run

bash

looking-glass-client -s -a

and should finally see Windows UI in a Linux Desktop window. I’m using two options: -s enables the built in SPICE client for input and/or clipboard support and -a will auto resize the window to the guest. So you can change the Windows screen resolution to whatever you want and the Windows window will be adjusted accordingly.

And here are two screenshots how it looks like in my case:

image70 image71

And it really works! Fortnite with the NVIDIA GTX 1060 works very well in FullHD (1920x1080) with Epic detail setting. In the screen shot above I tried the a resolution of 3840x1080. It was playable but you have to reduce details quite a bit in Fortnite. I guess a NVIDIA 2070 Super would be able to handle it ;-)

Maybe one note for KDE users: In my case when I start looking-glass-client my KDE/Plasma desktop effects are getting disabled. But they can just be enabled again. It makes no difference regarding performance.

Another thing: I try to use the same refresh rate in Windows and in Linux. That means I’m using 60 Hz refresh rate in Windows and I also use 60 Hz in Linux. The AMD Navi10 chip is still a little bit tricky to use with Linux. So here are two links that might be of interest:

Archlinux forum: Anyone got AMD RX 5700 (XT) to work?
Freedesktop bugzilla: Sapphire Pulse RX 5700 XT power consumption

As usual Archlinux wiki has good documentation if you need further help: Using Looking Glass to stream guest screen to the host.

One further interesting tip maybe: If you want to exchange files between Windows VM and Linux host you can install OpenSSH. You don’t need cygwin anymore for this. It’s already included in Windows 10. You can install it is described at Installation of OpenSSH For Windows Server 2019 and Windows 10.

On more general note: This applies basically always if Windows asks for permission. E.g. if you installed OpenSSH server and you want to configure it as described above in the link the documentation stats that you should open PowerShell as administrator. If you do this in your Looking Glass window (search for powershell in the Windows search bar, right click on Windows PowerShell App and choose Run as administrator) you’ll only hear a notification sound and nothing further happens. In this case Windows wants you to approve that you want to run this app as admin. But you won’t see this pop up window in Looking Glass. You either switch the monitor input or just blindly hit the cursor left key on your keyboard and press <enter>. This works everytime Windows wants approval for several actions like changing system settings or stuff like that. You just need to remember that there may pop up such a confirmation window and you need to do something ;-)

Regarding power consumption of the NVIDIA card: After starting Linux the idle power consumption was around 20 Watt for this card. After starting the Windows VM and shutting it down again the idle power consumption of the NVIDIA card dropped to the expected 8 W. I guess that the graphic card driver activates some power manamagent stuff and since Linux doesn’t touch that card at all (as we want to pass it through to Windows VM of course) no Linux driver will care about power management. So we need the NVIDIA Windows drivers to do this for us.

And finally: If you find Looking Glass useful consider a donation. You can find the donation links at the end of the Downloading Looking Glass website. And yes: I donated ;-)