Re: [PATCH v1 20/29] cxl/region: Use translated HPA ranges to find the port's decoder
From: Gregory Price
Date: Tue Jan 07 2025 - 17:33:20 EST
On Tue, Jan 07, 2025 at 03:10:06PM +0100, Robert Richter wrote:
> This is the second step to find the port's decoder with address
> translation enabled. The translated HPA range must be used to find a
> decoder. The port's HPA range is determined by applying address
> translation when crossing memory domains for the HPA range to each
> port while traversing the topology from the endpoint up to the port.
>
> Introduce a function cxl_find_auto_decoder() that calculates the
> port's translated address range to determine the corresponding
> decoder. Use the existing helper function cxl_port_calc_hpa() for HPA
> range calculation.
>
> Signed-off-by: Robert Richter <rrichter@xxxxxxx>
> ---
> drivers/cxl/core/region.c | 63 +++++++++++++++++++++++++++++++++++++--
> 1 file changed, 61 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 23b86de3d4e7..8d7893878362 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -876,6 +876,66 @@ static int match_auto_decoder(struct device *dev, void *data)
> return 0;
> }
>
> +static struct device *
> +cxl_find_auto_decoder(struct cxl_port *port, struct cxl_endpoint_decoder *cxled,
> + struct cxl_region *cxlr)
> +{
> + struct cxl_port *parent, *iter = cxled_to_port(cxled);
> + struct cxl_decoder *cxld = &cxled->cxld;
> + struct range hpa = cxld->hpa_range;
> + struct cxl_region_ref *rr;
> +
> + while (1) {
Similar to prior patch, probably we should have while(parent) instead of
while(1) and be at least a bit defensive against (extremely unlikely) loops.
At the very least maybe we can express the condition more explicitly.
> + parent = parent_port_of(iter);
> + if (!parent) {
> + dev_warn(&port->dev,
> + "port not a parent of endpoint decoder %s\n",
> + dev_name(&cxled->cxld.dev));
> + return NULL;
> + }
... snip ...