diff mbox series

[1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter

Message ID 20240403083611.172833-1-aneesh.kumar@kernel.org (mailing list archive)
State Accepted
Commit 5ca096161cdccfa328acf6704a4615528471d309
Headers show
Series [1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter | expand

Commit Message

Aneesh Kumar K.V April 3, 2024, 8:36 a.m. UTC
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>
---
 arch/powerpc/kernel/prom.c      | 7 +++++--
 arch/powerpc/kernel/prom_init.c | 4 ++--
 2 files changed, 7 insertions(+), 4 deletions(-)


base-commit: 3e92c1e6cd876754b64d1998ec0a01800ed954a6

Comments

Joel Savitz April 17, 2024, 2:36 p.m. UTC | #1
Acked-by: Joel Savitz <jsavitz@redhat.com>
Joel Savitz May 2, 2024, 7:20 p.m. UTC | #2
On Wed, Apr 17, 2024 at 10:36 AM Joel Savitz <jsavitz@redhat.com> wrote:
>
> Acked-by: Joel Savitz <jsavitz@redhat.com>
>

Hi,

What is the status of this? This patch fixes a bug where a powerpc
machine hangs at boot when passed an unaligned value in the mem=
kernel parameter.
Best,
Joel Savitz
Michael Ellerman May 3, 2024, 2:20 a.m. UTC | #3
Joel Savitz <jsavitz@redhat.com> writes:
> On Wed, Apr 17, 2024 at 10:36 AM Joel Savitz <jsavitz@redhat.com> wrote:
>>
>> Acked-by: Joel Savitz <jsavitz@redhat.com>
>>
>
> Hi,
>
> What is the status of this? This patch fixes a bug where a powerpc
> machine hangs at boot when passed an unaligned value in the mem=
> kernel parameter.

It's in linux-next for v6.10

cheers
Michael Ellerman May 3, 2024, 10:41 a.m. UTC | #4
On Wed, 03 Apr 2024 14:06:09 +0530, Aneesh Kumar K.V (IBM) wrote:
> 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.
> 
> [...]

Applied to powerpc/next.

[1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter
      https://git.kernel.org/powerpc/c/5ca096161cdccfa328acf6704a4615528471d309
[2/3] powerpc/fadump: Don't update the user-specified memory limit
      https://git.kernel.org/powerpc/c/f94f5ac07983cb53de0c964f5428366c19e81993
[3/3] powerpc/mm: Update the memory limit based on direct mapping restrictions
      https://git.kernel.org/powerpc/c/5a799af9522641517f6d871d9f56e2658ee7db58

cheers
Joel Savitz May 3, 2024, 7:59 p.m. UTC | #5
On Thu, May 2, 2024 at 10:20 PM Michael Ellerman <mpe@ellerman.id.au> wrote:
>
> Joel Savitz <jsavitz@redhat.com> writes:
> > On Wed, Apr 17, 2024 at 10:36 AM Joel Savitz <jsavitz@redhat.com> wrote:
> >>
> >> Acked-by: Joel Savitz <jsavitz@redhat.com>
> >>
> >
> > Hi,
> >
> > What is the status of this? This patch fixes a bug where a powerpc
> > machine hangs at boot when passed an unaligned value in the mem=
> > kernel parameter.
>
> It's in linux-next for v6.10
>
> cheers
>

Thanks!

Best,
Joel Savitz
diff mbox series

Patch

diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index cd8d8883de90..7451bedad1f4 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -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)
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index 0ef358285337..fbb68fc28ed3 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -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
 	}