x86/mm: if memblock size is adjusted, update the cached value
RFC PATCH 1/2 x86/mm: if memblock size is adjusted, update the cached value
When parsing CFMWS, we need to know the current block size expected to avoid accidentally adjusting the size upward. This causes a value 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 blocksize is changed at an unexpected time.
--- arch/x86/mm/init_64.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
arch/x86/mm/init_64.c +14 -1
@@ -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 __init set_memory_block_size_order (unsigned int order) {unsigned long size =1UL << order;
@@ -1432,6 +1433,19 @@ int __init 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)
Signature · 1 line
2.43.0
RFC PATCH 2/2 acpi,srat: reduce memory block size if CFMWS has a smaller alignment
The CXL Fixed Memory Window allows for memory aligned down to the size of 256MB. However, by default, memory blocks increase in size as total System RAM capacity increases. On x86, this caps out at 2G when 64GB of System RAM is reached.
When the CFMWS regions are not 2GB aligned, this results in lost capacity on either side of the alignment - regardless of if the memory is mapped as normal system ram or hotplug.
In ACPI, when the CFMWS is parsed, reduce the block size to the smallest amount detected if it is less than 2GB.
--- drivers/acpi/numa/srat.c | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
drivers/acpi/numa/srat.c +44 -0
@@ -14,6 +14,7 @@#include <linux/errno.h> #include <linux/acpi.h> #include <linux/memblock.h> +#include <linux/memory.h> #include <linux/numa.h> #include <linux/nodemask.h> #include <linux/topology.h>
@@ -333,6 +334,35 @@ acpi_parse_memory_affinity(union acpi_subtable_headers *header,return 0 ; } +/* +* CXL allows CFMW to be aligned along 256MB boundaries, but larger +* memory systems typically default to ~2GB memory boundaries for +* memblocks. Calculate the largest supported alignment for all CFMWS. +* +* Only adjust downward if less than 2G, and error on invalid alignment. +*/ +static int __init acpi_align_cfmws (union acpi_subtable_headers *header, +void *arg,const unsigned long table_end) +{ +struct acpi_cedt_cfmws *cfmws = (struct acpi_cedt_cfmws *)header; +u64 start = cfmws->base_hpa; +u64 size = cfmws->window_size; +unsigned long *fin_bz = arg; +unsigned long bz; + +for (bz =SZ_2G ; bz >=SZ_256M ; bz >>=1 ) { +if (IS_ALIGNED (start, bz) &&IS_ALIGNED (size, bz)) +break ; + } + +if (bz < *fin_bz && bz >=SZ_256M ) + *fin_bz = bz; +else if (bz <SZ_256M ) +pr_err ("CFMWS: [BIOS BUG] base/size alignment violates spec\n" ); + +return 0 ; +} +static int __init acpi_parse_cfmws (union acpi_subtable_headers *header,void *arg,const unsigned long table_end) {
@@ -501,6 +531,8 @@ acpi_table_parse_srat(enum acpi_srat_type id,int __init acpi_numa_init (void ) {int i, fake_pxm, cnt =0 ; +unsigned long block_sz =memory_block_size_bytes (); +unsigned long cfmw_align = block_sz;if (acpi_disabled)return -EINVAL ;
@@ -552,6 +584,18 @@ int __init acpi_numa_init(void) } last_real_pxm = fake_pxm; fake_pxm++; + +/* +* First parse the CFMWS to determine if the memory block size +* should be smaller than 2G. We don't care about larger sizes, +* this simply avoids losing memory to smaller alignements. +*/ +acpi_table_parse_cedt (ACPI_CEDT_TYPE_CFMWS , acpi_align_cfmws, + &cfmw_align); +if (cfmw_align < block_sz && cfmw_align >=SZ_256M ) +set_memory_block_size_order (ffs (cfmw_align)-1 ); + +/* Then we need to make a pass to fill the numa nodes */ acpi_table_parse_cedt (ACPI_CEDT_TYPE_CFMWS , acpi_parse_cfmws, &fake_pxm);
Signature · 1 line
2.43.0
kernel test robot
build botRe: [RFC PATCH 2/2] acpi,srat: reduce memory block size if CFMWS has a smaller alignment
kernel test robot noticed the following build errors:
Hi Gregory,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on tip/x86/mm]
[also build test ERROR on rafael-pm/linux-next rafael-pm/bleeding-edge tip/master tip/auto-latest linus/master v6.11 next-20240927] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Gregory-Price/acpi-srat-reduce-memory-block-size-if-CFMWS-has-a-smaller-alignment/20240925-233344 base: tip/x86/mm patch link: https://lore.kernel.org/r/20240925045242.3735-2-gourry%40gourry.net patch subject: [RFC PATCH 2/2] acpi,srat: reduce memory block size if CFMWS has a smaller alignment config: arm64-randconfig-002-20240928 (https://download.01.org/0day-ci/archive/20240928/[email protected]/config) compiler: aarch64-linux-gcc (GCC) 14.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240928/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
aarch64-linux-ld: drivers/acpi/numa/srat.o: in function `acpi_numa_init':
srat.c:(.init.text+0xc10): undefined reference to `set_memory_block_size_order'
>> srat.c:(.init.text+0xc10): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `set_memory_block_size_order'
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [RFC PATCH 2/2] acpi,srat: reduce memory block size if CFMWS has a smaller alignment
In reply to Gregory Pricekernel test robot noticed the following build errors:
Hi Gregory,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on tip/x86/mm]
[also build test ERROR on rafael-pm/linux-next rafael-pm/bleeding-edge tip/master linus/master v6.11 next-20240927] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Gregory-Price/acpi-srat-reduce-memory-block-size-if-CFMWS-has-a-smaller-alignment/20240925-233344 base: tip/x86/mm patch link: https://lore.kernel.org/r/20240925045242.3735-2-gourry%40gourry.net patch subject: [RFC PATCH 2/2] acpi,srat: reduce memory block size if CFMWS has a smaller alignment config: loongarch-allmodconfig (https://download.01.org/0day-ci/archive/20240928/[email protected]/config) compiler: loongarch64-linux-gcc (GCC) 14.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240928/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
loongarch64-linux-ld: drivers/acpi/numa/srat.o: in function `acpi_numa_init':
>> srat.c:(.init.text+0x17c0): undefined reference to `set_memory_block_size_order'
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki