Single Root IO Virtualization (SR-IOV)
是一种规范,允许出于可管理性和性能原因隔离 PCI Express 资源,用来为 VM(虚拟机)
提供独立的内存空间、中断、DMA 数据流等资源
Mellanox 网卡开启 SR-IOV
# 开启了IOMMU,sudo vim /etc/default/grub,在GRUB_CMDLINE_LINUX字段中添加
intel_iommu=on iommu=pt
sudo update-grub
sudo reboot
$ dmesg | grep -i dmar
[ 0.745740] DMAR: IOMMU enabled
- 启动 MST(Mellanox Software Tools)
mst start
$ sudo mst status
MST modules:
---
MST PCI module is not loaded
MST PCI configuration module loaded
## MST devices:
/dev/mst/mt4119_pciconf0 - PCI configuration cycles access.
domain:bus:dev.fn=0000:e3:00.0 addr.reg=88 data.reg=92 cr_bar.gw_offset=-1
Chip revision is: 00
$ sudo mlxconfig -d /dev/mst/mt4119_pciconf0 q
...
NUM_OF_VFS 0
...
SRIOV_EN False(0) # 未开启
- 开启 SR-IOV,设置 VF 数量为 4,NUM_OF_VFS 是 VF 的数量上限,不是已经分配的 VF 数量
$ sudo mlxconfig -d /dev/mst/mt4119_pciconf0 set SRIOV_EN=1
$ sudo mlxconfig -d /dev/mst/mt4119_pciconf0 set NUM_OF_VFS=4
$ sudo reboot
- 打开 mst,查看设备状态,发现 SR-IOV 是否启动
$ sudo mst start
$ sudo mlxconfig -d /dev/mst/mt4119_pciconf0 q
NUM_OF_VFS 4
SRIOV_EN True(1) # 已开启
$ cat /sys/class/net/ens10f1/device/sriov_totalvfs
4
$ cat /sys/class/net/ens10f1/device/sriov_numvfs
0
$ sudo chmod +666 /sys/class/net/ens10f1/device/sriov_numvfs
$ sudo echo 4 > /sys/class/net/ens10f1/device/sriov_numvfs
$ lspci -D | grep Mellanox
0000:e3:00.0 Infiniband controller: Mellanox Technologies MT27800 Family [ConnectX-5]
0000:e3:00.1 Ethernet controller: Mellanox Technologies MT27800 Family [ConnectX-5]
0000:e3:00.6 Ethernet controller: Mellanox Technologies MT27800 Family [ConnectX-5 Virtual Function]
0000:e3:00.7 Ethernet controller: Mellanox Technologies MT27800 Family [ConnectX-5 Virtual Function]
0000:e3:01.0 Ethernet controller: Mellanox Technologies MT27800 Family [ConnectX-5 Virtual Function]
0000:e3:01.1 Ethernet controller: Mellanox Technologies MT27800 Family [ConnectX-5 Virtual Function]
$ sudo ibdev2netdev -v
0000:e3:00.0 mlx5_0 (MT4119 - MCX556A-ECAT) CX556A - ConnectX-5 QSFP28 fw 16.35.3006 port 1 (ACTIVE) ==> ibs10f0 (Up)
0000:e3:00.1 mlx5_1 (MT4119 - MCX556A-ECAT) CX556A - ConnectX-5 QSFP28 fw 16.35.3006 port 1 (ACTIVE) ==> ens10f1 (Up)
0000:e3:00.6 mlx5_2 (MT4120 - NA) fw 16.35.3006 port 1 (ACTIVE) ==> ens10f1v0 (Up)
0000:e3:00.7 mlx5_3 (MT4120 - NA) fw 16.35.3006 port 1 (ACTIVE) ==> ens10f1v1 (Up)
0000:e3:01.0 mlx5_4 (MT4120 - NA) fw 16.35.3006 port 1 (ACTIVE) ==> ens10f1v2 (Up)
0000:e3:01.1 mlx5_5 (MT4120 - NA) fw 16.35.3006 port 1 (ACTIVE) ==> ens10f1v3 (Up)