From: Niklas Schnelle <schnelle@linux.ibm.com>
To: Bjorn Helgaas <bhelgaas@google.com>,
Huacai Chen <chenhuacai@kernel.org>,
Jan Kiszka <jan.kiszka@siemens.com>,
Rob Herring <robh@kernel.org>
Cc: "Juergen Gross" <jgross@suse.com>,
"Ajay Kaher" <ajay.kaher@broadcom.com>,
"Alexey Makhalov" <alexey.makhalov@broadcom.com>,
"Broadcom internal kernel review list"
<bcm-kernel-feedback-list@broadcom.com>,
"Thomas Gleixner" <tglx@kernel.org>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Manivannan Sadhasivam" <mani@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-pci@vger.kernel.org,
virtualization@lists.linux.dev, x86@kernel.org,
"Niklas Schnelle" <schnelle@linux.ibm.com>
Subject: [PATCH v6 2/4] PCI: loongson: Handle missing function 0 explicitly not via isolated functions
Date: Fri, 04 Dec 2026 15:14:03 +0100 [thread overview]
Message-ID: <20261204-ari_no_bus_dev-v6-2-855e75237600@linux.ibm.com> (raw)
In-Reply-To: <20261204-ari_no_bus_dev-v6-0-855e75237600@linux.ibm.com>
Since commit a02fd05661d7 ("PCI: Extend isolated function probing to
LoongArch") LoongArch indicates support for isolated PCI functions. In
later patch proposals it turned out however that the real use case for
LoongArch is actually a hardware quirk where a PCI device has function
0 disabled. At the same time some Loongson systems can't handle
probing for PCI functions blind as seen at the link. This is however
required to handle arbitrary topologies of isolated PCI functions. Thus
interfering with the primary use case of isolated PCI function probing
on hypervisors that pass-through individual functions.
Detangle this mess by introducing an explicit PCI bus flag for the bare
metal use case of missing PCI function 0 which triggers the same
behavior as current isolated function probing. With the bare metal case
handled stop claiming isolated PCI function pass-through for LoongArch.
Cc: stable@vger.kernel.org
Fixes: a02fd05661d7 ("PCI: Extend isolated function probing to LoongArch")
Link: https://lore.kernel.org/lkml/CAAhV-H6qqppoX_G5KrWmPor16bXfvNTE2x8Xx6yajAYPqxpigw@mail.gmail.com/
Link: https://lore.kernel.org/linux-pci/20251014074100.2149737-1-chenhuacai@loongson.cn/
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
drivers/pci/controller/pci-loongson.c | 16 ++++++++++++++++
drivers/pci/probe.c | 22 ++++++++++++++--------
include/linux/hypervisor.h | 3 ---
include/linux/pci.h | 1 +
4 files changed, 31 insertions(+), 11 deletions(-)
diff --git a/drivers/pci/controller/pci-loongson.c b/drivers/pci/controller/pci-loongson.c
index 6c0b7a3f4ba0..6241b8038fe1 100644
--- a/drivers/pci/controller/pci-loongson.c
+++ b/drivers/pci/controller/pci-loongson.c
@@ -252,6 +252,19 @@ static void __iomem *cfg1_map(struct loongson_pci *priv, struct pci_bus *bus,
return priv->cfg1_base + addroff;
}
+static int pci_loongson_add_bus(struct pci_bus *bus)
+{
+ /*
+ * Some Loongson systems rely on PCI devices with
+ * a disabled function 0. Tell common code to keep looking
+ * for PCI functions even if function 0 is missing.
+ * This does not drop the checks for ARI and multifunction.
+ */
+ bus->bus_flags |= PCI_BUS_FLAGS_MAYBE_NO_FN0;
+
+ return 0;
+}
+
static bool pdev_may_exist(struct pci_bus *bus, unsigned int device,
unsigned int function)
{
@@ -317,6 +330,7 @@ static struct pci_ops loongson_pci_ops = {
.map_bus = pci_loongson_map_bus,
.read = pci_generic_config_read,
.write = pci_generic_config_write,
+ .add_bus = pci_loongson_add_bus,
};
/* RS780/SR5690 only accept 32-bit PCI config operations */
@@ -324,6 +338,7 @@ static struct pci_ops loongson_pci_ops32 = {
.map_bus = pci_loongson_map_bus,
.read = pci_generic_config_read32,
.write = pci_generic_config_write32,
+ .add_bus = pci_loongson_add_bus,
};
static const struct loongson_pci_data ls2k_pci_data = {
@@ -441,6 +456,7 @@ const struct pci_ecam_ops loongson_pci_ecam_ops = {
.map_bus = pci_loongson_map_bus,
.read = pci_generic_config_read,
.write = pci_generic_config_write,
+ .add_bus = pci_loongson_add_bus,
}
};
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 9a178e0e5f7f..bbce3756f8f8 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2861,6 +2861,18 @@ static int only_one_child(struct pci_bus *bus)
return 0;
}
+static bool pci_stop_at_missing_fn0(struct pci_bus *bus)
+{
+ /*
+ * Function 0 is required unless we are running on
+ * a hypervisor that passes through individual PCI
+ * functions or the bus indicates that function 0
+ * may be missing.
+ */
+ return !hypervisor_isolated_pci_functions() &&
+ !(bus->bus_flags & PCI_BUS_FLAGS_MAYBE_NO_FN0);
+}
+
/**
* pci_scan_slot - Scan a PCI slot on a bus for devices
* @bus: PCI bus to scan
@@ -2887,14 +2899,8 @@ int pci_scan_slot(struct pci_bus *bus, int devfn)
nr++;
if (fn > 0)
dev->multifunction = 1;
- } else if (fn == 0) {
- /*
- * Function 0 is required unless we are running on
- * a hypervisor that passes through individual PCI
- * functions.
- */
- if (!hypervisor_isolated_pci_functions())
- break;
+ } else if (fn == 0 && pci_stop_at_missing_fn0(bus)) {
+ break;
}
fn = next_fn(bus, dev, fn);
} while (fn >= 0);
diff --git a/include/linux/hypervisor.h b/include/linux/hypervisor.h
index ce5a173bdefb..d94cb3e020b3 100644
--- a/include/linux/hypervisor.h
+++ b/include/linux/hypervisor.h
@@ -39,9 +39,6 @@ static inline bool hypervisor_isolated_pci_functions(void)
if (IS_ENABLED(CONFIG_S390))
return true;
- if (IS_ENABLED(CONFIG_LOONGARCH))
- return true;
-
return jailhouse_paravirt();
}
diff --git a/include/linux/pci.h b/include/linux/pci.h
index aa3765a20a96..5cac6b6d4094 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -279,6 +279,7 @@ enum pci_bus_flags {
PCI_BUS_FLAGS_NO_MMRBC = (__force pci_bus_flags_t) 2,
PCI_BUS_FLAGS_NO_AERSID = (__force pci_bus_flags_t) 4,
PCI_BUS_FLAGS_NO_EXTCFG = (__force pci_bus_flags_t) 8,
+ PCI_BUS_FLAGS_MAYBE_NO_FN0 = (__force pci_bus_flags_t) 16,
};
/* Values from Link Status register, PCIe r3.1, sec 7.8.8 */
--
2.53.0
next prev parent reply other threads:[~2026-12-04 14:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 14:14 [PATCH v6 0/4] PCI: Fix isolated function probing and enable ARI for s390 Niklas Schnelle
2026-12-04 14:14 ` [PATCH v6 1/4] jailhouse: Fix leak of device node in jailhouse_paravirt() on non-x86 Niklas Schnelle
2026-12-04 14:14 ` Niklas Schnelle [this message]
2026-12-04 14:45 ` [PATCH v6 2/4] PCI: loongson: Handle missing function 0 explicitly not via isolated functions sashiko-bot
2026-12-04 14:14 ` [PATCH v6 3/4] PCI: Fix isolated PCI function probing with ARI and SR-IOV Niklas Schnelle
2026-12-04 15:02 ` sashiko-bot
2026-12-04 14:14 ` [PATCH v6 4/4] PCI: s390: Handle ARI on bus without associated struct pci_dev Niklas Schnelle
2026-12-04 15:25 ` sashiko-bot
2026-12-04 15:25 ` [PATCH v6 0/4] PCI: Fix isolated function probing and enable ARI for s390 sashiko-bot
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=20261204-ari_no_bus_dev-v6-2-855e75237600@linux.ibm.com \
--to=schnelle@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=ajay.kaher@broadcom.com \
--cc=alexey.makhalov@broadcom.com \
--cc=alifm@linux.ibm.com \
--cc=bcm-kernel-feedback-list@broadcom.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=jgross@suse.com \
--cc=kwilczynski@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=maobibo@loongson.cn \
--cc=mjrosato@linux.ibm.com \
--cc=robh@kernel.org \
--cc=svens@linux.ibm.com \
--cc=tglx@kernel.org \
--cc=virtualization@lists.linux.dev \
--cc=x86@kernel.org \
--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