KVM : GPU Passthrough2021/10/06 |
Configure GPU Passthrough for Virtual Machines.
By this configuration, it's possible to run GPU computing on Virtual Machines.
Before configuration, Enable VT-d (Intel) or AMD IOMMU (AMD) on BIOS Setting first.
|
|
[1] | Enable IOMMU feature and [vfio-pci] kernel module on KVM Host. |
root@dlp:~#
vi /etc/default/grub # line 10 : add # for AMD CPU, set [amd_iommu=on] # for Intel CPU, set [intel_iommu=on] GRUB_CMDLINE_LINUX=" intel_iommu=on "
root@dlp:~#
grub-mkconfig -o /boot/grub/grub.cfg # make sure PCI identification number and [Vendor-ID : Device-ID] of Graphic card # example below # PCI identification ⇒ [01:00.*] # [Vendor-ID : Device-ID] ⇒ [10de:***] root@dlp:~# lspci -nn | grep -i nvidia 01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GP106 [GeForce GTX 1060 6GB] [10de:1c03] (rev a1) 01:00.1 Audio device [0403]: NVIDIA Corporation GP106 High Definition Audio Controller [10de:10f1] (rev a1)
root@dlp:~#
vi /etc/modprobe.d/vfio.conf # create new : for [ids=***], specify [Vendor-ID : Device-ID] options vfio-pci ids=10de:1c03,10de:10f1
root@dlp:~#
echo 'vfio-pci' > /etc/modules-load.d/vfio-pci.conf
root@dlp:~#
reboot
# OK if [IOMMU enabled] is shown root@dlp:~# dmesg | grep -E "DMAR|IOMMU" [ 0.010654] ACPI: DMAR 0x000000005C6E6B70 0000C4 (v01 ALASKA A M I 00000001 INTL 20091013) [ 0.010676] ACPI: Reserving DMAR table memory at [mem 0x5c6e6b70-0x5c6e6c33] [ 0.021239] DMAR: IOMMU enabled [ 0.079969] DMAR: Host address width 46 [ 0.079971] DMAR: DRHD base: 0x000000fbffd000 flags: 0x0 [ 0.079976] DMAR: dmar0: reg_base_addr fbffd000 ver 1:0 cap 8d2008c10ef0466 ecap f0205b [ 0.079977] DMAR: DRHD base: 0x000000fbffc000 flags: 0x1 [ 0.079980] DMAR: dmar1: reg_base_addr fbffc000 ver 1:0 cap 8d2078c106f0466 ecap f020df [ 0.079981] DMAR: RMRR base: 0x0000005ce2b000 end: 0x0000005ce3afff [ 0.079983] DMAR: ATSR flags: 0x0 [ 0.079984] DMAR: RHSA base: 0x000000fbffc000 proximity domain: 0x0 [ 0.079985] DMAR-IR: IOAPIC id 1 under DRHD base 0xfbffc000 IOMMU 1 [ 0.079986] DMAR-IR: IOAPIC id 2 under DRHD base 0xfbffc000 IOMMU 1 [ 0.079987] DMAR-IR: HPET id 0 under DRHD base 0xfbffc000 [ 0.079988] DMAR-IR: x2apic is disabled because BIOS sets x2apic opt out bit. [ 0.079989] DMAR-IR: Use 'intremap=no_x2apic_optout' to override the BIOS setting. [ 0.080474] DMAR-IR: Enabled IRQ remapping in xapic mode [ 1.085020] DMAR: dmar0: Using Queued invalidation [ 1.085024] DMAR: dmar1: Using Queued invalidation [ 1.094125] DMAR: Intel(R) Virtualization Technology for Directed I/O [ 1.102037] AMD-Vi: AMD IOMMUv2 driver by Joerg Roedel <jroedel@suse.de> [ 1.102038] AMD-Vi: AMD IOMMUv2 functionality not available on this system # OK if [vfio-pci] is enabled root@dlp:~# dmesg | grep -i vfio [ 3.243739] VFIO - User Level meta-driver version: 0.3 [ 3.252081] vfio-pci 0000:01:00.0: vgaarb: changed VGA decodes: olddecodes=io+mem,decodes=io+mem:owns=io+mem [ 3.276061] vfio_pci: add [10de:1c03[ffffffff:ffffffff]] class 0x000000/00000000 [ 3.296056] vfio_pci: add [10de:10f1[ffffffff:ffffffff]] class 0x000000/00000000 |
[2] | That's OK. When creating a VM with GPU, Specify PCI identification number of GPU for [--host-device]. |
root@dlp:~# virt-install \
--name debian11 \
--ram 8192 \
--disk path=/var/kvm/images/debian11.img,size=30 \
--vcpus 4 \
--os-variant debian10 \
--network bridge=br0 \
--graphics none \
--console pty,target_type=serial \
--location /home/debian-11.0.0-amd64-DVD-1.iso \
--extra-args 'console=ttyS0,115200n8 serial' \
--host-device 01:00.0 \
--features kvm_hidden=on \
--machine q35
|
[3] | That's OK if GPU is found on a VM. |
root@localhost:~# lspci | grep -i nvidia 05:00.0 VGA compatible controller: NVIDIA Corporation GP106 [GeForce GTX 1060 6GB] (rev a1) |
Sponsored Link |
|