Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH v2] PCI/IOV: Add pci_ari_enabled check before adding virtual functions
@ 2023-09-20  7:14 Achal Verma
  0 siblings, 0 replies; only message in thread
From: Achal Verma @ 2023-09-20  7:14 UTC (permalink / raw)
  To: Bjorn Helgaas, Russell Currey, Jan H . Sch_nherr; +Cc: linux-pci, Achal Verma

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()")
Signed-off-by: Achal Verma <a-verma1@ti.com>
---

Changes from v1:
* Rebased on next-20230920

 drivers/pci/iov.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 25dbe85c4217..cac647ac4cd6 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -287,7 +287,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;
@@ -295,6 +295,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;
@@ -303,7 +307,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;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-20  7:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-20  7:14 [PATCH v2] PCI/IOV: Add pci_ari_enabled check before adding virtual functions Achal Verma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox