public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/e820: apply 'mem=' boot command while reserving memory using boot_params
@ 2024-04-23 10:13 Byungchul Park
  2024-04-23 10:23 ` Byungchul Park
  0 siblings, 1 reply; 6+ messages in thread
From: Byungchul Park @ 2024-04-23 10:13 UTC (permalink / raw)
  To: tglx, mingo, bp, dave.hansen, x86, hpa, jbohac, dyoung
  Cc: kernel_team, linux-kernel

I might miss something.  Please lemme know if I go wrong.  Thanks.

	Byungchul

--->8---
From 51f3b5b9bf9685aa431c00908771151edd702483 Mon Sep 17 00:00:00 2001
From: Byungchul Park <byungchul@sk.com>
Date: Tue, 23 Apr 2024 18:54:48 +0900
Subject: [PATCH] x86/e820: apply 'mem=' boot command while reserving memory
 using boot_params

When a user specifies 'mem=' boot command, it's expected to limit the
maximum address of usable memory for the kernel no matter what the
memory map source is.  However, 'mem=' boot command doesn't work since
it doesn't respect it when reserving memory using boot_params.

Applied the restriction when reserving memory using boot_params.  While
at it, renamed mem_size to a more specific name, boot_mem_limit.

Signed-off-by: Byungchul Park <byungchul@sk.com>
---
 arch/x86/kernel/e820.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 6f1b379e3b38..af9d1d95ef5a 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -880,11 +880,11 @@ static void __init early_panic(char *msg)
 
 static int userdef __initdata;
 
+static u64 boot_mem_limit = U64_MAX;
+
 /* The "mem=nopentium" boot option disables 4MB page tables on 32-bit kernels: */
 static int __init parse_memopt(char *p)
 {
-	u64 mem_size;
-
 	if (!p)
 		return -EINVAL;
 
@@ -899,16 +899,16 @@ static int __init parse_memopt(char *p)
 	}
 
 	userdef = 1;
-	mem_size = memparse(p, &p);
+	boot_mem_limit = memparse(p, &p);
 
 	/* Don't remove all memory when getting "mem={invalid}" parameter: */
-	if (mem_size == 0)
+	if (boot_mem_limit == 0)
 		return -EINVAL;
 
-	e820__range_remove(mem_size, ULLONG_MAX - mem_size, E820_TYPE_RAM, 1);
+	e820__range_remove(boot_mem_limit, ULLONG_MAX - boot_mem_limit, E820_TYPE_RAM, 1);
 
 #ifdef CONFIG_MEMORY_HOTPLUG
-	max_mem_size = mem_size;
+	max_mem_size = boot_mem_limit;
 #endif
 
 	return 0;
@@ -1036,6 +1036,8 @@ void __init e820__reserve_setup_data(void)
 		early_memunmap(data, len);
 	}
 
+	e820__range_remove(boot_mem_limit, ULLONG_MAX - boot_mem_limit,
+			E820_TYPE_RESERVED_KERN, 1);
 	e820__update_table(e820_table);
 
 	pr_info("extended physical RAM map:\n");
-- 
2.17.1


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

end of thread, other threads:[~2024-05-21  4:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-23 10:13 [PATCH] x86/e820: apply 'mem=' boot command while reserving memory using boot_params Byungchul Park
2024-04-23 10:23 ` Byungchul Park
2024-04-24  1:03   ` [PATCH v2] " Byungchul Park
2024-04-26  4:40     ` Byungchul Park
2024-04-26 16:52       ` H. Peter Anvin
2024-05-21  4:19         ` Byungchul Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox