diff mbox series

PCI/MSI: Clear MSI/MSI-X on resume if it's not enabled

Message ID 20220712072455.148512-1-kai.heng.feng@canonical.com
State New
Headers show
Series PCI/MSI: Clear MSI/MSI-X on resume if it's not enabled | expand

Commit Message

Kai-Heng Feng July 12, 2022, 7:24 a.m. UTC
MSI/MSI-X can have garbage data after system resume.

Before suspend:
Capabilities: [a0] MSI: Enable- Count=1/4 Maskable- 64bit+
	Address: 0000000000000000  Data: 0000
Capabilities: [c0] MSI-X: Enable+ Count=4 Masked-
	Vector table: BAR=5 offset=00042000
	PBA: BAR=5 offset=00043000

After resume:
Capabilities: [a0] MSI: Enable+ Count=128/4 Maskable- 64bit+
	Address: fffffffffffffffc  Data: ffff
Capabilities: [c0] MSI-X: Enable+ Count=4 Masked-
	Vector table: BAR=5 offset=00042000
	PBA: BAR=5 offset=00043000

So clear the MSI/MSI-X config on resume to ensure it's not enabled
unintentionally.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=216242
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 drivers/pci/msi/msi.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/pci/msi/msi.c b/drivers/pci/msi/msi.c
index 9037a7827eca7..cf8374a877f3f 100644
--- a/drivers/pci/msi/msi.c
+++ b/drivers/pci/msi/msi.c
@@ -263,8 +263,12 @@  static void __pci_restore_msi_state(struct pci_dev *dev)
 	struct msi_desc *entry;
 	u16 control;
 
-	if (!dev->msi_enabled)
+	if (!dev->msi_enabled) {
+		if (dev->msi_cap)
+			pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, 0);
+
 		return;
+	}
 
 	entry = irq_get_msi_desc(dev->irq);
 
@@ -295,8 +299,12 @@  static void __pci_restore_msix_state(struct pci_dev *dev)
 	struct msi_desc *entry;
 	bool write_msg;
 
-	if (!dev->msix_enabled)
+	if (!dev->msix_enabled) {
+		if (dev->msix_cap)
+			pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, 0);
+
 		return;
+	}
 
 	/* route the table */
 	pci_intx_for_msi(dev, 0);