On Thu, Jun 27, 2024 at 09:47:05AM +0200, Lukas Wunner wrote: > On Wed, Jun 12, 2024 at 11:16:24AM -0700, Keith Busch wrote: > > PCIe hotplug events modify the topology in their IRQ thread once it can > > acquire the global pci_rescan_remove_lock. > > > > If a different removal event happens to acquire that lock first, and > > that removal event is for the parent device of the bridge processing the > > other hotplug event, then we are deadlocked: the parent removal will > > wait indefinitely on the child's IRQ thread because the parent is > > holding the global lock the child thread needs to make forward progress. > > Yes, that's a known problem. I submitted a fix for it in 2018: > > https://lore.kernel.org/all/4c882e25194ba8282b78fe963fec8faae7cf23eb.1529173804.git.lukas@xxxxxxxxx/ > > The patch I proposed was similar to yours, but was smaller and > confined to pciehp_pci.c. It was part of a larger series and > when respinning that series I dropped the patch, which is the > reason it never got applied. I explained the rationale for > dropping it in this message: > > https://lore.kernel.org/all/20180906162634.ylyp3ydwujf5wuxx@xxxxxxxxx/ > > Basically all these proposals (both mine and yours) are not great > because they add another layer of duct tape without tackling the > underlying problem -- that pci_lock_rescan_remove() is way too > coarse-grained and needs to be replaced by finer-grained locking. > That however is a complex task that we haven't made significant > forward progress on in the last couple of years. Something else > always seemed more important. Thinking about this some more: The problem is pci_lock_rescan_remove() is a single global lock. What if we introduce a lock at each bridge or for each pci_bus. Before a portion of the hierarchy is removed, all locks in that sub-hierarchy are acquired bottom-up. I think that should avoid the deadlock. Thoughts? Thanks, Lukas