Skip to content

Commit e326023

Browse files
l1kbjorn-helgaas
authored andcommitted
PCI: pciehp: Avoid unnecessary device replacement check
Hot-removal of nested PCI hotplug ports suffers from a long-standing race condition which can lead to a deadlock: A parent hotplug port acquires pci_lock_rescan_remove(), then waits for pciehp to unbind from a child hotplug port. Meanwhile that child hotplug port tries to acquire pci_lock_rescan_remove() as well in order to remove its own children. The deadlock only occurs if the parent acquires pci_lock_rescan_remove() first, not if the child happens to acquire it first. Several workarounds to avoid the issue have been proposed and discarded over the years, e.g.: https://lore.kernel.org/r/4c882e25194ba8282b78fe963fec8faae7cf23eb.1529173804.git.lukas@wunner.de/ A proper fix is being worked on, but needs more time as it is nontrivial and necessarily intrusive. Recent commit 9d573d1 ("PCI: pciehp: Detect device replacement during system sleep") provokes more frequent occurrence of the deadlock when removing more than one Thunderbolt device during system sleep. The commit sought to detect device replacement, but also triggered on device removal. Differentiating reliably between replacement and removal is impossible because pci_get_dsn() returns 0 both if the device was removed, as well as if it was replaced with one lacking a Device Serial Number. Avoid the more frequent occurrence of the deadlock by checking whether the hotplug port itself was hot-removed. If so, there's no sense in checking whether its child device was replaced. This works because the ->resume_noirq() callback is invoked in top-down order for the entire hierarchy: A parent hotplug port detecting device replacement (or removal) marks all children as removed using pci_dev_set_disconnected() and a child hotplug port can then reliably detect being removed. Link: https://lore.kernel.org/r/02f166e24c87d6cde4085865cce9adfdfd969688.1741674172.git.lukas@wunner.de Fixes: 9d573d1 ("PCI: pciehp: Detect device replacement during system sleep") Reported-by: Kenneth Crudup <[email protected]> Closes: https://lore.kernel.org/r/[email protected]/ Reported-by: Chia-Lin Kao (AceLan) <[email protected]> Closes: https://lore.kernel.org/r/[email protected]/ Tested-by: Kenneth Crudup <[email protected]> Tested-by: Mika Westerberg <[email protected]> Signed-off-by: Lukas Wunner <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Mika Westerberg <[email protected]> Reviewed-by: Kuppuswamy Sathyanarayanan <[email protected]> Cc: [email protected] # v6.11+
1 parent 9d7db4d commit e326023

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/pci/hotplug/pciehp_core.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,12 @@ static int pciehp_suspend(struct pcie_device *dev)
286286

287287
static bool pciehp_device_replaced(struct controller *ctrl)
288288
{
289-
struct pci_dev *pdev __free(pci_dev_put);
289+
struct pci_dev *pdev __free(pci_dev_put) = NULL;
290290
u32 reg;
291291

292+
if (pci_dev_is_disconnected(ctrl->pcie->port))
293+
return false;
294+
292295
pdev = pci_get_slot(ctrl->pcie->port->subordinate, PCI_DEVFN(0, 0));
293296
if (!pdev)
294297
return true;

0 commit comments

Comments
 (0)