Skip to contentSkip to conversation

cxl/region: Fix the first aliased address miscalculation

PATCH Applied Li Ming 4 participants 4 messages Mar 17, 2025 – Mar 20, 2025 CXL

lore
Share & tools
lore

Li Ming

author reviewer
#0 lore raw

PATCH 1/1 cxl/region: Fix the first aliased address miscalculation

In extended linear cache(ELC) case, cxl_port_get_spa_cache_alias() helps to get the aliased address of a SPA, it considers the first address in CXL memory range is "region start + region cache size + 1", but it should be "region start + region cache size".

So if a SPA is equal to "region start + region cache size", its aliased address should be "SPA - region cache size".

---
 drivers/cxl/core/region.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/region.c +1 -1
index 6d8bdb53f258..c3f4dc244df7 100644
@@ -3460,7 +3460,7 @@ u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, u64 spa)
 			if (!p->cache_size)
 				return ~0ULL;
 
-			if (spa > p->res->start + p->cache_size)
+			if (spa >= p->res->start + p->cache_size)
 				return spa - p->cache_size;
 
 			return spa + p->cache_size;
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Li Ming

In extended linear cache(ELC) case, cxl_port_get_spa_cache_alias() helps to get the aliased address of a SPA, it considers the first address in CXL memory range is "region start + region cache size + 1", but it should be "region start + region cache size".

So if a SPA is equal to "region start + region cache size", its aliased address should be "SPA - region cache size".

Nice catch Ming!

Quoted 22 lines
---
 drivers/cxl/core/region.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/region.c +1 -1
index 6d8bdb53f258..c3f4dc244df7 100644
@@ -3460,7 +3460,7 @@ u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, u64 spa)
 			if (!p->cache_size)
 				return ~0ULL;
 
-			if (spa > p->res->start + p->cache_size)
+			if (spa >= p->res->start + p->cache_size)
 				return spa - p->cache_size;
 
 			return spa + p->cache_size;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Li Ming
Quoted 9 lines · Li Ming

In extended linear cache(ELC) case, cxl_port_get_spa_cache_alias() helps to get the aliased address of a SPA, it considers the first address in CXL memory range is "region start + region cache size + 1", but it should be "region start + region cache size".

So if a SPA is equal to "region start + region cache size", its aliased address should be "SPA - region cache size".

[snip]

maintainer Applied
#3 lore raw
In reply to Li Ming
Quoted 9 lines · Li Ming

In extended linear cache(ELC) case, cxl_port_get_spa_cache_alias() helps to get the aliased address of a SPA, it considers the first address in CXL memory range is "region start + region cache size + 1", but it should be "region start + region cache size".

So if a SPA is equal to "region start + region cache size", its aliased address should be "SPA - region cache size".

Applied to cxl/next

Quoted 17 lines
---
 drivers/cxl/core/region.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/region.c +1 -1
index 6d8bdb53f258..c3f4dc244df7 100644
@@ -3460,7 +3460,7 @@ u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, u64 spa)
 			if (!p->cache_size)
 				return ~0ULL;
 
-			if (spa > p->res->start + p->cache_size)
+			if (spa >= p->res->start + p->cache_size)
 				return spa - p->cache_size;
 
 			return spa + p->cache_size;