Skip to contentSkip to conversation

cxl/test: Enforce PMD alignment for volatile mock regions

PATCH Superseded Richard Cheng 2 participants 4 messages May 22 – May 27 CXL

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 cxl/test: Enforce PMD alignment for volatile mock regions

cxl_test allocates synthetic CFMWS HPA windows from a gen_pool with SZ_256M alignment. On arm64 with CONFIG_ARM64_64K_PAGES=y and CONFIG_PGTABLE_LEVELS=3, PMD_SIZE is 512M, so every CXL region carved from a volatile window inherits a non-PMD-aligned start, and cxl_dax_region_probe() -> alloc_dax_region() fails:

"""
cxl_dax_region dax_region1: probe with driver cxl_dax_region failed
with error -12
"""

Enforce that every volatile mock CFMWS is PMD-aligned in both start and size

---
Changelog:

v2->v3:
- Correct hunk headers
- Add base commit SHA

v1->v2:
- Reframe from "fix start alignment" to "enforce PMD invariant for volatile CFMWS"
- Bump cfmws5.window_size to max(SZ_256M, PMD_SIZE)
- Gate populate_cedt() alignment on ACPI_CEDT_CFMWS_RESTRICT_VOLATILE so PMEM windows stay at SZ_256M
- Add BUILD_BUG_ON for MOCK_AUTO_REGION_SIZE_DEFAULT v.s. PMD_SIZE in cxl_test_init()

Best regards,
Richard Cheng.

---
 tools/testing/cxl/test/cxl.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/testing/cxl/test/cxl.c +7 -2
index 418669927fb0..7a1105f9a0bb 100644
@@ -318,7 +318,7 @@ static struct {
 			.restrictions = ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM |
 					ACPI_CEDT_CFMWS_RESTRICT_VOLATILE,
 			.qtg_id = FAKE_QTG_ID,
-			.window_size = SZ_256M,
+			.window_size = SZ_256M > PMD_SIZE ? SZ_256M : PMD_SIZE,
 		},
 		.target = { 3 },
 	},
@@ -495,9 +495,12 @@ static int populate_cedt(void)
 
 	for (i = cfmws_start; i <= cfmws_end; i++) {
 		struct acpi_cedt_cfmws *window = mock_cfmws[i];
+		int align = SZ_256M;
 
 		cfmws_elc_update(window, i);
-		res = alloc_mock_res(window->window_size, SZ_256M);
+		if (window->restrictions & ACPI_CEDT_CFMWS_RESTRICT_VOLATILE)
+			align = max_t(int, SZ_256M, PMD_SIZE);
+		res = alloc_mock_res(window->window_size, align);
 		if (!res)
 			return -ENOMEM;
 		window->base_hpa = res->range.start;
@@ -1826,6 +1829,8 @@ static __init int cxl_test_init(void)
 	int rc, i;
 	struct range mappable;
 
+	BUILD_BUG_ON(!IS_ALIGNED(MOCK_AUTO_REGION_SIZE_DEFAULT, PMD_SIZE));
+
 	cxl_acpi_test();
 	cxl_core_test();
 	cxl_mem_test();

base-commit: 6779b50faa562e6cca1aa6a4649a4d764c6c7e28

Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 44 lines · Richard Cheng

cxl_test allocates synthetic CFMWS HPA windows from a gen_pool with SZ_256M alignment. On arm64 with CONFIG_ARM64_64K_PAGES=y and CONFIG_PGTABLE_LEVELS=3, PMD_SIZE is 512M, so every CXL region carved from a volatile window inherits a non-PMD-aligned start, and cxl_dax_region_probe() -> alloc_dax_region() fails:

"""
cxl_dax_region dax_region1: probe with driver cxl_dax_region failed
with error -12
"""

Enforce that every volatile mock CFMWS is PMD-aligned in both start and size

---
Changelog:

v2->v3:
- Correct hunk headers
- Add base commit SHA

v1->v2:
- Reframe from "fix start alignment" to "enforce PMD invariant for volatile CFMWS"
- Bump cfmws5.window_size to max(SZ_256M, PMD_SIZE)
- Gate populate_cedt() alignment on ACPI_CEDT_CFMWS_RESTRICT_VOLATILE so PMEM windows stay at SZ_256M
- Add BUILD_BUG_ON for MOCK_AUTO_REGION_SIZE_DEFAULT v.s. PMD_SIZE in cxl_test_init()

Best regards,
Richard Cheng.

---
 tools/testing/cxl/test/cxl.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/testing/cxl/test/cxl.c +0 -0
index 418669927fb0..7a1105f9a0bb 100644

tools/testing/cxl/test/cxl.c static struct { · line 321

Quoted 5 lines
tools/testing/cxl/test/cxl.c +1 -1
@@ -318,7 +318,7 @@ static struct {
 			.restrictions = ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM |
 					ACPI_CEDT_CFMWS_RESTRICT_VOLATILE,
 			.qtg_id = FAKE_QTG_ID,
-			.window_size = SZ_256M,
+			.window_size = SZ_256M > PMD_SIZE ? SZ_256M : PMD_SIZE,

Why not this: max_t(resource_size_t, SZ_256M, PMD_SIZE)

Quoted 18 lines
tools/testing/cxl/test/cxl.c +4 -1
 		},
 		.target = { 3 },
 	},
@@ -495,9 +495,12 @@ static int populate_cedt(void)
 
 	for (i = cfmws_start; i <= cfmws_end; i++) {
 		struct acpi_cedt_cfmws *window = mock_cfmws[i];
+		int align = SZ_256M;
 
 		cfmws_elc_update(window, i);
-		res = alloc_mock_res(window->window_size, SZ_256M);
+		if (window->restrictions & ACPI_CEDT_CFMWS_RESTRICT_VOLATILE)
+			align = max_t(int, SZ_256M, PMD_SIZE);
+		res = alloc_mock_res(window->window_size, align);
 		if (!res)
 			return -ENOMEM;
 		window->base_hpa = res->range.start;

tools/testing/cxl/test/cxl.c static __init int cxl_test_init(void) · line 1832

Quoted 4 lines
tools/testing/cxl/test/cxl.c +1 -0
@@ -1826,6 +1829,8 @@ static __init int cxl_test_init(void)
 	int rc, i;
 	struct range mappable;
 
+	BUILD_BUG_ON(!IS_ALIGNED(MOCK_AUTO_REGION_SIZE_DEFAULT, PMD_SIZE));

The rule we need to enforce is tha the actual auto region size is PMD aligned, not the default definition. So I think this needs to be a runtime check of IS_ALIGNED(mock_auto_region_size, PMD_SIZE).

-- Alison

Quoted 9 lines
tools/testing/cxl/test/cxl.c +1 -0
+
 	cxl_acpi_test();
 	cxl_core_test();
 	cxl_mem_test();

base-commit: 6779b50faa562e6cca1aa6a4649a4d764c6c7e28

Signature · 1 line
2.43.0
#2 lore raw
Quoted 40 lines · Alison Schofield
Quoted 39 lines · Richard Cheng

cxl_test allocates synthetic CFMWS HPA windows from a gen_pool with SZ_256M alignment. On arm64 with CONFIG_ARM64_64K_PAGES=y and CONFIG_PGTABLE_LEVELS=3, PMD_SIZE is 512M, so every CXL region carved from a volatile window inherits a non-PMD-aligned start, and cxl_dax_region_probe() -> alloc_dax_region() fails:

"""
cxl_dax_region dax_region1: probe with driver cxl_dax_region failed
with error -12
"""

Enforce that every volatile mock CFMWS is PMD-aligned in both start and size

---
Changelog:

v2->v3:
- Correct hunk headers
- Add base commit SHA

v1->v2:
- Reframe from "fix start alignment" to "enforce PMD invariant for volatile CFMWS"
- Bump cfmws5.window_size to max(SZ_256M, PMD_SIZE)
- Gate populate_cedt() alignment on ACPI_CEDT_CFMWS_RESTRICT_VOLATILE so PMEM windows stay at SZ_256M
- Add BUILD_BUG_ON for MOCK_AUTO_REGION_SIZE_DEFAULT v.s. PMD_SIZE in cxl_test_init()

Best regards,
Richard Cheng.

---
 tools/testing/cxl/test/cxl.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Quoted 13 lines

tools/testing/cxl/test/cxl.c static struct { · line 321

Quoted 10 lines
tools/testing/cxl/test/cxl.c +1 -1
index 418669927fb0..7a1105f9a0bb 100644
@@ -318,7 +318,7 @@ static struct {
 			.restrictions = ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM |
 					ACPI_CEDT_CFMWS_RESTRICT_VOLATILE,
 			.qtg_id = FAKE_QTG_ID,
-			.window_size = SZ_256M,
+			.window_size = SZ_256M > PMD_SIZE ? SZ_256M : PMD_SIZE,

Why not this: max_t(resource_size_t, SZ_256M, PMD_SIZE)

Hi Alison,

Thanks for the feedback, but I doubt this will work.
"max_t()" expands to a statement expression, which isn't a constant expression so it can't be used in this file-scope static initializer.

I did the change and compile, the error is
"""
include/linux/minmax.h:86:9: error: braced-group within expression

                                allowed only inside a function
     86 |     ({ type ux = (x); type uy = (y); __cmp(op, ux, uy); })
        |     ^
  test/cxl.c:295:40: note: in expansion of macro 'max_t'
    295 |     .window_size = max_t(resource_size_t, SZ_256M, PMD_SIZE),

"""

So I don't think this approach works, I would like to stick to ternary form if that's ok for you.

Quoted 22 lines
Quoted 22 lines
tools/testing/cxl/test/cxl.c +4 -1
 		},
 		.target = { 3 },
 	},
@@ -495,9 +495,12 @@ static int populate_cedt(void)
 
 	for (i = cfmws_start; i <= cfmws_end; i++) {
 		struct acpi_cedt_cfmws *window = mock_cfmws[i];
+		int align = SZ_256M;
 
 		cfmws_elc_update(window, i);
-		res = alloc_mock_res(window->window_size, SZ_256M);
+		if (window->restrictions & ACPI_CEDT_CFMWS_RESTRICT_VOLATILE)
+			align = max_t(int, SZ_256M, PMD_SIZE);
+		res = alloc_mock_res(window->window_size, align);
 		if (!res)
 			return -ENOMEM;
 		window->base_hpa = res->range.start;
@@ -1826,6 +1829,8 @@ static __init int cxl_test_init(void)
 	int rc, i;
 	struct range mappable;
 
Quoted 8 lines

tools/testing/cxl/test/cxl.c static __init int cxl_test_init(void) · line 1832

Quoted 1 line
tools/testing/cxl/test/cxl.c +1 -0
+	BUILD_BUG_ON(!IS_ALIGNED(MOCK_AUTO_REGION_SIZE_DEFAULT, PMD_SIZE));

The rule we need to enforce is tha the actual auto region size is PMD aligned, not the default definition. So I think this needs to be a runtime check of IS_ALIGNED(mock_auto_region_size, PMD_SIZE).

-- Alison

Thanks for the catch, I'll fix this and send a v4 to make it runtime check.

Do you prefer WARN_ON_ONCE() to be ammend or no? I mean

"""
if (!IS_ALIGNED(mock_auto_region_size, PMD_SIZE))

	return -EINVAL;

"""
or
"""
if (WARN_ON_ONCE(!IS_ALIGNED(mock_auto_region_size, PMD_SIZE)))

	return -EINVAL;

"""

Which one do you prefer ? or any other idea ? please let me know and I'll make the change.

Best regards,
Richard Cheng.

Quoted 9 lines
Quoted 9 lines
tools/testing/cxl/test/cxl.c +1 -0
+
 	cxl_acpi_test();
 	cxl_core_test();
 	cxl_mem_test();

base-commit: 6779b50faa562e6cca1aa6a4649a4d764c6c7e28

Signature · 1 line
2.43.0
maintainer
#3 lore raw
Quoted 2 lines · Richard Cheng
Quoted 1 line · Alison Schofield

On Fri, May 22, 2026 at 01:44:57PM +0800, Richard Cheng wrote:

snip

Quoted 22 lines
Quoted 4 lines
Quoted 4 lines
tools/testing/cxl/test/cxl.c +0 -0
index 418669927fb0..7a1105f9a0bb 100644
Quoted 9 lines

tools/testing/cxl/test/cxl.c static struct { · line 321

Quoted 6 lines
tools/testing/cxl/test/cxl.c +1 -1
@@ -318,7 +318,7 @@ static struct {
 			.restrictions = ACPI_CEDT_CFMWS_RESTRICT_HOSTONLYMEM |
 					ACPI_CEDT_CFMWS_RESTRICT_VOLATILE,
 			.qtg_id = FAKE_QTG_ID,
-			.window_size = SZ_256M,
+			.window_size = SZ_256M > PMD_SIZE ? SZ_256M : PMD_SIZE,

Why not this: max_t(resource_size_t, SZ_256M, PMD_SIZE)

Hi Alison,

Thanks for the feedback, but I doubt this will work.
"max_t()" expands to a statement expression, which isn't a constant expression so it can't be used in this file-scope static initializer.

I did the change and compile, the error is
"""
include/linux/minmax.h:86:9: error: braced-group within expression

Quoted 8 lines
                                allowed only inside a function
     86 |     ({ type ux = (x); type uy = (y); __cmp(op, ux, uy); })
        |     ^
  test/cxl.c:295:40: note: in expansion of macro 'max_t'
    295 |     .window_size = max_t(resource_size_t, SZ_256M, PMD_SIZE),

"""

So I don't think this approach works, I would like to stick to ternary form if that's ok for you.

Sounds good, and right. Thanks for the explanation.

Quoted 16 lines
Quoted 8 lines

tools/testing/cxl/test/cxl.c static __init int cxl_test_init(void) · line 1832

Quoted 1 line
tools/testing/cxl/test/cxl.c +1 -0
+	BUILD_BUG_ON(!IS_ALIGNED(MOCK_AUTO_REGION_SIZE_DEFAULT, PMD_SIZE));

The rule we need to enforce is tha the actual auto region size is PMD aligned, not the default definition. So I think this needs to be a runtime check of IS_ALIGNED(mock_auto_region_size, PMD_SIZE).

-- Alison

Thanks for the catch, I'll fix this and send a v4 to make it runtime check.

Do you prefer WARN_ON_ONCE() to be ammend or no? I mean

"""
if (!IS_ALIGNED(mock_auto_region_size, PMD_SIZE))

	return -EINVAL;
Quoted 8 lines

"""
or
"""
if (WARN_ON_ONCE(!IS_ALIGNED(mock_auto_region_size, PMD_SIZE)))

	return -EINVAL;

"""

Which one do you prefer ? or any other idea ? please let me know and I'll make the change.

I don't think we need the backtrace of warn, how about this:

if (!IS_ALIGNED(mock_auto_region_size, PMD_SIZE)) {
    pr_err_once("mock_auto_region_size %d must be PMD-aligned\n",
                mock_auto_region_size);
    return -EINVAL;
}
Quoted 13 lines

Best regards,
Richard Cheng.

Quoted 9 lines
Quoted 9 lines
tools/testing/cxl/test/cxl.c +1 -0
+
 	cxl_acpi_test();
 	cxl_core_test();
 	cxl_mem_test();

base-commit: 6779b50faa562e6cca1aa6a4649a4d764c6c7e28

Signature · 1 line
2.43.0