Skip to contentSkip to conversation

pci: fix unhandled interrupt on shutdown

RFC PATCH Superseded Michael S. Tsirkin 1 participant 6 messages Mar 16, 2015

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

cover pci: fix unhandled interrupt on shutdown

Fam Zheng noticed that pci shutdown disables msi and msix of a device while device is still active. This was intended to fix kexec with fusion devices but had the unintended effect of breaking even regular shutdown when using virtio.

The same problem would affect any driver which doesn't register a level interrupt handler when using msix.

I think the fix is to avoid touching device on shutdown:
we clear bus master anyway, so we won't get any more msi interrupts, and bus reset will clear the msi/msix state eventually anyway.

Fam, could you please confirm whether this patchset fixes the problem you have observed?

Thanks!

Michael S. Tsirkin (4):
pci: disable msi/msix at probe time
pci: don't disable msi/msix at shutdown
pci: make msi/msix shutdown functions static
virtio_pci: drop msi_off on probe

 include/linux/pci.h                | 4 ----
 drivers/pci/msi.c                  | 4 ++--
 drivers/pci/pci-driver.c           | 8 ++++++--
 drivers/virtio/virtio_pci_common.c | 3 ---
 4 files changed, 8 insertions(+), 11 deletions(-)
Signature · 1 line
MST
author maintainer
#1 lore raw

RFC PATCH 1/4 pci: disable msi/msix at probe time

commit d52877c7b1afb8c37ebe17e2005040b79cb618b0
pci/irq: let pci_device_shutdown to call pci_msi_shutdown v2

attempted to address the problem of kexec getting started after linux enabled msi/msix for a device, and drivers being confused by msi being enabled, by disabling msi at shutdown.

But arguably, it's better to disable msi/msix when kexec starts - for example, kexec might run after a crash (kdump) and shutdown callbacks are not always invoked in that case.

Cc Yinghai Lu <[email protected]>
Cc Ulrich Obergfell <[email protected]>
Cc Fam Zheng <[email protected]>
Cc Rusty Russell <[email protected]>
---
 drivers/pci/pci-driver.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/pci/pci-driver.c +6 -0
index 3cb2210..dac6d47 100644
@@ -305,6 +305,12 @@ static long local_pci_probe(void *_ddi)
 	 */
 	pm_runtime_get_sync(dev);
 	pci_dev->driver = pci_drv;
+	/*
+	 * When using kexec, msi might be left enabled by the previous kernel,
+	 * this breaks things as some drivers assume msi/msi-x is off at boot.
+	 * Fix this by forcing msi off at startup.
+	 */
+	pci_msi_off(dev);
 	rc = pci_drv->probe(pci_dev, ddi->id);
 	if (!rc)
 		return rc;
Signature · 1 line
MST
author maintainer
#3 lore raw

RFC PATCH 2/4 pci: don't disable msi/msix at shutdown

In reply to Michael S. Tsirkin

This partially reverts commit d52877c7b1afb8c37ebe17e2005040b79cb618b0:
"pci/irq: let pci_device_shutdown to call pci_msi_shutdown v2"

It's un-necessary now that we disable msi at start, and it actually turns out to cause problems: some device drivers don't register a level interrupt handler when they detect msi/msix capability, switching off msi while device is going causes device to assert a level interrupt which is never de-asserted, causing a kernel hang.

In particular, this was observed with virtio.

Cc Yinghai Lu <[email protected]>
Cc Ulrich Obergfell <[email protected]>
Cc Rusty Russell <[email protected]>
---
 drivers/pci/pci-driver.c | 2 --
 1 file changed, 2 deletions(-)
drivers/pci/pci-driver.c +0 -2
index dac6d47..4746f93 100644
@@ -456,8 +456,6 @@ static void pci_device_shutdown(struct device *dev)
 
 	if (drv && drv->shutdown)
 		drv->shutdown(pci_dev);
-	pci_msi_shutdown(pci_dev);
-	pci_msix_shutdown(pci_dev);
 
 #ifdef CONFIG_KEXEC
 	/*
Signature · 1 line
MST
author maintainer
#4 lore raw

RFC PATCH 3/4 pci: make msi/msix shutdown functions static

In reply to Michael S. Tsirkin

pci_msi_shutdown and pci_msix_shutdown are now internal to msi.c, drop them from header and make them static.

---
 include/linux/pci.h | 4 ----
 drivers/pci/msi.c   | 4 ++--
 2 files changed, 2 insertions(+), 6 deletions(-)
include/linux/pci.h +0 -4
index 211e9da..a34df45 100644
@@ -1209,11 +1209,9 @@ struct msix_entry {
 
 #ifdef CONFIG_PCI_MSI
 int pci_msi_vec_count(struct pci_dev *dev);
-void pci_msi_shutdown(struct pci_dev *dev);
 void pci_disable_msi(struct pci_dev *dev);
 int pci_msix_vec_count(struct pci_dev *dev);
 int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec);
-void pci_msix_shutdown(struct pci_dev *dev);
 void pci_disable_msix(struct pci_dev *dev);
 void pci_restore_msi_state(struct pci_dev *dev);
 int pci_msi_enabled(void);
@@ -1237,13 +1235,11 @@ static inline int pci_enable_msix_exact(struct pci_dev *dev,
 }
 #else
 static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; }
-static inline void pci_msi_shutdown(struct pci_dev *dev) { }
 static inline void pci_disable_msi(struct pci_dev *dev) { }
 static inline int pci_msix_vec_count(struct pci_dev *dev) { return -ENOSYS; }
 static inline int pci_enable_msix(struct pci_dev *dev,
 				  struct msix_entry *entries, int nvec)
 { return -ENOSYS; }
-static inline void pci_msix_shutdown(struct pci_dev *dev) { }
 static inline void pci_disable_msix(struct pci_dev *dev) { }
 static inline void pci_restore_msi_state(struct pci_dev *dev) { }
 static inline int pci_msi_enabled(void) { return 0; }
drivers/pci/msi.c +2 -2
index c3e7dfc..0e037af 100644
@@ -908,7 +908,7 @@ int pci_msi_vec_count(struct pci_dev *dev)
 }
 EXPORT_SYMBOL(pci_msi_vec_count);
 
-void pci_msi_shutdown(struct pci_dev *dev)
+static void pci_msi_shutdown(struct pci_dev *dev)
 {
 	struct msi_desc *desc;
 	u32 mask;
@@ -1014,7 +1014,7 @@ int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec)
 }
 EXPORT_SYMBOL(pci_enable_msix);
 
-void pci_msix_shutdown(struct pci_dev *dev)
+static void pci_msix_shutdown(struct pci_dev *dev)
 {
 	struct msi_desc *entry;
 
Signature · 1 line
MST
author maintainer
#5 lore raw

RFC PATCH 4/4 virtio_pci: drop msi_off on probe

In reply to Michael S. Tsirkin

pci core now disables msi on probe automatically,
drop this from device-specific code.

---
 drivers/virtio/virtio_pci_common.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/virtio/virtio_pci_common.c +0 -3
index a0723d1..f506571 100644
@@ -501,9 +501,6 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 	INIT_LIST_HEAD(&vp_dev->virtqueues);
 	spin_lock_init(&vp_dev->lock);
 
-	/* Disable MSI/MSIX to bring device to a known good state. */
-	pci_msi_off(pci_dev);
-
 	/* enable the device */
 	rc = pci_enable_device(pci_dev);
 	if (rc)
Signature · 1 line
MST
author maintainer
#2 lore raw

Re: [PATCH RFC 1/4] pci: disable msi/msix at probe time

In reply to Michael S. Tsirkin
Quoted 26 lines · Michael S. Tsirkin

commit d52877c7b1afb8c37ebe17e2005040b79cb618b0
pci/irq: let pci_device_shutdown to call pci_msi_shutdown v2

attempted to address the problem of kexec getting started after linux enabled msi/msix for a device, and drivers being confused by msi being enabled, by disabling msi at shutdown.

But arguably, it's better to disable msi/msix when kexec starts - for example, kexec might run after a crash (kdump) and shutdown callbacks are not always invoked in that case.

Cc Yinghai Lu <[email protected]>
Cc Ulrich Obergfell <[email protected]>
Cc Fam Zheng <[email protected]>
Cc Rusty Russell <[email protected]>
---
 drivers/pci/pci-driver.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/pci/pci-driver.c +0 -0
index 3cb2210..dac6d47 100644

drivers/pci/pci-driver.c static long local_pci_probe(void *_ddi) · line 313

Quoted 9 lines
drivers/pci/pci-driver.c +6 -0
@@ -305,6 +305,12 @@ static long local_pci_probe(void *_ddi)
 	 */
 	pm_runtime_get_sync(dev);
 	pci_dev->driver = pci_drv;
+	/*
+	 * When using kexec, msi might be left enabled by the previous kernel,
+	 * this breaks things as some drivers assume msi/msi-x is off at boot.
+	 * Fix this by forcing msi off at startup.
+	 */
+	pci_msi_off(dev);

should be

	pci_msi_off(pci_dev);

obviously.

Which likely means I pushed a wrong tree
to the test machine again, so this wasn't
tested as I thought it is :(

I'll re-test and repost day after tomorrow, Fam, can you tweak this manually when you are testing? I don't want to spam the list.

Quoted 6 lines
drivers/pci/pci-driver.c +0 -0
 	rc = pci_drv->probe(pci_dev, ddi->id);
 	if (!rc)
 		return rc;
Signature · 1 line
MST