This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.
Please visit our production wiki at https://wiki.gentoo.org
GPU passthrough with libvirt qemu kvm
GPU passthrough is a technology that allows you to directly present an internal PCI GPU to a virtual machine. The device acts as if it were directly driven by the VM, and the VM detects the PCI device as if it were physically connected. GPU passthrough is also often known as IOMMU, although this is a bit of a misnomer, since the IOMMU is the hardware technology that provides this feature but also provides other features such as some protection from DMA attacks or ability to address 64-bit memory spaces with 32-bit addresses.
As you can imagine, the most common application for GPU passthrough at least gaming, since GPU passthrough allows a VM direct access to your graphics card with the end result of being able to play games with nearly the same performance as if you were running your game directly on your computer.
QEMU (Quick EMUlator) is a generic, open source hardware emulator and virtualization suite.
This article typically uses KVM as the accelerator of choice due to its GPL licensing and availability. Without KVM nearly all commands described here will still work (unless KVM specific).
Installation
BIOS and UEFI firmware
In order to utilize KVM either Vt-x or AMD-V must be supported by the processor. Vt-x or AMD-V are Intel and AMD's respective technologies for permitting multiple operating systems to concurrently execute operations on the processors.
To inspect hardware for visualization support issue the following command:
user $
grep --color -E "vmx|svm" /proc/cpuinfo
For a period manufacturers were shipping with virtualization turned off by default in the system BIOS
Hardware
- A CPU that supports Intel VT-d or AMD-Vi. Check List of compatible Intel CPUs (Intel VT-x and Intel VT-d)
- A motherboard that supports the aforementioned technologies. To find this out, check in your motherboard's BIOS configuration for an option to enable IOMMU or something similar. Chances are that your motherboard will support it if it's from 2013 or newer, but make sure to check since this is a niche technology and some manufacturers may save costs by axing it from their motherboards or delivering a defective implementation (such as Gigabyte's 2015-2016 series) simply because NORPs never use it.
- At least two GPUs: one for your physical OS, another for your VM. (You can in theory run your computer headless through SSH or a serial console, but it might not work and you risk locking yourself away from your computer if you do so).
- Optional but recommended: Additional monitor, keyboard and mouse
EFI configuration Turn on VT-d Turn on IOMMU
Preparations ACS patch
* Applying 4400_alpha-sysctl-uac.patch (-p1) ... [ ok ] * Applying 4567_distro-Gentoo-Kconfig.patch (-p1) ... [ ok ]
>>> Source unpacked in /var/tmp/portage/sys-kernel/gentoo-sources-4.14.52/work >>> Preparing source in /var/tmp/portage/sys-kernel/gentoo-sources-4.14.52/work/linux-4.14.52-gentoo ...
* Applying override_for_missing_acs_capabilities.patch ... [ ok ] * User patches applied.
IOMMU
Software installation
Emerge Grub configuration
Libvirt configuration
Windows guest configuration
- Workaround for AMD graphic card (turn on/off amd vcard)
Sound
create dir /home/qemu copy /home/USER/.config/pulse to /home/qemu chown qemu:qemu -R /home/qemu
change home dir for qemu: usermod -d /home/qemu qemu
Set home dir:
See also
- QEMU — a generic, open source hardware emulator and virtualization suite.
External resources
- https://forum.level1techs.com/t/linux-host-windows-guest-gpu-passthrough-reinitialization-fix/121097?source_topic_id=121737 - AMD GPU on windows guest
- https://wiki.installgentoo.com/index.php/PCI_passthrough - PCI passthrough on gentoo