PCI/IOV: Add sysfs MSI-X vector assignment interface
authorLeon Romanovsky <leonro@nvidia.com>
Sun, 4 Apr 2021 07:22:18 +0000 (10:22 +0300)
committerLeon Romanovsky <leonro@nvidia.com>
Sun, 4 Apr 2021 07:26:30 +0000 (10:26 +0300)
commitc3d5c2d96d69f2578d6fbf66e39cc2cf840d9812
tree04d5f784853bafe12c034f35a9a013431a746217
parent26bf30902c10473ba38f220d3401a61c56d8db3b
PCI/IOV: Add sysfs MSI-X vector assignment interface

A typical cloud provider SR-IOV use case is to create many VFs for use by
guest VMs. The VFs may not be assigned to a VM until a customer requests a
VM of a certain size, e.g., number of CPUs. A VF may need MSI-X vectors
proportional to the number of CPUs in the VM, but there is no standard way
to change the number of MSI-X vectors supported by a VF.

Some Mellanox ConnectX devices support dynamic assignment of MSI-X vectors
to SR-IOV VFs. This can be done by the PF driver after VFs are enabled,
and it can be done without affecting VFs that are already in use. The
hardware supports a limited pool of MSI-X vectors that can be assigned to
the PF or to individual VFs.  This is device-specific behavior that
requires support in the PF driver.

Add a read-only "sriov_vf_total_msix" sysfs file for the PF and a writable
"sriov_vf_msix_count" file for each VF. Management software may use these
to learn how many MSI-X vectors are available and to dynamically assign
them to VFs before the VFs are passed through to a VM.

If the PF driver implements the ->sriov_get_vf_total_msix() callback,
"sriov_vf_total_msix" contains the total number of MSI-X vectors available
for distribution among VFs.

If no driver is bound to the VF, writing "N" to "sriov_vf_msix_count" uses
the PF driver ->sriov_set_msix_vec_count() callback to assign "N" MSI-X
vectors to the VF.  When a VF driver subsequently reads the MSI-X Message
Control register, it will see the new Table Size "N".

Link: https://lore.kernel.org/linux-pci/20210314124256.70253-2-leon@kernel.org
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Documentation/ABI/testing/sysfs-bus-pci
drivers/pci/iov.c
drivers/pci/pci-sysfs.c
drivers/pci/pci.h
include/linux/pci.h