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 09/19] cxl: Refresh cached PCI HDM decoder settings
Date: Sat, 05 Dec 2026 04:38:43 +0000 [thread overview]
Message-ID: <sashiko-outbox-251092@kernel.org> (raw)
In-Reply-To: <20261205041453.3946529-10-smadhavan@nvidia.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] cxl: stale PCI HDM cache after
cxl_endpoint_decoder_clear_reset_flags()
- [Medium] cxl: stale emulated flag in devm_cxl_enumerate_decoders()
caches DVSEC state
- [Medium] cxl: TOCTOU race on cxled->skip in cxl_decoder_commit() cache
refresh
- [Low] cxl: unnecessary CXL export of cxl_hdm_check_decoder_count()
--
commit 4920baebe7a19ee7d660630b38e29f5630e4ed37
Author: Srirangan Madhavan <smadhavan@nvidia.com>
cxl: Refresh cached PCI HDM decoder settings
This commit adds the struct cxl_hdm_info cache to struct pci_dev under
CONFIG_CXL_RESET and refreshes cached endpoint decoder settings when
decoders are enumerated, committed, or reset.
> diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c
> index 1fabbd4a63a3f..f884181775824 100644
> --- a/drivers/cxl/core/hdm.c
> +++ b/drivers/cxl/core/hdm.c
[ ... ]
> @@ -830,6 +848,7 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld)
> }
> port->commit_end++;
> cxld->config.flags |= CXL_DECODER_F_ENABLE;
> + cxl_hdm_refresh_decoder(cxlhdm, cxld);
>
> return 0;
> }
[Severity: Medium]
Can cxl_hdm_refresh_decoder() cache a zeroed cxled->skip after hardware
committed a non-zero skip?
CPU0 CPU1
commit_store() -> __commit()
down_write(&cxl_rwsem.region)
cxl_decoder_commit()
down_read(&cxl_rwsem.dpa)
setup_hw_decoder() // skip != 0
up_read(&cxl_rwsem.dpa)
cxld_await_commit() // sleeps
device_unbind_cleanup(&port->dev)
cxl_dpa_release(cxled)
down_write(&cxl_rwsem.dpa)
cxled->skip = 0;
up_write(&cxl_rwsem.dpa)
cxld->config.flags |= ...ENABLE
cxl_hdm_refresh_decoder()
down_write(&cxl_rwsem.dpa)
settings->skip = cxled->skip <-- caches 0 while HW has skip != 0
cxl_dpa_alloc() registers cxl_dpa_release() on &port->dev after
cxl_decoder_autoremove() registers cxld_unregister(), so LIFO devres
teardown on port unbind runs cxl_dpa_release() first without holding
cxl_rwsem.region. If a PCI or CXL reset then restores from
pdev->hdm->settings[id] (or permanently if CXL_REGION_F_LOCK prevents
reset teardown), hardware is reprogrammed with skip = 0 instead of the
committed DPA offset.
Passing the snapshot captured under cxl_rwsem.dpa in setup_hw_decoder()
to the cache refresh helper would avoid re-reading a mutated cxled->skip.
> @@ -902,6 +921,7 @@ static void cxl_decoder_reset(struct cxl_decoder *cxld)
> writel(0, hdm + CXL_HDM_DECODER0_BASE_LOW_OFFSET(id));
>
> cxld->config.flags &= ~CXL_DECODER_F_ENABLE;
> + cxl_hdm_refresh_decoder(cxlhdm, cxld);
>
> /* Userspace is now responsible for reconfiguring this decoder */
> if (is_endpoint_decoder(&cxld->dev)) {
[Severity: Medium]
Does pdev->hdm->settings[id] stay stale when
cxl_endpoint_decoder_clear_reset_flags() clears CXL_DECODER_F_ENABLE?
When an SBR wipes active HDM decoders, cxl_reset_done() in
drivers/cxl/pci.c calls cxl_endpoint_decoder_clear_reset_flags(), which
clears CXL_DECODER_F_RESET_MASK (including CXL_DECODER_F_ENABLE) on
cxled->cxld.config.flags without refreshing pdev->hdm.
When the region is later torn down, cxl_decoder_reset() sees
CXL_DECODER_F_ENABLE already cleared and returns early before reaching
cxl_hdm_refresh_decoder(). The stale enabled decoder and HPA range
remain in pdev->hdm->settings[id], so a subsequent CXL or PCI reset can
try to reserve the old HPA range or reprogram a torn-down decoder.
> @@ -1121,6 +1141,8 @@ static int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm,
> {
> void __iomem *hdm = cxlhdm->regs.hdm_decoder;
> struct cxl_port *port = cxlhdm->port;
> + /* DVSEC-emulated decoders do not describe the cached HDM registers. */
> + bool emulated = should_emulate_decoders(info);
> u64 dpa_base = 0;
> int i, rc;
[ ... ]
> @@ -1182,6 +1210,8 @@ static int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm,
> put_device(&cxld->dev);
> return rc;
> }
> + if (!emulated)
> + cxl_hdm_refresh_decoder(cxlhdm, cxld);
> rc = add_hdm_decoder(port, cxld);
> if (rc) {
> dev_warn(&port->dev,
[Severity: Medium]
Can a concurrent PCI reset cause devm_cxl_enumerate_decoders() to write
DVSEC-emulated decoder state into pdev->hdm?
CPU0 CPU1
devm_cxl_enumerate_decoders()
emulated = should_emulate_decoders() // false (HDM enabled)
cxl_settle_decoders() // sleeps up to 20ms
pci_try_reset_bridge()
SBR clears HDM global ctrl to 0
init_hdm_decoder()
should_emulate_decoders() // now true
cxl_setup_hdm_decoder_from_dvsec()
cxld->config.flags |= ENABLE | LOCK
if (!emulated) // still false
cxl_hdm_refresh_decoder() <-- caches DVSEC range & LOCK in pdev->hdm
devm_cxl_enumerate_decoders() does not hold device_lock(&pdev->dev) or
cxl_rwsem.region, and init_hdm_decoder() re-evaluates
should_emulate_decoders(info) on each decoder after cxl_settle_decoders().
If a reset clears CXL_HDM_DECODER_ENABLE in between, init_hdm_decoder()
falls back to cxl_setup_hdm_decoder_from_dvsec(), while the stale
emulated == false still lets cxl_hdm_refresh_decoder() record the
DVSEC-emulated range, CXL_DECODER_F_LOCK, and zeroed global_ctrl into
pdev->hdm.
Passing emulated into init_hdm_decoder() (or gating the refresh on
whether init_hdm_decoder() actually initialized a hardware decoder)
would avoid this mismatch.
> diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c
> index 63dc3f39b5d80..d0da38763b4bc 100644
> --- a/drivers/cxl/core/pci.c
> +++ b/drivers/cxl/core/pci.c
[ ... ]
> +int cxl_hdm_check_decoder_count(struct cxl_hdm *cxlhdm)
> +{
> + struct pci_dev *pdev __free(pci_dev_put) =
> + cxl_port_get_uport_pci_dev(cxlhdm->port);
> +
> + if (!pdev)
> + return 0;
> +
> + if (!cxl_hdm_cache_decoder_count_match(pdev, cxlhdm->decoder_count))
> + return -ENXIO;
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_NS_GPL(cxl_hdm_check_decoder_count, "CXL");
[Severity: Low]
Does cxl_hdm_check_decoder_count() need to be exported? Its declaration
lives only in the cxl_core-private drivers/cxl/core/core.h and its only
caller is devm_cxl_enumerate_decoders() in drivers/cxl/core/hdm.c, which
is linked into the same module. Dropping the export (or making it a
static helper alongside cxl_hdm_refresh_decoder() in
drivers/cxl/core/hdm.c) avoids widening the CXL module ABI unnecessarily.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205041453.3946529-1-smadhavan@nvidia.com?part=9
next prev parent reply other threads:[~2026-12-05 4:38 UTC|newest]
Thread overview: 32+ 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 [this message]
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
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:50 ` sashiko-bot
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:48 ` sashiko-bot
2026-12-05 4:14 ` [PATCH v18 17/19] PCI/CXL: Restore CXL state after CXL bus reset Srirangan Madhavan
2026-12-05 4:47 ` sashiko-bot
2026-12-05 4:14 ` [PATCH v18 18/19] PCI/CXL: Flush host and device caches for " Srirangan Madhavan
2026-12-05 4:54 ` sashiko-bot
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-251092@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