Thomas Prescher, Stefan Hertrampf · 4 min read

Graphics Virtualization Support in KVM Backend for VirtualBox

Modern applications from CAD to games need beefy graphics hardware to work. In a virtual machine they are unusable, because they use slow emulated graphics. Learn in this article how to enjoy blazingly fast graphics by unlocking the graphics virtualization capability that ships in every modern Intel CPU.

Graphics Virtualization Support in KVM Backend for VirtualBox

Overview

There are different approaches to graphics virtualization that all have their advantages and disadvantages. The following image depicts the different approaches to graphics virtualization and the tradeoff of flexibility and performance.

Graphics virtualization overview

The Full Emulation approach offers the most flexibility because the graphics controller presented to the virtual machine is fully emulated in software. There is no dependency on any hardware in the host system. The user can start as many virtual machines with fully emulated graphics controllers as the system can handle.

On the other side, there is Full Passthrough, where a physical graphics controller is assigned to a Virtual Machine (VM). This option offers the best performance for the VM, but completely utilizes the graphics controller for a single guest.

API forwarding translates and executes graphics commands issued by the VM on the host GPU. The number of API endpoints that must be forwarded is quite high, or guest applications will be very limited in graphical features they can use. Nonetheless, the approach can lead to good performance with only a few dependencies on the underlying hardware.

As an alternative, there is Hardware-Assisted graphics virtualization. The graphics controller has built-in support for shared usage of its resources in the context of virtualization while the IOMMU is used to guarantee isolation of those resources. This approach can lead to very good performance while multiple VMs can benefit from graphics acceleration. The Intel SR-IOV technology belongs to this type of graphics virtualization. While SR-IOV is a PCI standard and already available and well known for network controllers, it is relatively new for graphics controllers outside of server environments.

Intel SR-IOV graphics virtualization

Intel SR-IOV graphics virtualization support requires a hardware generation of Alder Lake (also called 10th gen Intel Core) or newer. You can check if your Intel graphics controller supports SR-IOV by invoking lspci -s 2.0 -v and checking for the Single Root I/O Virtualization (SR-IOV) PCI capability.

lspci output for an SR-IOV capable GPU.

The following image gives a conceptual overview of how SR-IOV is used to provide graphics acceleration to virtual machines.

SR-IOV graphics acceleration concept

The host Linux has complete control over the whole GPU and is the only one with access to the Physical Function (PF). Using the Virtual Function I/O (VFIO) driver, Linux can create Virtual Functions (VFs) which will appear in the PCI tree and can be passed to a virtual machine via PCI passthrough. The VM will see the VF as a complete graphics device in its PCI tree and can attach a respective GPU driver to it. The physical GPU takes care of sharing resources, multiplexing and handling all incoming graphical commands. The IOMMU takes care of separating memory and interrupts so that a virtual machine cannot compromise the host system or other virtual machines.

The only part missing now is receiving the display output of the VM and displaying it in the host Linux. For this, a VirtIO GPU is attached to the VM as a second graphics controller with the single purpose of allowing the KVM Backend to access the VMs framebuffer. The respective guest drivers of the Intel and VirtIO graphics take care of transferring the framebuffer of the Intel graphics to the Virtual Machine Monitor via the VirtIO GPU.

Usage

To set up SR-IOV graphics acceleration, have a look into our setup instructions. The resulting graphics acceleration can be seen in the following screenshot of a Windows 10 VM running the Unigine Heaven benchmark:

VM with accelerated graphics via SR-IOV

Performance

We’ve measured performance using the Unigine Heaven Benchmark on a Lenovo X1 Yoga using an Intel i7-1360P CPU. As expected, software rendering is a lot slower than native performance (about 2% of native performance for this particular benchmark). Using SR-IOV Graphics Virtualization we were able to achieve about 92% of the original performance.

Relative performance measured with the Unigine Heaven benchmark.

These results show that running graphics-intensive workloads in virtual machines is feasible and quite efficient.

Getting Support

If you would like to use SR-IOV graphics acceleration or if you have a need for custom virtualization solutions, we are happy to provide guidance and engineering services. Please reach out to us via our support form or via e-mail at service@cyberus-technology.de.

Share: