From: Dan Williams <dan.j.williams@intel.com>
To: Yao Xingtao <yaoxt.fnst@fujitsu.com>, <dave@stgolabs.net>,
<jonathan.cameron@huawei.com>, <dave.jiang@intel.com>,
<alison.schofield@intel.com>, <vishal.l.verma@intel.com>,
<ira.weiny@intel.com>, <dan.j.williams@intel.com>,
<jim.harris@samsung.com>
Cc: <linux-cxl@vger.kernel.org>, Yao Xingtao <yaoxt.fnst@fujitsu.com>
Subject: RE: [PATCH v4 2/2] cxl/region: check interleave capability
Date: Mon, 22 Apr 2024 17:59:22 -0700 [thread overview]
Message-ID: <662707ea3fb4_6910294cf@dwillia2-xfh.jf.intel.com.notmuch> (raw)
In-Reply-To: <20240422091350.4701-3-yaoxt.fnst@fujitsu.com>
Yao Xingtao wrote:
> Since interleave capability is not verified, a target can successfully
> attach to a region even if it lacks support for the specified interleave
> ways or granularity.
>
> When attempting to access memory, unexpected behavior occurs due to the
> incorrect conversion of HPA to a faulty DPA, leading to a segmentation
> fault, as observed when executing the command:
> $ numactl -m 2 ls
This is a QEMU specific statement, right?
That should be called out, because I suspect the behavior on hardware to
be different.
> According to the CXL specification (section 8.2.4.20 CXL HDM Decoder
> Capability Structure), bits 11 and 12 within the 'CXL HDM Decoder
> Capability Register' indicate the capability to establish interleaving
> in 3, 6, 12, and 16 ways. If these bits are not set, the target cannot
> be attached to a region utilizing such interleave ways.
>
> Additionally, bits 8 and 9 in the same register represent the capability
> of the bits used for interleaving in the address, commonly referred to as
> the interleave mask.
Perhaps replace "commonly referred to as" with "Linux tracks this in the
cxl_port interleave_mask"
> Regarding 'Decoder Protection':
> If IW is less than 8 (for interleave ways of 1, 2, 4, 8, 16), the
> interleave bits start at bit position IG + 8 and end at IG + IW + 8 - 1.
>
> If the IW is greater than or equal to 8 (for interleave ways of 3, 6, 12),
> the interleave bits start at bit position IG + 8 and end at IG + IW - 1.
>
> If the interleave mask is insufficient to cover the required interleave
> bits, the target cannot be attached to the region.
>
> The above check does not apply to the host-bridges with single port and
> switches with single dport, because there does not have a instance of
> CXL HDM Decoder Capability Structure for them.
>
> Fixes: 384e624bb211 ("cxl/region: Attach endpoint decoders")
> Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com>
> ---
> drivers/cxl/core/hdm.c | 5 +++
> drivers/cxl/core/region.c | 70 +++++++++++++++++++++++++++++++++++++++
> drivers/cxl/cxl.h | 2 ++
> drivers/cxl/cxlmem.h | 1 +
> 4 files changed, 78 insertions(+)
>
> diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c
> index 27fb4f9d489e..b201be4b8d76 100644
> --- a/drivers/cxl/core/hdm.c
> +++ b/drivers/cxl/core/hdm.c
> @@ -80,6 +80,11 @@ static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm)
> cxlhdm->interleave_mask |= GENMASK(11, 8);
> if (FIELD_GET(CXL_HDM_DECODER_INTERLEAVE_14_12, hdm_cap))
> cxlhdm->interleave_mask |= GENMASK(14, 12);
> + cxlhdm->iw_cap_mask = BIT(1) | BIT(2) | BIT(4) | BIT(8);
> + if (FIELD_GET(CXL_HDM_DECODER_INTERLEAVE_3_6_12_WAY, hdm_cap))
> + cxlhdm->iw_cap_mask |= BIT(3) | BIT(6) | BIT(12);
> + if (FIELD_GET(CXL_HDM_DECODER_INTERLEAVE_16_WAY, hdm_cap))
> + cxlhdm->iw_cap_mask |= BIT(16);
> }
>
> static bool should_emulate_decoders(struct cxl_endpoint_dvsec_info *info)
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 5c186e0a39b9..5c09652136c9 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -1210,6 +1210,60 @@ static int check_last_peer(struct cxl_endpoint_decoder *cxled,
> return 0;
> }
>
> +static int check_interleave_cap(struct cxl_decoder *cxld, int iw, int ig)
> +{
> + struct cxl_port *port = to_cxl_port(cxld->dev.parent);
> + struct cxl_hdm *cxlhdm = dev_get_drvdata(&port->dev);
> + struct cxl_switch_decoder *cxlsd;
> + unsigned int interleave_mask;
> + u8 eiw;
> + u16 eig;
> + int rc, high_pos, low_pos;
> +
> + if (is_switch_decoder(&cxld->dev)) {
> + cxlsd = to_cxl_switch_decoder(&cxld->dev);
> + if (cxlsd->passthrough)
> + return 0;
> + }
> +
> + rc = ways_to_eiw(iw, &eiw);
> + if (rc)
> + return rc;
> +
> + if (!(cxlhdm->iw_cap_mask & BIT(iw)))
Would be nice to just write this as:
if (!test_bit(iw, &cxlhdm->iw_cap_mask))
...requires making iw_cap_mask an 'unsigned long', but that's worth it
to me.
> + return -EOPNOTSUPP;
This should be -ENXIO like all the other hardware mismatch /
misconfiguration errors in cxl_region_attach().
> +
> + rc = granularity_to_eig(ig, &eig);
> + if (rc)
> + return rc;
> +
> + /*
> + * Per CXL specification (8.2.3.20.13 Decoder Protection in r3.1)
> + * if IW < 8, the interleave bits start at bit position IG + 8, and
> + * end at IG + IW + 8 - 1.
> + * if IW >= 8, the interleave bits start at bit position IG + 8, and
> + * end at IG + IW - 1.
> + */
> + if (eiw >= 8)
> + high_pos = eiw + eig - 1;
> + else
> + high_pos = eiw + eig + 7;
> + low_pos = eig + 8;
> + /*
> + * when the IW is 0 or 8 (interlave way is 1 or 3), the low_pos is
> + * larger than high_pos, since the target is in the target list of a
> + * passthrough decoder, the following check is ignored.
> + */
> + if (low_pos > high_pos)
> + return 0;
> +
> + interleave_mask = GENMASK(high_pos, low_pos);
> + if (interleave_mask & ~cxlhdm->interleave_mask)
> + return -EOPNOTSUPP;
> +
> + return 0;
> +}
> +
> static int cxl_port_setup_targets(struct cxl_port *port,
> struct cxl_region *cxlr,
> struct cxl_endpoint_decoder *cxled)
> @@ -1360,6 +1414,14 @@ static int cxl_port_setup_targets(struct cxl_port *port,
> return -ENXIO;
> }
> } else {
> + rc = check_interleave_cap(cxld, iw, ig);
This seems too late to be doing the check. check_interleave_cap() only
needs to operate on all the 'struct cxl_port' instances between the
endpoint and the root. That check can be done be walking ports at
cxl_region_attach() time, no need to wait until switch decoders are
being allocated.
next prev parent reply other threads:[~2024-04-23 0:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-22 9:13 [PATCH v4 0/2] cxl/region: add interleave capability check Yao Xingtao
2024-04-22 9:13 ` [PATCH v4 1/2] cxl/core: add passthrough flag to struct cxl_switch_decoder Yao Xingtao
2024-04-22 11:12 ` Jonathan Cameron
2024-04-22 23:56 ` Xingtao Yao (Fujitsu)
2024-04-23 0:37 ` Dan Williams
2024-04-22 9:13 ` [PATCH v4 2/2] cxl/region: check interleave capability Yao Xingtao
2024-04-22 11:17 ` Jonathan Cameron
2024-04-23 0:02 ` Xingtao Yao (Fujitsu)
2024-04-23 0:59 ` Dan Williams [this message]
2024-04-23 2:47 ` Xingtao Yao (Fujitsu)
2024-05-12 23:43 ` Xingtao Yao (Fujitsu)
2024-05-23 9:05 ` Xingtao Yao (Fujitsu)
2024-05-23 18:47 ` Dan Williams
2024-05-24 9:15 ` Xingtao Yao (Fujitsu)
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=662707ea3fb4_6910294cf@dwillia2-xfh.jf.intel.com.notmuch \
--to=dan.j.williams@intel.com \
--cc=alison.schofield@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=ira.weiny@intel.com \
--cc=jim.harris@samsung.com \
--cc=jonathan.cameron@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--cc=vishal.l.verma@intel.com \
--cc=yaoxt.fnst@fujitsu.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