PCIE接口直通
参考链接: kvm虚拟机PCI设备直通
预配置
- 打开Bios中的VT-d配置
- Kernel引导配置iommu,参见文章 linux开启IOMMU方法 Linux开启IOMMU方法
# 重启生效
grubby --update-kernel=ALL --args=intel_iommu=on
# (amd_iommu/intel_iommu/AuthenticAMD))
安装lspci命令
yum -y install pciutils
识别设备
# 查看想希望卡的接口信息
[root@dell_3650t qemu]# lspci | grep 0719
01:00.0 Processing accelerators: Device 00a1:0719 (rev ff)
# 查看接口具体名称
[root@dell_3650t qemu]# virsh nodedev-list --tree |grep pci
+- pci_0000_00_00_0
+- pci_0000_00_01_0
| +- pci_0000_01_00_0
+- pci_0000_00_02_0
获取设备xml信息
- 确认bus,slot,function信息
[root@dell_3650t qemu]# virsh nodedev-dumpxml pci_0000_01_00_0
<device>
<name>pci_0000_01_00_0</name>
<path>/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0</path>
<parent>pci_0000_00_01_0</parent>
<driver>
<name>aicard</name>
</driver>
<capability type='pci'>
<domain>0</domain>
<bus>1</bus>
<slot>0</slot>
<function>0</function>
<product id='0x0719' />
<vendor id='0x00a1' />
<iommuGroup number='9'>
<address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</iommuGroup>
<pci-express>
<link validity='cap' port='0' speed='16' width='16'/>
<link validity='sta' speed='16' width='16'/>
</pci-express>
</capability>
</device>
Detach设备
[root@dell_3650t ~]# virsh nodedev-dettach pci_0000_01_00_0
Device pci_0000_01_00_0 detached
配置虚拟机xml文件
- 根据之前查询到的Bus,slot,function信息修改相关数据
[root@dell_3650t qemu]# cat pci.xml
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</source>
</hostdev>
加载虚拟机xml文件
[root@dell_3650t qemu]# virsh attach-device kvm-122.10 pci.xml
Device attached successfully
确认是否加载成功
# 登陆kvm服务器,使用lspci查看
[root@kvm-122 ~]# lspci | grep 0719
00:04.0 Processing accelerators: Device 00a1:0719 (rev ff)