[PATCH v3 1/2] PCI/MSI: Skip MSI/MSI-X restoration when config space is inaccessible
From: Richard Cheng
Date: Mon Nov 16 2026 - 01:52:53 EST
PCI state restoration runs even when a reset fails. If the device's
config space remains inaccessible, MSI-X restoration still writes the
MSI-X table. The table lives in device memory space, and these MMIO
accesses can trigger additional errors, including DPC.
MSI is programmed entirely through config space, so it doesn't issue
such MMIO accesses. Restoring it is still pointless when config space is
inaccessible: reads return all ones and the restore path writes back
values derived from them.
Check whether config space of pci device is accessible or not at the
start of both MSI and MSI-X path, after msi_enabled/msix_enabled test
and before any config access, and skip the restoration if the device is
inaccessible.
Make the helper non-static and declare it in pci.h so the MSI code can
use it, too.
Signed-off-by: Richard Cheng <icheng@xxxxxxxxxx>
---
Changelog:
v2 -> v3:
- Cover MSI restoration path as well (Farhan)
- Use pci_dev_config_accessible() instead of open-coding the check, and
make it non-static (Farhan)
- Move the check before any config space access in the restore
functions (Farhan)
- The return value of the PCI Command read is no longer checked, since
the helper only tests for an all-ones value.
- Update the subject and commit message accordingly
---
drivers/pci/msi/msi.c | 6 ++++++
drivers/pci/pci.c | 2 +-
drivers/pci/pci.h | 1 +
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/msi/msi.c b/drivers/pci/msi/msi.c
index 8a0133a6a286..2865f73f5ead 100644
--- a/drivers/pci/msi/msi.c
+++ b/drivers/pci/msi/msi.c
@@ -524,6 +524,9 @@ void __pci_restore_msi_state(struct pci_dev *dev)
if (!dev->msi_enabled)
return;
+ if (!pci_dev_config_accessible(dev, "restore MSI state"))
+ return;
+
entry = irq_get_msi_desc(dev->irq);
pci_intx_for_msi(dev, 0);
@@ -877,6 +880,9 @@ void __pci_restore_msix_state(struct pci_dev *dev)
if (!dev->msix_enabled)
return;
+ if (!pci_dev_config_accessible(dev, "restore MSI-X state"))
+ return;
+
/* route the table */
pci_intx_for_msi(dev, 0);
pci_msix_clear_and_set_ctrl(dev, 0,
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7c6f2aba8144..671ffe4da1c8 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -714,7 +714,7 @@ u16 pci_find_dvsec_capability(struct pci_dev *dev, u16 vendor, u16 dvsec)
}
EXPORT_SYMBOL_GPL(pci_find_dvsec_capability);
-static bool pci_dev_config_accessible(struct pci_dev *dev, char *msg)
+bool pci_dev_config_accessible(struct pci_dev *dev, char *msg)
{
u32 val;
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 77efa4c5c960..98dd3dbd5edb 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -240,6 +240,7 @@ enum pci_mmap_api {
int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai,
enum pci_mmap_api mmap_api);
+bool pci_dev_config_accessible(struct pci_dev *dev, char *msg);
bool pci_reset_supported(struct pci_dev *dev);
void pci_init_reset_methods(struct pci_dev *dev);
int pci_bridge_secondary_bus_reset(struct pci_dev *dev);
--
2.43.0