HOW-TO make dual-boot obsolete using kvm VGA passthrough

Questions about virtualization software
Forum rules
Before you post please read how to get help
powerhouse
Level 5
Level 5
Posts: 986
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby powerhouse » Thu Jul 27, 2017 2:40 am

@talos_d: Thanks for the information. Considering your setup, a 14% drop in GPU performance when running on the fake monitor is not bad. I'm actually amazed that it works with your CPU, a dual core Pentium with hyperthreading. Nice work!

As to Spice configuration, I'm not much familiar (haven't used it for a long time). If you need to tweak qemu / kvm, have a look here: https://github.com/qemu/qemu/tree/master/docs. Many docs are for developers, but some are for ordinary users. You can select the version of Qemu you are using in the "Branch" selector - "Master" seems to be the latest.

If you don't mind, could you run the following benchmark and share the results: http://cpu.userbenchmark.com/Intel-Pentium-G4560/Rating/3892.

Userbenchmark is free and allows you to compare performance with other users having the same hardware.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

powerhouse
Level 5
Level 5
Posts: 986
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby powerhouse » Thu Jul 27, 2017 2:50 am

borg101 wrote:Is this possible to do with one gpu? Or could I use my mobo/cpu's gpu and my discreet gpu?


If your CPU has an integrated GPU (IGD in Intel talk), it will work fine. It is, however, important to know which CPU you have and which graphics card.

A typical setup is to use the discrete GPU for Windows (assuming that you play games etc. under Windows), and use the integrated graphics for Linux.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

talos_d
Level 1
Level 1
Posts: 6
Joined: Thu May 11, 2017 1:09 pm

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby talos_d » Thu Jul 27, 2017 4:26 am

powerhouse wrote:@talos_d: Thanks for the information. Considering your setup, a 14% drop in GPU performance when running on the fake monitor is not bad. I'm actually amazed that it works with your CPU, a dual core Pentium with hyperthreading. Nice work!

As to Spice configuration, I'm not much familiar (haven't used it for a long time). If you need to tweak qemu / kvm, have a look here: https://github.com/qemu/qemu/tree/master/docs. Many docs are for developers, but some are for ordinary users. You can select the version of Qemu you are using in the "Branch" selector - "Master" seems to be the latest.

If you don't mind, could you run the following benchmark and share the results: http://cpu.userbenchmark.com/Intel-Pentium-G4560/Rating/3892.

Userbenchmark is free and allows you to compare performance with other users having the same hardware.


Yeah,I did not believe I could make it happen work either at first.

Benchmark:here are my results through my actual monitor:http://www.userbenchmark.com/UserRun/4437706 but for whatever reason it is incomplete,
the cpu and gpu score seems to be about where it should be.

Also managed to get spice working by installing it along with virt-viewer.

then adding the lines:

Code: Select all

-vga qxl -spice port=3001,disable-ticketing \
-nographic \

to the script.

then ran

Code: Select all

remote-viewer spice://username:3001

through the terminal.

and the mouse lag is gone and I have 3d acceleration through the secondary qxl monitor.
Unfortunately this time there is a huge performance drop in unigine heaven.
I thought I had this working,..choosing between a laggy mouse or really bad performance in 3d applications-I might
just go with switching the inputs manually.
maybe I will try and see how this works next time I set a passthrough with window 7/8 and the qxl drivers that did not require spice to run.

powerhouse
Level 5
Level 5
Posts: 986
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby powerhouse » Thu Jul 27, 2017 6:30 am

@talos_d: So you got Spice working. Have you also installed the Windows binaries? See https://www.spice-space.org/download.html.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

talos_d
Level 1
Level 1
Posts: 6
Joined: Thu May 11, 2017 1:09 pm

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby talos_d » Thu Jul 27, 2017 4:30 pm

powerhouse wrote:@talos_d: So you got Spice working. Have you also installed the Windows binaries? See https://www.spice-space.org/download.html.

Tried it,same result-there is graphic acceleration through the gpu but I am getting 1740 score in unigine heaven which is 40 percent slower than the regular passthrough,
Maybe I didnt set spice correctly,some of the set up for spice includes the lines

Code: Select all

-device virtio-serial -chardev spicevmc,id=vdagent,debug=0,name=vdagent \
 device virtserialport,chardev=vdagent,name=com.redhat.spice.0 \

but when I add them to the script,it causes the qxl window to be unusable,maybe they are meant for installation only.

powerhouse
Level 5
Level 5
Posts: 986
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby powerhouse » Sat Jul 29, 2017 12:12 pm

talos_d wrote:
powerhouse wrote:@talos_d: So you got Spice working. Have you also installed the Windows binaries? See https://www.spice-space.org/download.html.

Tried it,same result-there is graphic acceleration through the gpu but I am getting 1740 score in unigine heaven which is 40 percent slower than the regular passthrough,
Maybe I didnt set spice correctly,some of the set up for spice includes the lines

Code: Select all

-device virtio-serial -chardev spicevmc,id=vdagent,debug=0,name=vdagent \
 device virtserialport,chardev=vdagent,name=com.redhat.spice.0 \

but when I add them to the script,it causes the qxl window to be unusable,maybe they are meant for installation only.

You have seen the documentation here: https://www.spice-space.org/spice-user-manual.html.

According to that documentation the best option is -vga qxl perhaps with the options above, and installing the spice tools in Windows including the qxd driver. You may have to consider the way you invoke qemu, perhaps some options are only available after installing the drivers in Windows.

Another thing are the kernel modules mentioned here: https://wiki.archlinux.org/index.php/QEMU#qxl. You may want to check this out.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

talos_d
Level 1
Level 1
Posts: 6
Joined: Thu May 11, 2017 1:09 pm

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby talos_d » Wed Aug 02, 2017 11:09 am

powerhouse wrote:
talos_d wrote:
powerhouse wrote:@talos_d: So you got Spice working. Have you also installed the Windows binaries? See https://www.spice-space.org/download.html.

Tried it,same result-there is graphic acceleration through the gpu but I am getting 1740 score in unigine heaven which is 40 percent slower than the regular passthrough,
Maybe I didnt set spice correctly,some of the set up for spice includes the lines

Code: Select all

-device virtio-serial -chardev spicevmc,id=vdagent,debug=0,name=vdagent \
 device virtserialport,chardev=vdagent,name=com.redhat.spice.0 \

but when I add them to the script,it causes the qxl window to be unusable,maybe they are meant for installation only.

You have seen the documentation here: https://www.spice-space.org/spice-user-manual.html.

According to that documentation the best option is -vga qxl perhaps with the options above, and installing the spice tools in Windows including the qxd driver. You may have to consider the way you invoke qemu, perhaps some options are only available after installing the drivers in Windows.

Another thing are the kernel modules mentioned here: https://wiki.archlinux.org/index.php/QEMU#qxl. You may want to check this out.


Thank you for the tips!
I have tried every single combination of drivers(spice tools included) even installing it in windows 8.1. but while running it through spice makes the mouse lag go away
it also causes issues with mouse alignment which is important to me since I draw with a wacom tablet,and also the performance drop in 3d applications persists.
I will try to see if updating the kernal modules does something.

garrettjk
Level 1
Level 1
Posts: 2
Joined: Wed Aug 02, 2017 1:45 pm

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby garrettjk » Wed Aug 02, 2017 2:02 pm

I currently get no display on my passthrough monitor when trying to run sudo ./windows10vm.sh
its contents are as follows:

#!/bin/bash

vmname="windows10vm"

if ps -A | grep -q $vmname; then
echo "$vmname is already running." &
exit 1

else

# use pulseaudio
export QEMU_AUDIO_DRV=pa
export QEMU_PA_SAMPLES=8192
export QEMU_AUDIO_TIMER_PERIOD=99
export QEMU_PA_SERVER=/run/user/1000/pulse/native

cp /usr/share/OVMF/OVMF_VARS.fd /tmp/my_vars.fd

qemu-system-x86_64 \
-name $vmname,process=$vmname \
-machine type=pc,accel=kvm \
-cpu host \
-smp 6,sockets=1,cores=3,threads=2\
-enable-kvm \
-m 2300 \
-mem-path /run/hugepages/kvm \
-mem-prealloc \
-balloon none \
-rtc clock=host,base=localtime \
-vga none \
-serial none \
-parallel none \
-soundhw hda \
-usb -usbdevice host04d9:fa52 -usbdevice host:04b4:5004 \
-device vfio-pci,host=07:00.0,multifunction=on \
-device vfio-pci,host=07:00.1 \
-drive if=pflash,format=raw,readonly,file=/usr/share/OVMF/OVMF_CODE.fd \
-drive if=pflash,format=raw,file=/tmp/my_vars.fd \
-boot order=dc \
-device virtio-scsi-pci,id=scsi \
-drive id=disk0,if=virtio,cache=none,format=raw,file=/media/libraries/win.img \
-drive file=/media/libraries/win10.iso,id=isocd,format=raw,if=none -device scsi-cd,drive=isocd \
-drive file=/media/libraries/virtio-win-0.1.126.iso,id=virtiocd,format=raw,if=none -device ide-cd,bus=ide.1,drive=virtiocd\
-netdev type=tap,id=net0,ifname=tap0,vhost=on \
-device virtio-net-pci,netdev=net0,mac=00:16:3e:00:01:01

exit 0
fi


My specs are:
Cpu - i5-6600k (IGPU for linux)
GPU - MSI R9 390 (passthrough)
Motherboard - Gigabyte GA-Z170-HD3P
Ram - 8G ddr4-2133


kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used

lsmod | grep kvm
kvm_intel 200704 0
kvm 593920 1 kvm_intel
irqbypass 16384 2 kvm,vfio_pci


lsmod | grep vfio
kvm_intel 200704 0
kvm 593920 1 kvm_intel
irqbypass 16384 2 kvm,vfio_pci


dmesg | grep vfio
[ 12.717423] vfio-pci 0000:07:00.0: vgaarb: changed VGA decodes: olddecodes=io+mem,decodes=io+mem:owns=none
[ 12.736184] vfio_pci: add [1002:67b1[ffff:ffff]] class 0x000000/00000000
[ 12.756189] vfio_pci: add [1002:aac8[ffff:ffff]] class 0x000000/00000000


VFIO - User Level meta-driver version: 0.3
QEMU version 2.5

powerhouse
Level 5
Level 5
Posts: 986
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby powerhouse » Wed Aug 02, 2017 2:21 pm

@talos_d: Thanks for the update. Hope you find a way to solve the issue.

Looking at the issue in a different way: What would happen if you pass through a USB port and reconnect your Wacom / mouse / keyboard via a small hub? You could start with the mouse at first to see if that solves anything.

As a next step, if that doesn't help, you could try to find a USB controller sitting on the PCI bus. List the PCI ports with:

Code: Select all

lspci


It might be worth trying, though it's not the same as what you want. Once you pass through a USB device, control passes to the guest. I wonder if Spice would show the mouse that is passed through.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

powerhouse
Level 5
Level 5
Posts: 986
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby powerhouse » Thu Aug 03, 2017 1:55 am

garrettjk wrote:I currently get no display on my passthrough monitor when trying to run sudo ./windows10vm.sh
its contents are as follows:

#!/bin/bash

...
qemu-system-x86_64 \
...
-machine type=pc,accel=kvm \
...
-m 2300 \
...
-usb -usbdevice host04d9:fa52 -usbdevice host:04b4:5004 \
...
-drive file=/media/libraries/virtio-win-0.1.126.iso,id=virtiocd,format=raw,if=none -device ide-cd,bus=ide.1,drive=virtiocd\


My specs are:
Cpu - i5-6600k (IGPU for linux)
GPU - MSI R9 390 (passthrough)
Motherboard - Gigabyte GA-Z170-HD3P
Ram - 8G ddr4-2133


Looking at the script, there are some typos and other issues - see bold text:

1. machine type=pc -- unless you have a good reason, try q35. Note that if you installed Windows already, you will need to reinstall when changing the type.

2. -m 2300 -- this is very little memory for your Windows VM. The minimum should be -m 4G. Linux doesn't need so much, so your 8G is enough to get it running, but increase the Windows memory to 4G. Don't forget to increase your hugepages too!!!

3. -usb -usbdevice host04d9:fa52 -- should read -usb -usbdevice host:04d9:fa52 -- note the colon.

4. drive=virtiocd\ -- don't forget the space, this should read drive=virtiocd \

Please list your IOMMU groups, especially for the graphics card you want to pass through. If there are any problems, that is there are other devices inside the same IOMMU group with the graphics card, have a look at my new blog: https://heiko-sieger.info/iommu-groups-what-you-need-to-consider/.

My guess: You run the script, the screen switches and you can't see the messages in the Linux terminal anymore. Is that correct? First fix your start script and run it again.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

powerhouse
Level 5
Level 5
Posts: 986
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby powerhouse » Thu Aug 03, 2017 5:32 am

Because of the forum limitations (text length, no. of pictures, etc.), I'm hosting the tutorial on my own website here.

Inside the troubleshooting section, there is a correction:

BSOD when installing AMD Crimson drivers under Windows

Several users on the Redhat VFIO mailing list have reported problems with the installation of AMD Crimson drivers under Windows. This seems to affect a number of AMD graphics cards, as well as a number of different AMD Crimson driver releases. A workaround is described here: https://www.redhat.com/archives/vfio-users/2016-April/msg00153.html

In this workaround the following line is added to the startup script, right above the definition of the graphics device:

Code: Select all

-device ioh3420,bus=pci,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1


Should the above configuration give you a “Bus ‘pci’ not found” error, change the line as follows:

Code: Select all

-device ioh3420,bus=pci.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1


Then change the graphics card passthrough options as follows:

Code: Select all

-device vfio-pci,host=02:00.0,bus=root.1,addr=00.0,multifunction=on \
-device vfio-pci,host=02:00.1,bus=root.1,addr=00.1 \

Replace the PCI IDs with the ones of your graphics card.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

swe3tdave
Level 1
Level 1
Posts: 1
Joined: Sun Aug 06, 2017 1:38 pm

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby swe3tdave » Sun Aug 06, 2017 2:11 pm

After days of trying to make this work on fedora, i removed it to install Linux Mint and tried it again with your tutorial... Same problem... :twisted:
Thanks to your troubleshooting section, i got the idea that my Windows 8 ISO might be the issue. So i tried with an Ubuntu ISO i still had and it booted fine... :roll: After that, a fresh ISO from microsoft and everything went smoothly! i even got my onboard Creative ZxR Sound Card working on Windows!! :D

i am sending sound from my Linux host to the Windows VM. This link was extremely usefull for that: https://www.tomjepp.co.uk/post/20150531 ... to-windows

Ahh, the nice sound of Victory! Thank You for the Tutorial, so far, its the best one i've seen yet.

powerhouse
Level 5
Level 5
Posts: 986
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby powerhouse » Tue Aug 08, 2017 1:12 am

@swe3tdave: Thanks for your kind words. Your link to the audio tutorial will certainly be helpful to others and I will link to it in the tutorial.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

garrettjk
Level 1
Level 1
Posts: 2
Joined: Wed Aug 02, 2017 1:45 pm

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby garrettjk » Tue Aug 08, 2017 2:24 pm

powerhouse wrote:
Looking at the script, there are some typos and other issues - see bold text:

1. machine type=pc -- unless you have a good reason, try q35. Note that if you installed Windows already, you will need to reinstall when changing the type.

2. -m 2300 -- this is very little memory for your Windows VM. The minimum should be -m 4G. Linux doesn't need so much, so your 8G is enough to get it running, but increase the Windows memory to 4G. Don't forget to increase your hugepages too!!!

3. -usb -usbdevice host04d9:fa52 -- should read -usb -usbdevice host:04d9:fa52 -- note the colon.

4. drive=virtiocd\ -- don't forget the space, this should read drive=virtiocd \

Please list your IOMMU groups, especially for the graphics card you want to pass through. If there are any problems, that is there are other devices inside the same IOMMU group with the graphics card, have a look at my new blog: https://heiko-sieger.info/iommu-groups-what-you-need-to-consider/.

My guess: You run the script, the screen switches and you can't see the messages in the Linux terminal anymore. Is that correct? First fix your start script and run it again.


I attempted to fix the typos that you suggested...
Now I am unable to view my iommu groups at all ( the iommu group folder is empty). I am also told that my kernel does not support huge pages when i try to edit those. I recently update my kernel and I believe that it may be the cause of the issue.

powerhouse
Level 5
Level 5
Posts: 986
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby powerhouse » Sat Aug 12, 2017 1:16 pm

garrettjk wrote:
powerhouse wrote:
Looking at the script, there are some typos and other issues - see bold text:

1. machine type=pc -- unless you have a good reason, try q35. Note that if you installed Windows already, you will need to reinstall when changing the type.

2. -m 2300 -- this is very little memory for your Windows VM. The minimum should be -m 4G. Linux doesn't need so much, so your 8G is enough to get it running, but increase the Windows memory to 4G. Don't forget to increase your hugepages too!!!

3. -usb -usbdevice host04d9:fa52 -- should read -usb -usbdevice host:04d9:fa52 -- note the colon.

4. drive=virtiocd\ -- don't forget the space, this should read drive=virtiocd \

Please list your IOMMU groups, especially for the graphics card you want to pass through. If there are any problems, that is there are other devices inside the same IOMMU group with the graphics card, have a look at my new blog: https://heiko-sieger.info/iommu-groups-what-you-need-to-consider/.

My guess: You run the script, the screen switches and you can't see the messages in the Linux terminal anymore. Is that correct? First fix your start script and run it again.


I attempted to fix the typos that you suggested...
Now I am unable to view my iommu groups at all ( the iommu group folder is empty). I am also told that my kernel does not support huge pages when i try to edit those. I recently update my kernel and I believe that it may be the cause of the issue.


You may need to re-install hugepages. As to the IOMMU groups, make sure your /etc/default/grub file contains the option that enables IOMMU (see tutorial), and that you run

Code: Select all

update-grub

Reboot and your /sys/kernel/iommu_groups directory should be filled with folders. If that does not happen, check your BIOS settings (see my tutorial as well as the motherboard manual for more).

EDIT: If the above suggestions don't help, it might be better to do a clean installation of Linux and start from scratch. The start script changes you made have no bearing on the IOMMU groups. And the fact that hugepages aren't found may just indicate that you have made other alterations, or that something is wrong with either hardware or the Linux installation. You must stick to the tutorial - no shortcuts.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

wye141
Level 1
Level 1
Posts: 2
Joined: Sat Aug 12, 2017 1:20 pm

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby wye141 » Sat Aug 12, 2017 4:02 pm

I follow this thread a long time and i want to say that this is a great guide even if it doesnt work for me yet.

I tried to setup this for about ~9h now, and im stuck.

When im disabling "-vga none" everything seems to work fine, with this option enabled, the machine wont start, only the compatmonitor pops up.

Without "-vga none" it uses a MIcrosoft Standard Display Adaptor with 800x600 and average performance.
The Nvidia card is displayed beneath the unicorns graphics adaptor in the device manager.

I tried to follow the guide step by step, maybe iam missing something, maybe you can see the wrong option/typo/error.

Here is my config:

Code: Select all

i7 3930k
16GB RAM
AMD RX550 (host)
Nvidia GTX1080 (WindowsVM)


I am using Windows 10 for the VM.

Here is my config:

Code: Select all

#!/bin/bash

vmname="GAMINGVM"

if ps -A | grep -q $vmname; then
   echo "$vmname is already running." &
   exit 1

else

# use pulseaudio
export QEMU_AUDIO_DRV=pa
export QEMU_PA_SAMPLES=8192
export QEMU_AUDIO_TIMER_PERIOD=99
export QEMU_PA_SERVER=/run/user/1000/pulse/native

cp /usr/share/OVMF/OVMF_VARS.fd /tmp/my_vars.fd

qemu-system-x86_64 \
  -name $vmname,process=$vmname \
  -machine type=pc,accel=kvm \
  -cpu host,kvm=off \
  -smp 8,sockets=1,cores=4,threads=2 \
  -enable-kvm \
  -m 11264 \
  -mem-path /dev/hugepages \
  -mem-prealloc \
  -balloon none \
  -rtc clock=host,base=localtime \
  -vga none \
  -serial none \
  -parallel none \
  -soundhw hda \
  -usb -usbdevice host:046d:c331 -usbdevice host:1038:1369 \
  -device vfio-pci,host=02:00.0,multifunction=on \
  -device vfio-pci,host=02:00.1 \
  -drive if=pflash,format=raw,readonly,file=/usr/share/OVMF/OVMF_CODE.fd \
  -drive if=pflash,format=raw,file=/tmp/my_vars.fd \
  -boot order=dc \
  -device virtio-scsi-pci,id=scsi \
  -drive id=disk0,if=virtio,cache=none,format=raw,file=/home/pscl/data/gamingvm.img \
  -drive file=/home/pscl/isos/windoofs.iso,id=isocd,format=raw,if=none -device scsi-cd,drive=isocd \
  -drive file=/home/pscl/isos/virtio.iso,id=virtiocd,format=raw,if=none -device ide-cd,bus=ide.1,drive=virtiocd \
  -netdev type=tap,id=net0,ifname=tap0,vhost=on \
  -device virtio-net-pci,netdev=net0,mac=E0:3F:49:6D:0F:F3

   exit 0
fi


/etc/default/grub

Code: Select all

GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="modprobe.blacklist=nouveau quiet intel_iommu=on"
GRUB_CMDLINE_LINUX=""


Check for IOMMU

Code: Select all

dmesg | grep "Virtualization Technology for Directed I/O"
[    1.022297] DMAR: Intel(R) Virtualization Technology for Directed I/O


output of lspci | grep VGA

Code: Select all

01:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Device 699f (rev c7)
02:00.0 VGA compatible controller: NVIDIA Corporation Device 1b80 (rev a1)


output of lspci -nn | grep 02:00.

Code: Select all

02:00.0 VGA compatible controller [0300]: NVIDIA Corporation Device [10de:1b80] (rev a1)
02:00.1 Audio device [0403]: NVIDIA Corporation Device [10de:10f0] (rev a1)


/etc/modprobe.d/local.conf

Code: Select all

options vfio-pci ids=10de:1b80,10de:10f0


/etc/initramfs-tools/modules

Code: Select all

options vfio-pci ids=10de:1b80,10de:10f0


iommu_groups

Code: Select all

/sys/kernel/iommu_groups/17/devices/0000:01:00.1
/sys/kernel/iommu_groups/17/devices/0000:01:00.0
/sys/kernel/iommu_groups/18/devices/0000:02:00.1
/sys/kernel/iommu_groups/18/devices/0000:02:00.0


Code: Select all

# List of modules that you want to include in your initramfs.
# They will be loaded at boot time in the order below.
#
# Syntax:  module_name [args ...]
#
# You must run update-initramfs(8) to effect this change.
#
# Examples:
#
# raid1
# sd_mod
vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd
vhost-net


kvm-ok

Code: Select all

INFO: /dev/kvm exists
KVM acceleration can be used


lsmod | grep kvm

Code: Select all

kvm_intel             200704  0
kvm                   593920  1 kvm_intel
irqbypass              16384  2 kvm,vfio_pci


lsmod | grep vfio

Code: Select all

vfio_pci               45056  0
vfio_virqfd            16384  1 vfio_pci
irqbypass              16384  2 kvm,vfio_pci
vfio_iommu_type1       24576  0
vfio                   32768  2 vfio_iommu_type1,vfio_pci


qemu-system-x86_64 –version

Code: Select all

QEMU emulator version 2.5.0 (Debian 1:2.5+dfsg-5ubuntu10.14), Copyright (c) 2003-2008 Fabrice Bellard


dmesg | grep vfio

Code: Select all

[    2.533225] vfio-pci 0000:02:00.0: vgaarb: changed VGA decodes: olddecodes=io+mem,decodes=io+mem:owns=none
[    2.552559] vfio_pci: add [10de:1b80[ffff:ffff]] class 0x000000/00000000
[    2.572569] vfio_pci: add [10de:10f0[ffff:ffff]] class 0x000000/00000000
[    3.929284] vfio-pci 0000:02:00.0: vgaarb: changed VGA decodes: olddecodes=io+mem,decodes=io+mem:owns=none


dmesg | grep VFIO

Code: Select all

[    2.527406] VFIO - User Level meta-driver version: 0.3


I hope that this information could make this easy for you.

powerhouse
Level 5
Level 5
Posts: 986
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby powerhouse » Sun Aug 13, 2017 1:10 am

@wye141: You got nearly the same hardware I have and that is very good!

For completeness, please post the manufacturer and model of the motherboard. Check which BIOS software version the motherboard is running and if there are newer ones that might fix IOMMU issues - some manufacturers have had their issues, but in many cases they have been fixed.

The most obvious difference in your start script is the -machine type=pc option. You should change it to q35 for better performance. This option may or may not be the reason for your Windows VM not starting.

If you already installed Windows, changing the type to q35 or vice versa from q35 to pc will require you to reinstall your Windows VM.

When I install a VM I usually land in an UEFI command line screen and need to type "exit" to get to the UEFI menu. Make sure your Nvidia 1080 is connected to a screen and that you selected the proper input for that screen (via push-button or whatever).

You do not need the vga=on option.

Make sure your mouse and keyboard is passed through to the VM. It should not be working in Linux.

Let's start from here and see if it works.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

wye141
Level 1
Level 1
Posts: 2
Joined: Sat Aug 12, 2017 1:20 pm

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby wye141 » Sun Aug 13, 2017 2:44 am

Thank you for the quick response!

The mainboard manufacturer is ASUS, its an Rampage IV Gene; https://www.asus.com/de/Motherboards/RAMPAGE_IV_GENE/
I enabled Intel VT-d through the BIOS, i checked again, if it is still enabled, it was.

I had installed windows with pc and then switched to q35, it worked, but with the microsoft standard grpahics adaptor, and not with the gtx1080.
I deleted the VM, because i thought the problem were the drivers inside, because it could not be started.

thank you, the problem is solved now, i connected the cable to the display and started the vm with -vga none and -nographics and q35, it worked.
i had a wrong idea about how this work.

The System is using the Microsoft Standard Adaptor, i will take a look at this, thanks for help!

The i7 3930k is still a very good cpu and i hope this one runs for the next two years, my biggest fear about this, is, that the mainboard will stop working, because they are really hard/expensive to get nowadays.

EDIT: Everything does work now, i could install the nvidia drivers and can use the full resolution of my Screen.

Iam using three displays, at the middle screen runs the windows vm with synergy as a server and at the left and right is the linux host displayed, the linux host runs as a client.
Synergy runs like a charm, i cant recognize any input lag, switching the mouse works good, even the clipboard is available at both systems.

powerhouse
Level 5
Level 5
Posts: 986
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby powerhouse » Sun Aug 13, 2017 4:21 am

wye141 wrote:Thank you for the quick response!

The mainboard manufacturer is ASUS, its an Rampage IV Gene; https://www.asus.com/de/Motherboards/RAMPAGE_IV_GENE/
I enabled Intel VT-d through the BIOS, i checked again, if it is still enabled, it was.

I had installed windows with pc and then switched to q35, it worked, but with the microsoft standard grpahics adaptor, and not with the gtx1080.
I deleted the VM, because i thought the problem were the drivers inside, because it could not be started.

thank you, the problem is solved now, i connected the cable to the display and started the vm with -vga none and -nographics and q35, it worked.
i had a wrong idea about how this work.

The System is using the Microsoft Standard Adaptor, i will take a look at this, thanks for help!

The i7 3930k is still a very good cpu and i hope this one runs for the next two years, my biggest fear about this, is, that the mainboard will stop working, because they are really hard/expensive to get nowadays.

EDIT: Everything does work now, i could install the nvidia drivers and can use the full resolution of my Screen.

Iam using three displays, at the middle screen runs the windows vm with synergy as a server and at the left and right is the linux host displayed, the linux host runs as a client.
Synergy runs like a charm, i cant recognize any input lag, switching the mouse works good, even the clipboard is available at both systems.

Wow, good news! I'm glad everything is working so well. The 3930K is an excellent CPU. It may not have the fastest single thread performance, but when the software can make use of multiple cores, it kicks a..

You may want to install the CPU Frequency Scaling Monitor applet to your task bar. The VM doesn't automatically trigger turbo mode. With this applet to can switch to Performance mode and gain another ~20% performance boost.

It would be great if you could do a benchmark using http://www.userbenchmark.com/Software within Windows, then post the benchmark together with your hardware specs here: https://forums.linuxmint.com/viewtopic.php?f=225&t=153482. Of course, Passmark results are also welcome (I use both).

Enjoy the new experience! Any feedback on what you run on Windows (games, etc.) and its performance are welcome.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

juju
Level 1
Level 1
Posts: 7
Joined: Sun Aug 27, 2017 9:45 pm

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Postby juju » Sun Aug 27, 2017 10:16 pm

Signed up to post a big thanks to powerhouse and all other linux mint users in this thread who contributed. I had tried to do a passthrough about 1.5 years ago on a different machine, but could not do ACS Override with my configuration. I built a new machine specs below, some parts missing.

I just got the kvm VGA passthrough working without an ACS Override patch. I had IOMMU grouping conflicts between both of my cards, but I updated my BIOS to the latest version and it split the PCI-E Video devices into their own IOMMU groupings. I read using the ACS Override patch is insecure, I doubt I would ever run into that issue but I am glad I got it to work without having to resort to using it. I had poor audio quality so I setup the Realtek ac97 audio drivers for the audio device and installed within the Windows 10 VM.

Machine
Host OS: Xubuntu 16.0.4
Guest OS: Windows 10 x64
CPU: AMD Ryzen 7 1800x - 12 Cores Guest - 4 Cores Host
Mobo: ASUS Crosshair VI Hero - 1501 BIOS Version
Host Card: AMD Firepro v7900
Guest: NVIDIA GTX 970 (Current Nvidia Driver)
RAM: 64GB (32GB per system right now)
Disks:
--Host: SSD - 500GB
--Guest: SSD - 1TB

I have a GTX 1050 TI SC I would like to get working but it was too difficult for me to find a way to assign a different driver to my 1050ti and the 970, whatever I put on one would go to the other. Either way for the time being the Firepro card I had kicking around did the trick. I am going to get back to messing around in the guest thanks again! Ill check back here at some point soon in-case anyone asks me any questions about the setup.


Return to “Virtualization”

Who is online

Users browsing this forum: No registered users and 2 guests