When parsing CFMWS, we need to know the currently registered memory
block size to avoid accidentally adjusting the size upward. Querying
the size causes it to be cached in a static global. Update the static
global if the value is subsequently updated.
Print a warning that this has occurred for debugging purposes if
the memory block size is changed at an unexpected time (post-init).
Signed-off-by: Gregory Price <gourry@gourry.net>
---
arch/x86/mm/init_64.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index 6086f99449fa..733dfa899232 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -1424,6 +1424,7 @@ void mark_rodata_ro(void)
/* Adjustable memory block size */
static unsigned long set_memory_block_size;
+static unsigned long memory_block_size_probed;
int set_memory_block_size_order(unsigned int order)
{
unsigned long size = 1UL << order;
@@ -1432,6 +1433,19 @@ int set_memory_block_size_order(unsigned int order)
return -EINVAL;
set_memory_block_size = size;
+
+ /*
+ * If the block size has already been probed, we need to change it.
+ * This can happen during ACPI/CFMWS parsing, since it needs to
+ * probe the system for the existing block size to avoid increasing
+ * the block size if lower memory happens to be misaligned
+ */
+ if (memory_block_size_probed) {
+ memory_block_size_probed = size;
+ pr_warn("x86/mm: Memory block size changed: %ldMB\n",
+ size >> 20);
+ }
+
return 0;
}
@@ -1471,7 +1485,6 @@ static unsigned long probe_memory_block_size(void)
return bz;
}
-static unsigned long memory_block_size_probed;
unsigned long memory_block_size_bytes(void)
{
if (!memory_block_size_probed)
--
2.43.0