Skip to contentSkip to conversation

powerpc/eeh: avoid possible crash when edev->pdev changes

PATCH Superseded Ganesh Goudar 2 participants 3 messages May 27, 2024 – Jun 13, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/eeh: avoid possible crash when edev->pdev changes

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.

---
 arch/powerpc/kernel/eeh_pe.c | 2 ++
 1 file changed, 2 insertions(+)
arch/powerpc/kernel/eeh_pe.c +2 -0
index d1030bc52564..49f968733912 100644
@@ -859,7 +859,9 @@ 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);
+	pci_unlock_rescan_remove();
 	if (pdev)
 		return pdev->bus;
 
Signature · 1 line
2.44.0
#1 lore raw

Hi Ganesh,

Quoted 14 lines · Ganesh Goudar

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.

---
 arch/powerpc/kernel/eeh_pe.c | 2 ++
 1 file changed, 2 insertions(+)
arch/powerpc/kernel/eeh_pe.c +0 -0
index d1030bc52564..49f968733912 100644

arch/powerpc/kernel/eeh_pe.c struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe) · line 866

Quoted 8 lines
arch/powerpc/kernel/eeh_pe.c +2 -0
@@ -859,7 +859,9 @@ 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);
+	pci_unlock_rescan_remove();
 	if (pdev)
 		return pdev->bus;

What prevents pdev being freed/reused immediately after you drop the rescan/remove lock?

AFAICS eeh_dev_to_pci_dev() doesn't take an additional reference to the pdev or anything.

cheers

author
#2 lore raw
Quoted 18 lines · Michael Ellerman

Hi Ganesh,

Quoted 15 lines · Ganesh Goudar

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.

---
  arch/powerpc/kernel/eeh_pe.c | 2 ++
  1 file changed, 2 insertions(+)
arch/powerpc/kernel/eeh_pe.c +0 -0
index d1030bc52564..49f968733912 100644
@@ -859,7 +859,9 @@ struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe)
 
Quoted 9 lines

arch/powerpc/kernel/eeh_pe.c struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe) · line 866

Quoted 7 lines
arch/powerpc/kernel/eeh_pe.c +2 -0
  	/* 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);
+	pci_unlock_rescan_remove();
  	if (pdev)
  		return pdev->bus;

What prevents pdev being freed/reused immediately after you drop the rescan/remove lock?

Yeah, I should have released the lock after getting bus address, I will send v2.

Quoted 2 lines

AFAICS eeh_dev_to_pci_dev() doesn't take an additional reference to the pdev or anything.

Yes, I think we have to evaluate the possible eventualities of not taking the reference in all the cases.
But we need this lock here because, if the PCI error is encountered in the hotplug remove path, we need the pci rescan lock to avoid race between hotplug remove path and the bottom half of EEH recovery, this lets the hotplug remove to complete since it is already holding the lock and drop the recovery process as the device is no longer present.