[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1646461289-31992-4-git-send-email-yangtiezhu@loongson.cn>
Date: Sat, 5 Mar 2022 14:21:28 +0800
From: Tiezhu Yang <yangtiezhu@...ngson.cn>
To: Thomas Bogendoerfer <tsbogend@...ha.franken.de>,
Mike Rapoport <rppt@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>
Cc: Xuefeng Li <lixuefeng@...ngson.cn>, linux-mips@...r.kernel.org,
linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: [PATCH v5 3/4] MIPS: Refactor early_parse_memmap() to fix memmap= parameter
According to Documentation/admin-guide/kernel-parameters.txt,
the kernel command-line parameter memmap= means "Force usage
of a specific region of memory", but when add "memmap=3G@64M"
to the command-line, kernel boot hangs in sparse_init().
In order to support memmap=limit@...e, refactor the function
early_parse_memmap() to limit the memory region.
With this patch, when add "memmap=3G@64M" to the command-line,
the kernel boots successfully, we can see the following messages:
[ 0.000000] Memory limited to 64MB-3136MB
...
[ 0.000000] Early memory node ranges
[ 0.000000] node 0: [mem 0x0000000004000000-0x000000000effffff]
[ 0.000000] node 0: [mem 0x0000000090200000-0x00000000ffffffff]
[ 0.000000] node 0: [mem 0x0000000120000000-0x00000001653fffff]
...
[ 0.000000] Memory: 3070816K/3147776K available (...)
After login, the output of free command is consistent with the
above log.
Signed-off-by: Tiezhu Yang <yangtiezhu@...ngson.cn>
---
arch/mips/kernel/setup.c | 37 ++++++++++++++++++++++---------------
1 file changed, 22 insertions(+), 15 deletions(-)
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index de5824bc..6b7229f 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -361,7 +361,6 @@ early_param("mem", early_parse_mem);
static int __init early_parse_memmap(char *p)
{
char *oldp;
- u64 start_at, mem_size;
if (!p)
return -EINVAL;
@@ -372,30 +371,38 @@ static int __init early_parse_memmap(char *p)
}
oldp = p;
- mem_size = memparse(p, &p);
+ memory_limit = memparse(p, &p) & PAGE_MASK;
if (p == oldp)
return -EINVAL;
if (*p == '@') {
- start_at = memparse(p+1, &p);
- memblock_add(start_at, mem_size);
+ memory_base = memparse(p + 1, &p) & PAGE_MASK;
+ } else if (*p == '$') {
+ memory_base = memparse(p+1, &p) & PAGE_MASK;
+ memblock_reserve(memory_base, memory_limit);
+ pr_notice("Memory reserved to %lluMB-%lluMB\n",
+ (u64)memory_base >> 20, (u64)(memory_base + memory_limit) >> 20);
+ memory_base = 0;
+ memory_limit = 0;
+ return 0;
} else if (*p == '#') {
- pr_err("\"memmap=nn#ss\" (force ACPI data) invalid on MIPS\n");
+ pr_err("\"memmap=nn#ss\" invalid on MIPS\n");
+ memory_limit = 0;
+ return -EINVAL;
+ } else if (*p == '!') {
+ pr_err("\"memmap=nn!ss\" invalid on MIPS\n");
+ memory_limit = 0;
return -EINVAL;
- } else if (*p == '$') {
- start_at = memparse(p+1, &p);
- memblock_add(start_at, mem_size);
- memblock_reserve(start_at, mem_size);
} else {
- pr_err("\"memmap\" invalid format!\n");
+ pr_err("Unrecognized memmap syntax: %s\n", p);
+ memory_limit = 0;
return -EINVAL;
}
- if (*p == '\0') {
- usermem = 1;
- return 0;
- } else
- return -EINVAL;
+ pr_notice("Memory limited to %lluMB-%lluMB\n",
+ (u64)memory_base >> 20, (u64)(memory_base + memory_limit) >> 20);
+
+ return *p == '\0' ? 0 : -EINVAL;
}
early_param("memmap", early_parse_memmap);
--
2.1.0
Powered by blists - more mailing lists