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

Questions about virtualization software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
GregoriMarow

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

Post by GregoriMarow »

1. Problem is, I can not blacklist the driver, its also used by one intel usb controller.

Code: Select all

00:14.0 USB controller [0c03]: Intel Corporation 8 Series/C220 Series Chipset Family USB xHCI [8086:8c31] (rev 05)
	Subsystem: ASUSTeK Computer Inc. 8 Series/C220 Series Chipset Family USB xHCI [1043:8534]
	Kernel driver in use: xhci_hcd

05:00.0 USB controller [0c03]: Renesas Technology Corp. uPD720201 USB 3.0 Host Controller [1912:0014] (rev 03)
	Kernel driver in use: xhci_hcd
I added the Device to the pci_stub

Code: Select all

dmesg | grep pci-stub
[    2.806521] pci-stub: add 1912:0014 sub=FFFFFFFF:FFFFFFFF cls=00000000/00000000
But if i perform "lspci -nnk" xhci_hcd is still listed. What is wrong?

Code: Select all

05:00.0 USB controller [0c03]: Renesas Technology Corp. uPD720201 USB 3.0 Host Controller [1912:0014] (rev 03)
	Kernel driver in use: xhci_hcd
Without blocking and only use this on the startup script

Code: Select all

-device vfio-pci,host=5:00.0
my second keyboard, second mouse and the second soundcard are present in system when windows vm is shut down. So i want to knock it out.

Is there anything similar to rfkill for wireless devices?
--------------------------------

2. Tried to use this method without uninstalling network manager. Restarted and IPv6 was still active. I have done now something crazy. I have created a network bridge with the network manager and switched IPv6 off. Used as DNS my router ip. The real dns server address is set there. Oh i forgot to mention that i am using Mint 18.1 maybe the network-manager is improved. It seems to be possible to make all settings there.
That is the result:

ifconfig output:

Code: Select all

eno1      Link encap:Ethernet  Hardware Adresse e0:3f:49:ac:5c:08  
          inet Adresse:192.168.2.100  Bcast:192.168.2.255  Maske:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metrik:1
          RX-Pakete:7598 Fehler:0 Verloren:0 Überläufe:0 Fenster:0
          TX-Pakete:5599 Fehler:0 Verloren:0 Überläufe:0 Träger:0
          Kollisionen:0 Sendewarteschlangenlänge:1000 
          RX-Bytes:5792976 (5.7 MB)  TX-Bytes:722987 (722.9 KB)
          Interrupt:20 Speicher:f7400000-f7420000 

lo        Link encap:Lokale Schleife  
          inet Adresse:127.0.0.1  Maske:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metrik:1
          RX-Pakete:1122 Fehler:0 Verloren:0 Überläufe:0 Fenster:0
          TX-Pakete:1122 Fehler:0 Verloren:0 Überläufe:0 Träger:0
          Kollisionen:0 Sendewarteschlangenlänge:1 
          RX-Bytes:96956 (96.9 KB)  TX-Bytes:96956 (96.9 KB)

xenbr0    Link encap:Ethernet  Hardware Adresse 56:9d:42:2c:2f:fc  
          inet Adresse:192.168.2.117  Bcast:192.168.2.255  Maske:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metrik:1
          RX-Pakete:0 Fehler:0 Verloren:0 Überläufe:0 Fenster:0
          TX-Pakete:0 Fehler:0 Verloren:0 Überläufe:0 Träger:0
          Kollisionen:0 Sendewarteschlangenlänge:1000 
          RX-Bytes:0 (0.0 B)  TX-Bytes:0 (0.0 B)

brctl show

Code: Select all

bridge name	bridge id		STP enabled	interfaces
xenbr0		8000.e03f49ac5c08	no		eno1


My regular internet connection is working.
powerhouse
Level 6
Level 6
Posts: 1144
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

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

Post by powerhouse »

Sorry, my mistake! You do NOT blacklist the USB or PCIE drivers! Try to bind the PCIE card to vfio-PCI by adding an entry to the respective configuration file.

If that doesn't work,use the following config file and function in the startup script:

/etc/vfio-pci.cfg

Code: Select all

0000:00:1a.0
0000:08:00.0
No blank lines!

And here the script/function you need to add to the VM startup script:

Code: Select all

configfile=/etc/vfio-pci.cfg

vfiobind() {
	dev="$1"
        vendor=$(cat /sys/bus/pci/devices/$dev/vendor)
        device=$(cat /sys/bus/pci/devices/$dev/device)
        if [ -e /sys/bus/pci/devices/$dev/driver ]; then
                echo $dev > /sys/bus/pci/devices/$dev/driver/unbind
        fi
        echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id
   
}
Notice that you also need to specify the PCIe device(s) in the qemu command with

Code: Select all

  -device vfio-pci,host=00:1a.0 \
  -device vfio-pci,host=08:00.0 \
You call that function using the following code in the startup script:

Code: Select all

	cat $configfile | while read line;do
	echo $line | grep ^# >/dev/null 2>&1 && continue
		vfiobind $line
	done
Here is my entire startup script:

Code: Select all

#!/bin/bash

configfile=/etc/vfio-pci.cfg
vmname="win10vm"

vfiobind() {
	dev="$1"
        vendor=$(cat /sys/bus/pci/devices/$dev/vendor)
        device=$(cat /sys/bus/pci/devices/$dev/device)
        if [ -e /sys/bus/pci/devices/$dev/driver ]; then
                echo $dev > /sys/bus/pci/devices/$dev/driver/unbind
        fi
        echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id
   
}

if ps -A | grep -q $vmname; then
	zenity --info --window-icon=info --timeout=15 --text="$vmname is already running." &
	exit 1

else

	cat $configfile | while read line;do
	echo $line | grep ^# >/dev/null 2>&1 && continue
		vfiobind $line
	done

# 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
chown kvm:kvm /tmp/my_vars.fd

taskset -c 0-9 qemu-system-x86_64 \
  -serial none \
  -parallel none \
  -nodefaults \
  -nodefconfig \
  -enable-kvm \
  -name $vmname,process=$vmname \
  -machine q35,accel=kvm,kernel_irqchip=on,mem-merge=off \
  -cpu host,kvm=off,hv_vendor_id=1234567890ab,hv_vapic,hv_time,hv_relaxed,hv_spinlocks=0x1fff \
  -smp 10,sockets=1,cores=5,threads=2 \
  -m 20G \
  -mem-path /run/hugepages/kvm \
  -mem-prealloc \
  -balloon none \
  -rtc base=localtime,clock=host \
  -vga none \
  -nographic \
  -soundhw hda \
  -device vfio-pci,host=02:00.0,multifunction=on \
  -device vfio-pci,host=02:00.1 \
  -device vfio-pci,host=00:1a.0 \
  -device vfio-pci,host=08:00.0 \
  -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=c \
  -drive id=disk0,if=virtio,cache=none,format=raw,aio=native,file=/dev/mapper/lm13-win10 \
  -drive id=disk1,if=virtio,cache=none,format=raw,aio=native,file=/dev/mapper/photos-photo_stripe \
  -drive id=disk2,if=virtio,cache=none,format=raw,aio=native,file=/dev/mapper/media-photo_raw \
  -netdev type=tap,id=net0,ifname=tap0,vhost=on \
  -device virtio-net-pci,netdev=net0,mac=00:16:3e:00:01:01
#  -drive file=/media/OS-backup/ISOs/win10.iso,id=isocd,format=raw,if=none -device scsi-cd,drive=isocd \
#  -drive file=/media/OS-backup/ISOs/virtio.iso,id=virtiocd,format=raw,if=none -device ide-cd,bus=ide.1,drive=virtiocd \

	exit 0
fi
Of course you cannot run that without adapting it to your hardware. Also, this script won't install Windows. You would need to uncomment the lines:

Code: Select all

#  -drive file=/media/OS-backup/ISOs/win10.iso,id=isocd,format=raw,if=none -device scsi-cd,drive=isocd \
#  -drive file=/media/OS-backup/ISOs/virtio.iso,id=virtiocd,format=raw,if=none -device ide-cd,bus=ide.1,drive=virtiocd \
and change the directory to point to the Windows installation media and the Virtio image.

Regarding networking: Never mind which way you make it work. If network-manager allows you to define a bridge, by all means use it.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
GregoriMarow

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

Post by GregoriMarow »

Now I did the following for testing. Regarding to your alternative solution:
I have filled this into /etc/rc.local (thanks to Cosmo)

echo "0000:05:00.0" > /sys/bus/pci/drivers/xhci_hcd/unbind
echo "0000:05:00.0" > /sys/bus/pci/drivers/vfio-pci/bind

and its set up on startup :)

02:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Device [1002:67df] (rev c7)
Subsystem: PC Partner Limited / Sapphire Technology Device [174b:e347]
Kernel driver in use: vfio-pci

02:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Device [1002:aaf0]
Subsystem: PC Partner Limited / Sapphire Technology Device [174b:aaf0]
Kernel driver in use: vfio-pci
Kernel modules: snd_hda_intel

05:00.0 USB controller [0c03]: Renesas Technology Corp. uPD720201 USB 3.0 Host Controller [1912:0014] (rev 03)
Kernel driver in use: vfio-pci
powerhouse
Level 6
Level 6
Posts: 1144
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

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

Post by powerhouse »

GregoriMarow wrote:Now I did the following for testing. Regarding to your alternative solution:
I have filled this into /etc/rc.local (thanks to Cosmo)

echo "0000:05:00.0" > /sys/bus/pci/drivers/xhci_hcd/unbind
echo "0000:05:00.0" > /sys/bus/pci/drivers/vfio-pci/bind

and its set up on startup :)

02:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Device [1002:67df] (rev c7)
Subsystem: PC Partner Limited / Sapphire Technology Device [174b:e347]
Kernel driver in use: vfio-pci

02:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Device [1002:aaf0]
Subsystem: PC Partner Limited / Sapphire Technology Device [174b:aaf0]
Kernel driver in use: vfio-pci
Kernel modules: snd_hda_intel

05:00.0 USB controller [0c03]: Renesas Technology Corp. uPD720201 USB 3.0 Host Controller [1912:0014] (rev 03)
Kernel driver in use: vfio-pci
It looks fine - just what you need. The Kernel modules are irrelevant.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
powerhouse
Level 6
Level 6
Posts: 1144
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

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

Post by powerhouse »

Just added a possible solution to AMD Crimson driver installation causing a BSOD. See under "Troubleshooting" towards the end of the how-to. Here is the external reference: https://www.redhat.com/archives/vfio-us ... 00153.html.

For those who are looking for more information on KVM VGA passthrough, here a link to the VFIO forum: https://www.redhat.com/archives/vfio-users/.

However, it would be nice if those who find help/solutions on other forums, to share them here.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
GregoriMarow

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

Post by GregoriMarow »

okay a small summary for all:

My main problem is, that I have a board with a z87 chipset not supporting vt-d and my board also has only one hdmi out for onboard graphics.
I unplugged my second GPU because they where put into the same IOMMU group and used Intel GPU for Linux. Main reason maybe that my CPU only has 16 PCIe Lanes and with two GPUs they will be shared 2x8.
This is for testing purposes only if the RX480 will work.
For the full support I will buy new hardware with more cores, ACS support, 40 PCIe lanes 6 cores and a chipset with vt-d support so that i can use 2 dedicated GPUs (one for linux, one for windows) and also passtrough my usb card.
At the moment this is not possible because the PCIe 2.0 lanes are from the z87 chipset.
So with z87 you can passthrough a GPU but you have to use the intel GPU for linux.
It is not possible to passthrough additional hardware.
In the startup script I had to replace q35 with pc otherwise vm will crash after some minutes.
Passmark rating was okay, only 2D and RAM performance need some work.
Downloading Battlefield 1 for testing.

If you want to know more about your Intel CPU or your Intel chipset visit: http://ark.intel.com
and use google picture search and try to find a diagram for your chipset. (e.g z87 diagram)

**** edit: **********
Battlefield 1 with ultra settings is playable. Can't find major differences to native windows. maybe a little bit more loading time of maps.
powerhouse
Level 6
Level 6
Posts: 1144
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

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

Post by powerhouse »

Thanks GregoriMarow for your update!

VT-d does work in your case, it's just a lousy implementation. People with the same Z87 board who plan to use the IGD (integrated Intel graphics) for Linux can still pass through a dedicated graphics card. A very popular solution for keyboard/mouse support is synergy, which is now a commercial project, but worth the money.

Another possibility to improve matters is to build your own kernel with the ACS patch, which should help separate the GPUs into different IOMMUs and allow you to pass through a USB controller as a PCI device. Your hardware will then more or less reach its limits with 2 graphics cards installed.

In your case, wanting to run 2 discrete graphics cards and perhaps pass through a PCI controller, a hardware upgrade does make sense. A Z170 chipset board with a i7-6700K does - on paper at least - look like a possible upgrade. The other path could be a X99 based board. Note that Skylake series processors presented some new challenges, but to my understanding they are solvable (see https://forum.level1techs.com/t/gta-v-o ... gh/87440/2). The step that did the trick with Intel Skylake CPUs is the following addition / change to the grub line:

Code: Select all

i915.preliminary_hw_support=1 intel_iommu=on intel_iommu=igfx_off pcie_acs_override=downstream
In particular the option "intel_iommu=igfx" which, as far as I understand, removes the internal GPU from IOMMU. Note that the above mentioned tutorial uses a 4.1 kernel and a lot has changed (see below!).

Another important piece of info I just discovered (source: https://forum.level1techs.com/t/play-ga ... e/108981/1):
UPDATE:
Kernel 4.8 added better support for IOMMU group separation. If your GPU's IOMMU group has another device in it with the address 00:01.0 then you don't need the ACS patch.
Both Linux Mint 18 and 18.1 allow you to upgrade the kernel to 4.8. Open Update Manager --> View --> Linux kernels. You can choose the latest 4.8 kernel. It's best to make a backup before upgrading - who knows. I found that the new 4.8 kernels break ndiswrapper and some other packages, none of which I need.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
solacelost

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

Post by solacelost »

I just spent quite a long time trying to figure out why my audio seemed to work sometimes, but not most of the time. I was getting tons of errors about having permission to bind to the socket over and over. Permissions? For root? What the hell... Anyways, the default configuration appears to use cookies to secure pulse sockets as if file permissions weren't enough to keep people away from them.

Adding the following lines (one of which you included in your own script, but not in the walkthrough) to my startup script has brought my PulseAudio success rate to 100%. I don't know why it was anything before, but there you have it.

Code: Select all

	export QEMU_PA_SERVER=/run/user/1000/pulse/native
	export PULSE_COOKIE=/home/james/.config/pulse/cookie
Thanks a ton for the write-up. I see you're still actively working on it, and it's bound to be one of the best around before long.
powerhouse
Level 6
Level 6
Posts: 1144
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

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

Post by powerhouse »

Thanks for your input, solacelost! I've updated my how-to yo include the pulseaudio configuration I use. It's not perfect, at least not in my system, but it works more or less. When I have time I will add your cockies part to the troubleshooting section.

I'm glad the tutorial worked for you! Enjoy and, if possible, share some benchmarks (see link in tutorial).
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
powerhouse
Level 6
Level 6
Posts: 1144
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

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

Post by powerhouse »

Glossary

Here a few terms used in the how-to:
  • host: This is the operating system installed on the PC, in our case Linux Mint. This operating system "hosts" the VM (see below).
  • VM: VM is the abbreviation of Virtual Machine that runs on a host (see above). A virtual machine is an emulation of a real computer that runs an operating system and application software. In this tutorial we use full virtualization to install an unmodified Windows 10 operating system inside a VM. This operating system running in a VM is often referred to as "guest OS", the VM simply as "guest".
  • hardware-assisted virtualization: Modern CPU architectures include features to support / assist virtualization in hardware, that is in the CPU. KVM, Xen, VMware and other virtualization platforms are able to utilize this hardware to improve performance. In our tutorial, hardware-assisted virtualization features including VT-x and VT-d on Intel platforms or AMD-V or SVM on AMD platforms are a basic requirement. Before purchasing a CPU and/or motherboard, make sure these features are supported! See also VFIO below.
  • hypervisor or virtualization platform: A hypervisor is (usually) a software platform that creates and runs virtual machines (VM). The hypervisor runs on a computer called the host. A distinction is made between type 1 and type 2 hypervisors.
  • type 1 hypervisor: also called bare-metal hypervisor, this hypervisor runs directly on the hardware and controls both the hardware and the guest operating system(s). Type 1 hypervisors include Xen, Oracle VM Server for SPARC, Oracle VM Server for x86, the Citrix XenServer, Microsoft Hyper-V and VMware ESX/ESXi.
  • type 2 hypervisor: this hypervisor runs on a conventional operating system, just like any other computer program. Type 2 hypervisors include VMware Workstation, VMware Player, VirtualBox, Parallels Desktop for Mac and QEMU.
  • KVM: Stands for Kernel-based Virtual Machine. KVM effectively converts the host operating system into a type 1 hypervisor. However, since the host OS still functions as a regular Linux distribution, KVM may also be categorized as a type 2 hypervisor.
  • PCI passthrough (or passthru): This is a technique which allows the hypervisor to pass through a PCI device to the VM. The guest OS - in our case Windows 10 - then uses its own hardware driver to access the device directly.
  • VGA passthrough: This is a specialized form of PCI passthrough for graphics cards / GPU. These devices are more complex and so is the interaction with them. There are two forms of VGA passthrough:
    VGA passthrough to GPU as primary adapter: The VM boots and uses the passed through graphics card as its primary or only graphics adapter. This tutorial uses primary passthrough in combination with a special UEFI BIOS from the OVMF project (see http://www.tianocore.org/ovmf/ for more info). This latter method is also referred to as "VGA passthrough via OVMF", "legacy-free VGA passthrough", or "UEFI VGA passthrough".
    VGA passthrough to GPU as secondary adapter: Also referred to as legacy VGA passthrough. The VM first boots using the SeaBIOS virtual Cirrus adapter as the primary graphics adapter (you see the BIOS screen and the Windows boot logo in a window on the Linux desktop). After installation of the graphics driver under Windows and subsequent reboot of the VM, the VM will start with the SeaBIOS and then switch to the secondary graphics adapter at some stage of it's boot process.
  • IOMMU: The input–output memory management unit (IOMMU) is a memory management unit (MMU) that connects a direct-memory-access–capable (DMA-capable) I/O bus to the main memory. The IOMMU maps device-visible virtual addresses (also called device addresses or I/O addresses in this context) to physical addresses. Intel designates IOMMU technology as Virtualization Technology for Directed I/O, abbreviated VT-d. The virtualization solution described in this tutorial relies on IOMMU. See also VFIO below.
  • Qemu: Is a short for "Quick Emulator" and provides a hypervisor to virtualize hardware. Without KVM, it runs as a single process and emulates a complete computer system to the VM. Together with KVM it supports hardware-assisted virtualization which can greatly improve performance.
  • hugepages: Is a special application of "memory pages" or "virtual pages". Instead of managing thousands, perhaps millions of tiny 4 Kilobyte pages, hugepages allow the definition of larger pages (e.g. 2 Megabyte or 4 Megabyte), reducing the page table size and thus increasing the lookup speed. Hugepages are not a requirement for VGA passthrough, but they can help improve the performance of Virtual Machines.
  • VFIO: Is the abbreviation for Virtual Function I/O. The VFIO driver is an IOMMU/device agnostic framework for exposing direct device access to userspace in a secure, IOMMU protected environment. In other words, this allows safe, non-privileged, userspace drivers to access the hardware (see https://www.kernel.org/doc/Documentation/vfio.txt). IOMMU provides isolation of the devices, but not always at the granularity of a single device. Devices are collected in IOMMU groups - each group providing isolation of its devices from other IOMMU groups. Some CPU / motherboard chipsets provide good isolation, establishing an IOMMU group for each distinct device, whereas others provide little isolation, grouping many different devices into a single IOMMU group. In the latter case, the ACS (Access Control Services) kernel patch may come to the rescue.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
thunder5860

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

Post by thunder5860 »

I think I should add that Synergy developers release source code under GPL and night builds without encryption are free. If you want to use encrypted connections, you should build Synergy from source. Worked for me while I was doing my setup couple of years ago.
driz

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

Post by driz »

i followed these directions and my system works perfectly. I tried to make another system for my other daughter (i had 2 cores avail, 6G ram and another radeon video card (the host is headless)) both video cards are claimed by vfio-pci and my script is the same except for the changes to use the proper card (and changing tun0 to tun1 for the nic)
also thank you for the excellent write up, i was beating my head on vfio for 4 days before i found your thread and got it working very quickly. big change from how i used to run my kvm guests and MUCH faster!

I figured i would share my configs and build to give back

Code: Select all

Motherboard: ASRock Micro ATX H170M PRO4
CPU: Intel 3.7GHz Core i3-6100
RAM: Patriot Extreme Performance 8G PC4-25600 (3200MHz) Viper Elite Series (i just ordered a 2nd kit to give 16G total)
Video: 2x MSI AMD Radeon R7 240 2GB DDR3 Low Profile PCIE
Audio: 2x Sabrent USB External Stero Sound Adapter (C-Media)
Storage: 2x Adata SU800 128G 3D-NAND 2.5" SATA3 SSD
Host Storage: 1x NVMe 250G Samsung 960 EVO
Sadly, there appears to be only 1 USB controller in the system so i had to passthrough devices themselves.

Code: Select all

-[0000:00]-+-00.0  Intel Corporation Skylake Host Bridge/DRAM Registers [8086:190f]
           +-01.0-[01]--+-00.0  Advanced Micro Devices, Inc. [AMD/ATI] Oland PRO [Radeon R7 240/340] [1002:6613]
           |            \-00.1  Advanced Micro Devices, Inc. [AMD/ATI] Cape Verde/Pitcairn HDMI Audio [Radeon HD 7700/7800 Series] [1002:aab0]
           +-02.0  Intel Corporation HD Graphics 530 [8086:1912]
           +-14.0  Intel Corporation Sunrise Point-H USB 3.0 xHCI Controller [8086:a12f]
           +-14.2  Intel Corporation Sunrise Point-H Thermal subsystem [8086:a131]
           +-16.0  Intel Corporation Sunrise Point-H CSME HECI #1 [8086:a13a]
           +-17.0  Intel Corporation Sunrise Point-H SATA controller [AHCI mode] [8086:a102]
           +-1b.0-[02]--
           +-1c.0-[03]--
           +-1c.4-[04]--+-00.0  Advanced Micro Devices, Inc. [AMD/ATI] Oland PRO [Radeon R7 240/340] [1002:6613]
           |            \-00.1  Advanced Micro Devices, Inc. [AMD/ATI] Cape Verde/Pitcairn HDMI Audio [Radeon HD 7700/7800 Series] [1002:aab0]
           +-1d.0-[05]--
           +-1f.0  Intel Corporation Sunrise Point-H LPC Controller [8086:a144]
           +-1f.2  Intel Corporation Sunrise Point-H PMC [8086:a121]
           +-1f.3  Intel Corporation Sunrise Point-H HD Audio [8086:a170]
           +-1f.4  Intel Corporation Sunrise Point-H SMBus [8086:a123]
           \-1f.6  Intel Corporation Ethernet Connection (2) I219-V [8086:15b8]

Code: Select all

01:00.0 0300: 1002:6613 (rev 87)
        Subsystem: 1462:8094
        Kernel driver in use: vfio-pci
        Kernel modules: radeon
01:00.1 0403: 1002:aab0
        Subsystem: 1462:aab0
        Kernel driver in use: vfio-pci
        Kernel modules: snd_hda_intel
04:00.0 0300: 1002:6613 (rev 87)
        Subsystem: 1462:8094
        Kernel driver in use: vfio-pci
        Kernel modules: radeon
04:00.1 0403: 1002:aab0
        Subsystem: 1462:aab0
        Kernel driver in use: vfio-pci
        Kernel modules: snd_hda_intel
I include the radeon driver in /etc/initramfs-tools/modules
I blacklist the radeon driver in /etc/modprobe.d/blacklist.conf

i downloaded the latest ovmf from git and modified /etc/libvirt/qemu.conf to have

Code: Select all

nvram = [
        "/srv/ovmf-x64/OVMF_CODE-pure-efi.fd:/srv/ovmf-x64/OVMF_VARS-pure-efi.fd"
]
my grub commandline is as follows:

Code: Select all

GRUB_CMDLINE_LINUX_DEFAULT="rd.driver.pre=vfio-pci quiet splash intel_iommu=on vfio_iommu_type1.allow_unsafe_interrupts=1 iommu=pt"
There are a few items to add in here since i also have a 915 for the onboard skylake video, but not including those commands had no negatives that I've seen as of yet.

i load into /etc/modules the following

Code: Select all

vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd
vhost-net
kvm
kvm_intel
/etc/vfio-pci1.cfg

Code: Select all

0000:01:00.0
0000:01:00.1
/etc/vfio-pci2.cfg

Code: Select all

0000:04:00.0
0000:04:00.1
My /etc/network/interfaces is as such:

Code: Select all

auto br0
iface br0 inet dhcp
  bridge_ports enp0s31f6
  bridge_stp off
  bridge_maxwait 0
  bridge_fd 0
  post-up ip link set dev enp0s31f6 mtu 9000
in /etc/udev/rules.d/70-persistent-net.rules i have

Code: Select all

SUBSYSTEM=="net", ACTION=="add", KERNEL=="tap*", ATTR{mtu}="9000"
my launch script for system 1 is

Code: Select all

#!/bin/bash

configfile=/etc/vfio-pci1.cfg
vmname="system1"

vfiobind() {
   dev="$1"
        vendor=$(cat /sys/bus/pci/devices/$dev/vendor)
        device=$(cat /sys/bus/pci/devices/$dev/device)
        if [ -e /sys/bus/pci/devices/$dev/driver ]; then
                echo $dev > /sys/bus/pci/devices/$dev/driver/unbind
        fi
        echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id

}


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

else

   cat $configfile | while read line;do
   echo $line | grep ^# >/dev/null 2>&1 && continue
      vfiobind $line
   done


if [ ! -f /tmp/system1.fd ]; then
  cp /srv/ovmf-x64/OVMF_VARS-pure-efi.fd /tmp/system1.fd
fi

taskset -c 0,3 qemu-system-x86_64 \
  -name $vmname,process=$vmname \
  -serial none \
  -parallel none \
  -machine type=q35,accel=kvm \
  -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time \
  -smp 2,sockets=1,cores=1,threads=2 \
  -enable-kvm \
  -m 3G \
  -mem-prealloc \
  -balloon none \
  -rtc clock=host,base=localtime \
  -vga none \
  -nographic \
  -usb -usbdevice host:040b:2000 -usbdevice host:046d:c01e -usbdevice host:0d8c:0014 -usbdevice host:046d:0819 \
  -device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1 \
  -device vfio-pci,host=01:00.0,bus=root.1,addr=00.0,multifunction=on,romfile=/srv/rom1.rom \
  -device vfio-pci,host=01:00.1,bus=root.1 \
  -drive if=pflash,format=raw,readonly,file=/srv/ovmf-x64/OVMF_CODE-pure-efi.fd \
  -drive if=pflash,format=raw,file=/tmp/system1.fd \
  -boot order=c \
  -device virtio-scsi-pci,id=scsi \
  -drive file=/dev/sdc1,id=disk0,if=none,format=raw,cache=none,aio=native \
  -device scsi-hd,drive=disk0 \
  -netdev type=tap,id=net0,ifname=tap0,vhost=on \
  -device virtio-net-pci,netdev=net0,mac=52:54:00:ea:c8:8d

#  -mem-path /dev/hugepages1 \

exit 0
fi
system2 is

Code: Select all

#!/bin/bash

configfile=/etc/vfio-pci2.cfg
vmname="system2"

vfiobind() {
   dev="$1"
        vendor=$(cat /sys/bus/pci/devices/$dev/vendor)
        device=$(cat /sys/bus/pci/devices/$dev/device)
        if [ -e /sys/bus/pci/devices/$dev/driver ]; then
                echo $dev > /sys/bus/pci/devices/$dev/driver/unbind
        fi
        echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id

}


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

else

   cat $configfile | while read line;do
   echo $line | grep ^# >/dev/null 2>&1 && continue
      vfiobind $line
   done


if [ ! -f /tmp/system2.fd ]; then
  cp /srv/ovmf-x64/OVMF_VARS-pure-efi.fd /tmp/system2.fd
fi

taskset -c 1,2 qemu-system-x86_64 \
  -name $vmname,process=$vmname \
  -serial none \
  -parallel none \
  -machine type=q35,accel=kvm \
  -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time \
  -smp 2,sockets=1,cores=1,threads=2 \
  -enable-kvm \
  -m 3G \
  -mem-prealloc \
  -balloon none \
  -rtc clock=host,base=localtime \
  -vga none \
  -nographic \
  -usb -usbdevice host:04f2:0939 -usbdevice host:04f2:0833 \
  -device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1 \
  -device vfio-pci,host=04:00.0,bus=root.1,addr=00.0,multifunction=on,romfile=/srv/rom2.rom \
  -device vfio-pci,host=04:00.1,bus=root.1 \
  -drive if=pflash,format=raw,readonly,file=/srv/ovmf-x64/OVMF_CODE-pure-efi.fd \
  -drive if=pflash,format=raw,file=/tmp/system2.fd \
  -boot order=c \
  -device virtio-scsi-pci,id=scsi \
  -drive file=/dev/sdd1,id=disk0,if=none,format=raw,cache=none,aio=native \
  -device scsi-hd,drive=disk0 \
  -netdev type=tap,id=net0,ifname=tap1,vhost=on \
  -device virtio-net-pci,netdev=net0,mac=52:54:00:ea:c8:8e

#  -mem-path /dev/hugepages2 \

exit 0
fi
i create a screen session for each system and launch from within screen. This gives me the qemu console so i can wake the system up from sleep and such if needed.

I plan to reintroduce hugepages once i get the extra memory installed, although the guide here doesnt go into detail on using hugepages for 2 guests, you can simply add it to fstab from what i can tell and point each system to its relevant hugepage mount point.
---------------------------------------------------------------------
Issue1:Resolved!

that all said, the second system won't use the video card. i deleted the vga none line and built the whole system in qemu and in windows, i dont even see the video card listed in any state. It seems like the pci passthrough is being completely ignored. the strange thing is, it worked once and never again. Any thoughts come to mind?

got my second system issues resolved (rebooted host...)

---------------------------------------------------------------------
Issue2:
anyway, both systems are running great, my windows score on each is a 5.1. each system has 3G ram, 1core and 2threads (pinned) and a radeon r7 240 3G ddr3. I pass through a usb audio device, mouse, and keyboard to each system. for disk, each system has an SSD passed through except windows detects it as a thin provisioned disk (how do i fix this???)

I passed the SSD through as such:

Code: Select all

  -device virtio-scsi-pci,id=scsi \
  -drive file=/dev/sdc1,id=disk0,if=none,format=raw,cache=none,aio=native \
  -device scsi-hd,drive=disk0 \
and

Code: Select all

  -device virtio-scsi-pci,id=scsi \
  -drive file=/dev/sdd1,id=disk0,if=none,format=raw,cache=none,aio=native \
  -device scsi-hd,drive=disk0 \
for each machine respectively. I'm assuming i did something wrong here, but setting up lvm didn't interest me as I dont need snapshots or growth potential.

---------------------------------------------------------------------
Issue3: Resolved!

My next issue (which really doesnt matter much) is MTU

the host nic is 9000MTU, the br0 is 9000MTU, until a tap device joins, then it drops to 1500. I'm not sure how to get the tap device MTU set, but i'm actively researching it.

using this guide:
https://linuxaleph.blogspot.com/2013/01 ... guest.html

i manually resolved the issue, kid's are on their VMs so i cant test persistence yet.

---------------------------------------------------------------------
Issue4:
another issue is a slight crackle in the audio, no delays.. just crackly. im passing through the usb device via

Code: Select all

-usb -usbdevice host:046d:0819
I'm still researching this particular issue.

---------------------------------------------------------------------
Issue5:
aside from all those, i've trained my kids to put their computers to sleep when they finish, which they do... to my dismay since they can't wake the system up! i have to go into qemu and

Code: Select all

sendkeys ctrl 100
a couple times and it wakes up. I checked the ovmf config to see if there was a mouse wakeup event, but i found none.
powerhouse
Level 6
Level 6
Posts: 1144
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

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

Post by powerhouse »

thunder5860 wrote:I think I should add that Synergy developers release source code under GPL and night builds without encryption are free. If you want to use encrypted connections, you should build Synergy from source. Worked for me while I was doing my setup couple of years ago.
Thanks thunder5860, I will see to incorporate that into the how-to.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
powerhouse
Level 6
Level 6
Posts: 1144
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

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

Post by powerhouse »

Dear driz, this is awesome! Many thanks for sharing your configuration and setup. Very helpful indeed!

Now to your issues:

Issue2:

...for disk, each system has an SSD passed through except windows detects it as a thin provisioned disk (how do i fix this???)

Answer: Did you follow Part 8 of my how-to, the steps where you detect an SSD inside Windows?

Issue4:
another issue is a slight crackle in the audio, no delays.

Answer: I'm afraid I have similar issues. I used to pass through an entire USB controller, but wasn't very happy with the results. Now I use PulseAudio together with the -soundhw hda option. I also have this crackling sound. It never really bothered me so I haven't spent time on that. Still hoping that someone finds the magic bullet.

Issue5:
aside from all those, i've trained my kids to put their computers to sleep when they finish, which they do... to my dismay since they can't wake the system up!

If possible, disable sleep and hibernation in Windows. It doesn't make sense to use that in a VM, as the underlying PC keeps running. Also make sure to disable fast boot in Windows.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
powerhouse
Level 6
Level 6
Posts: 1144
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

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

Post by powerhouse »

Some information on kvm disk drive configurations can be found here:

https://github.com/qemu/qemu/blob/maste ... ce-use.txt - latest Qemu syntax for block devices (incl. drives).

https://www.redhat.com/archives/vfio-us ... 00009.html - Qemu syntax for defining drives.

https://m.reddit.com/r/VFIO/comments/43 ... _settings/ - a discussion about optimal drive settings under kvm.

I hope this helps.
Last edited by powerhouse on Thu Aug 03, 2017 3:07 pm, edited 2 times in total.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
driz

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

Post by driz »

powerhouse wrote:Dear driz, this is awesome! Many thanks for sharing your configuration and setup. Very helpful indeed!

Now to your issues:

Issue2:

...for disk, each system has an SSD passed through except windows detects it as a thin provisioned disk (how do i fix this???)

Answer: Did you follow Part 8 of my how-to, the steps where you detect an SSD inside Windows?

Issue4:
another issue is a slight crackle in the audio, no delays.

Answer: I'm afraid I have similar issues. I used to pass through an entire USB controller, but wasn't very happy with the results. Now I use PulseAudio together with the -soundhw hda option. I also have this crackling sound. It never really bothered me so I haven't spent time on that. Still hoping that someone finds the magic bullet.

Issue5:
aside from all those, i've trained my kids to put their computers to sleep when they finish, which they do... to my dismay since they can't wake the system up!

If possible, disable sleep and hibernation in Windows. It doesn't make sense to use that in a VM, as the underlying PC keeps running. Also make sure to disable fast boot in Windows.
Hey Powerhouse, thanks for replying!
I did indeed follow part 8, but i did not use an image like your guide suggested, i created a partition and then formatted it in windows. Windows detected it as a thin provisioned disk. I'm going to try passing the whole device without a partition on it.

sadly, my asrock motherboard has 1 controller for all usb ports so it ruined the possibility of passing through USB (at least without adding in a PCIE usb board). Passing sound through to the host is also not feasible since both girls play concurrently and would have independent audio streams. Luckily, they're young and don't notice the crackle... i do and it kills me :D

I actually ended up just letting them put their computers to sleep and I turn them on when needed. It gives me a little more control over when they can use the PC. (the girls are 7 and 4) so i think it's good :D
steakikan

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

Post by steakikan »

Hi, I have issue in qemu keep hanging/stuck and when I check the cpu usage per thread it is 100% when this happen. I suspect it is something to do with the USB card I pass through but can't be too sure about it ( I have used 2 differect add-on card with 2 different chipset, ASmedia and NEC, and problem persist). Is there anyway to find out what might be the problem? Thanks
driz

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

Post by driz »

steakikan wrote:Hi, I have issue in qemu keep hanging/stuck and when I check the cpu usage per thread it is 100% when this happen. I suspect it is something to do with the USB card I pass through but can't be too sure about it ( I have used 2 differect add-on card with 2 different chipset, ASmedia and NEC, and problem persist). Is there anyway to find out what might be the problem? Thanks
I actually made some changes to my above setup and encountered this same issue. You didnt post any useful info, but i'll post mine.

I recently changed from passing through a partition eg.

Code: Select all

 -device virtio-scsi-pci,id=scsi \
  -drive file=/dev/sdd1,id=disk0,if=none,format=raw,cache=none,aio=native \
  -device scsi-hd,drive=disk0,bootindex=2 \
to

Code: Select all

 -device virtio-scsi-pci,id=scsi \
  -drive file=/dev/sdd,id=disk0,if=none,format=raw,cache=none,aio=native \
  -device scsi-hd,drive=disk0,bootindex=2 \
upon completing OS installation (windows 10 pro) my cpu would spike to 100% and completely lock up the vm. Aside from adding 8G of memory and increasing the ram allocation to my guests, this was the only change made. My other guest which still uses a partition does not suffer this issue. I'm actively rebuilding vm2 using a partition again to test. Assuming success, i will attempt to pass an lvm volume through to the guest and see how that works. My intent is to make windows recognize the ssd rather than a thin provisioned disk.

I also built qemu from git, previously i was on 2.6, im now on 2.8.50 and experienced the same issue. I'm not sure why passing through the physical disk reacted this way. I may play with caching and aio for testing.


as it turns out, the second guest continues to use 100% cpu after completing the windows install... the script to launch is as shown above and matches the working system1 script aside from using different usb devices and a different video card. I'm at a loss.

somehow, reseating the graphics card did the trick.. both systems are up and functional again. I am back to passing the physical disk through via

Code: Select all

 -device virtio-scsi-pci,id=scsi \
 -drive file=/dev/sdd,id=disk0,if=none,format=raw,cache=none,aio=native \
 -device scsi-hd,drive=disk0,bootindex=2 \
@powerhouse : That being said, I got the same result (windows10 not detecting an ssd) by passing through the physical disk rather than a partition.

click to expand pictures
I ran winsat formal
Image
checked the status
Image no change
here's additional info
Image
GregoriMarow

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

Post by GregoriMarow »

@driz:
hi, i had the same when checking it in defragmentation.
I started analysing and then it was displayed as SSD.

@steakikan:
Hi, I have issue in qemu keep hanging/stuck and when I check the cpu usage per thread it is 100% when this happen. I suspect it is something to do with the USB card I pass through but can't be too sure about it ( I have used 2 differect add-on card with 2 different chipset, ASmedia and NEC, and problem persist). Is there anyway to find out what might be the problem? Thanks
Maybe try to start the VM without the USB Cards to be sure?
Did you get any error messages in the terminal or is it just hanging?
powerhouse
Level 6
Level 6
Posts: 1144
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

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

Post by powerhouse »

@driz: thin provisioned disk

Did you format the disk BEFORE you installed the WIndows VM?

As a rule, do NOT format any drive or media that is to hold the VM. If you plan to use /dev/sdd or the partition /dev/sdd1 to hold your Windows VM, make sure it is not formated. If necessary, delete the partition and recreate it without specifying a format.

When you install the Windows VM, Windows should take care of the partitioning and formating.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
Locked

Return to “Virtual Machines”