linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] powerpc/eeh: avoid possible crash when edev->pdev changes
@ 2024-06-17 14:02 Ganesh Goudar
  2024-06-24 12:30 ` Michael Ellerman
  0 siblings, 1 reply; 2+ messages in thread
From: Ganesh Goudar @ 2024-06-17 14:02 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Ganesh Goudar, mahesh, wenxiong

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>
---
v2: Hold rescan lock till we get the bus address.
v3: Now that we are taking copy of bus, holding the lock, update the
    commit message accordingly.
---
 arch/powerpc/kernel/eeh_pe.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/eeh_pe.c b/arch/powerpc/kernel/eeh_pe.c
index d1030bc52564..d283d281d28e 100644
--- a/arch/powerpc/kernel/eeh_pe.c
+++ b/arch/powerpc/kernel/eeh_pe.c
@@ -849,6 +849,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;
@@ -859,9 +860,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;
 }
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] powerpc/eeh: avoid possible crash when edev->pdev changes
  2024-06-17 14:02 [PATCH v3] powerpc/eeh: avoid possible crash when edev->pdev changes Ganesh Goudar
@ 2024-06-24 12:30 ` Michael Ellerman
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Ellerman @ 2024-06-24 12:30 UTC (permalink / raw)
  To: linuxppc-dev, mpe, Ganesh Goudar; +Cc: mahesh, wenxiong

On Mon, 17 Jun 2024 19:32:40 +0530, Ganesh Goudar wrote:
> 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.
> 
> 

Applied to powerpc/fixes.

[1/1] powerpc/eeh: avoid possible crash when edev->pdev changes
      https://git.kernel.org/powerpc/c/a1216e62d039bf63a539bbe718536ec789a853dd

cheers

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-06-24 12:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-17 14:02 [PATCH v3] powerpc/eeh: avoid possible crash when edev->pdev changes Ganesh Goudar
2024-06-24 12:30 ` Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).