Re: [PATCH v2 07/16] PCI: Serialize bridge window sizing and resource assignment
From: David Matlack
Date: Tue Nov 24 2026 - 14:47:53 EST
On Tue Nov 24, 2026 at 6:10 AM PST, Ilpo Järvinen wrote:
> I don't immediately see anything preventing from moving it into the host
> bridge struct, I'll look into this.
Thanks!
> 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).
A lock per bus seems hard to get right, since a sizing pass or a BAR
resize can span many buses and you'd have to lock up and down the
hierarchy. Per host bridge avoids that.
> ...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.
That would have saved me a lot of head scratching. Please Cc me when you
post it. I'm happy to review it and test it with Live Update.
> 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've been thinking the same thing. Both pci_bus_sem and
pci_rescan_remove_lock could move into struct pci_host_bridge, with a
small global lock for the root buses list as you said.
A big benefit of a per-host-bridge pci_rescan_remove_lock is that it
makes it obvious which lock to take during boot-time scans: the lock of
the host bridge being set up, which nothing else can be holding yet. It
would also solve the re-entrancy problem, at least for VMD.
vmd_remove() could always take the VMD domain's own lock, which is a
different lock from the parent domain's, whether or not the caller
holds the parent's.
Eventually, the per-host-bridge pci_bus_sem and res_setup_lock could be
merged into a single rwsem, with sizing and assignment taking it for
write.
Thanks,
David