From: Achal Verma <a-verma1@ti.com>
To: Bjorn Helgaas <bhelgaas@google.com>,
Russell Currey <ruscur@russell.cc>,
"Jan H . Sch_nherr" <jschoenh@amazon.de>
Cc: <linux-pci@vger.kernel.org>, Achal Verma <a-verma1@ti.com>
Subject: [PATCH v2] PCI/IOV: Add pci_ari_enabled check before adding virtual functions
Date: Wed, 20 Sep 2023 12:44:54 +0530 [thread overview]
Message-ID: <20230920071454.363245-1-a-verma1@ti.com> (raw)
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
reply other threads:[~2023-09-20 7:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230920071454.363245-1-a-verma1@ti.com \
--to=a-verma1@ti.com \
--cc=bhelgaas@google.com \
--cc=jschoenh@amazon.de \
--cc=linux-pci@vger.kernel.org \
--cc=ruscur@russell.cc \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).