Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Richard Cheng <icheng@nvidia.com>
To: dave@stgolabs.net, jic23@kernel.org, dave.jiang@intel.com,
	alison.schofield@intel.com, vishal.l.verma@intel.com,
	helgaas@google.com
Cc: iweiny@kernel.org, ming.li@zohomail.com, icheng@nvidia.com,
	linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-pci@vger.kernel.org, tglx@kernel.org,
	wangruikang@iscas.ac.cn, alifm@linux.ibm.com,
	shawn.lin@rock-chips.com, lihaoxiang@isrc.iscas.ac.cn,
	18255117159@163.com, xiangzao@linux.alibaba.com,
	vidyas@nvidia.com, kaihengf@nvidia.com, kobak@nvidia.com,
	newtonl@nvidia.com, kristinc@nvidia.com
Subject: [PATCH v3 2/2] cxl/pci: Guard decoder accesses after reset
Date: Mon, 16 Nov 2026 14:52:29 +0800	[thread overview]
Message-ID: <20261116065229.38194-3-icheng@nvidia.com> (raw)
In-Reply-To: <20261116065229.38194-1-icheng@nvidia.com>

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@intel.com>
Signed-off-by: Richard Cheng <icheng@nvidia.com>
---
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


  parent reply	other threads:[~2026-11-16  6:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  6:52 [PATCH v3 0/2] PCI/CXL: Guard device accesses during reset recovery Richard Cheng
2026-11-16  6:52 ` [PATCH v3 1/2] PCI/MSI: Skip MSI/MSI-X restoration when config space is inaccessible Richard Cheng
2026-11-16  7:02   ` sashiko-bot
2026-11-16  6:52 ` Richard Cheng [this message]
2026-11-16  7:00   ` [PATCH v3 2/2] cxl/pci: Guard decoder accesses after reset sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261116065229.38194-3-icheng@nvidia.com \
    --to=icheng@nvidia.com \
    --cc=18255117159@163.com \
    --cc=alifm@linux.ibm.com \
    --cc=alison.schofield@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=helgaas@google.com \
    --cc=iweiny@kernel.org \
    --cc=jic23@kernel.org \
    --cc=kaihengf@nvidia.com \
    --cc=kobak@nvidia.com \
    --cc=kristinc@nvidia.com \
    --cc=lihaoxiang@isrc.iscas.ac.cn \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=ming.li@zohomail.com \
    --cc=newtonl@nvidia.com \
    --cc=shawn.lin@rock-chips.com \
    --cc=tglx@kernel.org \
    --cc=vidyas@nvidia.com \
    --cc=vishal.l.verma@intel.com \
    --cc=wangruikang@iscas.ac.cn \
    --cc=xiangzao@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox