linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter
@ 2024-04-03  8:36 Aneesh Kumar K.V (IBM)
  2024-04-03  8:36 ` [PATCH 2/3] powerpc/fadump: Don't update the user-specified memory limit Aneesh Kumar K.V (IBM)
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Aneesh Kumar K.V (IBM) @ 2024-04-03  8:36 UTC (permalink / raw)
  To: linuxppc-dev, mpe, npiggin, christophe.leroy
  Cc: Aneesh Kumar K.V (IBM), Naveen N Rao

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

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
 	}
 

base-commit: 3e92c1e6cd876754b64d1998ec0a01800ed954a6
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] powerpc/fadump: Don't update the user-specified memory limit
  2024-04-03  8:36 [PATCH 1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter Aneesh Kumar K.V (IBM)
@ 2024-04-03  8:36 ` Aneesh Kumar K.V (IBM)
  2024-04-03  8:36 ` [PATCH 3/3] powerpc/mm: Update the memory limit based on direct mapping restrictions Aneesh Kumar K.V (IBM)
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Aneesh Kumar K.V (IBM) @ 2024-04-03  8:36 UTC (permalink / raw)
  To: linuxppc-dev, mpe, npiggin, christophe.leroy
  Cc: Aneesh Kumar K.V (IBM), Naveen N Rao, Mahesh Salgaonkar

If the user specifies the memory limit, the kernel should honor it such
that all allocation and reservations are made within the memory limit
specified. fadump was breaking that rule. Remove the code which updates
the memory limit such that fadump reservations are done within the
limit specified.

Cc: Mahesh Salgaonkar <mahesh@linux.ibm.com> 
Signed-off-by: Aneesh Kumar K.V (IBM) <aneesh.kumar@kernel.org>
---
 arch/powerpc/kernel/fadump.c | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index d14eda1e8589..4e768d93c6d4 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -573,22 +573,6 @@ int __init fadump_reserve_mem(void)
 		}
 	}
 
-	/*
-	 * Calculate the memory boundary.
-	 * If memory_limit is less than actual memory boundary then reserve
-	 * the memory for fadump beyond the memory_limit and adjust the
-	 * memory_limit accordingly, so that the running kernel can run with
-	 * specified memory_limit.
-	 */
-	if (memory_limit && memory_limit < memblock_end_of_DRAM()) {
-		size = get_fadump_area_size();
-		if ((memory_limit + size) < memblock_end_of_DRAM())
-			memory_limit += size;
-		else
-			memory_limit = memblock_end_of_DRAM();
-		printk(KERN_INFO "Adjusted memory_limit for firmware-assisted"
-				" dump, now %#016llx\n", memory_limit);
-	}
 	if (memory_limit)
 		mem_boundary = memory_limit;
 	else
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] powerpc/mm: Update the memory limit based on direct mapping restrictions
  2024-04-03  8:36 [PATCH 1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter Aneesh Kumar K.V (IBM)
  2024-04-03  8:36 ` [PATCH 2/3] powerpc/fadump: Don't update the user-specified memory limit Aneesh Kumar K.V (IBM)
@ 2024-04-03  8:36 ` Aneesh Kumar K.V (IBM)
  2024-04-17 14:36 ` [PATCH 1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter Joel Savitz
  2024-05-03 10:41 ` Michael Ellerman
  3 siblings, 0 replies; 8+ messages in thread
From: Aneesh Kumar K.V (IBM) @ 2024-04-03  8:36 UTC (permalink / raw)
  To: linuxppc-dev, mpe, npiggin, christophe.leroy
  Cc: Aneesh Kumar K.V (IBM), Naveen N Rao

memory limit value specified by the user are further updated such that
the value is 16MB aligned. This is because hash translation mode use
16MB as direct mapping page size. Make sure we update the global
variable 'memory_limit' with the 16MB aligned value such that all kernel
components will see the new aligned value of the memory limit.

Signed-off-by: Aneesh Kumar K.V (IBM) <aneesh.kumar@kernel.org>
---
 arch/powerpc/kernel/prom.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index 7451bedad1f4..b8f764453eaa 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -779,7 +779,6 @@ static inline void save_fscr_to_task(void) {}
 
 void __init early_init_devtree(void *params)
 {
-	phys_addr_t limit;
 
 	DBG(" -> early_init_devtree(%px)\n", params);
 
@@ -850,8 +849,8 @@ void __init early_init_devtree(void *params)
 		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);
+	memory_limit = ALIGN_DOWN(memory_limit ?: memblock_phys_mem_size(), SZ_16M);
+	memblock_enforce_memory_limit(memory_limit);
 
 #if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_PPC_4K_PAGES)
 	if (!early_radix_enabled())
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter
  2024-04-03  8:36 [PATCH 1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter Aneesh Kumar K.V (IBM)
  2024-04-03  8:36 ` [PATCH 2/3] powerpc/fadump: Don't update the user-specified memory limit Aneesh Kumar K.V (IBM)
  2024-04-03  8:36 ` [PATCH 3/3] powerpc/mm: Update the memory limit based on direct mapping restrictions Aneesh Kumar K.V (IBM)
@ 2024-04-17 14:36 ` Joel Savitz
  2024-05-02 19:20   ` Joel Savitz
  2024-05-03 10:41 ` Michael Ellerman
  3 siblings, 1 reply; 8+ messages in thread
From: Joel Savitz @ 2024-04-17 14:36 UTC (permalink / raw)
  To: aneesh.kumar; +Cc: naveen, npiggin, linuxppc-dev, Joel Savitz

Acked-by: Joel Savitz <jsavitz@redhat.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter
  2024-04-17 14:36 ` [PATCH 1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter Joel Savitz
@ 2024-05-02 19:20   ` Joel Savitz
  2024-05-03  2:20     ` Michael Ellerman
  0 siblings, 1 reply; 8+ messages in thread
From: Joel Savitz @ 2024-05-02 19:20 UTC (permalink / raw)
  To: aneesh.kumar; +Cc: linuxppc-dev, naveen, npiggin

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter
  2024-05-02 19:20   ` Joel Savitz
@ 2024-05-03  2:20     ` Michael Ellerman
  2024-05-03 19:59       ` Joel Savitz
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Ellerman @ 2024-05-03  2:20 UTC (permalink / raw)
  To: Joel Savitz, aneesh.kumar; +Cc: linuxppc-dev, naveen, npiggin

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter
  2024-04-03  8:36 [PATCH 1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter Aneesh Kumar K.V (IBM)
                   ` (2 preceding siblings ...)
  2024-04-17 14:36 ` [PATCH 1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter Joel Savitz
@ 2024-05-03 10:41 ` Michael Ellerman
  3 siblings, 0 replies; 8+ messages in thread
From: Michael Ellerman @ 2024-05-03 10:41 UTC (permalink / raw)
  To: linuxppc-dev, mpe, npiggin, christophe.leroy,
	Aneesh Kumar K.V (IBM)
  Cc: Naveen N Rao

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter
  2024-05-03  2:20     ` Michael Ellerman
@ 2024-05-03 19:59       ` Joel Savitz
  0 siblings, 0 replies; 8+ messages in thread
From: Joel Savitz @ 2024-05-03 19:59 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: aneesh.kumar, linuxppc-dev, naveen, npiggin

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-05-03 20:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-03  8:36 [PATCH 1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter Aneesh Kumar K.V (IBM)
2024-04-03  8:36 ` [PATCH 2/3] powerpc/fadump: Don't update the user-specified memory limit Aneesh Kumar K.V (IBM)
2024-04-03  8:36 ` [PATCH 3/3] powerpc/mm: Update the memory limit based on direct mapping restrictions Aneesh Kumar K.V (IBM)
2024-04-17 14:36 ` [PATCH 1/3] powerpc/mm: Align memory_limit value specified using mem= kernel parameter Joel Savitz
2024-05-02 19:20   ` Joel Savitz
2024-05-03  2:20     ` Michael Ellerman
2024-05-03 19:59       ` Joel Savitz
2024-05-03 10:41 ` Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).