When combined with virtualization features, modern technologies have made it feasible to use your hardware fully within the virtual ecosystems. Out of such technologies, there is GPU passthrough, which enables the virtualization of a single dedicated graphics card within a virtual machine to render games, do 3D rendering or use the machine for GPU-accelerated workloads. This is a GPU passthrough setup tutorial. We provide a complete step-by-step process to configure GPU passthrough on your system and allow virtual machines to operate as efficiently as native hardware.
This guide will look at the most critical parts regarding configuring GPU passthrough, including basic hardware and software requirements, setting up KVM or VMware virtualization environments, and addressing general issues that may arise during the project. This tutorial will be helpful for everyone who wants to create a robust gaming environment inside a virtual machine or people who want to utilize their hardware to the maximum level while maintaining safety and efficiency in the process.
What is GPU Passthrough and How Does It Work?
A GPU that would be used with a virtualized OS must first go through the GPU passthrough process. Since the VM will be able to access the full potential of the graphics card after it has gone through this procedure. Simply put, using a GPU passes through a hypervisor’s control, allowing a virtual machine direct access to the controlled hardware. Specific requirements include IOMMU-supporting hardware based on a suitable virtualization platform, e.g., KVM, VMware, etc. Such methods allow the utilization of GPU resources on the virtual machine itself. This means it can perform up to the limits of the VM’s resources alone. Such systems would be able to benefit the most from GPU rendering, gaming, or even specific heavy-duty machine-learning tasks.
Understanding IOMMU and Its Role in GPU Passthrough
The term IOMMU stands for Input-Output Memory Management Unit. IOMMU is one of the necessary devices enabling GPU passthrough as it controls memory access. This means it will allow the system to implement specific policies on the VM to prevent it from accessing memory that the system has not assigned. Essentially, IOMMU assists in providing a safe and sound environment for GPU virtualization by enabling device isolation. Handing a GPU to a virtual machine is impossible without the risk of memory footprint conflict or instability. When IOMMU is available in one’s hardware, turning it on in the BIOS or UEFI settings is generally done first when one wants to do a GPU passthrough.
The Difference Between GPU Passthrough and Virtual GPUs
Virtual GPUs and GPU passthrough are two different approaches to deploying GPUs with virtual machines. The key differences are performance and hardware setup.
Through GPU passthrough, one virtual machine (VM) can be assigned to one physical GPU. In passthrough setups, the VM sees the GPU as if it is wired directly to it. Hence, there is near-native performance. Support for AMD or Intel processors that have been designed for virtualization and can work with a hypervisor such as KVM or Xen is needed, along with the backing for IOMMU technology. It is most appropriate for gaming, video rendering, or AI operations, which demand high graphic resources because the VM has access to an entire GPU, significantly reducing resource competition.
Virtual graphics processing units typically employ a single graphics processing unit shared among several virtual machines. Among the virtualization methods utilized, NVIDIA vGPU and AMD MxGPU use Hypervisors to split the GPU resources among the virtual machines. While this configuration is very flexible, it can result in reduced performance owing to resource contention. For example, some of NVDIA’s vGPU profiles can configure the allocation of memory from 1 GB to the entire quantity of the video memory of a selected GPU, depending on the application and profile selection. This method would be reasonable for scenarios that are not graphical processor resource intensive, such as using several virtual desktops or light computational tasks.
Key Technical Parameters:
GPU Passthrough Requirements:
- CPU with IOMMU support (e.g., Intel VT-d, AMD-Vi)
- Enabled IOMMU in BIOS/UEFI
- Hypervisor with passthrough support (e.g., KVM, Xen)
- Dedicated GPU assigned per VM
Virtual GPU Requirements:
- GPU capable of virtualization (e.g., NVIDIA A-series or AMD MI-series)
- Hypervisor with vGPU support (e.g., VMware ESXi, Citrix Hypervisor)
- Proper driver and vGPU software installation (e.g., NVIDIA GRID, AMD ROCm)
Performance Trade-offs:
- GPU Passthrough: Near-native performance, single-user access, resource exclusivity
- vGPU: Slight performance reduction, multi-user access, improved resource utilization for lighter tasks
Ultimately, the choice between GPU passthrough and virtual GPUs depends on workload demands, hardware resources, and scalability requirements.
Benefits of GPU Passthrough for Gaming and High-Performance Computing
A significant benefit of GPU passthrough is that It benefits both computing and gaming but is mostly gained from gaming. With it, the user can gain a physical GPU, which then passes through the performance bottleneck, making it skilled in handling the demand required by gaming, which is a good characteristic since it is an arduous task-oriented task. Because resources are not shared among GPU resources, this method deletes any overhead typical when a GPU is used for multiple purposes, thus providing dedicated usage of the entire processing system of the GPU. Moreover, passthrough is suitable when applications require demanding graphics or heavy parallel computations.
Key Technical Parameters for GPU Passthrough:
- Hardware Requirements:
- CPU with IOMMU support (e.g., Intel VT-d, AMD-Vi)
- Motherboard with support for the required virtualization technology
- GPU capable of working in passthrough mode (e.g., NVIDIA GeForce or AMD Radeon series)
- Software Requirements:
- Hypervisor with GPU passthrough support (e.g., KVM, Xen, VMware Workstation Pro)
- Appropriate guest operating system GPU drivers
- Configuration Essentials:
- Configure IOMMU in BIOS/UEFI
- Allocate exclusive PCIe lanes for the passthrough GPU
- Suitable cooling and power supply to support high workloads
Because of this solution, high-end computing workflows and video games have specific hardware requirements that can be fulfilled without compromising the quality and performance each respective application requires.
How to Check if Your System Supports GPU
Passthrough
- Verify IOMMU Support:
Check if your CPU supports IOMMU by consulting the official specifications on the manufacturer’s website (Intel VT-d for Intel CPUs, AMD-Vi for AMD CPUs). Ensure that IOMMU is enabled in your BIOS/UEFI settings.
- Confirm Motherboard Compatibility:
Verify that your motherboard supports the necessary virtualization features. To confirm compatibility, consult the motherboard manual or the manufacturer’s documentation.
- Test GPU Compatibility:
Research whether your GPU model supports passthrough. Modern NVIDIA GeForce or AMD Radeon GPUs are commonly used, but specific driver or firmware limitations might need consideration.
- Confirm Hypervisor Requirements:
Ensure your hypervisor (e.g., KVM, Xen, VMware Workstation Pro) supports GPU passthrough. The hypervisor’s official documentation provides detailed requirements and configuration steps.
- Check for IOMMU Grouping:
Once IOMMU is enabled, boot your system into the hypervisor or a Linux distribution. Use tools like `lspci` or `dmesg` to confirm proper IOMMU groupings and ensure the GPU is assignable to the guest.
- Assess Power and Cooling Capacity:
Ensure that your power supply can handle the GPU’s additional load and that your system has adequate cooling for extended high-performance use.
These steps provide a clear pathway to evaluate your system’s readiness for GPU passthrough, ensuring a seamless configuration for demanding workloads.
Verifying CPU and Motherboard Compatibility
Intel VT-d and AMD-Vi usage are allowed on my CPU if I intend to make a GPU passthrough after properly checking for Virtualization Technology. The chipset and Firmware of the Motherboard are also checked to see if they have IOMMU required for Hardware assignment in virtual machines. Checking the mainboard’s manual or its manufacturer’s site, I check if IOMMU is toggleable in the BIOS/UEFI options. Also, I use the compatibility lists or user forums to verify that my CPU, motherboard, and GPU work together without any problems and to ensure that I am not using them out of context. This approach lessens the issues one would experience and guarantees that all the components used are fit.
Checking BIOS/UEFI Settings for Virtualization Support
The first step I take in validating the virtualization capability of the data source device is checking the BIOS or UEFI settings. I start by doing a pre-boot survey to see if virtualization options are available – this is done by looking for the Advanced Menu. In most cases, when I can find the options, they are predominantly under Advanced, CPU Configuration, or Chipset. Next, all BIOS or UEFI settings that pertain to virtualization activation are verified. For Intel CPUs, Intel VT-x and Intel VT-d are enabled. For AMD systems, AMD-V and AMD-Vi (IOMMU) are activated. Secure Boot and CSM (Compatibility Support Module) are also configured to the appropriate settings, as both can affect virtualization environments. Another critical component is ensuring “Intel Virtualization Technology” and “IOMMU Controller” are enabled, and these settings are checked before confirming the changes in the system settings. At the end of this process, the system has been confirmed to be congruent with virtualization.
Identifying IOMMU Groups Using lspci Command
Before identifying the IOMMU groups using the `lspci` command, I ensure I have the `pciutils` package installed on my machine. Now, I can run the command `lspci -vnn` and receive information for all PCI devices, including detailed ones. Since IOMMU group information is required, I either write a script or use existing scripts that extract data from the directory `/sys/kernel/iommu_groups`. For instance, I can run a loop through each directory under `/sys/kernel/iommu_groups/` and list the contents to know which devices comprise each IOMMU group. This practice provides a reliable device for group relations, which is of utmost importance for passthrough configurations in virtualization.
Step-by-Step Guide to Configure GPU Passthrough
Step 1: Verify Hardware and Enable Virtualization
First, I ensure that my system supports GPU passthrough by checking for CPU features such as Intel VT-d or AMD-Vi in the system specifications. I also confirm that these features are enabled in the BIOS/UEFI settings. Enabling virtualization and IOMMU in the BIOS is critical for passthrough functionality.
Step 2: Check IOMMU Groups
I verify the proper grouping of my PCI devices by using a script to list the contents of `/sys/kernel/iommu_groups.` This step is essential to ensure the GPU and other necessary devices are in isolated IOMMU groups without conflicts.
Step 3: Configure the Host System
After confirming the IOMMU groups, I edit my kernel parameters to enable GPU passthrough. This usually involves appending parameters such as `intel_iommu=on` or `amd_iommu=on` to the bootloader configuration (e.g., GRUB). Once updated, I regenerate the GRUB configuration file and restart the system to apply the changes.
Step 4: Bind the GPU to vfio-pci
I bind the GPU and associated devices to the `vfio-pci` kernel driver to prepare the GPU for passthrough. This requires identifying the PCI IDs of the GPU and its audio device, then updating the module options or using tools like `modprobe` to bind them correctly.
Step 5: Configure the Virtual Machine (VM)
Using a hypervisor such as QEMU/KVM, I create or modify the VM configuration to include the GPU. I specify the PCI device IDs for passthrough and ensure adequate resources (CPU, RAM) are allocated to the VM.
Step 6: Test and Troubleshoot
Finally, I start the VM and test GPU performance in the guest environment. If issues arise, I refer to system logs (`design and hypervisor logs) to debug errors, such as device initialization failures or driver conflicts. This iterative process ensures the setup achieves optimal compatibility and performance.
Enabling IOMMU in GRUB and Linux Kernel
To activate IOMMU, my first step would be to modify the GRUB’s configuration file stored within the path of /etc/default/grub. An appropriate parameter is added for Intel-powered machines as `intel_iommu=on` or for AMD-powered machines as `amd_iommu=on’ so that I` can append that line. So after saving this, I will update grub using either the ‘update-grub’ command on a Debian or Ubuntu-based system or by using grub2-mkconfig -o /boot/grub2/grub.cfg in a Red Hat-based distribution. Only after ensuring that IOMMU is supported on the Linux kernel will I proceed to check the boot message by entering ‘dmesg | grep -I iommu.’ This guarantees appropriate performance characteristics and lets devices function autonomously in a virtualized environment.
Troubleshooting Common GPU Passthrough Issues
The solution to issues related to GPU passthrough must contain a consistent technique for understanding and resolving the hardware and configuration mismatches that could have been a factor. Here are the commonly known issues along with their resolution:
1. NVIDIA GPUs Code 43 Error in Windows VM
This scenario is triggered when NVIDIA GPUs can recognize virtualized environments. To avoid this, ensure the VM XML configuration file has the `<kvm>` section and specifies a `<hidden state=’on’ />` configuration. It does so by disabling virtualization from the GPU driver
2. Black Screen Or VM Freezes on Boot
Although an incorrect extending screen outputs a black boot screen, it is not the only cause of such a dysfunction. To check that the VGA and its default audio device are correctly passed through the VFIO driver, check the output of ‘lspci -nnk.’ In addition, mitigate GPU lock by inserting blacklist commands which are appropriate to the GPU in use, e.g., ‘nouveau’ or ‘amdgpu’ for Linux systems.
3. IOMMU Grouping Issues
Devices that are improperly grouped in IOMMU can also cause issues; however, enabling the ACS override patch can resolve these issues. For this, use the kernel parameter form of ‘pcie_acs_override=downstream, multifunction.’ Then repeat groupings checks through the command ‘find /sys/kernel/iommu_groups/ -type l.’
4 . Host GPU Interference
Should the host output be rendered with a passthrough GPU additionally assigned to other shims, consider dedicating a different GPU for the host’s use or using a headless configuration with no monitors.
- GPU Virtualization Performance Bottlenecks
Another potential cause of performance loss that should be considered is whether huge pages are configured properly. Based on your memory requirement, specify the count of huge pages, N, and add default_hugepagesz=1G hugepagesz=1G hugepages=N to the kernel parameters.
An acceptable strategy for tackling most GPU passthrough difficulties is pinpointing the problem and implementing discrete solutions methodically. Always double-check the amendments about the specific hardware and VM requirements to sustain their composition.
Dealing with Error 43 on NVIDIA GPUs
Fighting against Error 43 while using NVIDIA GPUs in a virtualized environment, remedied by a few methods that are mostly common in the community, was not an effortless task. To resolve the passthrough NVIDIA GPU driver issue, which is a common issue while virtualizing, I first made sure I patched the driver in the Guest VM. Besides displaying supplementary GPU devices, the vfio-pci pass-through and the kernel module were configured. Device IDs were acknowledged and configured correctly.
Earlier this year, I used to use the ‘kvm=hidden” flag, but fortunately, I could locate the configuration file within the operating system and paste it. This is to say that the KVM hypervisor is hidden from the guest operating system, which concerns the proper use of virtualization. Additionally, implementing the requirement of ‘hypervisor.cpuid.v0=FALSE’ on the VM configuration provides further assurance that external interference is not an entry point.
Above that, I ensured that the actual physical GPU was not using the host system by verifying configurations clouded by my sight. The configurations that I looked at were shapeless assignments to the VM. I also validated that my VM XML configuration under the PCI part had the ABBA microelectronic device ID and the vendor ID. These modifications have systematically alleviated the reasserting of Error 43 alongside the return of disposable device control through the passed cable setup.
Resolving Audio Device Passthrough Problems
I fixed the issues associated with the passthrough of the audio device by monitoring the configurations within my VM settings. First, I checked if the audio device was adequately allocated to the VM by executing the command `virsh edit` and editing an XML file while confirming if the hardware settings specified in the <sound> tag had been included. Moreover, I noticed that the QEMU audio driver was set to `alsa,` where appropriate, for the specific OS in use. After installing the requisite drivers on the guest OS, I performed integration tests to confirm functionality. Lastly, I altered the latency settings and tried several configurations to eliminate the audio delay or distortion issues. These steps all contributed to effectively solving the passthrough problem.
Fixing Performance Issues and Input Lag
To fix performance issues and input lag, I verified the VM’s CPU and memory allocations by editing its XML file via `virsh edit` and adjusting the `<vcpu>` and `<memory>` values until they matched the workload requirements. Not compromising on CPU performance, I set `<cpu mode=’host-passthrough’>,` which allowed the guest to use specific host CPU features. Regarding GPU performance, I correctly passed through the GPUs by configuring those PCI IDs on the `<hostdev>` section together with the assigned VFIO. Moreover, I implemented massive page provisioning on the host for better memory performance by toggling the setting `vm.nr_hugepages` in the configuration file `/etc/sysctl.conf`. Furthermore, I also implemented a USB passthrough for keyboards and mice in `<hostdev>` assignments to alleviate input lag and inspected peripherals’ polling rates. Lastly, eliminating unnecessary background services on host and guest systems is also pivotal in optimal resource allocation. These changes significantly improved performance problems and input lag.
Key Parameters:
- CPU Allocation: `<vcpu>` (set to match workload requirements), `<cpu mode=’host-passthrough’>.`
- Memory Configuration: Hugepages are enabled with `vm.nr_hugepages` and adjusted in `/etc/sysctl.conf`.
- GPU Passthrough: Correct PCI IDs assigned under `<hostdev>.`
- Input Devices: USB passthrough via `<hostdev>` entries with optimal polling rates tested.
Advanced GPU Passthrough Techniques
The first step in using effective GPU passthrough is to optimize the software and the hardware; start by dedicating one or more CPU cores and threads to the machine; in your hypervisor configuration, use the ‘CPU’ option to minimize interference with the parent machine. Set the OVMF (UEFI) on the virtual machine to gain full advantage of the GPU in use; this is done to avoid BIOS restrictions. In systems that contain hardware with poor IOMMU groupings, make sure the ACS (Access Control Services) override feature is turned on for proper device isolation to occur. In addition to this, make sure to use VFIO capable kernel Parameters that enable the passthrough of devices and enhance the general PCI device performance, options such as ‘iommu=pt’ and ‘intel_iommu=on’ or ‘amd_iommu=on’ are recommended.
For optimal performance from the virtual machine, use a separate SSD or NVMe drive to enhance speed, as read/write operations would not act as performance chokepoints. Furthermore, it is worth noting that dynamic pages are more likely to be beneficial than static ones, as reduced fragmentation and increased flexibility are two valuable characteristics in extensive RAM usage & runtime. Ensure that your GPU can handle resets, especially from NVIDIA cards; this allows the virtual machine to turn on and off with minimal issues. These measures significantly improve system performance and enable users to utilize GPUs effortlessly.
Using ACS Override Patch for Improved IOMMU Grouping
The ACS patch is of value as it can be used to override limitations imposed by IOMMU groupings on hardware platforms that do not natively divide the devices into such groups. In my experience, what this patch does is pretty much make PCIe devices grouped into finer levels, making passthrough of holders that would otherwise be non-pass-through devices possible. But be careful when using this as it might bring about PCIe disaggregation and isolation, which can threaten some users. Ensure that it is compatible with your specific kernel, and consider trying it out on a controlled system before deploying it on production machines.
Implementing Looking Glass for Seamless VM Integration
To ensure smooth use of Looking Glass, several initial settings must be performed so the virtual machine runs correctly. First, Looking glass server and client applications must be set up correctly. This involves configuring network connections, satisfying specific protocol needs such as WebSockets or RDP, and confirming that the hardware is equipped with the appropriate virtualization extensions such as Intel VT-x or AMD-V. Furthermore, available patches for both the server and the client side are advisable as these patches mainly perform compatibility and performance enhancements. Also, correctly configured allocation of CPUs, memory, and storage resources within the VM environment is critical to avoiding potential bottlenecks during the operation. Revisiting the vendor documentation and compatibility lists during the implementation will help to maintain the correct approach.
Setting Up GPU Passthrough with Multiple GPUs
Configuring multiple GPUs with passthrough grace is meticulous since you must take care of almost everything during the setup. But before we begin, make sure to have the parts required for this, such as the IOMMU-enabled motherboard and multiple GPUs with dissimilar IOMMU groups. You must head to your BIOS/UEFI and enable virtualization options such as Intel VT-d or AMD-Vi. Following that, update the GRUB configuration so that it contains kernel flags which are required such as `intel_iommu=on` and or `amd_iommu=on`. After booting, it will be prudent to double-check the IOMMU groupings using commands such as `limma` or exploring the directory: `/sys/kernel/iommu_groups.` To avoid stereograms, you need to assign one GPU to a virtual machine, which will be done by binding its PCI address to the `vfio-pci` driver. So, in this case, update the appropriate disk or qemu configuration file and add the new GPU alongside its audio device. Finally, be sure to install the proper GPU drivers on both the host and the VM for the best performance optimization possible.
References
Frequently Asked Questions (FAQ)
Q: What is GPU passthrough, and why is it important for gaming in virtual machines?
A: GPU passthrough is a technique that allows a virtual machine (VM) direct access to a physical GPU. This is important for gaming in VMs because it significantly improves graphics performance, allowing you to run games at near-native speeds. Using VFIO (Virtual Function I/O) technology, you can dedicate a GPU directly to a VM, bypassing the host operating system and providing a seamless gaming experience.
Q: What are the prerequisites for setting up GPU passthrough?
A: To set up GPU passthrough, you’ll need: 1. A CPU and motherboard that support virtualization technologies (VT-d for Intel or AMD-Vi for AMD) 2. At least two GPUs (one for the host and one for the VM) 3. A Linux-based host operating system (e.g., Ubuntu) 4. A hypervisor such as KVM/QEMU or Proxmox 5. Sufficient RAM and storage for both host and guest systems
Q: How do I enable GPU passthrough in my BIOS/UEFI?
A: To enable GPU passthrough, you must access your computer’s BIOS/UEFI settings and enable virtualization technologies. For Intel systems, look for and enable VT-d (Virtualization Technology for Directed I/O). For AMD systems, enable AMD-Vi or IOMMU. These settings are usually found under CPU Configuration or Advanced Settings. After allowing, save the changes and reboot your system.
Q: What steps are involved in setting up VFIO for GPU passthrough?
A: Setting up VFIO involves the following steps: 1. Identify your GPU’s PCI device ID 2. Configure the VFIO driver to bind to your GPU 3. Blacklist the default GPU drivers 4. Update your bootloader configuration 5. Configure your VM to use the passed-through GPU. These steps may vary slightly depending on your specific setup and distribution.
Q: How do I blacklist the default GPU drivers to use VFIO instead?
A: To blacklist the default GPU drivers, you need to create or modify a configuration file in your system. For example, on Ubuntu, you can make a file named “blacklist-nvidia.conf” in the “/etc/modprobe.d/” directory. Add the following lines to blacklist the Nvidia drivers: blacklist nouveau blacklist nvidia blacklist nvidia_drm blacklist nvidia_modeset. This prevents the host system from using these drivers, allowing VFIO to take control of the GPU.
Q: How do I set up a Windows VM with GPU passthrough using QEMU/KVM and libvirt?
A: To set up a Windows VM with GPU passthrough using QEMU/KVM and libvirt: 1. Install QEMU, KVM, and libvirt on your host system 2. Create a new VM using virt-manager or virsh 3. Configure the VM to use UEFI firmware (OVMF) 4. Add your passed-through GPU as a PCI device in the VM configuration 5. Install Windows and the appropriate GPU drivers in the VM 6. Configure the VM to use the passed-through GPU for display output
Q: What are some common issues with GPU passthrough, and how can I troubleshoot them?
A: Common issues with GPU passthrough include: 1. Error 43 in Windows Device Manager: This can often be resolved by adding vendor_id and hidden state to the VM’s XML configuration. 2. Black screen on VM boot: Ensure you use UEFI firmware and that the GPU’s VBIOS is adequately passed through. 3. Poor performance: Check that you’ve installed the correct GPU drivers in the VM and that CPU pinning is configured correctly. 4. Host system freezes: This may be due to improper IOMMU group separation. Use the ACS override patch if necessary.
Q: How can I optimize my GPU passthrough setup for better gaming performance?
A: To optimize your GPU passthrough setup: 1. Use CPU pinning to dedicate specific cores to your VM 2. Enable huge pages for better memory management 3. Use virtio drivers for improved I/O performance 4. Consider using Looking Glass for seamless switching between host and guest 5. Experiment with different QEMU CPU models to find the best performance 6. Ensure your VM has enough allocated RAM and virtual CPUs. Remember to benchmark your setup to find the optimal configuration for your specific hardware.
Q: Can I use GPU passthrough with Nvidia GPUs, and are there any special considerations?
A: Yes, you can use GPU passthrough with Nvidia GPUs, but there are some special considerations: 1. Nvidia GPUs may require the “nvidia-vgpu-vfio” kernel module for proper functioning. 2. You may need to hide the hypervisor from the VM to prevent Nvidia drivers from detecting virtualization. 3. Some Nvidia consumer GPUs may require a patched vBIOS to work in a passthrough setup. 4. Ensure you’re using the latest Nvidia drivers in your Windows VM for the best compatibility and performance.