From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796397942; b=Z4FkK9qDFJxjaMyaT5Gz5JgOhmmK45jxWdR2yVs78IcMfCPQ5yLPSq+UKi297iQMcewx Z26RNEQ/S94sIanA55aWuG90VmVgT+Jy6iwmg5mMidKCyDa3ukcMsraa+XCTXswpozass UbzRO5bmN17PBGwH5CHqGnjpJ26eI/a7P3qhgJiRHiArdePIKDKpdKC1o9ZpU1NZ+PMEC Rs+hhCXVCUOYPEPFblEE5tr9w7WcyFu3EJ0Do7zzh57lzo3idEFEPx80swiBiebIqoZx0 afXlYS3+ltZLHKYkIZ2gLA2xPcs6fS+39v555PMJBozvmn3tS77uN/GXgevxx/GUh5Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796397942; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=ydXlaY+D5SzAAzaSQRnNKahlp7YIVq1D2rdeEnyJpR4=; b=Ik3RKEcLQTPjtXZrY+wsGNB8SmgHJ4CxIgoQw0axR85dKpQpIk93iCRLjgwPzNlr+idA AHHryjZNUeN30JwIcHu85MRy1Woa6GzyffKS2rmYMBbG9hW/zoMS2wuE/Leb8z4lPFtT8 MaeveXThsQOFetNPInMeYcfs2iCcUE9ss6PJ4uRYTEoxiVwiLnkJATmlVxkLySqZZQHj1 PR5bYEEozTET+TIO5kOiJcvaZUpXrXI5J0gz1hqqDcXVKm4fUOwsstc1v48yd2LpLUPRl HaMFalq+pupjx0KyzxrB6eBCW9GL4YltKo/cVjig5FAx2C6Dmwc0KS8Eyg+s+4TsWvg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gl89Unp7; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46BB2606A322; Fri, 4 Dec 2026 15:25:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gl89Unp7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5F811F000C2; Fri, 4 Dec 2026 15:25:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796397942; bh=ydXlaY+D5SzAAzaSQRnNKahlp7YIVq1D2rdeEnyJpR4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=gl89Unp7SfTpfOQ6G8eFZsgAE70S92YiipQ7tSHrUUKvCfmgfc08alrsCh1me5isb I6mpa79SczlPYJu/ss/p/XGxXnt1xiRcX5tjSvN0cnujLMgCq6P95mFUun8OsV0rEq Wha32FTR9fgvHuzPE+N5XeEIA/m2UYoG2t+D0W6ecP70b0ZEiRh/j58lWVPPvOZQ2E PQqPTdHhyOha/0RTBeXUmB8jua86fSLNnU+rHcqfMsVm+ByaKJHejaeNxbY4R1mu24 KBBqLp+F9wKUmbalnOcoQhnSxWgUtWEIGbxkf0xVogAKZRBylEe2wdiCbzcUjcOWjX rwr525hZ+63lg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v6 4/4] PCI: s390: Handle ARI on bus without associated struct pci_dev Reply-To: sashiko-reviews@lists.linux.dev To: "Niklas Schnelle" Cc: linux-s390 , linux-pci@vger.kernel.org, virtualization@lists.linux.dev, "Heiko Carstens" , "Vasily Gorbik" , "Alexander Gordeev" , "Christian Borntraeger" , "Michael S. Tsirkin" , "Eugenio Perez" In-Reply-To: <20261204-ari_no_bus_dev-v6-4-855e75237600@linux.ibm.com> References: <20261204-ari_no_bus_dev-v6-0-855e75237600@linux.ibm.com> <20261204-ari_no_bus_dev-v6-4-855e75237600@linux.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 15:25:41 +0000 X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 =3D pci_create_root_bus(NULL, ZPCI_BUS_NR, ops, zbus, &zbus->resour= ces); > 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 =3D 1; > zbus->bus =3D 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=3D0) bus->ari_enabled =3D 1 bus->is_added =3D 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 =3D 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 p= ci_bus *parent, > =20 > if (!bridge) { > child->dev.parent =3D parent->bridge; > + child->ari_enabled =3D 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 =3D 0x08, 0x10, ..., 0xf8 because only_one_child() returns 0 when bus->self is NULL. If a non-conforming VF at devfn >=3D 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=3D0) dev->bus->ari_enabled =3D 1 bus->flit_mode =3D ... <-- data ra= ce 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-ari_no_bus= _dev-v6-0-855e75237600@linux.ibm.com?part=3D4