From: Niklas Schnelle <schnelle@linux.ibm.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: Jan Kiszka <jan.kiszka@siemens.com>,
Huacai Chen <chenhuacai@kernel.org>,
Bibo Mao <maobibo@loongson.cn>,
linux-s390 <linux-s390@vger.kernel.org>,
loongarch@lists.linux.dev, Farhan Ali <alifm@linux.ibm.com>,
Matthew Rosato <mjrosato@linux.ibm.com>,
Tianrui Zhao <zhaotianrui@loongson.cn>,
Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Gerd Bayer <gbayer@linux.ibm.com>,
linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-pci@vger.kernel.org,
Niklas Schnelle <schnelle@linux.ibm.com>
Subject: [PATCH v5 1/2] PCI: Fix isolated PCI function probing with ARI and SR-IOV
Date: Wed, 29 Oct 2025 10:41:31 +0100 [thread overview]
Message-ID: <20251029-ari_no_bus_dev-v5-1-d9a5eab67ed0@linux.ibm.com> (raw)
In-Reply-To: <20251029-ari_no_bus_dev-v5-0-d9a5eab67ed0@linux.ibm.com>
When the isolated PCI function probing mechanism is used in conjunction
with ARI or SR-IOV it may not find all available PCI functions. In the
case of ARI the problem is that next_ari_fn() always returns -ENODEV if
dev is NULL and thus if fn 0 is missing the scan stops.
For SR-IOV things are more complex. Here the problem is that the check
for multifunction may fail. One example where this can occur is if the
first passed-through function is a VF with devfn 8. Now in
pci_scan_slot() this means it is fn 0 and thus multifunction doesn't get
set. Since VFs don't get multifunction set via PCI_HEADER_TYPE_MFD it
remains unset and probing stops even if there is a devfn 9.
Now at the moment both of these issues are hidden on s390. The first one
because ARI is detected as disabled as struct pci_bus's self is NULL
even though firmware does enable and use ARI. The second issue is hidden
as a side effect of commit 25f39d3dcb48 ("s390/pci: Ignore RID for
isolated VFs"). This is because VFs are either put on their own virtual
bus if the parent PF is not passed-through to the same instance or VFs
are hotplugged once SR-IOV is enabled on the parent PF and then
pci_scan_single_device() is used.
Still especially the first issue prevents correct detection of ARI and
the second might be a problem for other users of isolated function
probing. Fix both issues by keeping things as simple as possible. If
isolated function probing is enabled simply scan every possible devfn.
Cc: stable@vger.kernel.org
Fixes: 189c6c33ff42 ("PCI: Extend isolated function probing to s390")
Link: https://lore.kernel.org/linux-pci/d3f11e8562f589ddb2c1c83e74161bd8948084c3.camel@linux.ibm.com/
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
drivers/pci/probe.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 0ce98e18b5a876afe72af35a9f4a44d598e8d500..41dd1a339a994956a6bc7e1fea0fe0d55452a963 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2808,16 +2808,19 @@ static int next_ari_fn(struct pci_bus *bus, struct pci_dev *dev, int fn)
return next_fn;
}
-static int next_fn(struct pci_bus *bus, struct pci_dev *dev, int fn)
+static int next_fn(struct pci_bus *bus, struct pci_dev *dev, int fn,
+ bool isolated_fns)
{
- if (pci_ari_enabled(bus))
- return next_ari_fn(bus, dev, fn);
+ if (!isolated_fns) {
+ if (pci_ari_enabled(bus))
+ return next_ari_fn(bus, dev, fn);
+ /* only multifunction devices may have more functions */
+ if (dev && !dev->multifunction)
+ return -ENODEV;
+ }
if (fn >= 7)
return -ENODEV;
- /* only multifunction devices may have more functions */
- if (dev && !dev->multifunction)
- return -ENODEV;
return fn + 1;
}
@@ -2859,10 +2862,12 @@ int pci_scan_slot(struct pci_bus *bus, int devfn)
{
struct pci_dev *dev;
int fn = 0, nr = 0;
+ bool isolated_fns;
if (only_one_child(bus) && (devfn > 0))
return 0; /* Already scanned the entire slot */
+ isolated_fns = hypervisor_isolated_pci_functions();
do {
dev = pci_scan_single_device(bus, devfn + fn);
if (dev) {
@@ -2876,10 +2881,10 @@ int pci_scan_slot(struct pci_bus *bus, int devfn)
* a hypervisor that passes through individual PCI
* functions.
*/
- if (!hypervisor_isolated_pci_functions())
+ if (!isolated_fns)
break;
}
- fn = next_fn(bus, dev, fn);
+ fn = next_fn(bus, dev, fn, isolated_fns);
} while (fn >= 0);
/* Only one slot has PCIe device */
--
2.48.1
next prev parent reply other threads:[~2025-10-29 9:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-29 9:41 [PATCH v5 0/2] PCI: Fix isolated function probing and enable ARI for s390 Niklas Schnelle
2025-10-29 9:41 ` Niklas Schnelle [this message]
2025-11-03 9:50 ` [PATCH v5 1/2] PCI: Fix isolated PCI function probing with ARI and SR-IOV Huacai Chen
2025-11-03 11:23 ` Niklas Schnelle
2025-11-05 1:01 ` Huacai Chen
2025-11-05 9:46 ` Niklas Schnelle
2025-11-07 7:19 ` Huacai Chen
2025-10-29 9:41 ` [PATCH v5 2/2] PCI: s390: Handle ARI on bus without associated struct pci_dev Niklas Schnelle
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=20251029-ari_no_bus_dev-v5-1-d9a5eab67ed0@linux.ibm.com \
--to=schnelle@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=alifm@linux.ibm.com \
--cc=bhelgaas@google.com \
--cc=borntraeger@linux.ibm.com \
--cc=chenhuacai@kernel.org \
--cc=gbayer@linux.ibm.com \
--cc=gerald.schaefer@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=jan.kiszka@siemens.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=maobibo@loongson.cn \
--cc=mjrosato@linux.ibm.com \
--cc=svens@linux.ibm.com \
--cc=zhaotianrui@loongson.cn \
/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).