[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20230817093132.1078754-1-a-verma1@ti.com>
Date: Thu, 17 Aug 2023 15:01:32 +0530
From: Achal Verma <a-verma1@...com>
To: Bjorn Helgaas <bhelgaas@...gle.com>,
Russell Currey <ruscur@...sell.cc>,
"Jan H . Sch_nherr" <jschoenh@...zon.de>
CC: <linux-pci@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
Vignesh Raghavendra <vigneshr@...com>,
Achal Verma <a-verma1@...com>
Subject: [PATCH] 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()")
Signed-off-by: Achal Verma <a-verma1@...com>
---
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 b2e8322755c1..611b346331e8 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -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;
--
2.25.1
Powered by blists - more mailing lists