]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
powerpc/eeh: avoid possible crash when edev->pdev changes
authorGanesh Goudar <ganeshgr@linux.ibm.com>
Mon, 17 Jun 2024 14:02:40 +0000 (19:32 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 27 Jul 2024 08:38:31 +0000 (10:38 +0200)
[ Upstream commit a1216e62d039bf63a539bbe718536ec789a853dd ]

If a PCI device is removed during eeh_pe_report_edev(), edev->pdev
will change and can cause a crash, hold the PCI rescan/remove lock
while taking a copy of edev->pdev->bus.

Signed-off-by: Ganesh Goudar <ganeshgr@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20240617140240.580453-1-ganeshgr@linux.ibm.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/powerpc/kernel/eeh_pe.c

index 177852e39a25348963505a9005378fee75a3d791..4b6b1846e4d2356ec8b4fa668acc9c3d3080e7eb 100644 (file)
@@ -922,6 +922,7 @@ struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe)
 {
        struct eeh_dev *edev;
        struct pci_dev *pdev;
+       struct pci_bus *bus = NULL;
 
        if (pe->type & EEH_PE_PHB)
                return pe->phb->bus;
@@ -932,9 +933,11 @@ struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe)
 
        /* Retrieve the parent PCI bus of first (top) PCI device */
        edev = list_first_entry_or_null(&pe->edevs, struct eeh_dev, entry);
+       pci_lock_rescan_remove();
        pdev = eeh_dev_to_pci_dev(edev);
        if (pdev)
-               return pdev->bus;
+               bus = pdev->bus;
+       pci_unlock_rescan_remove();
 
-       return NULL;
+       return bus;
 }