kvm qemu pci passthough

1,  宿主机需要打开iommu特性
     验证host有没有打开iommu可以通过dmesg | grep iommu 查看
2,  通过lspci查看pci设备信息,得到pci设备的domain ,bus, slot, function信息(例如:0000.04.00.0)
3,  也可以通过virsh的命令得到pci设备信息:
     1) virsh nodedev-list --tree
 computer
|
+- net_lo_00_00_00_00_00_00
+- pci_0000_00_00_0
+- pci_0000_00_02_0
+- pci_0000_00_03_0
+- pci_0000_00_14_0
| |
| +- usb_usb2
| | |
| | +- usb_2_0_1_0
| | +- usb_2_7
| | | |
| | | +- usb_2_7_1_0
| | | +- usb_2_7_1_1
| | | 
| | +- usb_2_8
| | |
| | +- usb_2_8_1_0
| | +- usb_2_8_1_1
| | 
| +- usb_usb3

    2) virsh nodedev-dumpxml pci_0000_04_00_0
<device>
<name>pci_0000_04_00_0</name>
<path>/sys/devices/pci0000:00/0000:00:1c.2/0000:04:00.0</path>
<parent>pci_0000_00_1c_2</parent>
<driver>
<name>iwlwifi</name>
</driver>
<capability type='pci'>
<domain>0</domain>
<bus>4</bus>
<slot>0</slot>
<function>0</function>
<product id='0x08b4'>Wireless 3160</product>
<vendor id='0x8086'>Intel Corporation</vendor>
<iommuGroup number='13'>
<address domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
</iommuGroup>
</capability>
</device>

3, 在libvirt xml配置文件里面加入:
<hostdev mode='subsystem' type='pci' managed='yes'>
        <source>
        <address domain='0x00' bus='0x04' slot='0x00' function='0x00' />
       </source>
</hostdev>

至此再重新定义和开启虚拟机,然后lspci就可以看到穿透过来的pci设备了

猜你喜欢

转载自blog.csdn.net/hobertony_7/article/details/49968279