SR-Iov Introduction: (Reference: http://docs.oracle.com/cd/E38902_01/html/E38873/glbzi.html)
We know that the vt-d function can be directly assigned to the device to allow the virtual machine to use an I/O device that achieves similar physical machine performance, but there is a drawback to using vt-d: A device can only be used by one client, so is there any way to make the device performance, so that multiple virtual machines can be used simultaneously? This is
SR-Iov (single root I/O virtualization and sharing) technology, pictures from the book "KVM Virtualization Technology Principles and Practical analysis"
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/8B/7E/wKiom1hPkxXzm8BeAAFkci8aDi4137.png "title=" 930{@ 8kwr2keebfjqd_8ct3.png "alt=" Wkiom1hpkxxzm8beaafkci8adi4137.png "/>
SR-Iov Technology requires the support of a hardware device that provides two new types of functionality:
Physical function (physical function PF): For PCI features that support SR-Iov functionality, as defined in the SR-Iov specification. PF includes SR-IOV functional structure for managing SR-Iov functionality. PF is a full-featured PCIe feature that can be discovered, managed, and processed like any other PCIe device. PF has a fully configured resource that can be used to configure or control the PCIE device.
virtual function, VF: A function associated with a physical function. VF is a lightweight PCIe feature that shares one or more physical resources with physical capabilities and other VF associated with the same physical function. The VF only allows configuration resources for its own behavior.
In short, a PF can be configured with multiple VF, or it can be used by itself as a complete resource for virtual machines. Each VF has its own separate configuration space and full bar (base address register base register), which is a truly independent hardware resource. Hypervisor these resources through hardware virtualization technology such as Vd-x bypass their own software switches directly mapped to the client, you can assign multiple VF to different clients, so that multiple clients can directly manipulate the same hardware resources
In KVM, one or more VF can be assigned to a client, and the client operates the device's VF directly through its own VF driver without the need for KVM involvement.
SR-Iov use (with Nic as an example):
Lspci-v-S $BDF #查看Capability选项来确定设备是否支持 $BDF function, generally shown as capabilities: [+] Single Root I/O virtualization (SR-Iov )
Modinfo IGB#查看igb模块说明, PF uses different drivers to support a different number of VF, such as the network card driver igb up to 7, and Ixgbe up to 63, you can see the description of "Parm:max_vfs:Maximum num ber of virtual functions to allocate per physical function (UINT) "
Lsmod IGB
Rmmod IGB
Modprobe IGB max_vfs=7 #要想开启vf功能需要在加载驱动是加上max_vfs参数
Ls-l/sys/bus/pci/devices/$BDF#可以观察这里的链接来查看PF和VF的对应关系
Echo-n "$vendID $deviceID" >/sys/bus/pci/drivers/pci-stub/new_id
echo $BDF >/sys/bus/pci/devices/$BDF/driver/unbind
echo $BDF >/sys/bus/pci/drivers/pci-stub/bind#隐藏设备, of course, the BDF here refers to the BDF of the VF.
Qemu-system-x86_64-m 2048-SMP 3 xp.qcow2-device pci-assign,host= $BDF, Id=mydev0,addr=0x6-usb-usbdevice tablet #通过-device parameter assignment device to client
Hot-swappable PCI devices:
PCI devices require BIOS, PCI bus, guest operating system kernel, and driver support.
Adding a hot-swappable device to the client only needs to be in the monitor interface, using the following command:
Device_add pco-assign,host= $BDF, Id=yourid #id可以自定义
To delete, use:
Device_del Yourid#即插入时的id
Introduction to KVM SR-Iov Hot Swap