Re: [PATCH v2 07/16] PCI: Serialize bridge window sizing and resource assignment

From: David Matlack

Date: Mon Nov 23 2026 - 19:54:46 EST


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.

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, 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.

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.

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.

This is not a blocker by any means, just wanted to get your thoughts.

Thanks,
David.