From: Jonathan Cameron <jonathan.cameron@huawei.com>
Cc: Alison Schofield <alison.schofield@intel.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Dave Jiang <dave.jiang@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
Dan Williams <dan.j.williams@intel.com>,
<linux-cxl@vger.kernel.org>, Qing Huang <qing.huang@intel.com>
Subject: Re: [PATCH] cxl/region: Translate DPA->HPA in unaligned MOD3 regions
Date: Wed, 1 Oct 2025 15:44:02 +0100 [thread overview]
Message-ID: <20251001154402.00006f3e@huawei.com> (raw)
In-Reply-To: <20250930040838.353229-1-alison.schofield@intel.com>
On Mon, 29 Sep 2025 21:08:36 -0700
Alison Schofield <alison.schofield@intel.com> wrote:
> The CXL driver implementation of DPA->HPA address translation depends
> on a region's starting address always being aligned to Host Bridge
> Interleave Ways * 256MB. The driver follows the decode methods
> defined in the CXL Spec[1] and expanded upon in the CXL Driver Writers
> Guide[2], which describe bit manipulations based on power-of-2
> alignment to translate a DPA to an HPA.
>
> With the introduction of MOD3 interleave way support, platforms may
> create regions at starting addresses that are not power-of-2 aligned.
> This allows platforms to avoid gaps in the memory map, but addresses
> within those regions cannot be translated using the existing bit
> manipulation method.
>
> Introduce an unaligned translation method for DPA->HPA that
> reconstructs an HPA by restoring the address first at the port level
> and then at the host bridge level.
>
> [1] CXL Spec 3.2 8.2.4.20.13 Implementation Note Device Decoder Logic
> [2] CXL Type 3 Memory Software Guide 1.1 2.13.25 DPA to HPA Translation
>
> Suggested-by: Qing Huang <qing.huang@intel.com>
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
Hi Alison,
My 'favourite' headache inducer in the spec. Anyhow, questions on the comments
inline.
J
> ---
>
> Changes in v1 (was RFC):
> - Replace "/" with do_div() to quiet i386 build warning (lkp)
> - Replace 'cxld->interleave_ways' with 'hbiw' for clarity
> - Use div64_u64_rem() for alignment alignment
> - Fix up a printk format specifier (lkp)
> - Update code comments and commit log
> - Rebase on v717-rc7
>
> drivers/cxl/core/region.c | 125 ++++++++++++++++++++++++++++++++++++--
> 1 file changed, 119 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 71cc42d05248..4fc0d1450c2c 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -2918,13 +2918,115 @@ static bool cxl_is_hpa_in_chunk(u64 hpa, struct cxl_region *cxlr, int pos)
> return false;
> }
>
> +static int decode_pos(int region_ways, int pos, int *pos_port, int *pos_hb)
> +{
> + switch (region_ways) {
> + /*
> + * Extract the port and hb positions from an endpoint position.
> + * Knowing there is only one possible decode** for each of these
> + * regions, decode logic is:
> + * 3-way: port always 0, hb is pos
> + * 6-way: port cycles thru 0,1, hb increments every 2
Why is 6 host bridge option not relevant?
> + * 12-way: port cycles thru 0,1,2,3, hb increments every 4
Why is 6 host bridge option, cycle every 2 or indeed 12 host bridge option
not relevant?
> + *
> + * **CXL Spec 3.2 9.13.1.1 Legal Interleaving Configurations
> + */
> + case 3:
> + *pos_port = 0;
> + *pos_hb = pos;
> + break;
> + case 6:
> + *pos_port = pos % 2;
> + *pos_hb = pos / 2;
> + break;
> + case 12:
> + *pos_port = pos % 4;
> + *pos_hb = pos / 4;
> + break;
> + default:
> + return -EINVAL;
> + }
> + return 0;
> +}
...
next prev parent reply other threads:[~2025-10-01 14:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-30 4:08 [PATCH] cxl/region: Translate DPA->HPA in unaligned MOD3 regions Alison Schofield
2025-10-01 14:44 ` Jonathan Cameron [this message]
2025-10-02 2:01 ` Alison Schofield
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=20251001154402.00006f3e@huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=ira.weiny@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=qing.huang@intel.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.