[PATCH v5 4/6] PCI/IOV: Check that VF BAR fits within the reservation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When the resource representing 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 it's not possible to accommodate all VFs - the resource is not
assigned and no VFs can be created.

The following patch 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 VF BAR for all enabled VFs
fits within the underlying reservation resource.

Signed-off-by: Michał Winiarski <michal.winiarski@xxxxxxxxx>
---
 drivers/pci/iov.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 7cc17e898cea7..d6d63083884e6 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -646,8 +646,13 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
 
 	nres = 0;
 	for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
+		resource_size_t vf_bar_sz =
+			pci_iov_resource_size(dev,
+					      pci_resource_num_from_vf_bar(i));
 		bars |= (1 << pci_resource_num_from_vf_bar(i));
 		res = &dev->resource[pci_resource_num_from_vf_bar(i)];
+		if (vf_bar_sz * nr_virtfn > resource_size(res))
+			continue;
 		if (res->parent)
 			nres++;
 	}
-- 
2.48.1





[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux