From: Jonathan Cameron <jic23@kernel.org>
To: Srirangan Madhavan <smadhavan@nvidia.com>
Cc: Alison Schofield <alison.schofield@intel.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Dave Jiang <dave.jiang@intel.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Ira Weiny <ira.weiny@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
linux-cxl@vger.kernel.org, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org,
Alex Williamson <alex.williamson@redhat.com>,
vsethi@nvidia.com, alwilliamson@nvidia.com,
Sai Yashwanth Reddy Kancherla <skancherla@nvidia.com>,
Vishal Aslot <vaslot@nvidia.com>,
Manish Honap <mhonap@nvidia.com>, Jiandi An <jan@nvidia.com>,
Richard Cheng <icheng@nvidia.com>,
linux-tegra@vger.kernel.org
Subject: Re: [PATCH v13 13/15] cxl: Restore CXL state after PCI reset
Date: Thu, 24 Sep 2026 04:50:10 +0100 [thread overview]
Message-ID: <20260924045010.3c1b299f@jic23-hlaptop> (raw)
In-Reply-To: <20260922083924.2451158-14-smadhavan@nvidia.com>
On Tue, 22 Sep 2026 08:39:22 +0000
Srirangan Madhavan <smadhavan@nvidia.com> wrote:
> Restore the PCI configuration needed for HDM access, followed by cached
> HDM decoder and CXL Device DVSEC state. Recommit a cleared locked decoder
> before restoring its lock, but leave surviving locked state unchanged.
>
> Stop at the first restoration failure and preserve a disabled PCI command
> snapshot. Keep IOMMU exclusion active through restoration and post-reset
> cache invalidation.
>
> Signed-off-by: Srirangan Madhavan <smadhavan@nvidia.com>
Hi Srirangan,
I'm out of time for today so main request it to take a look at that
final function. It is running quite a complex statemachine with a bunch
of ownership transfers. That's the sort of single function that takes
too much energy to review. Please have a revisit and see if there
is a simpler stepwise way to do that.
> @@ -726,6 +1064,18 @@ static int cxl_reset_disable_cache(struct pci_dev *pdev, int dvsec, u16 cap)
> return cxl_reset_wait_cache_wbi(pdev, dvsec);
> }
>
> +static int cxl_reset_restore_cache_policy(struct pci_dev *pdev, int dvsec)
> +{
> + int rc;
> +
> + rc = cxl_reset_update_ctrl2_no_replay(pdev, dvsec, 0,
> + PCI_DVSEC_CXL_DISABLE_CACHING);
> + if (rc)
> + pci_err(pdev, "failed to re-enable CXL caching: %d\n", rc);
> +
> + return rc;
> +}
> +
> static int cxl_reset_wait_done(struct pci_dev *pdev, int dvsec, u16 cap)
> {
> unsigned long deadline;
> @@ -767,28 +1117,41 @@ static int cxl_reset_wait_done(struct pci_dev *pdev, int dvsec, u16 cap)
> }
> }
>
> -static int cxl_reset_execute(struct pci_dev *pdev, int dvsec, u16 cap,
> - struct cxl_hdm_range_context *range_ctx)
> +static int cxl_reset_execute(struct pci_dev *pdev, int dvsec, u16 cap)
> {
> + struct cxl_hdm_info *snapshot = NULL;
> + struct cxl_hdm_range_context range_ctx;
> + u16 command;
> int rc, rc2;
>
> - rc = cxl_reset_disable_cache(pdev, dvsec, cap);
> + down_write(&cxl_rwsem.region);
> + INIT_LIST_HEAD(&range_ctx.ranges);
> +
> + rc = cxl_hdm_ranges_prepare(&range_ctx, pdev);
> + if (rc)
> + goto out_destroy_ranges;
> +
> + rc = cxl_snapshot_hdm(pdev, &snapshot);
> if (rc)
> goto out_destroy_ranges;
>
> + rc = cxl_reset_disable_cache(pdev, dvsec, cap);
> + if (rc)
> + goto out_destroy_enable_cache;
> +
> if (!pci_wait_for_pending_transaction(pdev)) {
> pci_err(pdev, "timed out waiting for pending transactions\n");
> rc = -ETIMEDOUT;
> - goto out_destroy_ranges;
> + goto out_destroy_enable_cache;
> }
>
> rc = pci_dev_reset_iommu_prepare(pdev);
> if (rc) {
> pci_err(pdev, "failed to stop IOMMU for CXL reset: %d\n", rc);
> - goto out_destroy_ranges;
> + goto out_destroy_enable_cache;
> }
>
> - /* Clear Memory Clear again even if this command write reports failure. */
> + /* Clear Memory Clear below even if this command write reports failure. */
> rc = cxl_reset_update_ctrl2_no_replay(pdev, dvsec,
> PCI_DVSEC_CXL_INIT_CXL_RST |
> PCI_DVSEC_CXL_RST_MEM_CLR_EN, 0);
> @@ -798,39 +1161,60 @@ static int cxl_reset_execute(struct pci_dev *pdev, int dvsec, u16 cap,
> rc = cxl_reset_wait_done(pdev, dvsec, cap);
>
> out_clear_memory:
> - rc2 = cxl_reset_update_ctrl2_no_replay(
> - pdev, dvsec, 0, PCI_DVSEC_CXL_RST_MEM_CLR_EN);
> + rc2 = cxl_reset_update_ctrl2_no_replay(pdev, dvsec, 0,
> + PCI_DVSEC_CXL_RST_MEM_CLR_EN);
> if (rc2)
> pci_err(pdev, "failed to clear CXL Reset Memory Clear: %d\n",
> - rc2);
> + rc2);
> rc = rc ?: rc2;
> + if (rc)
> + goto out_finish_ranges;
> +
> + cxl_restore_pci_state_for_hdm_restore(pdev, &command);
> + rc = cxl_restore_state(pdev, snapshot);
>
> +out_finish_ranges:
> /* Evict lines fetched during reset before ending DMA exclusion. */
> - rc2 = cxl_hdm_ranges_finish(range_ctx);
> + rc2 = cxl_hdm_ranges_finish(&range_ctx);
> rc = rc ?: rc2;
> + if (rc)
> + goto out_fail_closed;
> +
> pci_dev_reset_iommu_done(pdev);
> - goto out_enable_cache;
>
> -out_destroy_ranges:
> - cxl_hdm_range_context_destroy(range_ctx);
> + rc = cxl_reset_restore_cache_policy(pdev, dvsec);
> + if (rc) {
> + cxl_reset_save_disabled_state(pdev);
> + goto out_unlock;
> + }
>
> -out_enable_cache:
> - /*
> - * DISABLE_CACHING was the first preparation step. Restore the original
> - * cache policy last, after reset exclusion has ended.
> - */
> - rc2 = cxl_reset_update_ctrl2_no_replay(
> - pdev, dvsec, 0, PCI_DVSEC_CXL_DISABLE_CACHING);
> - if (rc2)
> - pci_err(pdev, "failed to re-enable CXL caching: %d\n", rc2);
> + rc = cxl_reset_save_restored_state(pdev, command);
> + goto out_unlock;
> +
> +out_fail_closed:
> + cxl_reset_save_disabled_state(pdev);
> + pci_dev_reset_iommu_done(pdev);
> + rc2 = cxl_reset_restore_cache_policy(pdev, dvsec);
> rc = rc ?: rc2;
> + goto out_unlock;
> +
> +out_destroy_enable_cache:
> + cxl_hdm_range_context_destroy(&range_ctx);
> + rc2 = cxl_reset_restore_cache_policy(pdev, dvsec);
> + rc = rc ?: rc2;
> + goto out_unlock;
> +
> +out_destroy_ranges:
> + cxl_hdm_range_context_destroy(&range_ctx);
>
> +out_unlock:
> + kfree(snapshot);
> + up_write(&cxl_rwsem.region);
This is going to take some signficant unpicking but as
it stands it is very complex to follow with releases quite
often out of reverse order of setup and complex hand
off from one function to another. Please take another look
even if I don't get back to this with more specific comments.
> return rc;
> }
next prev parent reply other threads:[~2026-09-24 3:50 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 8:39 [PATCH v13 00/15] PCI/CXL: Add CXL reset support for Type 2 devices Srirangan Madhavan
2026-09-22 8:39 ` [PATCH v13 01/15] cxl: Drop stale decoder interleave limit comment Srirangan Madhavan
2026-09-24 1:16 ` Jonathan Cameron
2026-09-22 8:39 ` [PATCH v13 02/15] cxl: Share CXL port upstream PCI device lookup Srirangan Madhavan
2026-09-23 21:39 ` Cheatham, Benjamin
2026-09-24 1:21 ` Jonathan Cameron
2026-09-24 1:22 ` Jonathan Cameron
2026-09-22 8:39 ` [PATCH v13 03/15] cxl: Move HDM decoder programming helpers Srirangan Madhavan
2026-09-24 1:29 ` Jonathan Cameron
2026-09-22 8:39 ` [PATCH v13 04/15] cxl: Move decoder declarations to shared header Srirangan Madhavan
2026-09-24 1:31 ` Jonathan Cameron
2026-09-22 8:39 ` [PATCH v13 05/15] cxl: Introduce reusable HDM decoder settings Srirangan Madhavan
2026-09-23 21:39 ` Cheatham, Benjamin
2026-09-24 1:35 ` Jonathan Cameron
2026-09-24 2:45 ` Jonathan Cameron
2026-09-22 8:39 ` [PATCH v13 06/15] cxl: Make HDM reset helpers available to built-in PCI code Srirangan Madhavan
2026-09-23 21:40 ` Cheatham, Benjamin
2026-09-24 2:49 ` Jonathan Cameron
2026-09-22 8:39 ` [PATCH v13 07/15] cxl: Share HDM decoder register unpacking Srirangan Madhavan
2026-09-24 3:05 ` Jonathan Cameron
2026-09-22 8:39 ` [PATCH v13 08/15] cxl: Refresh cached PCI HDM decoder settings Srirangan Madhavan
2026-09-23 21:40 ` Cheatham, Benjamin
2026-09-24 3:08 ` Jonathan Cameron
2026-09-22 8:39 ` [PATCH v13 09/15] cxl: Cache endpoint HDM state during PCI enumeration Srirangan Madhavan
2026-09-23 21:40 ` Cheatham, Benjamin
2026-09-24 3:36 ` Jonathan Cameron
2026-09-22 8:39 ` [PATCH v13 10/15] cxl: Add CXL Device Reset sequencing Srirangan Madhavan
2026-09-23 21:40 ` Cheatham, Benjamin
2026-09-22 8:39 ` [PATCH v13 11/15] cxl: Validate and synchronize HDM ranges around reset Srirangan Madhavan
2026-09-23 21:40 ` Cheatham, Benjamin
2026-09-22 8:39 ` [PATCH v13 12/15] PCI/CXL: Reject reset with unsafe function scope Srirangan Madhavan
2026-09-23 21:41 ` Cheatham, Benjamin
2026-09-22 8:39 ` [PATCH v13 13/15] cxl: Restore CXL state after PCI reset Srirangan Madhavan
2026-09-24 3:50 ` Jonathan Cameron [this message]
2026-09-22 8:39 ` [PATCH v13 14/15] PCI/CXL: Expose CXL Reset as a PCI reset method Srirangan Madhavan
2026-09-22 8:39 ` [PATCH v13 15/15] PCI/CXL: Restore CXL state after CXL bus reset Srirangan Madhavan
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=20260924045010.3c1b299f@jic23-hlaptop \
--to=jic23@kernel.org \
--cc=alex.williamson@redhat.com \
--cc=alison.schofield@intel.com \
--cc=alwilliamson@nvidia.com \
--cc=bhelgaas@google.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=icheng@nvidia.com \
--cc=ira.weiny@intel.com \
--cc=jan@nvidia.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=mhonap@nvidia.com \
--cc=skancherla@nvidia.com \
--cc=smadhavan@nvidia.com \
--cc=vaslot@nvidia.com \
--cc=vishal.l.verma@intel.com \
--cc=vsethi@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
all inboxes | Powered by JetHome®