Skip to content

Commit 8e65f99

Browse files
skoralahdavejiang
authored andcommitted
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 <Smita.KoralahalliChannabasappa@amd.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Dan Williams <dan.j.williams@intel.com> Link: https://patch.msgid.link/20260322195343.206900-8-Smita.KoralahalliChannabasappa@amd.com Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 34f80bb commit 8e65f99

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

drivers/cxl/core/region.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/idr.h>
1313
#include <linux/memory-tiers.h>
1414
#include <linux/string_choices.h>
15+
#include <cxl/cxl.h>
1516
#include <cxlmem.h>
1617
#include <cxl.h>
1718
#include "core.h"
@@ -4173,6 +4174,35 @@ static int cxl_region_setup_poison(struct cxl_region *cxlr)
41734174
return devm_add_action_or_reset(dev, remove_debugfs, dentry);
41744175
}
41754176

4177+
static int region_contains_resource(struct device *dev, void *data)
4178+
{
4179+
struct resource *res = data;
4180+
struct cxl_region *cxlr;
4181+
struct cxl_region_params *p;
4182+
4183+
if (!is_cxl_region(dev))
4184+
return 0;
4185+
4186+
cxlr = to_cxl_region(dev);
4187+
p = &cxlr->params;
4188+
4189+
if (p->state != CXL_CONFIG_COMMIT)
4190+
return 0;
4191+
4192+
if (!p->res)
4193+
return 0;
4194+
4195+
return resource_contains(p->res, res) ? 1 : 0;
4196+
}
4197+
4198+
bool cxl_region_contains_resource(struct resource *res)
4199+
{
4200+
guard(rwsem_read)(&cxl_rwsem.region);
4201+
return bus_for_each_dev(&cxl_bus_type, NULL, res,
4202+
region_contains_resource) != 0;
4203+
}
4204+
EXPORT_SYMBOL_GPL(cxl_region_contains_resource);
4205+
41764206
static int cxl_region_can_probe(struct cxl_region *cxlr)
41774207
{
41784208
struct cxl_region_params *p = &cxlr->params;

include/cxl/cxl.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/* Copyright (c) 2026 Advanced Micro Devices, Inc. */
3+
#ifndef _CXL_H_
4+
#define _CXL_H_
5+
6+
#ifdef CONFIG_CXL_REGION
7+
bool cxl_region_contains_resource(struct resource *res);
8+
#else
9+
static inline bool cxl_region_contains_resource(struct resource *res)
10+
{
11+
return false;
12+
}
13+
#endif
14+
15+
#endif /* _CXL_H_ */

0 commit comments

Comments
 (0)