Re: [PATCH v4 07/14] cxl/region: Use region data to get the root decoder

Jonathan Cameron
2025-11-11T15:14:17Z

On Mon, 3 Nov 2025 19:47:48 +0100
Robert Richter <rrichter@amd.com> wrote:

> To find a region's root decoder, the endpoint's HPA range is used to
> search the matching decoder by its range. With address translation the
> endpoint decoder's range is in a different address space and thus
> cannot be used to determine the root decoder.
>
> The region parameters are encapsulated within struc cxl_region_context
> and may include the translated Host Physical Address (HPA) range. Use
> this context to identify the root decoder rather than relying on the
> endpoint.
>
> Modify cxl_find_root_decoder() and add the region context as
> parameter. Rename this function to get_cxl_root_decoder() as a
> counterpart to put_cxl_root_decoder(). Simplify the implementation by
> removing function cxl_port_find_switch_decode(). The function is
> unnecessary because it is not referenced or utilized elsewhere in the
> code.
>
> Signed-off-by: Robert Richter <rrichter@amd.com>

One trivial thing that tickled my "that looks different" filter.

Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>

> static int match_region_by_range(struct device *dev, const void *data)
> @@ -3584,9 +3576,11 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxled)
> };
>
> struct cxl_root_decoder *cxlrd __free(put_cxl_root_decoder) =
> - cxl_find_root_decoder(cxled);
> - if (!cxlrd)
> - return -ENXIO;
> + get_cxl_root_decoder(cxled, &ctx);
> +
> + rc = PTR_ERR_OR_ZERO(cxlrd);
> + if (rc)
> + return rc;

I think this is more often seen as:

if (IS_ERR(cxlrd))
return PTR_ERR(cxlrd);

>
> /*
> * Ensure that if multiple threads race to construct_region()