本文只介绍SR-IOV的基本内容,并不能cover SR-IOV的全部知识点。

1. prerequisites

  1. 需要理解VT-d的DMA remapping,interrupt remapping ,posted interrupt
  2. 需要理解PCI&PCIe的config space,MSI与MSI-X.
  3. 需要理解ATS,ACS,ARI
  4. PCIe config space位于MMIO空间内

2. motivation

推荐论文:High Performance Network Virtualization with SRIOV

可阅读Junming’s notes

3. details

BIOS should be able to enumerate SR-IOV capable device and allocate MMIO (Memory mapped IO) resource for VFs.

SR-IOV Extended Capability The SR-IOV Extended Capability defined here is a PCIe extended capability that must be implemented in each PF device that supports the SR-IOV feature. This capability is used to describe and control a PF’s SR-IOV capabilities.

3.1 the differences between a normal passthrough device and SR-IOV VF device

  1. physical device detection

The hypervisor uses Subsystem Vendor ID to detect the SR-IOV VF physical device instead of Vendor ID since no valid Vendor ID exists for the SR-IOV VF physical device.

  1. BARs initialization

The VF BARs are initialized by its associated PF’s SR-IOV capabilities, not PCI standard BAR registers.

  1. MSI-X initialization

The MSI-X mapping base address is also from the PF’s SR-IOV capabilities, not PCI standard BAR registers.

3.2 VF的bdf number如何分配

Routing ID就是BDF number,即采用Bus Number、Device Number和Function Number来确定目标设备的位置的id。

SR-IOV Extended Capability中用FirstVF Offset和VF Stride来标记VF的Routing ID。VF的Routing ID是以PF的Routing ID值为参考来计算的。

FirstVF Offset:第一个VF相对PF的Routing ID的偏移量

VF Stride: 相邻VF之间的Routing ID的偏移量

PF的Routing ID在PF枚举之后就已经分配好了。PF的驱动程序通过配置SR-IOV Extended Capability,打开这个PF关联的VF之后,通过FirstVF Offset和VF Stride就能计算出VF们的Routing ID。

3.3 VF的BAR空间如何分配

VF的BAR[n]空间是通过PF的SR-IOV Capability中每个VF_BAR[n]来分配的,和VF Configuration Space的BAR无关。

3.4 ACRN Enable SR-IOV Virtualization

建议阅读ACRN Enable SR-IOV Virtualization。😊


参考资料:

  1. Chapter 9 of PCI-SIG’s PCI Express Base Specification Revision 4.0, Version 1.0
  2. RichardSolomon_PCI_Express.pdf
  3. ACRN Enable SR-IOV Virtualization
  4. SR-IOV及linux驱动浅析