powerpc/mm: Align memory_limit value specified using mem= kernel parameter
authorAneesh Kumar K.V (IBM) <aneesh.kumar@kernel.org>
Wed, 3 Apr 2024 08:36:09 +0000 (14:06 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Fri, 19 Apr 2024 06:09:14 +0000 (16:09 +1000)
The value specified for the memory limit is used to set a restriction on
memory usage. It is important to ensure that this restriction is within
the linear map kernel address space range. The hash page table
translation uses a 16MB page size to map the kernel linear map address
space. htab_bolt_mapping() function aligns down the size of the range
while mapping kernel linear address space. Since the memblock limit is
enforced very early during boot, before we can detect the type of memory
translation (radix vs hash), we align the memory limit value specified
as a kernel parameter to 16MB. This alignment value will work for both
hash and radix translations.

Signed-off-by: Aneesh Kumar K.V (IBM) <aneesh.kumar@kernel.org>
Acked-by: Joel Savitz <jsavitz@redhat.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20240403083611.172833-1-aneesh.kumar@kernel.org
arch/powerpc/kernel/prom.c
arch/powerpc/kernel/prom_init.c

index cd8d8883de90409bb77691302b6d378be8f25c6f..7451bedad1f43ea7c4cb57907f7479ae31a8551b 100644 (file)
@@ -846,8 +846,11 @@ void __init early_init_devtree(void *params)
                reserve_crashkernel();
        early_reserve_mem();
 
-       /* Ensure that total memory size is page-aligned. */
-       limit = ALIGN(memory_limit ?: memblock_phys_mem_size(), PAGE_SIZE);
+       if (memory_limit > memblock_phys_mem_size())
+               memory_limit = 0;
+
+       /* Align down to 16 MB which is large page size with hash page translation */
+       limit = ALIGN_DOWN(memory_limit ?: memblock_phys_mem_size(), SZ_16M);
        memblock_enforce_memory_limit(limit);
 
 #if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_PPC_4K_PAGES)
index 0ef358285337412f14dcf073282bca863dc88949..fbb68fc28ed3a534be5b42214fa0c0fdba5ba4ca 100644 (file)
@@ -817,8 +817,8 @@ static void __init early_cmdline_parse(void)
                opt += 4;
                prom_memory_limit = prom_memparse(opt, (const char **)&opt);
 #ifdef CONFIG_PPC64
-               /* Align to 16 MB == size of ppc64 large page */
-               prom_memory_limit = ALIGN(prom_memory_limit, 0x1000000);
+               /* Align down to 16 MB which is large page size with hash page translation */
+               prom_memory_limit = ALIGN_DOWN(prom_memory_limit, SZ_16M);
 #endif
        }