Skip to content

Commit e1ba95a

Browse files
mwiniarsbjorn-helgaas
authored andcommitted
PCI/IOV: Check that VF BAR fits within the reservation
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
1 parent e200f4f commit e1ba95a

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

drivers/pci/iov.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,12 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
668668
nres = 0;
669669
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
670670
int idx = pci_resource_num_from_vf_bar(i);
671+
resource_size_t vf_bar_sz = pci_iov_resource_size(dev, idx);
671672

672673
bars |= (1 << idx);
673674
res = &dev->resource[idx];
675+
if (vf_bar_sz * nr_virtfn > resource_size(res))
676+
continue;
674677
if (res->parent)
675678
nres++;
676679
}

0 commit comments

Comments
 (0)