Virtio-nvgpu: NVIDIA GPU Access in KVM VMs

The virtio-nvgpu project is currently in development, aiming to create a virtio device that enables access to NVIDIA GPUs from guest systems running the KVM hypervisor with minimal performance loss. The project consists of a kernel module that is loaded in the guest system and a virtio device that operates within the host environment. The kernel module is coded in C and distributed under the GPLv2 license, while the virtio device code is written in Rust and distributed under the Apache License 2.0.

Developers claim that the performance loss when accessing the GPU through virtio-nvgpu does not exceed 2%. The system achieves high speed by directly redirecting ioctl calls to the native NVIDIA driver and operating at the ABI level of the NVIDIA driver, bypassing translation to the API level. On the guest system side, standard libraries and high-level NVIDIA drivers are utilized, running in user space.

In the guest system, a kernel module is loaded to provide device files such as /dev/nvidiactl, /dev/nvidia0…N, and /dev/nvidia-uvm. This module forwards ioctl() and mmap() calls through virtqueue to a handler in the host environment, which then relays them to the NVIDIA host driver. To eliminate context switches between the host system and the virtual machine, command buffers are mapped into shared memory accessible to both the host environment and the GPU.

Unlike exclusive GPU passthrough (VFIO Passthrough), virtio-nvgpu allows shared GPU access from multiple virtual machines. Additionally, unlike virtio-gpu (Venus, VirGL), virtio-nvgpu operates through ABI passthrough to the NVIDIA driver rather than translating requests at the Vulkan and OpenGL API level. However, there are limitations to virtio-nvgpu, including the lack of full isolation based on IOMMU and the need to adapt to ABI changes in NVIDIA drivers with each version update.

Virtio-nvgpu is capable of rendering, video encoding, and calculations using Vulkan, OpenGL, NVENC, and CUDA APIs. The primary use case mentioned is for cloud gaming services or virtual desktops, where a game or graphics application runs in a virtual machine, performs rendering, hardware encoding using NVENC, and transmits the output to a remote user as a compressed video stream.

/Reports, release notes, official announcements.