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
MiniDigger

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

Post by MiniDigger »

Hello,
first, thanks for that awesome tutorial. I was able to follow it very easy and you explained the steps very well.
However I am stuck now. VFIO doesn't want to grab my gpu (exactly like in trouble shooting section).
I ran the steps in section 9 but that doesn't seem to help me:

Code: Select all

# dmesg | grep -i vfio
[    3.125121] VFIO - User Level meta-driver version: 0.3

Code: Select all

# lspci -k | grep -i -A 3 vga
00:02.0 VGA compatible controller: Intel Corporation Sky Lake Integrated Graphics (rev 06)
	DeviceName:  Onboard IGD
	Subsystem: Gigabyte Technology Co., Ltd Skylake Integrated Graphics
	Kernel modules: i915
--
01:00.0 VGA compatible controller: NVIDIA Corporation GM204 [GeForce GTX 970] (rev a1)
	Subsystem: Micro-Star International Co., Ltd. [MSI] GM204 [GeForce GTX 970]
	Kernel modules: nvidiafb, nouveau
01:00.1 Audio device: NVIDIA Corporation GM204 High Definition Audio Controller (rev a1)
in your case it was the nvidia driver preventing VFIO from grabbing the gpu. that doesn't seem to be the case for me.
what could this be caused by?
below some info that could help:

Code: Select all

# lsmod | grep vfio
vfio_pci               40960  0
irqbypass              16384  2 kvm,vfio_pci
vfio_virqfd            16384  1 vfio_pci
vfio_iommu_type1       20480  0
vfio                   28672  2 vfio_iommu_type1,vfio_pci
content of /etc/initramfs-tools/modules

Code: Select all

vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd
vhost-net
content of /sbin/vfio-pci-override-vga.sh

Code: Select all

#!/bin/sh

DEVS="0000:01:00.0 0000:01:00.1"

for DEV in $DEVS; do
    echo "vfio-pci" > /sys/bus/pci/devices/$DEV/driver_override
done

modprobe -i vfio-pci
content of /etc/modprobe.d/local.cfg

Code: Select all

install vfio-pci /sbin/vfio-pci-override-vga.sh
grub (added the nouveau.blacklist=1 because a friend suggested that, didn't help, i915.enable_hd_vgaarb=1 comes from http://vfio.blogspot.de/2014/08/vfiovga-faq.html)

Code: Select all

GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=10
#GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT_STYLE=countdown
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="i915.enable_hd_vgaarb=1 nouveau.modeset=0 nouveau.blacklist=1 quiet nomodeset intel_iommu=on"
GRUB_CMDLINE_LINUX=""

Code: Select all

# lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Sky Lake Integrated Graphics (rev 06)
01:00.0 VGA compatible controller: NVIDIA Corporation GM204 [GeForce GTX 970] (rev a1)
I heard that there are problems with skylake and linux in general, thats why I upgraded to kernel 4.7.5

would appreciate every hint in the right direction
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 »

Hello minidigger:

1. Make sure you made the script executable:

Code: Select all

chmod 755 /sbin/vfio-pci-override-vga.sh
2. Update the initramfs!

3. Reboot, then go into Driver Manager and check which driver is bound to your graphics card.

You are using the Intel IDG graphics for Linux. If you want to pass through an Nvidia card, make sure you didn't install the Nvidia proprietary driver. Same goes for AMD.

EDIT: The following is incorrect:
Once you made sure there are no drivers binding to your graphics card, and the vfio script is executed, I suppose it has to do with the Intel VGA arbiter bug.
You need to have the vga arbiter patch applied to the kernel and enable it in grub (suppose you did, as mentioned in your post).

Unfortunately I'm unable to reproduce this since my hardware is different. I'm also not sure if kernel 4.7.5 has the vga arbiter patch. Did you read about that?
As long as you use UEFI boot using the OVMF BIOS, you do not need the i915 vga arbiter patch. Here a quote from the developer:
"...the i915 vga arbiter patch is necessary any time you have host Intel graphics and make use of the x-vga=on option." Using OVMF we bypass VGA.

Please shortly summarize your hardware, and post your /etc/default/grub file. You did run update-grub?
Last edited by powerhouse on Sat Oct 01, 2016 12:46 pm, edited 1 time in total.
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 »

@MiniDigger: Are you trying this tutorial on a laptop? I've updated some parts of the tutorial and added a little info to the troubleshooting section.

Looking at the information you gave, it seems the vfio-pci driver doesn't bind to the graphics card (02:00.0 in your case). Check each point I mentioned above, plus this one:

- Boot and enter the BIOS (usually by pressing DEL or similar): look for boot VGA and make sure that you selected the IGD (Intel graphics) as boot graphics device! Save and boot.

Hope it works.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
mcaron1234

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

Post by mcaron1234 »

Thank you for the very helpful tutorial!

I have a question about the location of the ovmf files. I was checking the paths and settings in windows10vm.sh and I went to verify this line:

Code: Select all

-drive if=pflash,format=raw,readonly,file=/usr/share/edk2.git/ovmf-x64/OVMF_CODE-pure-efi.fd
I installed ovmf with sudo apt-get install ovmf, but it looks like you have a version from git. Did you build it or install it from a different source? I'm not sure how to modify this line to match how the repository version installs.

Edit: I was able to overcome this by installing the ovmf version found here https://www.kraxel.org/repos/jenkins/edk2/ and coveting the .rpm to a deb file using the instructions found here: http://www.thegeekstuff.com/2010/11/ali ... -examples/

I have a new problem: qemu starts but there is not output via my passed through graphics card, and when I quit qemu I get the following error:

Code: Select all

./windows10vm.sh: line 33: -device: command not found
lines 33 and 34 of my windows10vm.sh file are:

Code: Select all

  -device vfio-pci,host=01:00.0,multifunction=on \
  -device vfio-pci,host=01:00.1 \
which corresponds to:

Code: Select all

lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Sky Lake Integrated Graphics (rev 06)
01:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Tahiti XT [Radeon HD 7970/8970 OEM / R9 280X]
and:

Code: Select all

lspci -nn | grep 01:00.
01:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Tahiti XT [Radeon HD 7970/8970 OEM / R9 280X] [1002:6798]
01:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Tahiti XT HDMI Audio [Radeon HD 7970 Series] [1002:aaa0]
Any idea what is causing that error?
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 »

mcaron1234 wrote:Thank you for the very helpful tutorial!

I have a question about the location of the ovmf files. I was checking the paths and settings in windows10vm.sh and I went to verify this line:

Code: Select all

-drive if=pflash,format=raw,readonly,file=/usr/share/edk2.git/ovmf-x64/OVMF_CODE-pure-efi.fd
I installed ovmf with sudo apt-get install ovmf, but it looks like you have a version from git. Did you build it or install it from a different source? I'm not sure how to modify this line to match how the repository version installs.
You are totally right - my mistake. I modified my tutorial when switching to Linux Mint 18, as there is no need to use OVMF from git. I forgot to correct the script. I just modified the script in my tutorial, so now it should be OK. Here is the corrected version:

Code: Select all

#!/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

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

qemu-system-x86_64 \
  -name $vmname,process=$vmname \
  -machine type=q35,accel=kvm \
  -cpu host,kvm=off \
  -smp 4,sockets=1,cores=2,threads=2 \
  -enable-kvm \
  -m 4G \
  -mem-path /run/hugepages/kvm \
  -mem-prealloc \
  -balloon none \
  -rtc clock=host,base=localtime \
  -vga none \
  -nographic \
  -serial none \
  -parallel none \
  -soundhw hda \
  -usb -usbdevice host:045e:076c -usbdevice host:045e:0750 \
  -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=/media/user/win.img \
  -drive file=/home/user/ISOs/win10.iso,id=isocd,format=raw,if=none -device scsi-cd,drive=isocd \
  -drive file=/home/user/Downloads/virtio-win-0.1.112.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
Modify your script to match the above - you need to replace two lines so they read like this:

Code: Select all

cp /usr/share/OVMF/OVMF_VARS.fd /tmp/my_vars.fd
  -drive if=pflash,format=raw,readonly,file=/usr/share/OVMF/OVMF_CODE.fd \
If you used OVMF from git, you need to reinstall OVMF via Synaptic. That should replace the git version.
mcaron1234 wrote:Edit: I was able to overcome this by installing the ovmf version found here https://www.kraxel.org/repos/jenkins/edk2/ and coveting the .rpm to a deb file using the instructions found here: http://www.thegeekstuff.com/2010/11/ali ... -examples/
That is what I was in fact using all the time. But it is not necessary and can be removed. The standard OVMF package works fine.
mcaron1234 wrote:I have a new problem: qemu starts but there is not output via my passed through graphics card, and when I quit qemu I get the following error:

Code: Select all

./windows10vm.sh: line 33: -device: command not found
lines 33 and 34 of my windows10vm.sh file are:

Code: Select all

  -device vfio-pci,host=01:00.0,multifunction=on \
  -device vfio-pci,host=01:00.1 \
which corresponds to:

Code: Select all

lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Sky Lake Integrated Graphics (rev 06)
01:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Tahiti XT [Radeon HD 7970/8970 OEM / R9 280X]
and:

Code: Select all

lspci -nn | grep 01:00.
01:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Tahiti XT [Radeon HD 7970/8970 OEM / R9 280X] [1002:6798]
01:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Tahiti XT HDMI Audio [Radeon HD 7970 Series] [1002:aaa0]
Any idea what is causing that error?
There are two possibilities I can think of:
1. Check the line above and see if it ends with a "\"
2. Check the "/sbin/vfio-pci-override-vga.sh" script. Make sure you
A. changed the PCI bus ID to 0000:01:00.0 and 0000:01:00.1;
B. made the script file executable.

Reboot your PC and run the tests before starting the VM. If all looks good, run the VM start script.
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 »

@minidigger and everybody who used my how-to for Linux Mint 18:

There were two mistakes in my VM startup script that would lead to errors and/or prevent the loading of the VM.

If you use Linux Mint 18 and your startup script contains the following line

Code: Select all

-drive if=pflash,format=raw,readonly,file=/usr/share/edk2.git/ovmf-x64/OVMF_CODE-pure-efi.fd
edit your windows10vm.sh file and replace the following lines:

Replace

Code: Select all

cp /usr/share/edk2.git/ovmf-x64/OVMF_VARS-pure-efi.fd /tmp/my_vars.fd
with

Code: Select all

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

Code: Select all

  -drive if=pflash,format=raw,readonly,file=/usr/share/edk2.git/ovmf-x64/OVMF_CODE-pure-efi.fd \
with

Code: Select all

  -drive if=pflash,format=raw,readonly,file=/usr/share/OVMF/OVMF_CODE.fd \
Save the file.

I apologize for the error!
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
mcaron1234

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

Post by mcaron1234 »

powerhouse wrote: There are two possibilities I can think of:
1. Check the line above and see if it ends with a "\"
2. Check the "/sbin/vfio-pci-override-vga.sh" script. Make sure you
A. changed the PCI bus ID to 0000:01:00.0 and 0000:01:00.1;
B. made the script file executable.

Reboot your PC and run the tests before starting the VM. If all looks good, run the VM start script.
It looks like my issue is that vfio is not biinding my AMD 280x. I am going through the tutorial line by line trying to find any errors I may have made. I have a few possibilities:
  1. You mention to note the PCI IDs of the graphics card and audio device, but I see no mention of using those anywhere. The PCI BUS numbers are used, but not the PCI IDs. Should I put those somewhere that I overlooked?
  2. When I look in /sys/bus/pci/devices/0000:01:00.0/driver_override it only contains (null) shouldn't it contain "vfio-pci"?
  3. Should I have anything in /etc/vfio-pci.cfg, or refer to it at all in my vm start script?
Thanks for the help!
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 »

mcaron1234 wrote:
powerhouse wrote: There are two possibilities I can think of:
1. Check the line above and see if it ends with a "\"
2. Check the "/sbin/vfio-pci-override-vga.sh" script. Make sure you
A. changed the PCI bus ID to 0000:01:00.0 and 0000:01:00.1;
B. made the script file executable.

Reboot your PC and run the tests before starting the VM. If all looks good, run the VM start script.
It looks like my issue is that vfio is not biinding my AMD 280x. I am going through the tutorial line by line trying to find any errors I may have made. I have a few possibilities:
  1. You mention to note the PCI IDs of the graphics card and audio device, but I see no mention of using those anywhere. The PCI BUS numbers are used, but not the PCI IDs. Should I put those somewhere that I overlooked?
  2. When I look in /sys/bus/pci/devices/0000:01:00.0/driver_override it only contains (null) shouldn't it contain "vfio-pci"?
  3. Should I have anything in /etc/vfio-pci.cfg, or refer to it at all in my vm start script?
Thanks for the help!
  • The PCI IDs are not needed for the graphics card. In the past I had used the pci_stub method which requires PCI IDs. vfio_pci, however, is the preferred method.
  • That is fine. I got the same.
  • No, since for now you only pass through the graphics card, which is handled in the /sbin/vfio-pci-override-vga.sh script. Make sure to make it executable using chmod 755 /sbin/vfio-pci-override-vga.sh
What do you get when you run

Code: Select all

dmesg | grep vfio
You should be seeing something like:
  • [ 2.725846] vfio_pci: add [10de:13c2[ffff:ffff]] class 0x000000/00000000
    [ 2.741841] vfio_pci: add [10de:0fbb[ffff:ffff]] class 0x000000/00000000
    [ 8.382383] vfio-pci 0000:02:00.0: enabling device (0000 -> 0003)
Of course, in your case it should be 0000:01:00.0. The 10de:13c2 and 10de:0fbb are the PCI IDs of my graphics card, by the way.

If not, make sure you added the "radeon.modeset=0" option to your grub file, then run update-grub.

If nothing helps, open the Driver Manager and see which driver is bound to your graphics card. If you have the proprietary fglrx driver in use, choose the radeon (open-source) driver. Reboot and try again.

One more thing: Make sure you selected the IGD (Intel graphics) in your BIOS as the graphics device to boot with!

Last not least, what kind of a PC do you have (laptop, PC, etc.)?
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

Thanks for this.
Unfortunately I discovered your article several days after I finally got it working which took me a year.
:-(

I have what I hope is a simple issue.
I start windows 7 using -vga none.
If I don't then windows 7 complains that the nvidia card cannot get enough resources to start.
Basically , the q35 emulation cannot run two video cards, period.

No problem, I just sit there for 5 minutes until windows finally loads the nvidia driver and suddenly windows 7 pops up on the external monitor (i am using a laptop with hybrid graphics. yes, it works).

My issue is that I do not want to pass through my usb mouse and keyboard to the emulator.
Windows holds on to it until i shutdown windows.
I want to "grab" my mouse keyboard for windows then press ctrl-alt to let go.

Because I have no vga adapter I get the qemu console screen in linux and there is no way to GRAB the emulator so the mouse and keyboard switches over to windows.
Is there a hotkey to grab windows?
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 »

@bash64: I am not familiar with hot keys for mouse or keyboard, would need to look that up myself. To my knowledge, usbdevice just passes through the device to Windows. However, there is Synergy (now commercial) that allows you to control multiple systems or VMs, switching between them by exiting the screen with the cursor or keyboard shortcuts.

Congratulations on getting passthrough working on a laptop! As for Windows 7, I assume you used legacy boot, as opposed to using the OVMF package for UEFI boot?

If you boot Windows without the -q35 option, the default is the older fx440 chipset. Have you tried that? Don't try it without first backing up your entire Windows installation - this little command option has the same effect as replacing the motherboard to a different one - Windows will install a whole new set of drivers, or perhaps even lock because of license issues.

Would you be able to share your hardware configuration, software (Linux Version etc.) and your boot script or xml file (if you used virt-manager or similar). I'm sure this is very helpful for others.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

I just happen to own a copy of synergy.
I am setting it up but windows 7 is set to dhcp and is getting 10.0.2.15.
My router doesn't do that.
Linux is 192.168.1.150.
I assume the emulator has some sort of built in router/dhcp server.
I changed the IP address in windows to no avail.

How do set the IP for windows ahead of time?
I am just using the default intel pro nic.
I have no switches related to ethernet.

I am using legacy boot with seabios.
Never could get ovmf working.

The 440 chipset doesn't support pci-express. No way to use my gtx 880m.
It is 3am in the morning.
My room mate came home having been hit by a car (moving very slow). He is 76.

I will give my complete setup tommorow.
I am a Microsoft certified tech and a Linux/Unix Admin.
I use Linux Mint 18 Cinnamon 64bit.
luisusr

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

Post by luisusr »

Hello

I'm a Linux noob and I have the same problem as mcaron1234. I'm unable to bind my graphics card. There is no output for:

Code: Select all

dmesg | grep vfio
I mannaged to bind it as pci stub when I followed a different tutorial but I got stuck on a black screen when trying to install windows. I already removed pci stub before starting this How-to. I actually tried your tutorial before you updated it and I got stuck at the same spot I am now.
The output of

Code: Select all

lspci -nk
was pci stub on my gfx card and the audio part of it. When I started up the VM it changed to something with vfio. Now I don't have any driver in use when looking up lspci -nk without pci stub.

My BIOS is set to IGP as primary boot but as long as my graphics card is connected via monitor it's ignoring this setting(it allows to output on both monitors though. The other setting doesn't) and I have to turn my monitor off up until the os booted up.

My GRUB is set to: splash iommu on and nouveaumodeset=0 (currently not booted in the os otherwise I would give you the exact line). If I set it to nomodeset my Intel driver is getting disabled aswell.

I haven't made use of my PCI IDs up until the dmesg | grep vfio command in your How-to. I previously had those in GRUB with pci stub but of cause I removed that line before following your tutorial. Did I miss something or do you only use the IDs in the bash scrip to start the VM?

Specs
CPU: 1245v5
GPU: Asus GTX 970 (it has UEFI)
MOBO: MSI C236A
RAM: 32GB
OS: Linux Mint x64

I have the option to clean install the OS. It's on a test SSD.
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

As promised here are my config files:

Hardware:
MSI GT70-2PE Dominator Pro Laptop
i7-4810mq 2.8ghz (3.6ghz turbo)
12GB ram
Nvidia GTX 880m 8gb
Intel Hybrid video (in the CPU)
(2) 2TB hard drives
Bluray burner

Windows 10/Linux Mint 18 64bit Cinnamon dual boot.

NOTE: I do not blacklist nouveau, the open source nvidia driver. After reserving the nvidia card using pci_stub nouveau doesn't even grab the card, but nouveau does load into memory, so no issue. I do uninstall ALL nvidia drivers and I use ">prime-select intel" before I uninstal the nvidia drivers to make sure linux is using intel.:
>inxi -Gx
Graphics: Card-1: Intel 4th Gen Core Processor Integrated Graphics Controller bus-ID: 00:02.0
Card-2: NVIDIA GK104M [GeForce GTX 880M] bus-ID: 01:00.0
Display Server: X.Org 1.18.3 drivers: intel (unloaded: fbdev,vesa) Resolution: 1920x1080@60.02hz
GLX Renderer: Mesa DRI Intel Haswell Mobile GLX Version: 3.0 Mesa 11.2.0 Direct Rendering: Yes


my boot line:
>cat /proc/cmdline
BOOT_IMAGE=/vmlinuz-4.5.4-040504-generic root=/dev/mapper/vg-root ro transparent_hugepage=never intel_pstate=disable intel_iommu=on quiet splash vt.handoff=7 init=/sbin/upstart

my iommu groups:
>find /sys/kernel/iommu_groups/ -type l
group 1 is the nvidia gaming card:
/sys/kernel/iommu_groups/1/devices/0000:00:01.0 (pci-e controller, not held for qemu, qemu emulates a "q35" pc with pci-e controller)
/sys/kernel/iommu_groups/1/devices/0000:01:00.0
/sys/kernel/iommu_groups/1/devices/0000:01:00.1

my nvidia hardware info:
>lspci -nnk
00:01.0 PCI bridge [0604]: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor PCI Express x16 Controller [8086:0c01] (rev 06)
Kernel driver in use: pcieport
Kernel modules: shpchp

01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GK104M [GeForce GTX 880M] [10de:1198] (rev a1)
Subsystem: Micro-Star International Co., Ltd. [MSI] GK104M [GeForce GTX 880M] [1462:1105]
Kernel driver in use: vfio-pci
Kernel modules: nvidiafb, nouveau
01:00.1 Audio device [0403]: NVIDIA Corporation GK104 HDMI Audio Controller [10de:0e0a] (rev a1)
Subsystem: Micro-Star International Co., Ltd. [MSI] GK104 HDMI Audio Controller [1462:1105]
Kernel driver in use: vfio-pci
Kernel modules: snd_hda_intel

/etc/initramfs-tools/modules (rebuild ramdisk after editing)
pci_stub ids=10de:1198,1462:1105,10de:0e0a

/etc/modules
pci_stub
vfio
vfio_iommu_type1
vfio_pci
kvm
kvm_intel

vfio-pci1.cfg
0000:01:00.0
0000:01:00.1

Code: Select all

#!/bin/bash

configfile=~/qemu/vfio-pci1.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

}

modprobe vfio-pci

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

sudo qemu-system-x86_64 -enable-kvm -M pc-q35-xenial -m 6144 -cpu host,kvm=off \
-smp 4,sockets=1,cores=4,threads=1 \
-bios /usr/share/seabios/bios.bin \
-serial none \
-parallel none \
-rtc clock=host,base=localtime \
-vga none \
-usbdevice host:413c:a503 \
-usbdevice host:046d:c52b \
-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,x-vga=on \
-hda /home/dad/qemu/windows1.img \
-cdrom /home/dad/qemu/Windows7.iso \
-boot menu=on \
-boot order=dc \


exit 0
I use a Dell usb soundbar and a logitech receiver with mouse/keyb combo.

I realize this does not tell anyone how to do it themselves, I will be writing an article later on.
There are a LOT of gotchas and catch22's with qemu. A LOT of them.
The main thing is that after launching this you have to sit and wait for 7 minutes with nothing but a qemu monitor console window before windows finally comes up on the external monitor. You cannot watch the pretty windows startup screen.

On my laptop the hdmi port is exclusively owned by the nvidia card.
Linux runs on the intel hybrid on the laptop screen.
The intel video does have access to the 15pin connector on the back and since my external 27" monitor has both hdmi and 15 pin I can hook up both video cards to one monitor and use the monitor panel buttons to switch back and forth.

If anyone needs help with this just contact me.

I still need help getting windows on the same network as linux so I can use synergy.
I assume windows synergy automatically runs on boot and connects to the linux synergy server.

I played some Doom 4 this morning to verify this all works.
I need to optimize load times with the hardfile as it is very slow.
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 »

@bash64: Sorry to hear about your roommate - hope he's doing OK.

About Windows and setting up synergy:
If you have a router and access to the configuration, the best way is to set up a bridge and let the router assign the IP. This way you set an IP on the router associated to with the "virtual" MAC address of your Windows 7 network interface. You need to install brctl under Linux. I described a network setup using bridging in my Xen how-to.
In the qemu startup script, add a network configuration and specify a MAC address. You don't need to do anything inside Windows, as long as it is set to get the IP via DHCP (which is the default).

Regarding OVMF and UEFI boot:
Windows 7 is a bad candidate for UEFI boot - the Windows ISO does not support it. There is a way to add UEFI support in an existing Windows 7 installation. You may want to try that, but only after you backup your entire Windows VM! However, before even trying that, you need to make certain that your graphics card BIOS supports UEFI. I have described how to check that in my KVM tutorial. If it works, it allows you to do primary passthrough without the Seabios screen directly into the Windows VM.

440 chipset and PCI-E:
Well, I've used both FX440 and the q35 - the later gives me better performance and is probably the preferred chipset emulation on newer Linux systems like Linux Mint 17 or 18. If you do not specify the q35 option on the qemu command line, the system will use the default which, iirc, is fx440.

Good luck with Synergy!
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

powerhouse wrote:@bash64: Sorry to hear about your roommate - hope he's doing OK.

About Windows and setting up synergy:
If you have a router and access to the configuration, the best way is to set up a bridge and let the router assign the IP. This way you set an IP on the router associated to with the "virtual" MAC address of your Windows 7 network interface. You need to install brctl under Linux. I described a network setup using bridging in my Xen how-to.
In the qemu startup script, add a network configuration and specify a MAC address. You don't need to do anything inside Windows, as long as it is set to get the IP via DHCP (which is the default).

Good luck with Synergy!
I still do not understand where windows is getting the 10.0.2.15 address when it is setup for DHCP.
I have a router and it hands out 192.168.0.x addresses.
If it doesnt get the IP from my router how will setting the mac address fix the issue?
I have an assigned address for the mac for my wireless which linux is using.
Sorry, but windows isnt talking to my router that I can tell.
I will check the router logs.


VERIFIED: Windows does not talk to the router. Got to figure out where it is getting that IP from. Perhaps linux acts as a DHCP server or the emulator does.
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

I am wondering if the default intel pro nic I am using has severe limitations.
I will try your nic settings.
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 »

@bash64: Thanks for your configuration!

Is there a reason you do not wish to upgrade your VM to Windows 10?

Your VGA legacy configuration requires the Intel VGA arbiter patch! There is a bug in the Intel i915 graphics driver with the result that VGA arbitration doesn't work properly. A Linux kernel patch exists to work around this problem, but it's not in the repository. You would need to recompile the kernel with the patch applied.

BUT, the good news is that if you can use UEFI boot, you won't need to patch at all. UEFI boot gets rid of all the legacy VGA stuff, which means that VGA and VGA arbitration becomes irrelevant. When VGA was standardized, nobody dreamed of having more than one graphics card. Running more than one VGA device requires the kernel to do some magic called arbitration. UEFI doesn't use VGA, so no arbitration needed. However, your graphics adapter (the GTX880m) must have a BIOS that supports UEFI. If it's a new model, it should.

The boot delay might very well be the result of that arbitration bug.

About pci_stub: My initial how-to uses pci_stub, which is fine as long as one doesn't use identical graphics cards for both host and guest. Some say pci_stub is old fashioned, and it's better to use vfio-pci. If pci_stub works, use it. My old LM 17.3 how-to found here uses pci_stub.

You write that you use pci_stub which is defined in /etc/initramfs-tools/modules with:

Code: Select all

pci_stub ids=10de:1198,1462:1105,10de:0e0a
Yet you have a vfio-pci config file with the PCI bus numbers and run a vfiobind function in your startup script. If you use pci_stub, you can remove:

Code: Select all

configfile=~/qemu/vfio-pci1.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

}

modprobe vfio-pci

cat $configfile | while read line;do
    echo $line | grep ^# >/dev/null 2>&1 && continue
        vfiobind $line
done
EDIT: Leave the above script in place if you need to pass through addition PCI devices that have been specified in vfio-pci1.cfg, using the long PCI bus number such as 0000:02:00.0. No empty lines allowed.

The two 10de IDs in your /etc/initramfs-tools/modules file are for the Nvidia graphics card (graphic and audio), but what is the 1462:1105? Make sure you don't pass through a PCI root device.

Do you need the following?

Code: Select all

-device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1 \
Before touching any config or script file, back it up so you can return!
Last edited by powerhouse on Thu Oct 06, 2016 3:17 pm, edited 1 time in total.
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 »

bash64 wrote:
powerhouse wrote:@bash64: Sorry to hear about your roommate - hope he's doing OK.

About Windows and setting up synergy:
If you have a router and access to the configuration, the best way is to set up a bridge and let the router assign the IP. This way you set an IP on the router associated to with the "virtual" MAC address of your Windows 7 network interface. You need to install brctl under Linux. I described a network setup using bridging in my Xen how-to.
In the qemu startup script, add a network configuration and specify a MAC address. You don't need to do anything inside Windows, as long as it is set to get the IP via DHCP (which is the default).

Good luck with Synergy!
I still do not understand where windows is getting the 10.0.2.15 address when it is setup for DHCP.
I have a router and it hands out 192.168.0.x addresses.
If it doesnt get the IP from my router how will setting the mac address fix the issue?
I have an assigned address for the mac for my wireless which linux is using.
Sorry, but windows isnt talking to my router that I can tell.
I will check the router logs.


VERIFIED: Windows does not talk to the router. Got to figure out where it is getting that IP from. Perhaps linux acts as a DHCP server or the emulator does.
I suppose the emulator does that. This is why you want to configure a network bridge on your host. If you do that, both your host and the Windows VM will get the IP from your router - they will actually be recognized by the router as two different network devices. Hence the need to specify a MAC address. Use my example in the how-to for a proper MAC address - they have reserved address spaces so you can only modify the last two -xx-yy.

As I'm reading your reply, it dawns to me that you have a wireless connection to your router. Oooops. With a wireless connection you can forget layer 2 bridging. You need to configure routing in your Linux host, and assign a static IP to your Windows VM. All is done under Linux. I haven't done that for a while, so you need to search for information on setting up routing on your Linux host and have your VM get an IP via DHCP.

Should your PC be hooked up to the router via an Ethernet cable, use a bridge.
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 »

bash64 wrote:I am wondering if the default intel pro nic I am using has severe limitations.
I will try your nic settings.
See my reply above. It's important to know whether or not your PC uses a wireless connection to your router.

EDIT: Also notice my earlier post on pci_stub and your startup script.
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 »

luisusr wrote:Hello

I'm a Linux noob and I have the same problem as mcaron1234. I'm unable to bind my graphics card. There is no output for:

Code: Select all

dmesg | grep vfio
I mannaged to bind it as pci stub when I followed a different tutorial but I got stuck on a black screen when trying to install windows. I already removed pci stub before starting this How-to. I actually tried your tutorial before you updated it and I got stuck at the same spot I am now.
The output of

Code: Select all

lspci -nk
was pci stub on my gfx card and the audio part of it. When I started up the VM it changed to something with vfio. Now I don't have any driver in use when looking up lspci -nk without pci stub.

My BIOS is set to IGP as primary boot but as long as my graphics card is connected via monitor it's ignoring this setting(it allows to output on both monitors though. The other setting doesn't) and I have to turn my monitor off up until the os booted up.

My GRUB is set to: splash iommu on and nouveaumodeset=0 (currently not booted in the os otherwise I would give you the exact line). If I set it to nomodeset my Intel driver is getting disabled aswell.

I haven't made use of my PCI IDs up until the dmesg | grep vfio command in your How-to. I previously had those in GRUB with pci stub but of cause I removed that line before following your tutorial. Did I miss something or do you only use the IDs in the bash scrip to start the VM?

Specs
CPU: 1245v5
GPU: Asus GTX 970 (it has UEFI)
MOBO: MSI C236A
RAM: 32GB
OS: Linux Mint x64

I have the option to clean install the OS. It's on a test SSD.
I do not use the PCI IDs when using vfio-pci with the /sbin/vfio-pci-override-vga.sh script. You need to make sure you modified that script and entered the correct PCI bus numbers, and make it executable (see how-to). Don't forget the following:

Code: Select all

echo "install vfio-pci /sbin/vfio-pci-override-vga.sh" >> /etc/modprobe.d/local.cfg
Check that your /etc/modprobe.d/local.cfg exists and has the install vfio-pci ... line! Make sure you update the initramfs after that.

If you made any changes, reboot and enter in a terminal:

Code: Select all

lspci -nnk | grep -A 4 VGA
Your output should be similar to this:
  • 01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GF106GL [Quadro 2000] [10de:0dd8] (rev a1)
    Subsystem: NVIDIA Corporation GF106GL [Quadro 2000] [10de:084a]
    Kernel driver in use: nvidia
    Kernel modules: nvidiafb, nouveau, nvidia_361
    01:00.1 Audio device [0403]: NVIDIA Corporation GF106 High Definition Audio Controller [10de:0be9] (rev a1)
    --
    02:00.0 VGA compatible controller [0300]: NVIDIA Corporation GM204 [GeForce GTX 970] [10de:13c2] (rev a1)
    Subsystem: Gigabyte Technology Co., Ltd GM204 [GeForce GTX 970] [1458:3679]
    Kernel driver in use: vfio-pci
    Kernel modules: nvidiafb, nouveau, nvidia_361
    02:00.1 Audio device [0403]: NVIDIA Corporation GM204 High Definition Audio Controller [10de:0fbb] (rev a1)
Have a look at the "Kernel driver in use" lines:
01:00.0 is my host graphics. It uses the proprietary Nvidia driver which is fine. In your case it will be the Intel driver.
02:00.0 is my VM graphics. It is successfully bound to vfio-pci.

If it's not like that, click Menu -> Control Center -> Driver Manager

It will take a little to load. Then see which drivers are used:

1. Your host GPU should use the proprietary driver.
2. Your VM graphics card (Nvidia GTX) should use the nouveau driver.

Make the appropriate changes, if required, and reboot.

Make sure you use OVMF for UEFI boot! Legacy VGA boot will not work in your case. I take it your Windows is Windows 8 or newer with UEFI boot?
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”