[PATCH] Disable Bus Master on PCI device shutdown

From: Khalid Aziz
Date: Fri Apr 27 2012 - 15:00:32 EST


Disable Bus Master bit on the device in
pci_device_shutdown() to ensure PCI devices do not continue
to DMA data after shutdown. This can cause memory
corruption in case of a kexec where the current kernel
shuts down and transfers control to a new kernel while a
PCI device continues to DMA to memory that does not belong
to it any more in the new kernel.

I have tested this code on two laptops, two workstations and
a 16-socket server. kexec worked correctly on all of them.


Signed-off-by: Khalid Aziz <khalid.aziz@xxxxxx>
---
drivers/pci/pci-driver.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 6b54b23..9db5940 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -420,6 +420,12 @@ static void pci_device_shutdown(struct device *dev)
pci_msi_shutdown(pci_dev);
pci_msix_shutdown(pci_dev);

+ /*
+ * Turn off Bus Master bit on the device to tell it to not
+ * continue to do DMA
+ */
+ pci_disable_device(pci_dev);
+
/*
* Devices may be enabled to wake up by runtime PM, but they need not
* be supposed to wake up the system from its "power off" state (e.g.
--
1.7.8.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/