Re: [PATCH mlx5-next v1 1/5] PCI: Add sysfs callback to allow MSI-X table size change of SR-IOV VFs
From: Leon Romanovsky <leon@kernel.org>
Date: 2021-01-13 19:50:16
Also in:
linux-pci, linux-rdma
On Wed, Jan 13, 2021 at 10:50:52AM -0700, Alex Williamson wrote:
On Sun, 10 Jan 2021 17:07:23 +0200 Leon Romanovsky [off-list ref] wrote:quoted
From: Leon Romanovsky <leonro@nvidia.com> Extend PCI sysfs interface with a new callback that allows configure the number of MSI-X vectors for specific SR-IO VF. This is needed to optimize the performance of newly bound devices by allocating the number of vectors based on the administrator knowledge of targeted VM. This function is applicable for SR-IOV VF because such devices allocate their MSI-X table before they will run on the VMs and HW can't guess the right number of vectors, so the HW allocates them statically and equally. The newly added /sys/bus/pci/devices/.../vf_msix_vec file will be seen for the VFs and it is writable as long as a driver is not bounded to the VF. The values accepted are: * > 0 - this will be number reported by the VF's MSI-X capability * < 0 - not valid * = 0 - will reset to the device default value Signed-off-by: Leon Romanovsky <leonro@nvidia.com> --- Documentation/ABI/testing/sysfs-bus-pci | 20 ++++++++ drivers/pci/iov.c | 62 +++++++++++++++++++++++++ drivers/pci/msi.c | 29 ++++++++++++ drivers/pci/pci-sysfs.c | 1 + drivers/pci/pci.h | 2 + include/linux/pci.h | 8 +++- 6 files changed, 121 insertions(+), 1 deletion(-)
<...>
quoted
+/** + * pci_set_msix_vec_count - change the reported number of MSI-X vectors + * This function is applicable for SR-IOV VF because such devices allocate + * their MSI-X table before they will run on the VMs and HW can't guess the + * right number of vectors, so the HW allocates them statically and equally. + * @dev: VF device that is going to be changed + * @numb: amount of MSI-X vectors + **/ +int pci_set_msix_vec_count(struct pci_dev *dev, int numb) +{ + struct pci_dev *pdev = pci_physfn(dev); + + if (!dev->msix_cap || !pdev->msix_cap) + return -EINVAL; + + if (dev->driver || !pdev->driver || + !pdev->driver->sriov_set_msix_vec_count) + return -EOPNOTSUPP;This seems racy, don't we need to hold device_lock on both the VF and PF to avoid driver {un}binding races? Does that happen implicitly somewhere? Thanks,
Yes, you are right absolutely, pdev and dev are not protected here. Thanks