* [PATCH v6 0/4] PCI: Fix isolated function probing and enable ARI for s390
@ 2026-12-04 14:14 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
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Niklas Schnelle @ 2026-12-04 14:14 UTC (permalink / raw)
To: Bjorn Helgaas, Huacai Chen, Jan Kiszka, Rob Herring
Cc: Juergen Gross, Ajay Kaher, Alexey Makhalov,
Broadcom internal kernel review list, Thomas Gleixner,
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Bibo Mao, linux-s390, loongarch,
Farhan Ali, Matthew Rosato, Tianrui Zhao, Gerald Schaefer,
Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Sven Schnelle,
Christian Borntraeger, Gerd Bayer, linux-s390, linux-pci,
virtualization, x86, Niklas Schnelle
Hi Bjorn, Hi Huacai,
This series originally aimed to correctly detect ARI as being used on
s390. I had missed however that this breaks the isolated function
probing because the ARI chain may be broken due to only a subset of the
chain being passed through. So instead of following ARI chains simply
probe all possible functions blindly. On platforms with virtualized
config space accesses this is generally safe and on s390 at least, it is
also fast as config access for non-existent functions gets
short-circuited..
Besides the effect on s390 moving ari_enabled to the bus should also
ensure that VFs on a virtual bus created via virtfn_add_bus() correctly
present ARI as enabled. Sadly, I don't have access to any affected
device to test this.
In v5 it turned out however that this breaks Loongson systems with
hidden functions which must not be touched. So now the first patch
detangles the LoongArch bare metal use case for handling missing
function 0 from the hypervisor use case and drop LoongArch's claim
for the latter.
If LoongArch still requires the hypervisor use-case too we could add
a virtualization check in hypervisor_isolated_pci_functions() and get
the existing behavior on bare metal and blind probing in VMs where it is
safe but so far I could not find evidence that LoongArch actually relies
on the hypervisor use case.
Note on Testing:
- Tested on a Xeon Sapphire Rapids x86_64 system with both as is and
with a temporary hack to return true from
hypervisor_isolated_pci_functions().
- Tested on s390 as is and with a temporary disable of the special
handling of VFs with their parent PF not visible introduced by commit
25f39d3dcb48 ("s390/pci: Ignore RID for isolated VFs")
- I need help testing on Loongson as I don't have the hardware
Thanks,
Niklas
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
Changes in v6:
- Detangle LoongArch's missing function 0 from the use of
hypervisor_isolated_pci_functions()
- On s390 don't disable ARI on a bus just because one device
doesn't have the capability, ARI is always enabled.
- Add a leak fix for jailhouse_paravirt() on non-x86
found by LLM review.
- Link to v5: https://lore.kernel.org/r/20251029-ari_no_bus_dev-v5-0-d9a5eab67ed0@linux.ibm.com
Changes in v5:
- Rename variables to match "fn" abbreviation
- Add Cc stable
- Rebase on v6.18-rc3
- Link to v4: https://lore.kernel.org/r/20251023-ari_no_bus_dev-v4-0-8482e2ed10bd@linux.ibm.com
---
Niklas Schnelle (4):
jailhouse: Fix leak of device node in jailhouse_paravirt() on non-x86
PCI: loongson: Handle missing function 0 explicitly not via isolated functions
PCI: Fix isolated PCI function probing with ARI and SR-IOV
PCI: s390: Handle ARI on bus without associated struct pci_dev
arch/s390/pci/pci_bus.c | 9 ++++++++-
drivers/pci/controller/pci-loongson.c | 16 +++++++++++++++
drivers/pci/pci.c | 4 ++--
drivers/pci/probe.c | 38 ++++++++++++++++++++++-------------
include/linux/hypervisor.h | 7 +++----
include/linux/pci.h | 5 +++--
6 files changed, 56 insertions(+), 23 deletions(-)
---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
change-id: 20240724-ari_no_bus_dev-52b2a27f3466
Best regards,
--
Niklas Schnelle
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v6 1/4] jailhouse: Fix leak of device node in jailhouse_paravirt() on non-x86
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 ` Niklas Schnelle
2026-12-04 14:14 ` [PATCH v6 2/4] PCI: loongson: Handle missing function 0 explicitly not via isolated functions Niklas Schnelle
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Niklas Schnelle @ 2026-12-04 14:14 UTC (permalink / raw)
To: Bjorn Helgaas, Huacai Chen, Jan Kiszka, Rob Herring
Cc: Juergen Gross, Ajay Kaher, Alexey Makhalov,
Broadcom internal kernel review list, Thomas Gleixner,
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Bibo Mao, linux-s390, loongarch,
Farhan Ali, Matthew Rosato, Tianrui Zhao, Gerald Schaefer,
Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Sven Schnelle,
Christian Borntraeger, Gerd Bayer, linux-s390, linux-pci,
virtualization, x86, Niklas Schnelle
The device node returned by of_find_compatible_node() is reference
counted, so drop the reference after lookup.
Cc: stable@vger.kernel.org
Fixes: 63338a38db95 ("jailhouse: Provide detection for non-x86 systems")
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
include/linux/hypervisor.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/include/linux/hypervisor.h b/include/linux/hypervisor.h
index be5417303ecf..ce5a173bdefb 100644
--- a/include/linux/hypervisor.h
+++ b/include/linux/hypervisor.h
@@ -27,7 +27,9 @@ static inline void hypervisor_pin_vcpu(int cpu)
static inline bool jailhouse_paravirt(void)
{
- return of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+ struct device_node *np __free(device_node) =
+ of_find_compatible_node(NULL, NULL, "jailhouse,cell");
+ return np;
}
#endif /* !CONFIG_X86 */
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v6 2/4] PCI: loongson: Handle missing function 0 explicitly not via isolated functions
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
2026-12-04 14:45 ` sashiko-bot
2026-12-04 14:14 ` [PATCH v6 3/4] PCI: Fix isolated PCI function probing with ARI and SR-IOV Niklas Schnelle
` (2 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Niklas Schnelle @ 2026-12-04 14:14 UTC (permalink / raw)
To: Bjorn Helgaas, Huacai Chen, Jan Kiszka, Rob Herring
Cc: Juergen Gross, Ajay Kaher, Alexey Makhalov,
Broadcom internal kernel review list, Thomas Gleixner,
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Bibo Mao, linux-s390, loongarch,
Farhan Ali, Matthew Rosato, Tianrui Zhao, Gerald Schaefer,
Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Sven Schnelle,
Christian Borntraeger, Gerd Bayer, linux-s390, linux-pci,
virtualization, x86, Niklas Schnelle
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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v6 3/4] PCI: Fix isolated PCI function probing with ARI and SR-IOV
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 ` [PATCH v6 2/4] PCI: loongson: Handle missing function 0 explicitly not via isolated functions Niklas Schnelle
@ 2026-12-04 14:14 ` 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 ` [PATCH v6 0/4] PCI: Fix isolated function probing and enable ARI for s390 sashiko-bot
4 siblings, 1 reply; 9+ messages in thread
From: Niklas Schnelle @ 2026-12-04 14:14 UTC (permalink / raw)
To: Bjorn Helgaas, Huacai Chen, Jan Kiszka, Rob Herring
Cc: Juergen Gross, Ajay Kaher, Alexey Makhalov,
Broadcom internal kernel review list, Thomas Gleixner,
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Bibo Mao, linux-s390, loongarch,
Farhan Ali, Matthew Rosato, Tianrui Zhao, Gerald Schaefer,
Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Sven Schnelle,
Christian Borntraeger, Gerd Bayer, linux-s390, linux-pci,
virtualization, x86, Niklas Schnelle
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 ARI chains may be broken or not even
have a starting point when only a subset of the device's functions is
passed-through.
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 may be a problem for other users of isolated function
probing. Fix both issues by doing the obvious thing and scanning all
possible functions which is generally safe on platforms where config
space access is virtualized and fast enough on s390 due to a short
circuit of config access for missing functions.
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 | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index bbce3756f8f8..404dce0a4f80 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2825,16 +2825,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 probe_all_fns)
{
- if (pci_ari_enabled(bus))
- return next_ari_fn(bus, dev, fn);
+ if (!probe_all_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;
}
@@ -2861,16 +2864,14 @@ static int only_one_child(struct pci_bus *bus)
return 0;
}
-static bool pci_stop_at_missing_fn0(struct pci_bus *bus)
+static bool pci_stop_at_missing_fn0(struct pci_bus *bus, bool probe_all_fns)
{
/*
- * Function 0 is required unless we are running on
- * a hypervisor that passes through individual PCI
+ * Function 0 is required unless we are probing all
* 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);
+ return !probe_all_fns && !(bus->bus_flags & PCI_BUS_FLAGS_MAYBE_NO_FN0);
}
/**
@@ -2887,11 +2888,12 @@ static bool pci_stop_at_missing_fn0(struct pci_bus *bus)
int pci_scan_slot(struct pci_bus *bus, int devfn)
{
struct pci_dev *dev;
+ bool probe_all_fns;
int fn = 0, nr = 0;
if (only_one_child(bus) && (devfn > 0))
return 0; /* Already scanned the entire slot */
-
+ probe_all_fns = hypervisor_isolated_pci_functions();
do {
dev = pci_scan_single_device(bus, devfn + fn);
if (dev) {
@@ -2899,10 +2901,11 @@ int pci_scan_slot(struct pci_bus *bus, int devfn)
nr++;
if (fn > 0)
dev->multifunction = 1;
- } else if (fn == 0 && pci_stop_at_missing_fn0(bus)) {
- break;
+ } else if (fn == 0) {
+ if (pci_stop_at_missing_fn0(bus, probe_all_fns))
+ break;
}
- fn = next_fn(bus, dev, fn);
+ fn = next_fn(bus, dev, fn, probe_all_fns);
} while (fn >= 0);
/* Only one slot has PCIe device */
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v6 4/4] PCI: s390: Handle ARI on bus without associated struct pci_dev
2026-12-04 14:14 [PATCH v6 0/4] PCI: Fix isolated function probing and enable ARI for s390 Niklas Schnelle
` (2 preceding siblings ...)
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 14:14 ` 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
4 siblings, 1 reply; 9+ messages in thread
From: Niklas Schnelle @ 2026-12-04 14:14 UTC (permalink / raw)
To: Bjorn Helgaas, Huacai Chen, Jan Kiszka, Rob Herring
Cc: Juergen Gross, Ajay Kaher, Alexey Makhalov,
Broadcom internal kernel review list, Thomas Gleixner,
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Bibo Mao, linux-s390, loongarch,
Farhan Ali, Matthew Rosato, Tianrui Zhao, Gerald Schaefer,
Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Sven Schnelle,
Christian Borntraeger, Gerd Bayer, linux-s390, linux-pci,
virtualization, x86, Niklas Schnelle
On s390 PCI buses are virtualized and the downstream ports are
invisible to the OS and self in struct pci_bus is NULL. This associated
struct pci_dev is however relied upon in pci_ari_enabled() to check
whether ARI is enabled for the bus. ARI is therefore always detected as
disabled. At the same time, firmware on s390 always enables and relies
upon ARI thus causing a mismatch.
Despite simply being a mismatch this causes problems as some PCI devices
present a different SR-IOV topology depending on PCI_SRIOV_CTRL_ARI.
A similar mismatch may occur with SR-IOV when virtfn_add_bus() creates new
buses with no associated struct pci_dev. Here too pci_ari_enabled()
on these buses returns false even if ARI is actually used.
Prevent both mismatches by moving the ari_enabled flag from struct
pci_dev to struct pci_bus making it independent from self in struct
pci_bus. Let the bus inherit the ari_enabled state from its parent bus
when there is no bridge device such that buses added by virtfn_add_bus()
match their parent. For s390 set ari_enabled unconditionally on all
buses in the awareness that all PCIe ports on s390 systems are ARI
capable.
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
arch/s390/pci/pci_bus.c | 9 ++++++++-
drivers/pci/pci.c | 4 ++--
drivers/pci/probe.c | 1 +
include/linux/pci.h | 4 ++--
4 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/arch/s390/pci/pci_bus.c b/arch/s390/pci/pci_bus.c
index 36a4807285fa..df2fa3de3e78 100644
--- a/arch/s390/pci/pci_bus.c
+++ b/arch/s390/pci/pci_bus.c
@@ -192,7 +192,14 @@ static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s
bus = pci_create_root_bus(NULL, ZPCI_BUS_NR, ops, zbus, &zbus->resources);
if (!bus)
goto out_remove_msi_domain;
-
+ /*
+ * On s390 PCI buses are virtualized and the bridge
+ * devices are invisible to the OS. Thus the normal
+ * ARI detection does not work. At the same time firmware
+ * has always enabled ARI. Reflect the actual state by
+ * setting ari_enabled unconditionally on the bus.
+ */
+ bus->ari_enabled = 1;
zbus->bus = bus;
dev_set_msi_domain(&zbus->bus->dev, zbus->msi_parent_domain);
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7c6f2aba8144..5b095a4ecbee 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3603,11 +3603,11 @@ void pci_configure_ari(struct pci_dev *dev)
if (pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI)) {
pcie_capability_set_word(bridge, PCI_EXP_DEVCTL2,
PCI_EXP_DEVCTL2_ARI);
- bridge->ari_enabled = 1;
+ dev->bus->ari_enabled = 1;
} else {
pcie_capability_clear_word(bridge, PCI_EXP_DEVCTL2,
PCI_EXP_DEVCTL2_ARI);
- bridge->ari_enabled = 0;
+ dev->bus->ari_enabled = 0;
}
}
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 404dce0a4f80..fca0344957c8 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1240,6 +1240,7 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
if (!bridge) {
child->dev.parent = parent->bridge;
+ child->ari_enabled = parent->ari_enabled;
goto add_dev;
}
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 5cac6b6d4094..f1e66205d21b 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -474,7 +474,6 @@ struct pci_dev {
unsigned int irq_reroute_variant:2; /* Needs IRQ rerouting variant */
unsigned int msi_enabled:1;
unsigned int msix_enabled:1;
- unsigned int ari_enabled:1; /* ARI forwarding */
unsigned int ats_enabled:1; /* Address Translation Svc */
unsigned int pasid_enabled:1; /* Process Address Space ID */
unsigned int pri_enabled:1; /* Page Request Interface */
@@ -744,6 +743,7 @@ struct pci_bus {
unsigned int is_added:1;
unsigned int unsafe_warn:1; /* warned about RW1C config write */
unsigned int flit_mode:1; /* Link in Flit mode */
+ unsigned int ari_enabled:1; /* ARI forwarding */
};
#define to_pci_bus(n) container_of(n, struct pci_bus, dev)
@@ -2899,7 +2899,7 @@ static inline bool pci_is_dev_assigned(struct pci_dev *pdev)
*/
static inline bool pci_ari_enabled(struct pci_bus *bus)
{
- return bus->self && bus->self->ari_enabled;
+ return bus->ari_enabled;
}
/**
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v6 2/4] PCI: loongson: Handle missing function 0 explicitly not via isolated functions
2026-12-04 14:14 ` [PATCH v6 2/4] PCI: loongson: Handle missing function 0 explicitly not via isolated functions Niklas Schnelle
@ 2026-12-04 14:45 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-04 14:45 UTC (permalink / raw)
To: Niklas Schnelle
Cc: linux-s390, linux-pci, virtualization, Heiko Carstens,
Vasily Gorbik, Alexander Gordeev, Christian Borntraeger,
Michael S. Tsirkin, Eugenio Perez
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] PCI: loongson: unsynchronized bus_flags RMW in
pci_loongson_add_bus()
--
commit a00d743eeef918a05cf235d984b0deccce027b91
Author: Niklas Schnelle <schnelle@linux.ibm.com>
PCI: loongson: Handle missing function 0 explicitly not via isolated functions
This commit introduces the PCI_BUS_FLAGS_MAYBE_NO_FN0 bus flag for
Loongson PCI controllers via pci_loongson_add_bus() and checks it in
pci_scan_slot(), replacing the CONFIG_LOONGARCH check in
hypervisor_isolated_pci_functions().
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/
> diff --git a/drivers/pci/controller/pci-loongson.c b/drivers/pci/controller/pci-loongson.c
> index 6c0b7a3f4ba05..6241b8038fe16 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;
> +}
[Severity: Low]
Can this read-modify-write on bus->bus_flags race with msi_bus_store()
on child buses?
During a PCI rescan or hotplug of a bridge, pci_device_add() exposes
the bridge's msi_bus sysfs attribute before pci_alloc_child_bus() creates
its subordinate bus. Inside pci_alloc_child_bus(), bridge->subordinate
is published before device_register(&child->dev) and
child->ops->add_bus(child) run, while msi_bus_store() modifies
subordinate->bus_flags without holding any lock:
CPU0 CPU1
pci_alloc_child_bus()
bridge->subordinate = child
device_register(&child->dev)
msi_bus_store()
subordinate = pdev->subordinate
pci_loongson_add_bus(child)
bus->bus_flags |= ... subordinate->bus_flags |= ...
<-- data race on bus_flags
Because both sides perform unlocked non-atomic read-modify-writes, a
concurrent update can silently lose a PCI_BUS_FLAGS_NO_MSI toggle even
though msi_bus_store() returns success.
Since pci_alloc_child_bus() already inherits parent->bus_flags before
publishing bridge->subordinate, setting PCI_BUS_FLAGS_MAYBE_NO_FN0 only
when pci_is_root_bus(bus) is true would avoid the redundant write on
child buses.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-ari_no_bus_dev-v6-0-855e75237600@linux.ibm.com?part=2
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v6 3/4] PCI: Fix isolated PCI function probing with ARI and SR-IOV
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
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-04 15:02 UTC (permalink / raw)
To: Niklas Schnelle
Cc: linux-s390, linux-pci, virtualization, Heiko Carstens,
Vasily Gorbik, Alexander Gordeev, Christian Borntraeger,
Michael S. Tsirkin, Eugenio Perez
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] pci: next_fn() skips ARI functions 8..255 on downstream ports
- [Medium] PCI: unconditional hypervisor_isolated_pci_functions() adds
scan overhead
--
commit ae63abdc9ce8242a0676132ebc8d8a1f2843aa23
Author: Niklas Schnelle <schnelle@linux.ibm.com>
PCI: Fix isolated PCI function probing with ARI and SR-IOV
This commit updates pci_scan_slot() and next_fn() to probe all functions
sequentially when hypervisor_isolated_pci_functions() is true, bypassing
the ARI next-function chain and multifunction checks.
Link: https://lore.kernel.org/linux-pci/d3f11e8562f589ddb2c1c83e74161bd8948084c3.camel@linux.ibm.com/
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index bbce3756f8f8a..404dce0a4f80f 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -2825,16 +2825,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 probe_all_fns)
> {
> - if (pci_ari_enabled(bus))
> - return next_ari_fn(bus, dev, fn);
> + if (!probe_all_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;
> }
[Severity: High]
Does capping fn at 7 when probe_all_fns is true break enumeration of ARI
functions 8..255 behind a PCIe Downstream Port?
For a PCIe Downstream Port, only_one_child(bus) returns 1 unless
PCI_SCAN_ALL_PCIE_DEVS is set. During bus enumeration, devfn 0 now stops
at fn 7 and pci_scan_slot() immediately returns 0 for devfn 8..248,
assuming devfn 0 already scanned all 256 ARI functions.
Similarly, pciehp_configure_device() only calls
pci_scan_slot(parent, PCI_DEVFN(0, 0)) once. This is a regression for
intact ARI chains when hypervisor_isolated_pci_functions() is true, and it
leaves isolated ARI or SR-IOV functions at devfn >= 8 undiscovered.
When function 0 is missing behind a Downstream Port, pci_configure_ari()
also skips setting ari_enabled while only_one_child(bus) still skips
devfn > 0.
[ ... ]
> @@ -2887,11 +2888,12 @@ static bool pci_stop_at_missing_fn0(struct pci_bus *bus)
> int pci_scan_slot(struct pci_bus *bus, int devfn)
> {
> struct pci_dev *dev;
> + bool probe_all_fns;
> int fn = 0, nr = 0;
>
> if (only_one_child(bus) && (devfn > 0))
> return 0; /* Already scanned the entire slot */
> -
> + probe_all_fns = hypervisor_isolated_pci_functions();
[Severity: Medium]
Can calling hypervisor_isolated_pci_functions() unconditionally here add
noticeable scan and hotplug overhead on non-s390 platforms?
Previously it only ran when function 0 was missing, so populated PCI
slots, PCIe Downstream Ports, and pciehp_configure_device() skipped it.
Now every call invokes jailhouse_paravirt(), which is uncached.
On non-x86 CONFIG_OF systems, jailhouse_paravirt() calls
of_find_compatible_node(), taking devtree_lock with IRQs disabled to walk
the full device tree and causing IRQ latency spikes during hotplug.
On x86 guests with CONFIG_JAILHOUSE_GUEST under other hypervisors such as
KVM, jailhouse_paravirt() executes 256 CPUID VM-exits per call. Caching
the result at boot would avoid this overhead.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-ari_no_bus_dev-v6-0-855e75237600@linux.ibm.com?part=3
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v6 4/4] PCI: s390: Handle ARI on bus without associated struct pci_dev
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
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-04 15:25 UTC (permalink / raw)
To: Niklas Schnelle
Cc: linux-s390, linux-pci, virtualization, Heiko Carstens,
Vasily Gorbik, Alexander Gordeev, Christian Borntraeger,
Michael S. Tsirkin, Eugenio Perez
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] PCI: non-atomic bitfield RMW race on struct pci_bus
ari_enabled
- [Medium] PCI: s390: bitfield race on bus->ari_enabled in
zpci_bus_create_pci_bus()
- [Low] pci: pci_scan_slot() can overflow devfn on bridge-less ARI
virtual buses
--
commit 328c80a2ef503c6710f7c3ee7a2cb73d9659c2ec
Author: Niklas Schnelle <schnelle@linux.ibm.com>
PCI: s390: Handle ARI on bus without associated struct pci_dev
This commit moves the ari_enabled flag from struct pci_dev to struct pci_bus
so that buses without an associated bridge device can report ARI status. It
propagates ari_enabled to bridge-less child buses in pci_alloc_child_bus()
and sets it unconditionally on s390 root buses.
> diff --git a/arch/s390/pci/pci_bus.c b/arch/s390/pci/pci_bus.c
> index 36a4807285fad..df2fa3de3e784 100644
> --- a/arch/s390/pci/pci_bus.c
> +++ b/arch/s390/pci/pci_bus.c
> @@ -192,7 +192,14 @@ static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, s
> bus = pci_create_root_bus(NULL, ZPCI_BUS_NR, ops, zbus, &zbus->resources);
> if (!bus)
> goto out_remove_msi_domain;
> -
> + /*
> + * On s390 PCI buses are virtualized and the bridge
> + * devices are invisible to the OS. Thus the normal
> + * ARI detection does not work. At the same time firmware
> + * has always enabled ARI. Reflect the actual state by
> + * setting ari_enabled unconditionally on the bus.
> + */
> + bus->ari_enabled = 1;
> zbus->bus = bus;
> dev_set_msi_domain(&zbus->bus->dev, zbus->msi_parent_domain);
[Severity: Medium]
Can setting bus->ari_enabled here race with a concurrent sysfs bus rescan?
CPU0 CPU1
zpci_bus_create_pci_bus()
pci_create_root_bus()
device_register(&bus->dev)
rescan_store()
pci_scan_child_bus_extend()
read bitfield (ari_enabled=0)
bus->ari_enabled = 1
bus->is_added = 1 <-- data race
During dynamic zPCI hot-add, zpci_bus_create_pci_bus() holds only
zpci_add_remove_lock, while rescan_store() holds only
pci_rescan_remove_lock. Because pci_create_root_bus() publishes bus->dev
before returning and ari_enabled shares a 32-bit bitfield word with
is_added in struct pci_bus, the non-atomic read-modify-write for
bus->is_added = 1 can overwrite bus->ari_enabled back to 0.
Since bus->self is NULL on s390, pci_configure_ari() never restores
ari_enabled, leaving pci_ari_enabled(bus) false for all subsequent scans
and SR-IOV setup on that bus. Setting ari_enabled before bus publication
(for example in pcibios_root_bridge_prepare()) or holding
pci_lock_rescan_remove() around root bus setup avoids the race.
[ ... ]
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index 404dce0a4f80f..fca0344957c88 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -1240,6 +1240,7 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
>
> if (!bridge) {
> child->dev.parent = parent->bridge;
> + child->ari_enabled = parent->ari_enabled;
> goto add_dev;
> }
[Severity: Low]
Can setting child->ari_enabled here cause pci_scan_slot() to pass a devfn
larger than 255 to pci_scan_single_device()?
When virtfn_add_bus() adds a virtual SR-IOV child bus, child->self is NULL
while child->ari_enabled is now 1. A sysfs rescan via bus_rescan_store()
calls pci_scan_slot() for devfn = 0x08, 0x10, ..., 0xf8 because
only_one_child() returns 0 when bus->self is NULL.
If a non-conforming VF at devfn >= 8 exposes PCI_EXT_CAP_ID_ARI with a
non-zero Next Function Number, next_ari_fn() returns an absolute 8-bit
function number, and pci_scan_slot() passes devfn + fn (up to 503) to
pci_scan_single_device(). On controllers that shift devfn into
config-space addresses without masking (such as cfg0_map() in
drivers/pci/controller/pci-loongson.c), this overflows into the bus number
bits and scans another bus.
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 5cac6b6d40944..f1e66205d21b4 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
[ ... ]
> @@ -744,6 +743,7 @@ struct pci_bus {
> unsigned int is_added:1;
> unsigned int unsafe_warn:1; /* warned about RW1C config write */
> unsigned int flit_mode:1; /* Link in Flit mode */
> + unsigned int ari_enabled:1; /* ARI forwarding */
> };
[Severity: Medium]
Can packing ari_enabled into the same bitfield word as flit_mode cause a
data race between pci_configure_ari() and pcie_bwnotif_irq()?
CPU0 CPU1
pci_configure_ari()
pcie_capability_set_word(...)
pcie_bwnotif_irq()
__pcie_update_link_speed()
read bitfield (ari_enabled=0)
dev->bus->ari_enabled = 1
bus->flit_mode = ... <-- data race
pci_configure_ari() writes dev->bus->ari_enabled in process context with
IRQs enabled while holding only pci_rescan_remove_lock. Concurrently,
pcie_bwnotif_irq() updates bus->flit_mode on the same port->subordinate
bus in hardirq context with no locks held.
Because these flags share a 32-bit storage unit, a non-atomic
read-modify-write can overwrite bus->ari_enabled back to 0 after
PCI_EXP_DEVCTL2_ARI is set in hardware, causing sriov_init() to clear
PCI_SRIOV_CTRL_ARI and next_fn() to miss ARI functions, or silently lose
updates to bus->flit_mode. Making ari_enabled a separate bool (or
synchronizing writes to the shared flags) avoids the bitfield race.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-ari_no_bus_dev-v6-0-855e75237600@linux.ibm.com?part=4
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v6 0/4] PCI: Fix isolated function probing and enable ARI for s390
2026-12-04 14:14 [PATCH v6 0/4] PCI: Fix isolated function probing and enable ARI for s390 Niklas Schnelle
` (3 preceding siblings ...)
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
4 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-04 15:25 UTC (permalink / raw)
To: Niklas Schnelle
Cc: linux-s390, linux-pci, virtualization, Heiko Carstens,
Vasily Gorbik, Alexander Gordeev, Christian Borntraeger,
Michael S. Tsirkin, Eugenio Perez
Sashiko has finished reviewing this 4-patch series:
- Patch 1: no issues found.
- Patch 2 ("PCI: loongson: Handle missing function 0 explicitly..."): 1
potential issue (1 Low)
- Patch 3 ("PCI: Fix isolated PCI function probing with ARI and..."): 2
potential issues (1 High, 1 Medium)
- Patch 4 ("PCI: s390: Handle ARI on bus without associated stru..."): 3
potential issues (2 Medium, 1 Low)
Detailed reviews have been sent as separate replies to patches 2-4.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-ari_no_bus_dev-v6-0-855e75237600@linux.ibm.com
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-12-04 15:25 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v6 2/4] PCI: loongson: Handle missing function 0 explicitly not via isolated functions Niklas Schnelle
2026-12-04 14:45 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox