Pass through to VM on Linux Host
Posted on Wed 07 July 2021 in Virtual Machine • 2 min read •
Before enabling pass through we need to enable IOMMU
(input–output memory management unit)
by adding following kernel parameters in /etc/default/grub
.
- For intel systems:
intel_iommu=on
- For AMD system, IOMMU is by default enabled.
Additionally add iommmu=pt
parameter to prevent linux kernel from touching
devices which cannot be passed through.
Update grub by sudo update-grub
command and
reboot the system. After reboot, check that the device to be passed through
(usually GPU) has separate IOMMU group by inspecting the output
of following shell script.
1 2 3 4 5 6 7 8 |
|
Sometimes, a number of sub-devices can be attached to a device in that case, please ensure that all of sub-devices belong to same IOMMU group and all of them should be passed through together.
Sample output:
1 2 3 4 5 6 7 |
|
For enabling pass through on the device, note its vendorID:productID and add
vfio-pci
parameter to kernel parameters. For instance to forward
Network controller from the above example the parameter should be
1 |
|
If you want to pass through IOMMU Group 8, then add following parameter
1 |
|
Then add vfio-pci
module to initramfs by adding to
/etc/initramfs-tools/modules
file. Regenerate the initramfs by
sudo update-initramfs -u
command and regenerate the grub configuration by
sudo update-grub
. Reboot the system.
After reboot, ensure that the concerned device have vfio-pci
as active
module by lspci -nnk -d vendorID:productID
. For instance, the correct output
for NVIDIA GPU card from IOMMU group 8 should be (output of lspci -nnk -d 10de:2191
)
1 2 3 4 |
|
Now, we are ready to pass this device to virtual machine (VM). Open properties
of VM in virt-manager
and add ‘PCI Host Device’ hardware for the NVIDIA GPU
and its sub-devices. Turn on VM to enjoy NVIDIA GPU with it.
Note: The host linux system will not use any device with vfio-pci
module.
To get the access to device, please remove the vfio-pci
related kernel
parameter. You can keep IOMMU on as it has added advantage.