Skip to contentSkip to conversation

cxl/test: Enforce PMD alignment for volatile mock regions

PATCH Superseded Richard Cheng 3 participants 4 messages May 21 – May 22 CXL

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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() -> alloca_dax_region() fails:

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

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

---
Changelog:

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()

v1 link: https://lore.kernel.org/r/[email protected]/

Best regards,
Richard Cheng.

---
 tools/testing/cxl/test/cxl.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
tools/testing/cxl/test/cxl.c +7 -2
index 418669927fb0..09c309af5fd1 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,17 @@ 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 +1834,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();
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 11 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() -> alloca_dax_region() fails:

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

Quoted 6 lines

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

Hi Richard,
I can't seem to apply this patch against v7.1-rc4. What base did you use?

DJ

Quoted 56 lines

---
Changelog:

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()

v1 link: https://lore.kernel.org/r/[email protected]/

Best regards,
Richard Cheng.

---
 tools/testing/cxl/test/cxl.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
tools/testing/cxl/test/cxl.c +7 -2
index 418669927fb0..09c309af5fd1 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,17 @@ 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 +1834,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();
maintainer
#2 lore raw
Quoted 17 lines · Dave Jiang
Quoted 14 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() -> alloca_dax_region() fails:

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

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

Quoted 6 lines
Quoted 3 lines

Hi Richard,
I can't seem to apply this patch against v7.1-rc4. What base did you use?

Hunk headers are wrong. Maybe hand editing without reformatting. Diffstat is wrong too but that didn't affect application.

I'll wait for the v3.

Quoted 62 lines

DJ

Quoted 56 lines

---
Changelog:

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()

v1 link: https://lore.kernel.org/r/[email protected]/

Best regards,
Richard Cheng.

---
 tools/testing/cxl/test/cxl.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
tools/testing/cxl/test/cxl.c +7 -2
index 418669927fb0..09c309af5fd1 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,17 @@ 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 +1834,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();
#3 lore raw
Quoted 22 lines · Alison Schofield
Quoted 21 lines · Dave Jiang
Quoted 17 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() -> alloca_dax_region() fails:

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

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

Quoted 9 lines
Quoted 2 lines

Hi Richard,
I can't seem to apply this patch against v7.1-rc4. What base did you use?

Hunk headers are wrong. Maybe hand editing without reformatting. Diffstat is wrong too but that didn't affect application.

I'll wait for the v3.

Hi Dave, Alison,

Sorry I hand eddited the sequence of this line
+ .window_size = SZ_256M > PMD_SIZE ? SZ_256M : PMD_SIZE,
without reformat the patch.
I've sent a v3 with base commit SHA as well. Please take a look while you're available, thanks!

Best regards,
Richard Cheng.

Quoted 62 lines
Quoted 62 lines

DJ

Quoted 56 lines

---
Changelog:

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()

v1 link: https://lore.kernel.org/r/[email protected]/

Best regards,
Richard Cheng.

---
 tools/testing/cxl/test/cxl.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
tools/testing/cxl/test/cxl.c +7 -2
index 418669927fb0..09c309af5fd1 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,17 @@ 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 +1834,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();