Re: [PATCH v6 6/9] cxl/region: Add helper to check Soft Reserved containment by CXL regions

Dan Williams
2026-03-12T00:29:57Z

Smita Koralahalli wrote:
> Add a helper to determine whether a given Soft Reserved memory range is
> fully contained within the committed CXL region.
>
> This helper provides a primitive for policy decisions in subsequent
> patches such as co-ordination with dax_hmem to determine whether CXL has
> fully claimed ownership of Soft Reserved memory ranges.
>
> Signed-off-by: Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com>
> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
> Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
> drivers/cxl/core/region.c | 30 ++++++++++++++++++++++++++++++
> include/cxl/cxl.h | 15 +++++++++++++++
> 2 files changed, 45 insertions(+)
> create mode 100644 include/cxl/cxl.h
>
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 45ee598daf95..96ed550bfd2e 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -12,6 +12,7 @@
> #include <linux/idr.h>
> #include <linux/memory-tiers.h>
> #include <linux/string_choices.h>
> +#include <cxl/cxl.h>
> #include <cxlmem.h>
> #include <cxl.h>
> #include "core.h"
> @@ -3875,6 +3876,35 @@ static int cxl_region_debugfs_poison_clear(void *data, u64 offset)
> DEFINE_DEBUGFS_ATTRIBUTE(cxl_poison_clear_fops, NULL,
> cxl_region_debugfs_poison_clear, "%llx\n");
>
> +static int region_contains_soft_reserve(struct device *dev, void *data)
> +{
> + struct resource *res = data;
> + struct cxl_region *cxlr;
> + struct cxl_region_params *p;
> +
> + if (!is_cxl_region(dev))
> + return 0;
> +
> + cxlr = to_cxl_region(dev);
> + p = &cxlr->params;
> +
> + if (p->state != CXL_CONFIG_COMMIT)
> + return 0;
> +
> + if (!p->res)
> + return 0;
> +
> + return resource_contains(p->res, res) ? 1 : 0;
> +}
> +
> +bool cxl_region_contains_soft_reserve(struct resource *res)
> +{
> + guard(rwsem_read)(&cxl_rwsem.region);
> + return bus_for_each_dev(&cxl_bus_type, NULL, res,
> + region_contains_soft_reserve) != 0;
> +}
> +EXPORT_SYMBOL_GPL(cxl_region_contains_soft_reserve);

To be specific, this function is simply
"cxl_region_contains_resource()", there is nothing "soft reserve"
specific about this implementation.

With that rename you can add:

Reviewed-by: Dan Williams <dan.j.williams@intel.com>