Nvidia显卡Libvirt虚拟机PCI pass throu
2018-12-11 本文已影响0人
听松客未眠
宿主机设置
首先需要在宿主机启用VFIO和SR-IOV功能。通过如下方式启用, 具体操作需要参考对应操作系统的说明
- 对于Intel宿主机,需要在启动选项GRUB中添加参数
intel_iommu=on
- 设置Kernel模块vfio_pci为启动状态
在/etc/modules-load.d/中新建文件vfio_pci.conf,内容为
vfio_pci
- 重新启动系统
-
lsmod | grep vfio
验证安装情况,应该能看到如下内容
vfio_pci 40960 0
vfio_iommu_type1 20480 0
vfio_virqfd 16384 1 vfio_pci
vfio 32768 2 vfio_iommu_type1,vfio_pci
irqbypass 16384 2 kvm,vfio_pci
Libvirt设置
- 获取NVIDIA显卡设备
lspci | grep NVIDIA
案例中为85:00.0和86:00.0
$ lspci | grep NVIDIA
85:00.0 VGA compatible controller: NVIDIA Corporation GM204GL [Tesla M60] (rev a1)
86:00.0 VGA compatible controller: NVIDIA Corporation GM204GL [Tesla M60] (rev a1)
- 获取PCI设备全名代号
$ virsh nodedev-list --cap pci| grep 85_00_0 # 替换上述冒号为下划线
pci_0000_85_00_0
- 获取PCI设备domain,bus,slot,function
$ virsh nodedev-dumpxml pci_0000_85_00_0| egrep 'domain|bus|slot|function'
<domain>0x0000</domain>
<bus>0x85</bus>
<slot>0x00</slot>
<function>0x0</function>
<address domain='0x0000' bus='0x85' slot='0x00' function='0x0'/>
- 设置虚拟机
$ virsh edit <vm-name>
在xml <devices>节点中插入如下内容:
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0x85' slot='0x00' function='0x0'/>
</source>
</hostdev>
- 启动虚拟机
virsh start vm-name