From patchwork Mon Feb 28 06:31:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiezhu Yang X-Patchwork-Id: 12762404 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9771C433F5 for ; Mon, 28 Feb 2022 06:31:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94A438D0003; Mon, 28 Feb 2022 01:31:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8846D8D0001; Mon, 28 Feb 2022 01:31:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79A828D0006; Mon, 28 Feb 2022 01:31:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 690468D0001 for ; Mon, 28 Feb 2022 01:31:13 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3FB4C22F17 for ; Mon, 28 Feb 2022 06:31:13 +0000 (UTC) X-FDA: 79191216426.07.86D182A Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by imf22.hostedemail.com (Postfix) with ESMTP id 9F9C8C000B for ; Mon, 28 Feb 2022 06:31:11 +0000 (UTC) Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9DxGMkrbBxiQxMIAA--.10334S5; Mon, 28 Feb 2022 14:31:08 +0800 (CST) From: Tiezhu Yang To: Thomas Bogendoerfer , Mike Rapoport , Andrew Morton Cc: Xuefeng Li , linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] MIPS: Refactor early_parse_memmap() to fix memmap= parameter Date: Mon, 28 Feb 2022 14:31:05 +0800 Message-Id: <1646029866-6692-4-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1646029866-6692-1-git-send-email-yangtiezhu@loongson.cn> References: <1646029866-6692-1-git-send-email-yangtiezhu@loongson.cn> X-CM-TRANSID: AQAAf9DxGMkrbBxiQxMIAA--.10334S5 X-Coremail-Antispam: 1UD129KBjvJXoWxCF17tw4rKFW8Ar18GrWkXrb_yoWrJrW7pw 1SvrWakr48JF9rJry8tr1kW345Jw1vkFWUGay2krn5Awn8Cr1UJ3yrWFWIkry2qryUJ3W2 qFs5tFW5Kw4Ikw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBv14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkIecxEwVAFwVW8AwCF04 k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18 MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr4 1lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1l IxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4 A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUyuWLUUUUU= X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9F9C8C000B X-Stat-Signature: dkoy6uiuzdpb6stc691m6npqsf5a1mdh Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of yangtiezhu@loongson.cn designates 114.242.206.163 as permitted sender) smtp.mailfrom=yangtiezhu@loongson.cn; dmarc=none X-Rspam-User: X-HE-Tag: 1646029871-606308 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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@base, refactor the function early_parse_memmap() and then use memblock_mem_range_remove_map() 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 (...) When add "memmap=128M@64M nr_cpus=1 init 3" to the command-line, the kernel also boots successfully, we can see the following messages: [ 0.000000] Memory limited to 64MB-192MB ... [ 0.000000] Early memory node ranges [ 0.000000] node 0: [mem 0x0000000004000000-0x000000000c1fffff] ... [ 0.000000] Memory: 95312K/133120K available (...) After login, the output of free command is consistent with the above log. By the way, this commit only supports memmap=limit@base format, the other formats such as memmap=limit#base, memmap=limit$base and memmap=limit!base can be added if they are necessary in the future. Signed-off-by: Tiezhu Yang --- arch/mips/kernel/setup.c | 42 +++++++++--------------------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 6b6d718..e3b1f2e 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -340,6 +340,7 @@ static void __init bootmem_init(void) static int usermem __initdata; static phys_addr_t memory_limit; +static phys_addr_t memory_base; static int __init early_parse_mem(char *p) { @@ -355,42 +356,17 @@ 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; + return 1; - if (!strncmp(p, "exactmap", 8)) { - pr_err("\"memmap=exactmap\" invalid on MIPS\n"); - return 0; - } + memory_limit = memparse(p, &p) & PAGE_MASK; + if (*p == '@') + memory_base = memparse(p + 1, &p) & PAGE_MASK; - oldp = p; - mem_size = memparse(p, &p); - if (p == oldp) - return -EINVAL; - - if (*p == '@') { - start_at = memparse(p+1, &p); - memblock_add(start_at, mem_size); - } else if (*p == '#') { - pr_err("\"memmap=nn#ss\" (force ACPI data) invalid on MIPS\n"); - 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"); - return -EINVAL; - } + pr_notice("Memory limited to %lldMB-%lldMB\n", + memory_base >> 20, (memory_base + memory_limit) >> 20); - if (*p == '\0') { - usermem = 1; - return 0; - } else - return -EINVAL; + return 0; } early_param("memmap", early_parse_memmap); @@ -667,7 +643,7 @@ static void __init arch_mem_init(char **cmdline_p) __pa_symbol(&__nosave_end) - __pa_symbol(&__nosave_begin)); /* Limit the memory. */ - memblock_enforce_memory_limit(memory_limit); + memblock_mem_range_remove_map(memory_base, memory_limit); memblock_allow_resize(); early_memtest(PFN_PHYS(ARCH_PFN_OFFSET), PFN_PHYS(max_low_pfn));