libvirt之vfio pci的passthrough
2015-08-18
一、准备
1.开机启动项
/etc/default/grub文件
在GRUB_CMDLINE_LINUX参数加入intel_iommu=on
2.加载模块
modprobe vfio
modprobe vfio-pci
3.准备一台虚拟机
e.g 一台虚拟机vfio_test
4. bios开启iommu groups
Navigate through each BIOS screen using the "arrow" keys and find the "IOMMU," "I/O Memory Management Unit," or "Intel ® VT-d"setting (usually located under the "Advanced" or "Chipset/Northbridge/Tylersburg IOH/Intel VT for Directed I/O Configuration"settings menu). Move the cursor over the setting selection box using the "arrow" keys and press the "Page Up" or "Page Down" or specified key to select "Enabled."
二、iommu_group单个设备
1.选择需要passthrough的pci设备,其pci地址是0000:0b:00.0
[root@host192 libvirt]# lspci | grep -i fibre
0b:00.0 Fibre Channel: QLogic Corp.ISP2432-based 4Gb Fibre Channel to PCI Express HBA (rev 03)
2. 查询其所处的iommu_group,看到iommu_group是19,并且整个组就一个设备0000:0b:00.0
[root@host192 libvirt]# readlink /sys/bus/pci/devices/0000\:0b\:00.0/iommu_group
../../../../kernel/iommu_groups/19
[root@host192 libvirt]# ls /sys/bus/pci/devices/0000\:0b\:00.0/iommu_group/devices/
0000:0b:00.0
3.将iommu_group下的设备unbind,将设备unbind之后,会发现目录下面的driver目录消失了
echo 0000:0b:00.0 >>/sys/bus/pci/devices/0000\:0b\:00.0/driver/unbind
注意:这条指令执行后/sys/bus/pci/devices/0000\:0b\:00.0/下的driver目录会消失
4.将设备地vendorid和deviceid绑定到new_id
[