Skip to contentSkip to conversation

PCI: Try to clean up resources via remove if shutdown doesn't exist

PATCH Superseded Sinan Kaya 1 participant 2 messages May 25, 2018

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Sinan Kaya

author
#0 lore raw

PATCH 1/1 PCI: Try to clean up resources via remove if shutdown doesn't exist

It is up to a driver to implement shutdown() callback. If shutdown() callback is not implemented, PCI device can have pending interrupt and even do DMA transactions while the system is going down.

If kexec is in use, this can damage the newly booting kexec kernel or even prevent it from booting altogether. Fallback to calling the remove() callback if shutdown() isn't implemented for a given driver.

---
 drivers/pci/pci-driver.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/pci/pci-driver.c +9 -0
index 6ace470..4ac72e3 100644
@@ -475,8 +475,17 @@ static void pci_device_shutdown(struct device *dev)
 
 	pm_runtime_resume(dev);
 
+	/*
+	 * Try shutdown callback if it exists, otherwise fallback to remove
+	 * callback. PCI drivers can do DMA and have pending interrupts.
+	 * Leaving the DMA and interrupts pending could damage the newly
+	 * booting kexec kernel as well as prevent it from booting altogether
+	 * if the pending interrupt is level.
+	 */
 	if (drv && drv->shutdown)
 		drv->shutdown(pci_dev);
+	else if (drv && drv->remove)
+		drv->remove(pci_dev);
 
 	/*
 	 * If this is a kexec reboot, turn off Bus Master bit on the
Signature · 1 line
2.7.4
author
#1 lore raw

[+cc kexec]

Quoted 36 lines · Sinan Kaya

It is up to a driver to implement shutdown() callback. If shutdown() callback is not implemented, PCI device can have pending interrupt and even do DMA transactions while the system is going down.

If kexec is in use, this can damage the newly booting kexec kernel or even prevent it from booting altogether. Fallback to calling the remove() callback if shutdown() isn't implemented for a given driver.

---
 drivers/pci/pci-driver.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/pci/pci-driver.c +9 -0
index 6ace470..4ac72e3 100644
@@ -475,8 +475,17 @@ static void pci_device_shutdown(struct device *dev)
 
 	pm_runtime_resume(dev);
 
+	/*
+	 * Try shutdown callback if it exists, otherwise fallback to remove
+	 * callback. PCI drivers can do DMA and have pending interrupts.
+	 * Leaving the DMA and interrupts pending could damage the newly
+	 * booting kexec kernel as well as prevent it from booting altogether
+	 * if the pending interrupt is level.
+	 */
 	if (drv && drv->shutdown)
 		drv->shutdown(pci_dev);
+	else if (drv && drv->remove)
+		drv->remove(pci_dev);
 
 	/*
 	 * If this is a kexec reboot, turn off Bus Master bit on the
Signature · 8 lines
Sinan Kaya
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec