Linux CXL
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: Alison Schofield <alison.schofield@intel.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Jonathan Cameron <jonathan.cameron@huawei.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Ira Weiny <ira.weiny@intel.com>,
	Dan Williams <dan.j.williams@intel.com>
Cc: linux-cxl@vger.kernel.org
Subject: Re: [PATCH v4 2/2] cxl/region: Translate HPA to DPA and memdev in unaligned regions
Date: Tue, 13 Jan 2026 17:24:26 -0700	[thread overview]
Message-ID: <720020ac-b35c-4331-8434-457d170e4c68@intel.com> (raw)
In-Reply-To: <0d7d47672e81d0c4d9a4e5e335ca536dbecb9dee.1768008522.git.alison.schofield@intel.com>



On 1/9/26 6:54 PM, Alison Schofield wrote:
> The CXL driver supports an expert user debugfs interface to inject and
> clear poison by a region offset. That feature requires translating a
> HPA (the region address) to a DPA and a memdev to perform the poison
> operation.
> 
> Unaligned regions do not have an algebraically invertible mapping
> from HPA to DPA due to the region offset skew. The region base is not
> aligned to a full interleave. Add a helper to perform the unaligned
> translations that first calculates the DPA offset and then tests it
> against each candidate endpoint decoder.
> 
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>

> ---
>  drivers/cxl/core/region.c | 46 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 146ae9e42496..f63fc15ba0c1 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -3307,6 +3307,48 @@ struct dpa_result {
>  	u64 dpa;
>  };
>  
> +static int unaligned_region_offset_to_dpa_result(struct cxl_region *cxlr,
> +						 u64 offset,
> +						 struct dpa_result *result)
> +{
> +	struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent);
> +	struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld;
> +	struct cxl_region_params *p = &cxlr->params;
> +	u64 interleave_width, interleave_index;
> +	u64 gran, gran_offset, dpa_offset;
> +	u64 hpa = p->res->start + offset;
> +
> +	/*
> +	 * Unaligned addresses are not algebraically invertible. Calculate
> +	 * a dpa_offset independent of the target device and then enumerate
> +	 * and test that dpa_offset against each candidate endpoint decoder.
> +	 */
> +	gran = cxld->interleave_granularity;
> +	interleave_width = gran * cxld->interleave_ways;
> +	interleave_index = offset / interleave_width;
> +	gran_offset = offset % gran;
> +
> +	dpa_offset = interleave_index * gran + gran_offset;
> +
> +	for (int i = 0; i < p->nr_targets; i++) {
> +		struct cxl_endpoint_decoder *cxled = p->targets[i];
> +		int pos = cxled->pos;
> +		u64 test_hpa;
> +
> +		test_hpa = unaligned_dpa_to_hpa(cxld, p, pos, dpa_offset);
> +		if (test_hpa == hpa) {
> +			result->cxlmd = cxled_to_memdev(cxled);
> +			result->dpa =
> +				cxl_dpa_resource_start(cxled) + dpa_offset;
> +			return 0;
> +		}
> +	}
> +	dev_err(&cxlr->dev,
> +		"failed to resolve HPA %#llx in unaligned MOD3 region\n", hpa);
> +
> +	return -ENXIO;
> +}
> +
>  static int region_offset_to_dpa_result(struct cxl_region *cxlr, u64 offset,
>  				       struct dpa_result *result)
>  {
> @@ -3336,6 +3378,10 @@ static int region_offset_to_dpa_result(struct cxl_region *cxlr, u64 offset,
>  		hpa_offset = offset;
>  	}
>  
> +	if (region_is_unaligned_mod3(cxlr))
> +		return unaligned_region_offset_to_dpa_result(cxlr, offset,
> +							     result);
> +
>  	pos = cxl_calculate_position(hpa_offset, eiw, eig);
>  	if (pos < 0 || pos >= p->nr_targets) {
>  		dev_dbg(&cxlr->dev, "Invalid position %d for %d targets\n",


  reply	other threads:[~2026-01-14  0:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-10  1:54 [PATCH v4 0/2] cxl/region: Support unaligned address translations Alison Schofield
2026-01-10  1:54 ` [PATCH v4 1/2] cxl/region: Translate DPA->HPA in unaligned MOD3 regions Alison Schofield
2026-01-14  0:24   ` Dave Jiang
2026-01-10  1:54 ` [PATCH v4 2/2] cxl/region: Translate HPA to DPA and memdev in unaligned regions Alison Schofield
2026-01-14  0:24   ` Dave Jiang [this message]
2026-01-15 17:30   ` Jonathan Cameron

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=720020ac-b35c-4331-8434-457d170e4c68@intel.com \
    --to=dave.jiang@intel.com \
    --cc=alison.schofield@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave@stgolabs.net \
    --cc=ira.weiny@intel.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-cxl@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox