From: sashiko-bot@kernel.org
To: "Niklas Schnelle" <schnelle@linux.ibm.com>
Cc: linux-s390 <linux-s390@vger.kernel.org>,
linux-pci@vger.kernel.org, virtualization@lists.linux.dev,
"Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH v6 4/4] PCI: s390: Handle ARI on bus without associated struct pci_dev
Date: Fri, 04 Dec 2026 15:25:41 +0000 [thread overview]
Message-ID: <sashiko-outbox-250091@kernel.org> (raw)
In-Reply-To: <20261204-ari_no_bus_dev-v6-4-855e75237600@linux.ibm.com>
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
next prev parent reply other threads:[~2026-12-04 15:25 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 ` [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 [this message]
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=sashiko-outbox-250091@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=eperezma@redhat.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-pci@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mst@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=schnelle@linux.ibm.com \
--cc=virtualization@lists.linux.dev \
/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