From: Richard Cheng <icheng@nvidia.com>
To: Alison Schofield <alison.schofield@intel.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>,
Jonathan Cameron <jic23@kernel.org>,
Dave Jiang <dave.jiang@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Ira Weiny <iweiny@kernel.org>, Dan Williams <djbw@kernel.org>,
Li Ming <ming.li@zohomail.com>,
linux-cxl@vger.kernel.org,
Srirangan Madhavan <smadhavan@nvidia.com>
Subject: Re: [PATCH v2 1/3] cxl/hdm: Reject switch decoder interleave ways that overflow targets
Date: Thu, 16 Jul 2026 16:49:35 +0800 [thread overview]
Message-ID: <aliaSasHogM2go8g@MWDK4CY14F> (raw)
In-Reply-To: <0d7618c36e20bfda585699f8641d62928b23f6d5.1784150131.git.alison.schofield@intel.com>
On Wed, Jul 15, 2026 at 02:45:47PM +0800, Alison Schofield wrote:
> Switch decoder enumeration validates that the interleave ways encoding
> is legal, but not that the resulting number of ways fits the available
> targets. This can overrun the target arrays during enumeration.
>
> Reject committed decoders whose interleave ways exceed either the
> hardware target list capacity or the reported target count. Reject
> switch decoders that report zero targets.
>
> For uncommitted decoders, ignore the stale interleave ways value and
> reset it to one until the decoder is committed.
>
> Add a clarifying comment that target_count is a direct count, not
> 0-based like decoder_count.
>
> Link: https://sashiko.dev/#/patchset/20260711180755.1779002-1-alison.schofield@intel.com?part=1
> Fixes: d17d0540a0db ("cxl/core/hdm: Add CXL standard decoder enumeration to the core")
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
> ---
> drivers/cxl/core/hdm.c | 26 ++++++++++++++++++++++++++
> drivers/cxl/core/port.c | 2 +-
> drivers/cxl/cxl.h | 2 ++
> 3 files changed, 29 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c
> index 0c80b76a5f9b..9f005f3193e2 100644
> --- a/drivers/cxl/core/hdm.c
> +++ b/drivers/cxl/core/hdm.c
> @@ -76,6 +76,8 @@ static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm)
>
> hdm_cap = readl(cxlhdm->regs.hdm_decoder + CXL_HDM_DECODER_CAP_OFFSET);
> cxlhdm->decoder_count = cxl_hdm_decoder_count(hdm_cap);
> +
> + /* target_count is a direct count (1h..8h), not 0-based like decoder_count */
> cxlhdm->target_count =
> FIELD_GET(CXL_HDM_DECODER_TARGET_COUNT_MASK, hdm_cap);
> if (FIELD_GET(CXL_HDM_DECODER_INTERLEAVE_11_8, hdm_cap))
> @@ -1084,6 +1086,30 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld,
> cxld->interleave_ways, cxld->interleave_granularity);
>
> if (!cxled) {
> + struct cxl_switch_decoder *cxlsd =
> + to_cxl_switch_decoder(&cxld->dev);
> +
> + if (!committed) {
> + /* Ignore interleave ways until commit */
> + cxld->interleave_ways = 1;
> + return 0;
> + }
> +
> + if (cxld->interleave_ways > CXL_HDM_DECODER0_TL_TARGETS) {
> + dev_err(&port->dev,
> + "decoder%d.%d: interleave ways: %d exceeds target list capacity: %d\n",
> + port->id, cxld->id, cxld->interleave_ways,
> + CXL_HDM_DECODER0_TL_TARGETS);
> + return -ENXIO;
> + }
> + if (cxld->interleave_ways > cxlsd->nr_targets) {
> + dev_err(&port->dev,
> + "decoder%d.%d: interleave ways: %d exceeds targets: %d\n",
> + port->id, cxld->id, cxld->interleave_ways,
> + cxlsd->nr_targets);
> + return -ENXIO;
> + }
> +
> lo = readl(hdm + CXL_HDM_DECODER0_TL_LOW(which));
> hi = readl(hdm + CXL_HDM_DECODER0_TL_HIGH(which));
> target_list.value = (hi << 32) + lo;
> diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
> index 1215ee4f4035..28eccfdd75b8 100644
> --- a/drivers/cxl/core/port.c
> +++ b/drivers/cxl/core/port.c
> @@ -1979,7 +1979,7 @@ static int cxl_switch_decoder_init(struct cxl_port *port,
> struct cxl_switch_decoder *cxlsd,
> int nr_targets)
> {
> - if (nr_targets > CXL_DECODER_MAX_INTERLEAVE)
> + if (nr_targets < 1 || nr_targets > CXL_DECODER_MAX_INTERLEAVE)
This contradict to what the comment claims.
The comment says that Target Count is a direct cound with 1h to 8h. However,
this check uses CXL_DECODER_MAX_INTERLEAVE, which is 16.
I think since the capability field is 4 bits wide, values 9 to 15 are still
acceptable.
I'm confused by this part, it looks inconsistent, refusing enumeration above 9
doesn't make sense to me either.
Maybe some explanation to explain why ?
Best regards,
Richard Cheng.
> return -EINVAL;
>
> cxlsd->nr_targets = nr_targets;
> diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
> index c0e5308e4d1b..291ada46b646 100644
> --- a/drivers/cxl/cxl.h
> +++ b/drivers/cxl/cxl.h
> @@ -67,6 +67,8 @@ extern const struct nvdimm_security_ops *cxl_security_ops;
> #define CXL_HDM_DECODER0_CTRL_HOSTONLY BIT(12)
> #define CXL_HDM_DECODER0_TL_LOW(i) (0x20 * (i) + 0x24)
> #define CXL_HDM_DECODER0_TL_HIGH(i) (0x20 * (i) + 0x28)
> +/* Two registers with one target ID per byte */
> +#define CXL_HDM_DECODER0_TL_TARGETS 8
> #define CXL_HDM_DECODER0_SKIP_LOW(i) CXL_HDM_DECODER0_TL_LOW(i)
> #define CXL_HDM_DECODER0_SKIP_HIGH(i) CXL_HDM_DECODER0_TL_HIGH(i)
>
> --
> 2.37.3
>
>
next prev parent reply other threads:[~2026-07-16 8:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 21:45 [PATCH v2 0/3] Harden HDM decoder enumeration Alison Schofield
2026-07-15 21:45 ` [PATCH v2 1/3] cxl/hdm: Reject switch decoder interleave ways that overflow targets Alison Schofield
2026-07-15 22:04 ` sashiko-bot
2026-07-16 8:49 ` Richard Cheng [this message]
2026-07-15 21:45 ` [PATCH v2 2/3] cxl/hdm: Make switch decoder target parsing endian-safe Alison Schofield
2026-07-16 8:45 ` Richard Cheng
2026-07-15 21:45 ` [PATCH v2 3/3] cxl/hdm: Restore commit_end when decoder enumeration fails Alison Schofield
2026-07-15 21:57 ` sashiko-bot
2026-07-16 8:41 ` Richard Cheng
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=aliaSasHogM2go8g@MWDK4CY14F \
--to=icheng@nvidia.com \
--cc=alison.schofield@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=djbw@kernel.org \
--cc=iweiny@kernel.org \
--cc=jic23@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=ming.li@zohomail.com \
--cc=smadhavan@nvidia.com \
--cc=vishal.l.verma@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.