Skip to contentSkip to conversation

cxl: Fixes for extended linear cache

PATCH Applied Dave Jiang 4 participants 13 messages Oct 10, 2025 – Oct 14, 2025 CXL

lore
Share & tools
lore

Dave Jiang

author maintainer
#0 lore raw

cover cxl: Fixes for extended linear cache

This patch series contains 2 fixes for extended-linear cache to make it functional again. One is a regression from code refactoring. The other is a missed range compare during region matching.

Dave Jiang (3):
cxl/acpi: Fix setup of memory resource in cxl_acpi_set_cache_size()
cxl: Set range param for region_res_match_cxl_range() as const
cxl: Fix match_region_by_range() to use region_res_match_cxl_range()

 drivers/cxl/acpi.c        | 2 +-
 drivers/cxl/core/region.c | 7 ++-----
 2 files changed, 3 insertions(+), 6 deletions(-)

base-commit: c8e0f4f4be40a20f976344a821615e2b1bdb1f2b

Signature · 1 line
2.51.0
author maintainer
#1 lore raw

PATCH 1/3 cxl/acpi: Fix setup of memory resource in cxl_acpi_set_cache_size()

In order to compare the resource against the HMAT memory target, the resource needs to be memory type. Change the DEFINE_RES() macro to DEFINE_RES_MEM() in order to set the correct resource type. This causes a regression for platforms with the extended linear cache enabled as the comparison always fails and the cache size is not set. User visible impact is that when 'cxl list' is issued, a CXL region with extended linear cache support will only report half the size of the actual size. And this also breaks MCE reporting of the memory region due to incorrect offset calculation for the memory.

Fixes 12b3d697c812 ("cxl: Remove core/acpi.c and cxl core dependency on ACPI")
---
 drivers/cxl/acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/acpi.c +1 -1
index cb92efbd5914..abd2475b3493 100644
@@ -345,7 +345,7 @@ static int cxl_acpi_set_cache_size(struct cxl_root_decoder *cxlrd)
 	struct resource res;
 	int nid, rc;
 
-	res = DEFINE_RES(start, size, 0);
+	res = DEFINE_RES_MEM(start, size);
 	nid = phys_to_target_node(start);
 
 	rc = hmat_get_extended_linear_cache_size(&res, nid, &cache_size);
Signature · 1 line
2.51.0
author maintainer
#5 lore raw

PATCH 2/3 cxl: Set range param for region_res_match_cxl_range() as const

In reply to Dave Jiang

The function takes two parameters and compares them. The second parameter should be const since no modification should be done to it.

---
 drivers/cxl/core/region.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/region.c +1 -1
index 71cc42d05248..0ce50998c49f 100644
@@ -831,7 +831,7 @@ static int match_free_decoder(struct device *dev, const void *data)
 }
 
 static bool region_res_match_cxl_range(const struct cxl_region_params *p,
-				       struct range *range)
+				       const struct range *range)
 {
 	if (!p->res)
 		return false;
Signature · 1 line
2.51.0
author maintainer
#8 lore raw

PATCH 3/3 cxl: Fix match_region_by_range() to use region_res_match_cxl_range()

In reply to Dave Jiang

match_region_by_range() is not using the helper function that also takes extended linear cache size into account when comparing regions. This causes a x2 region to show up as 2 partial incomplete regions rather than a single CXL region with extended linear cache support. Replace the open coded compare logic with the proper helper function for comparison. User visible impact is that when 'cxl list' is issued, no activa CXL region(s) are shown. There may be multiple idle regions present. No actual active CXL region is present in the kernel.

Fixes 0ec9849b6333 ("acpi/hmat / cxl: Add extended linear cache support for CXL")
---
 drivers/cxl/core/region.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/cxl/core/region.c +1 -4
index 0ce50998c49f..be4521184328 100644
@@ -3287,10 +3287,7 @@ static int match_region_by_range(struct device *dev, const void *data)
 	p = &cxlr->params;
 
 	guard(rwsem_read)(&cxl_rwsem.region);
-	if (p->res && p->res->start == r->start && p->res->end == r->end)
-		return 1;
-
-	return 0;
+	return region_res_match_cxl_range(p, r);
 }
 
 static int cxl_extended_linear_cache_resize(struct cxl_region *cxlr,
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] cxl/acpi: Fix setup of memory resource in cxl_acpi_set_cache_size()

In reply to Dave Jiang
Quoted 9 lines · Dave Jiang

In order to compare the resource against the HMAT memory target, the resource needs to be memory type. Change the DEFINE_RES() macro to DEFINE_RES_MEM() in order to set the correct resource type. This causes a regression for platforms with the extended linear cache enabled as the comparison always fails and the cache size is not set. User visible impact is that when 'cxl list' is issued, a CXL region with extended linear cache support will only report half the size of the actual size. And this also breaks MCE reporting of the memory region due to incorrect offset calculation for the memory.

Quoted 24 lines
Fixes 12b3d697c812 ("cxl: Remove core/acpi.c and cxl core dependency on ACPI")
---
 drivers/cxl/acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/acpi.c +1 -1
index cb92efbd5914..abd2475b3493 100644
@@ -345,7 +345,7 @@ static int cxl_acpi_set_cache_size(struct cxl_root_decoder *cxlrd)
 	struct resource res;
 	int nid, rc;
 
-	res = DEFINE_RES(start, size, 0);
+	res = DEFINE_RES_MEM(start, size);
 	nid = phys_to_target_node(start);
 
 	rc = hmat_get_extended_linear_cache_size(&res, nid, &cache_size);
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 2/3
#6 lore raw

Re: [PATCH 2/3] cxl: Set range param for region_res_match_cxl_range() as const

In reply to Dave Jiang
Quoted 2 lines · Dave Jiang

The function takes two parameters and compares them. The second parameter should be const since no modification should be done to it.

Quoted 23 lines
---
 drivers/cxl/core/region.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/region.c +1 -1
index 71cc42d05248..0ce50998c49f 100644
@@ -831,7 +831,7 @@ static int match_free_decoder(struct device *dev, const void *data)
 }
 
 static bool region_res_match_cxl_range(const struct cxl_region_params *p,
-				       struct range *range)
+				       const struct range *range)
 {
 	if (!p->res)
 		return false;
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 3/3
#9 lore raw

Re: [PATCH 3/3] cxl: Fix match_region_by_range() to use region_res_match_cxl_range()

In reply to Dave Jiang
Quoted 8 lines · Dave Jiang

match_region_by_range() is not using the helper function that also takes extended linear cache size into account when comparing regions. This causes a x2 region to show up as 2 partial incomplete regions rather than a single CXL region with extended linear cache support. Replace the open coded compare logic with the proper helper function for comparison. User visible impact is that when 'cxl list' is issued, no activa CXL region(s) are shown. There may be multiple idle regions present. No actual active CXL region is present in the kernel.

Quoted 27 lines
Fixes 0ec9849b6333 ("acpi/hmat / cxl: Add extended linear cache support for CXL")
---
 drivers/cxl/core/region.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/cxl/core/region.c +1 -4
index 0ce50998c49f..be4521184328 100644
@@ -3287,10 +3287,7 @@ static int match_region_by_range(struct device *dev, const void *data)
 	p = &cxlr->params;
 
 	guard(rwsem_read)(&cxl_rwsem.region);
-	if (p->res && p->res->start == r->start && p->res->end == r->end)
-		return 1;
-
-	return 0;
+	return region_res_match_cxl_range(p, r);
 }
 
 static int cxl_extended_linear_cache_resize(struct cxl_region *cxlr,
Signature · 1 line
2.51.0
Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] cxl/acpi: Fix setup of memory resource in cxl_acpi_set_cache_size()

In reply to Dave Jiang
Quoted 10 lines · Dave Jiang

In order to compare the resource against the HMAT memory target, the resource needs to be memory type. Change the DEFINE_RES() macro to DEFINE_RES_MEM() in order to set the correct resource type. This causes a regression for platforms with the extended linear cache enabled as the comparison always fails and the cache size is not set. User visible impact is that when 'cxl list' is issued, a CXL region with extended linear cache support will only report half the size of the actual size. And this also breaks MCE reporting of the memory region due to incorrect offset calculation for the memory.

Quoted 3 lines
Fixes 12b3d697c812 ("cxl: Remove core/acpi.c and cxl core dependency on ACPI")
Reviewed-by on v1 3/3
#10 lore raw

Re: [PATCH 3/3] cxl: Fix match_region_by_range() to use region_res_match_cxl_range()

In reply to Dave Jiang
Quoted 9 lines · Dave Jiang

match_region_by_range() is not using the helper function that also takes extended linear cache size into account when comparing regions. This causes a x2 region to show up as 2 partial incomplete regions rather than a single CXL region with extended linear cache support. Replace the open coded compare logic with the proper helper function for comparison. User visible impact is that when 'cxl list' is issued, no activa CXL region(s) are shown. There may be multiple idle regions present. No actual active CXL region is present in the kernel.

Quoted 3 lines
Fixes 0ec9849b6333 ("acpi/hmat / cxl: Add extended linear cache support for CXL")
author maintainer Applied
#12 lore raw
In reply to Dave Jiang
Quoted 9 lines · Dave Jiang

This patch series contains 2 fixes for extended-linear cache to make it functional again. One is a regression from code refactoring. The other is a missed range compare during region matching.

Dave Jiang (3):
cxl/acpi: Fix setup of memory resource in cxl_acpi_set_cache_size()
cxl: Set range param for region_res_match_cxl_range() as const
cxl: Fix match_region_by_range() to use region_res_match_cxl_range()

Quoted 6 lines
 drivers/cxl/acpi.c        | 2 +-
 drivers/cxl/core/region.c | 7 ++-----
 2 files changed, 3 insertions(+), 6 deletions(-)

base-commit: c8e0f4f4be40a20f976344a821615e2b1bdb1f2b

applied to cxl/fixes

Reviewed-by on v1 1/3
#4 lore raw

Re: [PATCH 1/3] cxl/acpi: Fix setup of memory resource in cxl_acpi_set_cache_size()

In reply to Dave Jiang
Quoted 9 lines · Dave Jiang

In order to compare the resource against the HMAT memory target, the resource needs to be memory type. Change the DEFINE_RES() macro to DEFINE_RES_MEM() in order to set the correct resource type. This causes a regression for platforms with the extended linear cache enabled as the comparison always fails and the cache size is not set. User visible impact is that when 'cxl list' is issued, a CXL region with extended linear cache support will only report half the size of the actual size. And this also breaks MCE reporting of the memory region due to incorrect offset calculation for the memory.

Might be useful to mention that hmat_get_extended_linear_cache_size() uses resource_contains() internally, took me a moment to look that up.

Quoted 2 lines
Fixes 12b3d697c812 ("cxl: Remove core/acpi.c and cxl core dependency on ACPI")

The stable alias is [email protected]

Otherwise:

Reviewed-by on v1 3/3
#11 lore raw

Re: [PATCH 3/3] cxl: Fix match_region_by_range() to use region_res_match_cxl_range()

In reply to Dave Jiang
Quoted 11 lines · Dave Jiang

match_region_by_range() is not using the helper function that also takes extended linear cache size into account when comparing regions. This causes a x2 region to show up as 2 partial incomplete regions rather than a single CXL region with extended linear cache support. Replace the open coded compare logic with the proper helper function for comparison. User visible impact is that when 'cxl list' is issued, no activa CXL region(s) are shown. There may be multiple idle regions present. No actual active CXL region is present in the kernel.

Fixes 0ec9849b6333 ("acpi/hmat / cxl: Add extended linear cache support for CXL")

Wrong stable@ alias.

Quoted 10 lines
---
 drivers/cxl/core/region.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/cxl/core/region.c +0 -0
index 0ce50998c49f..be4521184328 100644

drivers/cxl/core/region.c static int match_region_by_range(struct device *dev, const void *data) · line 3290

Quoted 8 lines
drivers/cxl/core/region.c +1 -4
@@ -3287,10 +3287,7 @@ static int match_region_by_range(struct device *dev, const void *data)
 	p = &cxlr->params;
 
 	guard(rwsem_read)(&cxl_rwsem.region);
-	if (p->res && p->res->start == r->start && p->res->end == r->end)
-		return 1;
-
-	return 0;
+	return region_res_match_cxl_range(p, r);

Below are comments for future cleanups / clarifications.

For this:

I would never have guessed that a function named region_res_match_cxl_range() takes into account cache size. Something like "spa_maps_hpa()" gives more clue what address comparison is being performed.

Additionally, this comment in region_res_match_cxl_range() does not add any value to understanding the implementation:

/*
* If an extended linear cache region then the CXL range is assumed
* to be fronted by the DRAM range in current known implementation.
* This assumption will be made until a variant implementation exists. */

What does "current known" mean? Either the configuration is an extended linear cache or it is not. If this needs to refer to what an extended linear cache implies, i.e. that the SPA maps equal amounts of DDR and CXL HPA capacity with CXL decoders at the high end of that SPA range, just do that. Otherwise, there is no such thing as a "variant implementation".

In general the future must always be backwards compatible and is not worth a foreshadow comment to make that claim. A variant will require a whole new spa_maps_hpa() implementation that does not break existing deployments, but no such Code First ECN variant has been proposed.

So a future spa_maps_hpa() might be:

	/* Extend linear cache: <insert definition> */
	<linear cache compare>

	/* Foo bar baz cache: <insert definition> */
	<foo bar baz compare>

	...