[PATCH v3 2/2] cxl/pci: Guard decoder accesses after reset
From: Richard Cheng
Date: Mon Nov 16 2026 - 01:54:02 EST
The PCI core calls the driver's reset_done() callback even when a reset
fails and the device has not recovered. cxl_reset_done() then reads the
HDM decoder registers to check whether decoder state was lost. Reading
device MMIO while the device is inaccessible can trigger another error.
Skip the decoder check if the PCI Command read fails, returns all ones,
or Memory Space Enable is clear.
Fixes: 934edcd436dc ("cxl: Add post-reset warning if reset results in loss of previously committed HDM decoders")
Reviewed-by: Dave Jiang <dave.jiang@xxxxxxxxx>
Signed-off-by: Richard Cheng <icheng@xxxxxxxxxx>
---
Changelog:
v2 -> v3:
- Add Fixes tag (Sashiko)
- Read the PCI Command register with pci_read_config_word() instead of
pci_read_config_dword(), since it's a 16-bit register.
- Reword the commit message and code comment
---
drivers/cxl/pci.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c
index 8ce58917c32d..dadca2db429d 100644
--- a/drivers/cxl/pci.c
+++ b/drivers/cxl/pci.c
@@ -1106,6 +1106,12 @@ static void cxl_reset_done(struct pci_dev *pdev)
struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
struct cxl_memdev *cxlmd = cxlds->cxlmd;
struct device *dev = &pdev->dev;
+ u16 command;
+
+ /* The device may still be inaccessible after a failed reset. */
+ if (pci_read_config_word(pdev, PCI_COMMAND, &command) ||
+ PCI_POSSIBLE_ERROR(command) || !(command & PCI_COMMAND_MEMORY))
+ return;
/*
* FLR does not expect to touch the HDM decoders and related
--
2.43.0