美文网首页
Nvidia显卡Libvirt虚拟机PCI pass throu

Nvidia显卡Libvirt虚拟机PCI pass throu

作者: 听松客未眠 | 来源:发表于2018-12-11 16:23 被阅读0次

    宿主机设置

    首先需要在宿主机启用VFIO和SR-IOV功能。通过如下方式启用, 具体操作需要参考对应操作系统的说明

    1. 对于Intel宿主机,需要在启动选项GRUB中添加参数intel_iommu=on
    2. 设置Kernel模块vfio_pci为启动状态
      在/etc/modules-load.d/中新建文件vfio_pci.conf,内容为
    vfio_pci
    
    1. 重新启动系统
    2. 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设置

    1. 获取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)
    
    1. 获取PCI设备全名代号
    $ virsh nodedev-list --cap pci| grep 85_00_0  # 替换上述冒号为下划线
    pci_0000_85_00_0
    
    1. 获取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'/>
    
    1. 设置虚拟机
    $ 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>
    
    1. 启动虚拟机
    virsh start vm-name
    

    相关文章

      网友评论

          本文标题:Nvidia显卡Libvirt虚拟机PCI pass throu

          本文链接:https://www.haomeiwen.com/subject/ezjshqtx.html