update: gaming inside kvm vm on GNU Linux host? YES!

but TWO (2x) GPUs / dedicated grafix cards are needed! (or one one onboard gpu and one PCIE dedicated GPU card)

“QEMU/KVM VGA PCI Pass-Through of a dedicated AMD Radeon R9 280”

“using a CPU and Motherboard which supports hardware virtualization (Intel VT-x/VT-d or AMD-V) along with two graphics cards, one for the Linux Base and another dedicated PCIe GPU for the Windows Virtual Machine (VM). Gaming experience within the Windows VM is exceptional, yielding a 96% performance return in comparison to native play.”

  • Processor: Intel Core i7-4790
  • Motherboard: ASUS Z87-Pro
  • RAM: Crucial Ballistix 32GB (8GBx4)
  • GPU 1: Intel HD 4600 Integrated Graphics
  • GPU 2: AMD Radeon R9 280
  • Monitor1: Connected to Intel HD 4600 (HDMI1) and AMD Radeon R9 280 (HDMI2)
  • Monitor2: Connected to Intel HD 4600 (HDMI1)

its pretty hard to setup but it can be done 😀

you should have TWO! Graphic-Cards – one onboard (does not need to be very powerfull) for displaying your host-linux – one to pass through to the VM (it will not be available for the host).

this was tested on:

hostnamectl
  Operating System: Debian GNU/Linux 9 (stretch)
            Kernel: Linux 4.9.0-4-amd64
      Architecture: x86-64

lspci 
00:00.0 Host bridge: Intel Corporation Skylake Host Bridge/DRAM Registers (rev 08)
00:02.0 VGA compatible controller: Intel Corporation HD Graphics 520 (rev 07)
00:08.0 System peripheral: Intel Corporation Skylake Gaussian Mixture Model
00:14.0 USB controller: Intel Corporation Sunrise Point-LP USB 3.0 xHCI Controller (rev 21)
00:14.2 Signal processing controller: Intel Corporation Sunrise Point-LP Thermal subsystem (rev 21)
00:17.0 SATA controller: Intel Corporation Sunrise Point-LP SATA Controller [AHCI mode] (rev 21)
00:1c.0 PCI bridge: Intel Corporation Device 9d12 (rev f1)
00:1e.0 Signal processing controller: Intel Corporation Sunrise Point-LP Serial IO UART Controller #0 (rev 21)
00:1f.0 ISA bridge: Intel Corporation Sunrise Point-LP LPC Controller (rev 21)
00:1f.2 Memory controller: Intel Corporation Sunrise Point-LP PMC (rev 21)
00:1f.3 Audio device: Intel Corporation Sunrise Point-LP HD Audio (rev 21)
00:1f.4 SMBus: Intel Corporation Sunrise Point-LP SMBus (rev 21)
00:1f.6 Ethernet controller: Intel Corporation Ethernet Connection I219-LM (rev 21)
01:00.0 Ethernet controller: Intel Corporation I211 Gigabit Network Connection (rev 03)

follow this excellent guide: https://davidyat.es/2016/09/08/gpu-passthrough/

for me those settings did work:

vim /etc/default/grub 

GRUB_DEFAULT=0
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=oni pci_stub.ids=00:02.0"
GRUB_CMDLINE_LINUX=""

# generate new grub config /boot/grub/grub.cfg
# Debian/Ubuntu
update-grub2
# update-grub2 can not be found in Debian10?
# it is probably this problem
# simulate proper root login
su - root
# try again
update-grub2

# RedHat/Fedora/CentOS
grub2-mkconfig -o /boot/grub2/grub.cfg
vim /etc/initramfs-tools/modules # 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 pci_stub 

definitely need a cpu with virtualization support (VT).

egrep '^flags.*(vmx|svm)' /proc/cpuinfo;
# should display some output like

flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp

egrep '^flags.*(vmx|svm)' /proc/cpuinfo|grep --color -e vmx -e svm;

if no vmx or svm shows up, reboot now to make changes active and check the bios for possible enabling VT support.

sync; sync; sync; reboot;

after reboot, the output of should display something like:

dmesg | grep pci_stub
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.9.0-4-amd64 root=UUID=4287dcc2-278b-4413-9d59-10c1710f35bd ro quiet intel_iommu=oni pci_stub.ids=00:02.0
[    0.000000] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-4.9.0-4-amd64 root=UUID=4287dcc2-278b-4413-9d59-10c1710f35bd ro quiet intel_iommu=oni pci_stub.ids=00:02.0

inside virt-manager:

  1. open the vm
  2. go to “connection details”
  3. r-click in the list of devices and + add device
  4. under pci-devices select your dedicated graphic card

run the VM… if your screen gets dark and even your keyboard passess out… than you only have one graphic card.

maybe install vncserver inside the windows vm prior to that.

install drivers for your graphic card

now you should see device manager should show the correct naming of your chip model…

not just “Default-VGA-Graphic”…. or something is wrong.

fire up some basic 3d benchmark http://www.geeks3d.com/20140304/gputest-0-7-0-opengl-benchmark-win-linux-osx-new-fp64-opengl-4-test-and-online-gpu-database/

or the more advanced 😀 Heaven 4.0 Benchmark

it is amazing that KVM can do this… VirtualBox virtual graphic card adapter is unfortunately not often recognized correctly by 3d applications…

but you will need two graphic cards… like one on board and one dedicated PCI device.

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin