SR-IOV是PCI passthrough 的增强,设备本身(例如网卡)要支持SR-IOV
example for Intel 82576 NIC
1. enable Intel VT-d in BIOS
2. using "lspci | grep 82576" to verify the NIC was detected
3. list SR-IOV module using "lsmod | grep igb", if not, "modprobe igb"
4. Activate Virtual Functions
# modprobe -r igb
# modprobe igb max_vfs=7
5. Make the Virtual Functions persistent
# modprobe /etc/modprobe.d/igb.conf igb max_vfs=7
6. Inspect the new Virtual Functions
# lspci | grep 82576
7. Verify devices exist with virsh
# virsh nodedev-list | grep 0b
pci_0000_0b_00_0
pci_0000_0b_00_1
pci_0000_0b_10_0
pci_0000_0b_10_1
pci_0000_0b_10_2
pci_0000_0b_10_3
pci_0000_0b_10_4
pci_0000_0b_10_5
pci_0000_0b_10_6
pci_0000_0b_11_7
pci_0000_0b_11_1
pci_0000_0b_11_2
pci_0000_0b_11_3
pci_0000_0b_11_4
pci_0000_0b_11_5
8. Get device details with virsh
The pci_0000_0b_00_0
is one of the Physical Functions and pci_0000_0b_10_0
is the first corresponding Virtual Function for that Physical Function. Use the virsh nodedev-dumpxml
command to get advanced output for both devices.
# virsh nodedev-dumpxml pci_0000_0b_00_0 <device> <name>pci_0000_0b_00_0</name> <parent>pci_0000_00_01_0</parent> <driver> <name>igb</name> </driver> <capability type='pci'> <domain>0</domain> <bus>11</bus> <slot>0</slot> <function>0</function> <product id='0x10c9'>Intel Corporation</product> <vendor id='0x8086'>82576 Gigabit Network Connection</vendor> </capability> </device>
# virsh nodedev-dumpxml pci_0000_0b_10_0 <device> <name>pci_0000_0b_10_0</name> <parent>pci_0000_00_01_0</parent> <driver> <name>igbvf</name> </driver> <capability type='pci'> <domain>0</domain> <bus>11</bus> <slot>16</slot> <function>0</function> <product id='0x10ca'>Intel Corporation</product> <vendor id='0x8086'>82576 Virtual Function</vendor> </capability> </device>
9. Detach the Virtual Functions
Detach the Virtual Function from the host so that the Virtual Function can be used by the guest.
# virsh nodedev-dettach pci_0000_0b_10_0 Device pci_0000_0b_10_0 dettached
10. Add the Virtual Function to the guest
virsh nodedev-dumpxml pci_0000_0b_10_0
command for the values required for the configuration file.
bus='3' slot='16' function='1'
printf
utility to convert from decimal values:
$ printf %x 3 3 $ printf %x 16 10 $ printf %x 1 1
bus='0x0b' slot='0x10' function='0x01'
virsh edit
command. This example edits a guest named
MyGuest
.
# virsh edit MyGuest
devices
section of the XML configuration file.
<hostdev mode='subsystem' type='pci' managed='yes'> <source> <address bus='0x0b' slot='0x10' function='0x01'/> </source> </hostdev>
11. Restart
# virsh start MyGuest