mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "David Matlack" <dmatlack@google.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	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>,
	linux-kernel@vger.kernel.org
Cc: <stable@vger.kernel.org>
Subject: Re: [PATCH v2 07/16] PCI: Serialize bridge window sizing and resource assignment
Date: Mon, 23 Nov 2026 16:54:35 -0800	[thread overview]
Message-ID: <DN314UP7ZLCR.39N4XNGLWKR05@google.com> (raw)
In-Reply-To: <20261120134716.3027-8-ilpo.jarvinen@linux.intel.com>

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.

  reply	other threads:[~2026-11-24  0:54 UTC|newest]

Thread overview: 20+ 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 [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=DN314UP7ZLCR.39N4XNGLWKR05@google.com \
    --to=dmatlack@google.com \
    --cc=alex@shazbot.org \
    --cc=bhelgaas@google.com \
    --cc=christian.koenig@amd.com \
    --cc=ilpo.jarvinen@linux.intel.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®