Skip to contentSkip to conversation

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

PATCH In review Sinan Kaya 3 participants 7 messages May 28, 2018 – Jun 1, 2018

Subsystems (5)
lore
Share & tools
lore

Sinan Kaya

author
#0 lore raw

PATCH v3 1/2 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.

Fixes cc27b735ad3a ("PCI/portdrv: Turn off PCIe services during shutdown")
Cc stable at vger.kernel.org
---
 drivers/pci/pci-driver.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/pci/pci-driver.c +9 -0
index cbda0e6..75a00fe 100644
@@ -477,8 +477,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

PATCH v3 2/2 scsi: hpsa: drop shutdown callback

'Commit cc27b735ad3a ("PCI/portdrv: Turn off PCIe services during shutdown")' has been added to kernel to shutdown pending PCIe port service interrupts during reboot so that a newly started kexec kernel wouldn't observe pending interrupts.

pcie_port_device_remove() is disabling the root port and switches by calling pci_disable_device() after all PCIe service drivers are shutdown.

This has been found to cause crashes on HP DL360 Gen9 machines during reboot due to hpsa driver not clearing the bus master bit during the shutdown procedure by calling pci_disable_device().

Drop the shutdown API and do an orderly clean up by using the remove.

Fixes cc27b735ad3a ("PCI/portdrv: Turn off PCIe services during shutdown")
Cc stable at vger.kernel.org
---
 drivers/scsi/hpsa.c | 1 -
 1 file changed, 1 deletion(-)
drivers/scsi/hpsa.c +0 -1
index 3a9eca1..3dbef28 100644
@@ -8970,7 +8970,6 @@ static struct pci_driver hpsa_pci_driver = {
 	.probe = hpsa_init_one,
 	.remove = hpsa_remove_one,
 	.id_table = hpsa_pci_device_id,	/* id_table */
-	.shutdown = hpsa_shutdown,
 	.suspend = hpsa_suspend,
 	.resume = hpsa_resume,
 };
Signature · 1 line
2.7.4
Tested-by on v3 1/2
#6 lore raw
In reply to Sinan Kaya
Quoted 8 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.

Quoted 5 lines
Fixes cc27b735ad3a ("PCI/portdrv: Turn off PCIe services during shutdown")
Cc stable at vger.kernel.org

Tested successfully on DL360 Gen9 and DL380 Gen9.

Tested-by on v3 2/2
#2 lore raw

Re: [PATCH V3 2/2] scsi: hpsa: drop shutdown callback

In reply to Sinan Kaya
Quoted 12 lines · Sinan Kaya

'Commit cc27b735ad3a ("PCI/portdrv: Turn off PCIe services during shutdown")' has been added to kernel to shutdown pending PCIe port service interrupts during reboot so that a newly started kexec kernel wouldn't observe pending interrupts.

pcie_port_device_remove() is disabling the root port and switches by calling pci_disable_device() after all PCIe service drivers are shutdown.

This has been found to cause crashes on HP DL360 Gen9 machines during reboot due to hpsa driver not clearing the bus master bit during the shutdown procedure by calling pci_disable_device().

Quoted 7 lines

Drop the shutdown API and do an orderly clean up by using the remove.

Fixes cc27b735ad3a ("PCI/portdrv: Turn off PCIe services during shutdown")
Cc stable at vger.kernel.org

Tested successfully on DL360 Gen9 and DL380 Gen9.

#3 lore raw

PATCH v3 2/2 scsi: hpsa: drop shutdown callback

Quoted 38 lines

-----Original Message-----
From: Ryan Finnie [mailto:ryan at finnie.org]
Sent: Tuesday, May 29, 2018 8:50 PM
To: Sinan Kaya <[email protected]>; linux-pci at vger.kernel.org; timur at codeaurora.org
Cc: linux-arm-msm at vger.kernel.org; linux-arm-kernel at lists.infradead.org; stable at vger.kernel.org; Don Brace <[email protected]>; James E.J. Bottomley <[email protected]>; Martin K. Petersen <[email protected]>; esc.storagedev <[email protected]>; open list:HEWLETT-PACKARD SMART ARRAY RAID DRIVER (hpsa) <[email protected]>; open list <linux- kernel at vger.kernel.org>
Subject: Re: [PATCH V3 2/2] scsi: hpsa: drop shutdown callback

EXTERNAL EMAIL

Quoted 12 lines · Sinan Kaya

'Commit cc27b735ad3a ("PCI/portdrv: Turn off PCIe services during shutdown")' has been added to kernel to shutdown pending PCIe port service interrupts during reboot so that a newly started kexec kernel wouldn't observe pending interrupts.

pcie_port_device_remove() is disabling the root port and switches by calling pci_disable_device() after all PCIe service drivers are shutdown.

This has been found to cause crashes on HP DL360 Gen9 machines during reboot due to hpsa driver not clearing the bus master bit during the shutdown procedure by calling pci_disable_device().

Quoted 7 lines

Drop the shutdown API and do an orderly clean up by using the remove.

Fixes cc27b735ad3a ("PCI/portdrv: Turn off PCIe services during shutdown")
Cc stable at vger.kernel.org
Quoted 3 lines

Tested successfully on DL360 Gen9 and DL380 Gen9.

The shutdown path issues a cache flush to the controller. Without this flush, you will see "Dirty Cache" messages at POST. It is best to keep the shutdown path.

Thanks,
Don Brace
ESC - Smart Storage
Microsemi Corporation

#4 lore raw

Re: [PATCH V3 2/2] scsi: hpsa: drop shutdown callback

Quoted 40 lines · Don Brace
Quoted 40 lines

-----Original Message-----
From: Ryan Finnie [mailto:ryan at finnie.org]
Sent: Tuesday, May 29, 2018 8:50 PM
To: Sinan Kaya <[email protected]>; linux-pci at vger.kernel.org; timur at codeaurora.org
Cc: linux-arm-msm at vger.kernel.org;
linux-arm-kernel at lists.infradead.org;
stable at vger.kernel.org; Don Brace <[email protected]>; James E.J.
Bottomley <[email protected]>; Martin K. Petersen <[email protected]>; esc.storagedev <[email protected]>; open list:HEWLETT-PACKARD SMART ARRAY RAID DRIVER (hpsa) <[email protected]>; open list <linux- kernel at vger.kernel.org>
Subject: Re: [PATCH V3 2/2] scsi: hpsa: drop shutdown callback

EXTERNAL EMAIL

Quoted 19 lines · Sinan Kaya

'Commit cc27b735ad3a ("PCI/portdrv: Turn off PCIe services during shutdown")' has been added to kernel to shutdown pending PCIe port service interrupts during reboot so that a newly started kexec kernel wouldn't observe pending interrupts.

pcie_port_device_remove() is disabling the root port and switches by calling pci_disable_device() after all PCIe service drivers are shutdown.

This has been found to cause crashes on HP DL360 Gen9 machines during reboot due to hpsa driver not clearing the bus master bit during the shutdown procedure by calling pci_disable_device().

Drop the shutdown API and do an orderly clean up by using the remove.

Fixes cc27b735ad3a ("PCI/portdrv: Turn off PCIe services during shutdown")
Cc stable at vger.kernel.org
Quoted 8 lines
Quoted 3 lines

Tested successfully on DL360 Gen9 and DL380 Gen9.

The shutdown path issues a cache flush to the controller. Without this flush, you will see "Dirty Cache" messages at POST. It is best to keep the shutdown path.

I have seen that shutdown() is also called from remove().

remove() is supposed to do a safe cleanup too. If it is leaving the hw in inconsistent state even though it is c lling shutdown , it is yet another bug.

Quoted 4 lines

Thanks,
Don Brace
ESC - Smart Storage
Microsemi Corporation

author
#5 lore raw

Re: [PATCH V3 2/2] scsi: hpsa: drop shutdown callback

Quoted 3 lines · okaya at codeaurora.org

I have seen that shutdown() is also called from remove().

remove() is supposed to do a safe cleanup too. If it is leaving the hw in inconsistent state even though it is c lling shutdown , it is yet another bug.

Let's try to be constructive. I'll post a patch with the pci_disable added to shutdown only as in my original proposal.

Somebody can deal with remove another day.

Signature · 3 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.