From: sashiko-bot@kernel.org
To: "Srirangan Madhavan" <smadhavan@nvidia.com>,
linux-cxl@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v18 12/19] PCI/CXL: Add CXL Device Reset sequencing
Date: Sat, 05 Dec 2026 04:38:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-251091@kernel.org> (raw)
In-Reply-To: <20261205041453.3946529-13-smadhavan@nvidia.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] PCI/CXL: cxl_reset_function() gates probe on dynamic CXL
enable bits
- [Medium] PCI/CXL: cxl_reset_wait_cache_wbi() misses post-deadline
status read
- [Medium] PCI/CXL: cxl_reset_wait_done() checks deadline after status
read
- [Medium] PCI/CXL: cxl_reset_function() requires CXL.cache capability
and enable
--
commit 7d770790d7d42c69d9dc663a5c3fce0ee4f98b17
Author: Srirangan Madhavan <smadhavan@nvidia.com>
PCI/CXL: Add CXL Device Reset sequencing
This commit adds CXL Device Reset sequencing for Type 2 devices,
including cache writeback and invalidation, transaction draining,
IOMMU preparation, reset initiation with Memory Clear, and completion
polling.
> diff --git a/drivers/pci/cxl.c b/drivers/pci/cxl.c
> index 56119e3fd03a6..4d6cfabab2c0e 100644
> --- a/drivers/pci/cxl.c
> +++ b/drivers/pci/cxl.c
[ ... ]
> @@ -224,3 +228,238 @@ void pci_cxl_hdm_cache_release(struct pci_dev *pdev)
[ ... ]
> +static int cxl_reset_wait_cache_wbi(struct pci_dev *pdev, int dvsec)
> +{
> + unsigned long deadline;
> + u16 status2;
> + int rc;
> +
> + rc = cxl_reset_update_ctrl2(pdev, dvsec,
> + PCI_DVSEC_CXL_INIT_CACHE_WBI, 0);
> + if (rc)
> + return rc;
> +
> + deadline = jiffies + usecs_to_jiffies(CXL_CACHE_WBI_TIMEOUT_US);
> + while (time_before(jiffies, deadline)) {
> + usleep_range(CXL_CACHE_WBI_POLL_US,
> + CXL_CACHE_WBI_POLL_US * 2);
> +
> + rc = cxl_pci_read_config_word(pdev,
> + dvsec + PCI_DVSEC_CXL_STATUS2,
> + &status2);
> + if (rc)
> + return rc;
> + if (status2 & PCI_DVSEC_CXL_CACHE_INV)
> + return 0;
> + }
> +
> + pci_warn(pdev, "timed out waiting for CXL cache writeback and invalidate\n");
> + return -ETIMEDOUT;
> +}
[Severity: Medium]
Can cxl_reset_wait_cache_wbi() return a spurious -ETIMEDOUT without
re-checking PCI_DVSEC_CXL_STATUS2 after the deadline passes?
If the thread is preempted across the 100 ms deadline right after
computing deadline, or after a poll where PCI_DVSEC_CXL_CACHE_INV was
still clear, time_before() exits the loop without reading Status2 again.
That aborts the reset even if hardware completed writeback and
invalidation in time.
Sampling whether the timeout expired before reading Status2 (as
poll_timeout_us() does) ensures one final check after the deadline.
[ ... ]
> + for (;;) {
> + rc = pci_read_config_word(pdev, dvsec + PCI_DVSEC_CXL_STATUS2,
> + &status2);
> + if (rc)
> + return pcibios_err_to_errno(rc);
> + if (status2 != U16_MAX) {
> + if (status2 & PCI_DVSEC_CXL_RST_ERR)
> + return -EIO;
> + if (status2 & PCI_DVSEC_CXL_RST_DONE)
> + return 0;
> + }
> +
> + if (time_after_eq(jiffies, deadline)) {
> + pci_err(pdev, "timed out waiting for CXL reset to complete\n");
> + return -ETIMEDOUT;
> + }
> +
> + msleep(CXL_RESET_STATUS_POLL_MS);
> + }
[Severity: Medium]
Can cxl_reset_wait_done() also report a spurious -ETIMEDOUT by checking
time_after_eq(jiffies, deadline) after pci_read_config_word()?
For a device advertising a 10 ms or 100 ms reset timeout, deadline is
only 20 ms after the 100 ms quiet period. If the first config read
stalls in RRS retries or the thread is preempted before the timeout
check, the loop returns -ETIMEDOUT without reading Status2 again after
the deadline.
Recording expiration before reading PCI_DVSEC_CXL_STATUS2 avoids
failing a reset that completed before the deadline.
[ ... ]
> +int cxl_reset_function(struct pci_dev *pdev, bool probe)
> +{
> + u16 dvsec, cap, ctrl;
> + int rc;
> +
> + rc = cxl_pci_device_dvsec(pdev, &dvsec, &cap);
> + if (rc)
> + return rc;
> + if (!(cap & PCI_DVSEC_CXL_CACHE_CAPABLE) ||
> + !(cap & PCI_DVSEC_CXL_MEM_CAPABLE) ||
> + !(cap & PCI_DVSEC_CXL_RST_CAPABLE) ||
> + !(cap & PCI_DVSEC_CXL_RST_MEM_CLR_CAPABLE))
> + return -ENOTTY;
> +
> + rc = cxl_pci_read_config_word(pdev, dvsec + PCI_DVSEC_CXL_CTRL, &ctrl);
> + if (rc)
> + return rc;
> + if (!(ctrl & PCI_DVSEC_CXL_CACHE_ENABLE) ||
> + !(ctrl & PCI_DVSEC_CXL_MEM_ENABLE))
> + return -ENOTTY;
[Severity: Medium]
As reported by Jonathan Cameron on v12 [1], should cxl_reset_function()
require PCI_DVSEC_CXL_CACHE_CAPABLE and PCI_DVSEC_CXL_CACHE_ENABLE?
A Type 2 device running with CXL.mem enabled and CXL.cache disabled, or
a CXL.mem-only device with CXL Reset and Reset Memory Clear, gets
-ENOTTY here and falls through to FLR without clearing device memory or
resetting CXL.mem state.
Relaxing the CXL.cache requirement here and gating cache disable, WBI,
and policy restore in cxl_reset_execute() on CXL.cache being capable and
enabled would cover those devices as well.
> +
> + if (probe)
> + return 0;
[Severity: Medium]
Should the PCI_DVSEC_CXL_CTRL enable check happen after the probe return
rather than before it?
pci_init_reset_methods() probes reset methods once during PCI
enumeration, before any driver binds to enable PCI_DVSEC_CXL_MEM_ENABLE
or PCI_DVSEC_CXL_CACHE_ENABLE. If firmware leaves them disabled,
cxl_reset is permanently excluded from dev->reset_methods[] and later
resets fall back to FLR or bus reset without CXL Memory Clear.
Checking only static capability bits in PCI_DVSEC_CXL_CAP during probe
and checking PCI_DVSEC_CXL_CTRL only when executing the reset lets
__pci_reset_function_locked() fall through cleanly when CXL is disabled.
[1] https://lore.kernel.org/r/20260912022617.47860862@jic23-hlaptop
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205041453.3946529-1-smadhavan@nvidia.com?part=12
next prev parent reply other threads:[~2026-12-05 4:38 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 4:14 [PATCH v18 00/19] PCI/CXL: Add CXL reset support for Type 2 devices Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 01/19] cxl: Clarify decoder interleave limit Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 02/19] cxl: Share CXL port upstream PCI device lookup Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 03/19] cxl: Move decoder declarations to shared header Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 04/19] cxl: Embed decoder configuration in a standalone structure Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 05/19] cxl: Introduce endpoint HDM decoder settings Srirangan Madhavan
2026-12-05 4:30 ` sashiko-bot
2026-12-05 4:14 ` [PATCH v18 06/19] cxl: Move HDM decoder helpers to built-in code Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 07/19] cxl: Share HDM decoder register unpacking Srirangan Madhavan
2026-12-05 4:30 ` sashiko-bot
2026-12-05 4:14 ` [PATCH v18 08/19] cxl: Move cxl_rwsem into built-in code Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 09/19] cxl: Refresh cached PCI HDM decoder settings Srirangan Madhavan
2026-12-05 4:38 ` sashiko-bot
2026-12-05 4:14 ` [PATCH v18 10/19] cxl: Build register block helpers into the kernel Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 11/19] PCI/CXL: Cache endpoint HDM state during PCI enumeration Srirangan Madhavan
2026-12-05 4:44 ` sashiko-bot
2026-12-05 4:14 ` [PATCH v18 12/19] PCI/CXL: Add CXL Device Reset sequencing Srirangan Madhavan
2026-12-05 4:38 ` sashiko-bot [this message]
2026-12-05 4:14 ` [PATCH v18 13/19] cxl: Validate and synchronize HDM ranges around reset Srirangan Madhavan
2026-12-05 4:47 ` sashiko-bot
2026-12-05 4:14 ` [PATCH v18 14/19] PCI/CXL: Reject reset with unsafe function scope Srirangan Madhavan
2026-12-05 4:43 ` sashiko-bot
2026-12-05 4:14 ` [PATCH v18 15/19] PCI/CXL: Restore CXL state after PCI reset Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 16/19] PCI/CXL: Expose CXL Reset as a PCI reset method Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 17/19] PCI/CXL: Restore CXL state after CXL bus reset Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 18/19] PCI/CXL: Flush host and device caches for " Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 19/19] cxl: Add KUnit checks for HDM decoder unpacking Srirangan Madhavan
2026-12-05 4:38 ` 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=sashiko-outbox-251091@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=smadhavan@nvidia.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