From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: David Matlack <dmatlack@google.com>
Cc: linux-pci@vger.kernel.org, "Bjorn Helgaas" <bhelgaas@google.com>,
"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Wilczyński" <kw@linux.com>,
"Rafael J. Wysocki (Intel)" <rafael@kernel.org>,
"Christian König" <christian.koenig@amd.com>,
"Alex Williamson" <alex@shazbot.org>,
LKML <linux-kernel@vger.kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH v2 07/16] PCI: Serialize bridge window sizing and resource assignment
Date: Tue, 24 Nov 2026 16:10:20 +0200 (EET) [thread overview]
Message-ID: <42d7af61-bf69-b440-8685-5d9cec4863dd@linux.intel.com> (raw)
In-Reply-To: <DN314UP7ZLCR.39N4XNGLWKR05@google.com>
[-- Attachment #1: Type: text/plain, Size: 5303 bytes --]
On Mon, 23 Nov 2026, David Matlack wrote:
> On Fri Nov 20, 2026 at 5:47 AM PST, Ilpo Järvinen wrote:
> > +/*
> > + * Serializes bridge window sizing, resource fitting, and assignment.
> > + * pci_rescan_remove_lock cannot be used for this because BAR resize and
> > + * some drivers run these operations under device_lock() during probe.
> > + *
> > + * Context:
> > + * - Nests inside pci_rescan_remove_lock and device_lock().
> > + * - Nests outside pci_bus_sem.
> > + */
> > +static DEFINE_MUTEX(pci_res_setup_lock);
>
> Hi Ilpo,
>
> Could this lock live in struct pci_host_bridge instead of being global?
>
> As far as I can tell, a sizing and assignment pass never goes above a
> root bus, and root bus windows are only allocated from, never modified.
> So passes on different host bridges never touch the same resources.
> Every entrypoint has a pci_bus or pci_dev to look up the host bridge
> with, and pci_assign_unassigned_resources() already goes one root bus at
> a time.
Hi David,
I don't immediately see anything preventing from moving it into the host
bridge struct, I'll look into this. pci_assign_unassigned_resources() does
process all root busses but sequentially so it should work too.
Not sure if it really helps much currently because pci_bus_sem is also
held but that might eventually change (there's the series which
attempted to split that into a separate lock in each bus, I don't
remember why that work stalled).
> To be clear, the lock wouldn't protect any fields of struct
> pci_host_bridge itself. It would protect the resource[] entries of the
> devices below the host bridge, and the BAR, bridge window and Resizable
> BAR registers they mirror. The host bridge is just the smallest object
> that contains a whole pass.
>
> My motivation isn't performance. It's that global locks make it hard to
> tell what data they protect. pci_rescan_remove_lock is a good example:
> it's held around runtime rescans, but not around enumeration of ACPI
> host bridges at boot,
Not yet. ;-)
...I already have another (unsubmitted) series that adds
pci_rescan_remove_lock around host bridge setups because they too can race
with a sysfs /rescan leading to adding devices more than once, etc.
Early enumeration obviously won't need it but to be able to add lockdep
asserts to strategic places, I want to cover early init paths too.
The host bridge setup locking series requires though that
pci_rescan_remove_lock is reentrant (the v16 series inflight) because
there are a few cases that face lock-divergent callers (VMD, some HP
driver, some arch code that will be partially fixed by that v16 series,
and a few others I don't now recall).
The races that this series is fixing, however, are easier to hit than host
bridge setup ones, because, e.g., ThunderBolt hotplug racing with some
probe() initiated BAR resize does not depend on root triggering a racing
rescan call through sysfs.
> and that was confusing when I was working on PCI
> Live Update. This is a different lock, of course, but it would be nice
> to avoid adding another global lock.
Now I actually started to wonder why couldn't pci_rescan_remove_lock also
be per host bridge?? (+ a separate lock to protect root buses list)
...I think I'll take a look at this as well.
> I tried it on top of this series to see how much it changes. Only this
> patch is affected. It adds a mutex to struct pci_host_bridge,
> initializes it in pci_init_host_bridge(), and uses a small helper in
> setup-bus.c:
>
> static struct mutex *pci_res_setup_lock(struct pci_bus *bus)
> {
> return &pci_find_host_bridge(bus)->res_setup_lock;
> }
>
> All of the guard() sites and most of the lockdep asserts already have a
> bus or dev to pass in. __assign_resources_sorted() only gets a list, so
> it would have to assert using the first entry.
I can just move that assert one level up to avoid this problem.
> Putting the lock in the host bridge would also make it reachable from
> remove.c. pci_destroy_dev() drops pci_bus_sem after list_del() and then
> calls pci_free_resources() without pci_res_setup_lock. I couldn't find a
> path where this can cause bugs, but that seems like just a lucky
> side-effect of the current code. It would be nice to have the new lock
> explicitly cover that case too.
I don't think remove can cause problems because we also hold pci_bus_sem
over the entire sizing and assignment operation on purpose to keep the bus
devices from coming and going underneath us.
So either:
1. list_del() has already removed the dev and sizing nor assigned never
sees it.
2. pci_destroy_dev() cannot remove it from list until the sizing and
assignment algorithm has finished.
...So to me it looks it works as designed, and luck has nothing to do with
it. :-)
...I think what you were actually suggesting is to extend this new lock to
do something else than serialize sizing and assignment calls. :-) It is
not meant for that, and even less so competing with pci_bus_sem's role in
protecting devices in buses.
> This is not a blocker by any means, just wanted to get your thoughts.
I really appreciate you taking a look on this.
--
i.
next prev parent reply other threads:[~2026-11-24 14:10 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 13:46 [PATCH v2 00/16] " Ilpo Järvinen
2026-11-20 13:46 ` [PATCH v2 01/16] PCI: Add pci_bus_size_and_assign_resources() Ilpo Järvinen
2026-11-20 13:46 ` [PATCH v2 02/16] alpha/PCI: Convert to pci_bus_size_and_assign_resources() Ilpo Järvinen
2026-11-20 13:46 ` [PATCH v2 03/16] PCI: Use guard() for pci_bus_sem in pci_do_resource_release_and_resize() Ilpo Järvinen
2026-11-20 13:46 ` [PATCH v2 04/16] PCI: Add pci_assign_unassigned_slot_resources() Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 05/16] PCI: acpiphp: Use pci_assign_unassigned_slot_resources() Ilpo Järvinen
2026-11-20 14:33 ` Rafael J. Wysocki (Intel)
2026-11-20 13:47 ` [PATCH v2 06/16] PCI: Hold pci_bus_sem across sizing and assignment entrypoints Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 07/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
2026-11-24 0:54 ` David Matlack
2026-11-24 14:10 ` Ilpo Järvinen [this message]
2026-11-20 13:47 ` [PATCH v2 08/16] PCI: Make internal sizing and assignment functions static Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 09/16] EDAC/i82875p: Convert to pci_assign_unassigned_bus_resources() Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 10/16] platform/x86: asus-wmi: " Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 11/16] platform/x86: eeepc-laptop: " Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 12/16] parisc/PCI: " Ilpo Järvinen
2026-11-21 22:27 ` Helge Deller
2026-11-20 13:47 ` [PATCH v2 13/16] PCI: octep_hp: " Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 14/16] PCI: ftpci100: " Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 15/16] PCI: hv: " Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 16/16] PCI: Remove pci_bus_assign_resources() Ilpo Järvinen
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=42d7af61-bf69-b440-8685-5d9cec4863dd@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=alex@shazbot.org \
--cc=bhelgaas@google.com \
--cc=christian.koenig@amd.com \
--cc=dmatlack@google.com \
--cc=kw@linux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®