Skip to contentSkip to conversation

PCI/IOV: Add pci_ari_enabled() check before adding virtual functions

PATCH Superseded Achal Verma 1 participant 1 message Aug 17, 2023 PCI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI/IOV: Add pci_ari_enabled() check before adding virtual functions

Absence of pci_ari_enabled() check in pci_iov_add_virtfn() allows addition of virtual functions with function number > 7, even for devices which doesn't have ARI Fowarding Support. So, adding pci_ari_enabled() check to prevent addition of function number > 7 and thus avoid later invalid access to such functions, resulting in "Unsupported Request" error response.

Fixes 753f61247181 ("PCI: Remove reset argument from pci_iov_{add,remove}_virtfn()")
---
 drivers/pci/iov.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/pci/iov.c +6 -2
index b2e8322755c1..611b346331e8 100644
@@ -288,7 +288,7 @@ const struct attribute_group sriov_vf_dev_attr_group = {
 
 int pci_iov_add_virtfn(struct pci_dev *dev, int id)
 {
-	int i;
+	int i, devfn;
 	int rc = -ENOMEM;
 	u64 size;
 	struct pci_dev *virtfn;
@@ -296,6 +296,10 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id)
 	struct pci_sriov *iov = dev->sriov;
 	struct pci_bus *bus;
 
+	devfn = pci_iov_virtfn_devfn(dev, id);
+	if ((devfn > 7) && !pci_ari_enabled(dev->bus))
+		return -ENODEV;
+
 	bus = virtfn_add_bus(dev->bus, pci_iov_virtfn_bus(dev, id));
 	if (!bus)
 		goto failed;
@@ -304,7 +308,7 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id)
 	if (!virtfn)
 		goto failed0;
 
-	virtfn->devfn = pci_iov_virtfn_devfn(dev, id);
+	virtfn->devfn = devfn;
 	virtfn->vendor = dev->vendor;
 	virtfn->device = iov->vf_device;
 	virtfn->is_virtfn = 1;
Signature · 1 line
2.25.1