Skip to content

Commit 0ec9849

Browse files
committed
acpi/hmat / cxl: Add extended linear cache support for CXL
The current cxl region size only indicates the size of the CXL memory region without accounting for the extended linear cache size. Retrieve the cache size from HMAT and append that to the cxl region size for the cxl region range that matches the SRAT range that has extended linear cache enabled. The SRAT defines the whole memory range that includes the extended linear cache and the CXL memory region. The new HMAT ECN/ECR to the Memory Side Cache Information Structure defines the size of the extended linear cache size and matches to the SRAT Memory Affinity Structure by the memory proxmity domain. Add a helper to match the cxl range to the SRAT memory range in order to retrieve the cache size. There are several places that checks the cxl region range against the decoder range. Use new helper to check between the two ranges and address the new cache size. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Li Ming <ming.li@zohomail.com> Reviewed-by: Alison Schofield <alison.schofield@intel.com> Link: https://patch.msgid.link/20250226162224.3633792-3-dave.jiang@intel.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 84b2592 commit 0ec9849

File tree

8 files changed

+147
-7
lines changed

8 files changed

+147
-7
lines changed

drivers/acpi/numa/hmat.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,45 @@ static struct memory_target *find_mem_target(unsigned int mem_pxm)
108108
return NULL;
109109
}
110110

111+
/**
112+
* hmat_get_extended_linear_cache_size - Retrieve the extended linear cache size
113+
* @backing_res: resource from the backing media
114+
* @nid: node id for the memory region
115+
* @cache_size: (Output) size of extended linear cache.
116+
*
117+
* Return: 0 on success. Errno on failure.
118+
*
119+
*/
120+
int hmat_get_extended_linear_cache_size(struct resource *backing_res, int nid,
121+
resource_size_t *cache_size)
122+
{
123+
unsigned int pxm = node_to_pxm(nid);
124+
struct memory_target *target;
125+
struct target_cache *tcache;
126+
struct resource *res;
127+
128+
target = find_mem_target(pxm);
129+
if (!target)
130+
return -ENOENT;
131+
132+
list_for_each_entry(tcache, &target->caches, node) {
133+
if (tcache->cache_attrs.address_mode !=
134+
NODE_CACHE_ADDR_MODE_EXTENDED_LINEAR)
135+
continue;
136+
137+
res = &target->memregions;
138+
if (!resource_contains(res, backing_res))
139+
continue;
140+
141+
*cache_size = tcache->cache_attrs.size;
142+
return 0;
143+
}
144+
145+
*cache_size = 0;
146+
return 0;
147+
}
148+
EXPORT_SYMBOL_NS_GPL(hmat_get_extended_linear_cache_size, "CXL");
149+
111150
static struct memory_target *acpi_find_genport_target(u32 uid)
112151
{
113152
struct memory_target *target;

drivers/cxl/core/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ cxl_core-y += pci.o
1414
cxl_core-y += hdm.o
1515
cxl_core-y += pmu.o
1616
cxl_core-y += cdat.o
17+
cxl_core-y += acpi.o
1718
cxl_core-$(CONFIG_TRACING) += trace.o
1819
cxl_core-$(CONFIG_CXL_REGION) += region.o

drivers/cxl/core/acpi.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/* Copyright(c) 2024 Intel Corporation. All rights reserved. */
3+
#include <linux/acpi.h>
4+
#include "cxl.h"
5+
#include "core.h"
6+
7+
int cxl_acpi_get_extended_linear_cache_size(struct resource *backing_res,
8+
int nid, resource_size_t *size)
9+
{
10+
return hmat_get_extended_linear_cache_size(backing_res, nid, size);
11+
}

drivers/cxl/core/core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,7 @@ bool cxl_need_node_perf_attrs_update(int nid);
115115
int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,
116116
struct access_coordinate *c);
117117

118+
int cxl_acpi_get_extended_linear_cache_size(struct resource *backing_res,
119+
int nid, resource_size_t *size);
120+
118121
#endif /* __CXL_CORE_H__ */

drivers/cxl/core/region.c

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,21 @@ static int match_free_decoder(struct device *dev, const void *data)
824824
return 1;
825825
}
826826

827+
static bool region_res_match_cxl_range(const struct cxl_region_params *p,
828+
struct range *range)
829+
{
830+
if (!p->res)
831+
return false;
832+
833+
/*
834+
* If an extended linear cache region then the CXL range is assumed
835+
* to be fronted by the DRAM range in current known implementation.
836+
* This assumption will be made until a variant implementation exists.
837+
*/
838+
return p->res->start + p->cache_size == range->start &&
839+
p->res->end == range->end;
840+
}
841+
827842
static int match_auto_decoder(struct device *dev, const void *data)
828843
{
829844
const struct cxl_region_params *p = data;
@@ -836,7 +851,7 @@ static int match_auto_decoder(struct device *dev, const void *data)
836851
cxld = to_cxl_decoder(dev);
837852
r = &cxld->hpa_range;
838853

839-
if (p->res && p->res->start == r->start && p->res->end == r->end)
854+
if (region_res_match_cxl_range(p, r))
840855
return 1;
841856

842857
return 0;
@@ -1424,8 +1439,7 @@ static int cxl_port_setup_targets(struct cxl_port *port,
14241439
if (test_bit(CXL_REGION_F_AUTO, &cxlr->flags)) {
14251440
if (cxld->interleave_ways != iw ||
14261441
cxld->interleave_granularity != ig ||
1427-
cxld->hpa_range.start != p->res->start ||
1428-
cxld->hpa_range.end != p->res->end ||
1442+
!region_res_match_cxl_range(p, &cxld->hpa_range) ||
14291443
((cxld->flags & CXL_DECODER_F_ENABLE) == 0)) {
14301444
dev_err(&cxlr->dev,
14311445
"%s:%s %s expected iw: %d ig: %d %pr\n",
@@ -1951,13 +1965,13 @@ static int cxl_region_attach(struct cxl_region *cxlr,
19511965
return -ENXIO;
19521966
}
19531967

1954-
if (resource_size(cxled->dpa_res) * p->interleave_ways !=
1968+
if (resource_size(cxled->dpa_res) * p->interleave_ways + p->cache_size !=
19551969
resource_size(p->res)) {
19561970
dev_dbg(&cxlr->dev,
1957-
"%s:%s: decoder-size-%#llx * ways-%d != region-size-%#llx\n",
1971+
"%s:%s-size-%#llx * ways-%d + cache-%#llx != region-size-%#llx\n",
19581972
dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev),
19591973
(u64)resource_size(cxled->dpa_res), p->interleave_ways,
1960-
(u64)resource_size(p->res));
1974+
(u64)p->cache_size, (u64)resource_size(p->res));
19611975
return -EINVAL;
19621976
}
19631977

@@ -2921,7 +2935,7 @@ u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,
29212935
hpa_offset |= dpa_offset & GENMASK_ULL(eig + 7, 0);
29222936

29232937
/* Apply the hpa_offset to the region base address */
2924-
hpa = hpa_offset + p->res->start;
2938+
hpa = hpa_offset + p->res->start + p->cache_size;
29252939

29262940
/* Root decoder translation overrides typical modulo decode */
29272941
if (cxlrd->hpa_to_spa)
@@ -3224,6 +3238,52 @@ static int match_region_by_range(struct device *dev, const void *data)
32243238
return rc;
32253239
}
32263240

3241+
static int cxl_extended_linear_cache_resize(struct cxl_region *cxlr,
3242+
struct resource *res)
3243+
{
3244+
struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent);
3245+
struct cxl_region_params *p = &cxlr->params;
3246+
int nid = phys_to_target_node(res->start);
3247+
resource_size_t size, cache_size, start;
3248+
int rc;
3249+
3250+
size = resource_size(res);
3251+
if (!size)
3252+
return -EINVAL;
3253+
3254+
rc = cxl_acpi_get_extended_linear_cache_size(res, nid, &cache_size);
3255+
if (rc)
3256+
return rc;
3257+
3258+
if (!cache_size)
3259+
return 0;
3260+
3261+
if (size != cache_size) {
3262+
dev_warn(&cxlr->dev,
3263+
"Extended Linear Cache size %#lld != CXL size %#lld. No Support!",
3264+
cache_size, size);
3265+
return -EOPNOTSUPP;
3266+
}
3267+
3268+
/*
3269+
* Move the start of the range to where the cache range starts. The
3270+
* implementation assumes that the cache range is in front of the
3271+
* CXL range. This is not dictated by the HMAT spec but is how the
3272+
* current known implementation is configured.
3273+
*
3274+
* The cache range is expected to be within the CFMWS. The adjusted
3275+
* res->start should not be less than cxlrd->res->start.
3276+
*/
3277+
start = res->start - cache_size;
3278+
if (start < cxlrd->res->start)
3279+
return -ENXIO;
3280+
3281+
res->start = start;
3282+
p->cache_size = cache_size;
3283+
3284+
return 0;
3285+
}
3286+
32273287
/* Establish an empty region covering the given HPA range */
32283288
static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,
32293289
struct cxl_endpoint_decoder *cxled)
@@ -3270,6 +3330,18 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,
32703330

32713331
*res = DEFINE_RES_MEM_NAMED(hpa->start, range_len(hpa),
32723332
dev_name(&cxlr->dev));
3333+
3334+
rc = cxl_extended_linear_cache_resize(cxlr, res);
3335+
if (rc) {
3336+
/*
3337+
* Failing to support extended linear cache region resize does not
3338+
* prevent the region from functioning. Only causes cxl list showing
3339+
* incorrect region size.
3340+
*/
3341+
dev_warn(cxlmd->dev.parent,
3342+
"Extended linear cache calculation failed.\n");
3343+
}
3344+
32733345
rc = insert_resource(cxlrd->res, res);
32743346
if (rc) {
32753347
/*

drivers/cxl/cxl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ enum cxl_config_state {
493493
* @res: allocated iomem capacity for this region
494494
* @targets: active ordered targets in current decoder configuration
495495
* @nr_targets: number of targets
496+
* @cache_size: extended linear cache size if exists, otherwise zero.
496497
*
497498
* State transitions are protected by the cxl_region_rwsem
498499
*/
@@ -504,6 +505,7 @@ struct cxl_region_params {
504505
struct resource *res;
505506
struct cxl_endpoint_decoder *targets[CXL_DECODER_MAX_INTERLEAVE];
506507
int nr_targets;
508+
resource_size_t cache_size;
507509
};
508510

509511
/*

include/linux/acpi.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,17 @@ static inline acpi_handle acpi_get_processor_handle(int cpu)
10951095

10961096
#endif /* !CONFIG_ACPI */
10971097

1098+
#ifdef CONFIG_ACPI_HMAT
1099+
int hmat_get_extended_linear_cache_size(struct resource *backing_res, int nid,
1100+
resource_size_t *size);
1101+
#else
1102+
static inline int hmat_get_extended_linear_cache_size(struct resource *backing_res,
1103+
int nid, resource_size_t *size)
1104+
{
1105+
return -EOPNOTSUPP;
1106+
}
1107+
#endif
1108+
10981109
extern void arch_post_acpi_subsys_init(void);
10991110

11001111
#ifdef CONFIG_ACPI_HOTPLUG_IOAPIC

tools/testing/cxl/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ cxl_core-y += $(CXL_CORE_SRC)/pci.o
6161
cxl_core-y += $(CXL_CORE_SRC)/hdm.o
6262
cxl_core-y += $(CXL_CORE_SRC)/pmu.o
6363
cxl_core-y += $(CXL_CORE_SRC)/cdat.o
64+
cxl_core-y += $(CXL_CORE_SRC)/acpi.o
6465
cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o
6566
cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o
6667
cxl_core-y += config_check.o

0 commit comments

Comments
 (0)