Re: [PATCH v2 10/15] cxl/region: Use root decoders interleaving parameters to create a region

From: Gregory Price
Date: Tue Apr 01 2025 - 14:03:58 EST


On Tue, Feb 18, 2025 at 02:23:51PM +0100, Robert Richter wrote:
> Endpoints requiring address translation might not be aware of the
> system's interleaving configuration. Instead, interleaving can be
> configured on an upper memory domain (from an endpoint view) and thus
> is not visible to the endpoint. For region creation this might cause
> an invalid interleaving config that does not match the CFMWS entries.
>
> Use the interleaving configuration of the root decoders to create a
> region which bases on CFMWS entries. This always matches the system's
> interleaving configuration and is independent of the underlying memory
> topology.
>
> Signed-off-by: Robert Richter <rrichter@xxxxxxx>
... snip ...
> @@ -1955,12 +1971,23 @@ static int cxl_port_calc_interleave(struct cxl_port *port,
> if (is_cxl_root(port))
> return 0;
>
> - rc = find_pos_and_ways(port, ctx->hpa_range, &parent_pos, &parent_ways);
> + rc = find_pos_and_ways(port, ctx->hpa_range, &parent_pos, &parent_ways,
> + &parent_granularity);
> if (rc)
> return rc;
>
> ctx->pos = ctx->pos * parent_ways + parent_pos;
>
> + if (ctx->interleave_ways)
> + ctx->interleave_ways *= parent_ways;
> + else
> + ctx->interleave_ways = parent_ways;
> +
> + if (ctx->interleave_granularity)
> + ctx->interleave_granularity *= ctx->interleave_ways;
> + else
> + ctx->interleave_granularity = parent_granularity;
> +
> return ctx->pos;
> }


The root is always build from the CFMWS, so you don't need to do any
math, you just need to take the root. Since the logic calling this will
always climb to the root, you'll always get the right value.

So I think you just want this

---

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index fe23dc106956..05b24b008a1b 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -1977,17 +1977,8 @@ static int cxl_port_calc_interleave(struct cxl_port *port,
return rc;

ctx->pos = ctx->pos * parent_ways + parent_pos;
-
- if (ctx->interleave_ways)
- ctx->interleave_ways *= parent_ways;
- else
- ctx->interleave_ways = parent_ways;
-
- if (ctx->interleave_granularity)
- ctx->interleave_granularity *= ctx->interleave_ways;
- else
- ctx->interleave_granularity = parent_granularity;
-
+ ctx->interleave_ways = parent_ways;
+ ctx->interleave_granularity = parent_granularity;
return ctx->pos;
}