From: Smita Koralahalli Date: Sun, 22 Mar 2026 19:53:40 +0000 (+0000) Subject: cxl/region: Add helper to check Soft Reserved containment by CXL regions X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8e65f99b525b3f49b87db0db0d0e0fc1a0c53e40;p=thirdparty%2Fkernel%2Flinux.git cxl/region: Add helper to check Soft Reserved containment by CXL regions 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 Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang Reviewed-by: Dan Williams Link: https://patch.msgid.link/20260322195343.206900-8-Smita.KoralahalliChannabasappa@amd.com Signed-off-by: Dan Williams Signed-off-by: Dave Jiang --- diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 42874948b589b..f7b20f60ac5cd 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include "core.h" @@ -4173,6 +4174,35 @@ static int cxl_region_setup_poison(struct cxl_region *cxlr) return devm_add_action_or_reset(dev, remove_debugfs, dentry); } +static int region_contains_resource(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_resource(struct resource *res) +{ + guard(rwsem_read)(&cxl_rwsem.region); + return bus_for_each_dev(&cxl_bus_type, NULL, res, + region_contains_resource) != 0; +} +EXPORT_SYMBOL_GPL(cxl_region_contains_resource); + static int cxl_region_can_probe(struct cxl_region *cxlr) { struct cxl_region_params *p = &cxlr->params; diff --git a/include/cxl/cxl.h b/include/cxl/cxl.h new file mode 100644 index 0000000000000..b12d3d0f66588 --- /dev/null +++ b/include/cxl/cxl.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2026 Advanced Micro Devices, Inc. */ +#ifndef _CXL_H_ +#define _CXL_H_ + +#ifdef CONFIG_CXL_REGION +bool cxl_region_contains_resource(struct resource *res); +#else +static inline bool cxl_region_contains_resource(struct resource *res) +{ + return false; +} +#endif + +#endif /* _CXL_H_ */