]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
PCI/IOV: Check that VF BAR fits within the reservation
authorMichał Winiarski <michal.winiarski@intel.com>
Wed, 2 Jul 2025 09:35:21 +0000 (11:35 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Mon, 14 Jul 2025 20:04:23 +0000 (15:04 -0500)
When the resource representing a VF MMIO BAR reservation is created, its
size is always large enough to accommodate the BAR of all SR-IOV Virtual
Functions that can potentially be created (total VFs). If for whatever
reason it's not possible to accommodate all VFs, the resource is not
assigned and no VFs can be created.

An upcoming change will allow VF BAR size to be modified by drivers at a
later point in time, which means that the check for resource assignment is
no longer sufficient.

Add an additional check that verifies that the VF BAR for all enabled VFs
fits within the underlying reservation resource.

Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://patch.msgid.link/20250702093522.518099-5-michal.winiarski@intel.com
drivers/pci/iov.c

index 852424cf2ae158f31f4ab9acb7d6f4f6f6007995..f34173c70b32a59e32b6553f636474c0358b826c 100644 (file)
@@ -668,9 +668,12 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
        nres = 0;
        for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
                int idx = pci_resource_num_from_vf_bar(i);
+               resource_size_t vf_bar_sz = pci_iov_resource_size(dev, idx);
 
                bars |= (1 << idx);
                res = &dev->resource[idx];
+               if (vf_bar_sz * nr_virtfn > resource_size(res))
+                       continue;
                if (res->parent)
                        nres++;
        }