From: sashiko-bot@kernel.org
To: "Srirangan Madhavan" <smadhavan@nvidia.com>
Cc: linux-pci@vger.kernel.org, linux-cxl@vger.kernel.org
Subject: Re: [PATCH v9 08/11] cxl: Restore CXL HDM state after PCI reset
Date: Thu, 09 Jul 2026 01:17:16 +0000 [thread overview]
Message-ID: <20260709011717.0B8A71F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260709010304.680422-9-smadhavan@nvidia.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Hardware PCI BARs are not restored before attempting HDM MMIO access post-reset, causing the restore to fail silently or trigger bus errors.
- [Medium] Mixing `goto`-based error handling with scope-based cleanups (`__free()` and `scoped_guard()`) in the same function.
--
--- Patch [8]: [PATCH v9 08/11] cxl: Restore CXL HDM state after PCI reset ---
commit a1cce28cbb5bb68a25127de7ce247a2950193943
Author: Srirangan Madhavan <smadhavan@nvidia.com>
cxl: Restore CXL HDM state after PCI reset
After CXL reset, restore PCI config state enough to reach HDM MMIO,
restore cached global and per-decoder HDM state, and then run the normal
PCI restore callbacks.
> diff --git a/drivers/cxl/core/reset.c b/drivers/cxl/core/reset.c
> --- a/drivers/cxl/core/reset.c
> +++ b/drivers/cxl/core/reset.c
> @@ -455,6 +531,164 @@ void pci_cxl_hdm_init(struct pci_dev *pdev)
[ ... ]
> +static int cxl_restore_hdm(struct pci_dev *pdev)
> +{
> + struct cxl_hdm_decoder_state *decoder_state __free(kfree) = NULL;
> + struct cxl_decoder_settings *settings __free(kfree) = NULL;
[ ... ]
> + hdm = cxl_pci_hdm_ioremap_current(pdev, hdm_bar, hdm_offset, hdm_size);
> + if (IS_ERR(hdm)) {
> + first_rc = PTR_ERR(hdm);
> + goto out_restore_command;
> + }
[Severity: Medium]
Is it safe to mix goto-based error handling with scope-based cleanups
like __free() in this function?
The kernel cleanup guidelines suggest converting all resources that need a
goto cleanup to scope-based cleanup, or converting none of them, because
mixing them creates confusing ownership semantics.
> +
> + /*
> + * Restore global HDM control before per-decoder commit. PCI config
> + * memory decoding is enabled for MMIO access, but IOMMU reset blocks
> + * remain active until HDM restore completes.
> + */
> + writel(global_ctrl, hdm + CXL_HDM_DECODER_CTRL_OFFSET);
[Severity: High]
Will this MMIO access fail or trigger bus errors?
The CXL reset clears the device's PCI configuration space, which sets the
hardware BARs to 0. Although cxl_hdm_enable_mem() sets the
PCI_COMMAND_MEMORY bit earlier in this function, it doesn't appear to write
the physical address back into the hardware BARs before we attempt to access
the MMIO region here.
[ ... ]
> int cxl_reset_function(struct pci_dev *pdev, bool probe)
> {
[ ... ]
> cxl_hdm_range_context_init(&range_ctx);
>
> + if (!cxl_reset_scope_hdm_available(&ctx)) {
> + rc = -ENOTTY;
> + goto out;
> + }
> +
> + rc = cxl_pci_target_reset_prepare(&ctx);
> + if (rc)
> + goto out;
> +
> scoped_guard(rwsem_write, &cxl_rwsem.region) {
[Severity: Medium]
Could we also avoid mixing the legacy goto error paths with the
scoped_guard() block in this function?
> - rc = cxl_hdm_ranges_prepare(&range_ctx, pdev);
> + rc = cxl_hdm_ranges_prepare(&range_ctx, &ctx);
> if (!rc)
> rc = cxl_reset_execute(pdev, dvsec);
> + if (!rc)
> + rc = cxl_restore_hdm_decoders(&ctx);
> }
> +
> + cxl_pci_target_reset_done(&ctx);
> +out:
> cxl_hdm_range_context_destroy(&range_ctx);
> return rc;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260709010304.680422-1-smadhavan@nvidia.com?part=8
next prev parent reply other threads:[~2026-07-09 1:17 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 1:02 [PATCH v9 00/11] PCI/CXL: Add CXL reset support for Type 2 devices Srirangan Madhavan
2026-07-09 1:02 ` [PATCH v9 01/11] cxl: Split decoder programming into a reusable helper Srirangan Madhavan
2026-07-09 1:14 ` sashiko-bot
2026-07-09 1:02 ` [PATCH v9 02/11] cxl: Cache decoder settings on PCI devices Srirangan Madhavan
2026-07-09 1:16 ` sashiko-bot
2026-07-09 1:02 ` [PATCH v9 03/11] cxl: Share HDM decoder decode logic Srirangan Madhavan
2026-07-09 1:18 ` sashiko-bot
2026-07-09 1:02 ` [PATCH v9 04/11] cxl: Cache endpoint decoder settings during PCI enumeration Srirangan Madhavan
2026-07-09 1:17 ` sashiko-bot
2026-07-09 3:30 ` Alison Schofield
2026-07-10 0:48 ` Dan Williams (nvidia)
2026-07-09 1:02 ` [PATCH v9 05/11] cxl: Add CXL Device Reset helper Srirangan Madhavan
2026-07-09 1:15 ` sashiko-bot
2026-07-09 1:02 ` [PATCH v9 06/11] cxl: Validate HDM ranges before CXL reset Srirangan Madhavan
2026-07-09 1:28 ` sashiko-bot
2026-07-09 1:03 ` [PATCH v9 07/11] PCI/CXL: Discover the CXL reset scope Srirangan Madhavan
2026-07-09 1:24 ` sashiko-bot
2026-07-10 1:00 ` Dan Williams (nvidia)
2026-07-09 1:03 ` [PATCH v9 08/11] cxl: Restore CXL HDM state after PCI reset Srirangan Madhavan
2026-07-09 1:17 ` sashiko-bot [this message]
2026-07-09 1:03 ` [PATCH v9 09/11] PCI/CXL: Expose CXL Reset as a PCI reset method Srirangan Madhavan
2026-07-09 1:27 ` sashiko-bot
2026-07-09 1:03 ` [PATCH v9 10/11] Documentation/ABI: Document CXL Reset " Srirangan Madhavan
2026-07-09 1:05 ` sashiko-bot
2026-07-09 1:03 ` [PATCH v9 11/11] PCI/CXL: Restore HDM state after CXL bus reset Srirangan Madhavan
2026-07-09 1:20 ` 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=20260709011717.0B8A71F000E9@smtp.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