From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: <alison.schofield@intel.com>
Cc: 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>
Subject: Re: [PATCH v2 2/4] cxl/acpi: Restore XOR'd position bits during address translation
Date: Fri, 7 Jun 2024 16:01:14 +0100 [thread overview]
Message-ID: <20240607160114.00006e4d@Huawei.com> (raw)
In-Reply-To: <77d251960a557f23aa6e6e0465e0e42f1d461514.1715192606.git.alison.schofield@intel.com>
On Wed, 8 May 2024 11:47:51 -0700
alison.schofield@intel.com wrote:
> From: Alison Schofield <alison.schofield@intel.com>
>
> When a CXL region is created in a CXL Window (CFMWS) that uses XOR
> interleave arithmetic XOR maps are applied during the HPA->DPA
> translation. The XOR function changes the interleave selector
> bit (aka position bit) in the HPA thereby varying which host bridge
> services an HPA. The purpose is to minimize hot spots thereby
> improving performance.
>
> When a device reports a DPA in events such as poison, general_media,
> and dram, the driver translates that DPA back to an HPA. Presently,
> the CXL driver translation only considers the modulo position and
> will report the wrong HPA for XOR configured CFMWS's.
>
> Add a helper function that restores the XOR'd bits during DPA->HPA
> address translation. Plumb a root decoder callback to the new helper
> when XOR interleave arithmetic is in use. For MODULO arithmetic, just
> let the callback be NULL - as in no extra work required.
>
> Fixes: 28a3ae4ff66c ("cxl/trace: Add an HPA to cxl_poison trace events")
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
Trivial comment inline. Agree entirely that some tests would be good.
I ran through a few trivial cases on a bit of paper and it looks to
me like it works but that hardly counts as testing :)
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> drivers/cxl/acpi.c | 48 ++++++++++++++++++++++++++++++++++++---
> drivers/cxl/core/port.c | 5 +++-
> drivers/cxl/core/region.c | 5 ++++
> drivers/cxl/cxl.h | 6 ++++-
> 4 files changed, 59 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c
> index 571069863c62..20488e7b09ac 100644
> --- a/drivers/cxl/acpi.c
> +++ b/drivers/cxl/acpi.c
> @@ -74,6 +74,43 @@ static struct cxl_dport *cxl_hb_xor(struct cxl_root_decoder *cxlrd, int pos)
> return cxlrd->cxlsd.target[n];
> }
>
> +static u64 cxl_xor_translate(struct cxl_root_decoder *cxlrd, u64 hpa)
> +{
> + struct cxl_cxims_data *cximsd = cxlrd->platform_data;
> + int hbiw = cxlrd->cxlsd.nr_targets;
> + u64 val;
> + int pos;
> +
> + /* No xormaps for host bridge interleave ways of 1 or 3 */
> + if (hbiw == 1 || hbiw == 3)
> + return hpa;
> +
> + /*
> + * For root decoders using xormaps (hbiw: 2,4,6,8,12,16) restore
> + * the position bit to its value before the xormap was applied at
> + * HPA->DPA translation.
> + *
> + * pos is the lowest set bit in an XORMAP
> + * val is the XORALLBITS(HPA & XORMAP)
> + *
> + * XORALLBITS: The CXL spec (3.1 Table 9-22) defines XORALLBITS
> + * as an operation that outputs a single bit by XORing all the
> + * bits in the input (hpa & xormap). Implement XORALLBITS using
> + * hweight64(). If the hamming weight is even the XOR of those
> + * bits results in 0, if odd the XOR result is 1.
> + */
> +
> + for (int i = 0; i < cximsd->nr_maps; i++) {
> + if (!cximsd->xormaps[i])
> + continue;
> + pos = __ffs(cximsd->xormaps[i]);
At the moment the comment on XORALLBITS isn't associated with this
code very well. I'd factor it out as cxl_xorallbits() mostly so
you can stick the comment next to the bit that does the work.
Or maybe a #define XORALLBITS(hpa, xormap) is good enough if
you move it up under the comment.
> + val = (hweight64(hpa & cximsd->xormaps[i]) & 1);
> + hpa = (hpa & ~(1ULL << pos)) | (val << pos);
> + }
> +
> + return hpa;
> +}
> +
next prev parent reply other threads:[~2024-06-07 15:01 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-08 18:47 [PATCH v2 0/4] XOR Math Fixups: translation & position alison.schofield
2024-05-08 18:47 ` [PATCH v2 1/4] cxl/core: Rename cxl_trace_hpa() to cxl_translate() alison.schofield
2024-05-30 3:45 ` Dan Williams
2024-06-07 14:40 ` Jonathan Cameron
2024-06-07 17:45 ` Alison Schofield
2024-06-07 17:55 ` Jonathan Cameron
2024-05-08 18:47 ` [PATCH v2 2/4] cxl/acpi: Restore XOR'd position bits during address translation alison.schofield
2024-05-30 3:55 ` Dan Williams
2024-05-30 22:29 ` Alison Schofield
2024-05-31 1:46 ` Dan Williams
2024-06-07 15:01 ` Jonathan Cameron [this message]
2024-06-07 18:20 ` Alison Schofield
2024-06-10 10:20 ` Jonathan Cameron
2024-05-08 18:47 ` [PATCH v2 3/4] cxl/region: Verify target positions using the ordered target list alison.schofield
2024-06-07 15:04 ` Jonathan Cameron
2024-06-11 21:50 ` Dan Williams
2024-05-08 18:47 ` [PATCH v2 4/4] cxl: Remove defunct code calculating host bridge target positions alison.schofield
2024-06-07 15:06 ` 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=20240607160114.00006e4d@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=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