Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp130820pxp; Fri, 4 Mar 2022 23:48:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJwL2tv0gxY6iLelg5kMZ8e8XBDUz8sHU28CLz373a8VcWHE9Pas9GkEmq8G7FHrTNMRNZd/ X-Received: by 2002:a17:906:5a94:b0:6c5:5aa4:da87 with SMTP id l20-20020a1709065a9400b006c55aa4da87mr1975187ejq.381.1646466519621; Fri, 04 Mar 2022 23:48:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646466519; cv=none; d=google.com; s=arc-20160816; b=u74v6Bfi4i/fsA/8MypoVSpJXZfYly5QG/KYwcSoypcWp/QvRHUAyqynZtVLHRUzTD ogVqCgOZIRh23db622r3EVyhFaLIZpPKc9anuDl1aTIfi4mPa/RI+bAP2j6UTWNMjrmZ o8yN0r2ZlNqXihkaYCC4zR8no2UWHwJm9hOwxS7vYuVSfDl9m6EGj4FxyX+/3l/M+1pF dEvdq2sAkKvHZWYXAbY7TGKy90LFKtEGvFzFJ6iot7WpNkQP29qmIiexOgCu8r8nsjmf UnloDDOxZYirpIhU+102P8S5XKmvFCh+CU/JqPId9dsthud8D/gRpERpb9lWYoEF7wSA aSSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=6ILwZqFkvegxZ62h8Vse6I3fne6wDM4Ma9YV4MReyO0=; b=VIPchyYugB7ZGVoC51AuhrHtTJwOUJbBPC6IwVvCGCe+ebMSZ9TP3zgJSpyfbwPfbo cW/GfdeFy+/ED4siPWHgLco96yeWvGcPA7JdfdThCfWqmqZaPo7eXJQzQdibNIOlBwZ/ WvHZsZv3E4iTkK+F6N55XN6yQj/cqYPHIfAlpXvw/X2wSeouFMvVOgPgNb/2JHed1y3H CBuVK2zq5k0fIn0S2sweb5gUlirI7HkEMV9fMFZXXr7ONgOucP+eauuQj0oCdoP4w+9Z bHLg1V5/bHp8XHjisYpBM+L+9XBTCR7fKNbPgoMBs++E/BRu4lbvbVkVJ8di9GdKwJEt 8O4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id js8-20020a17090797c800b006d6dc43f6ecsi5596679ejc.333.2022.03.04.23.48.15; Fri, 04 Mar 2022 23:48:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231374AbiCEGWc (ORCPT + 99 others); Sat, 5 Mar 2022 01:22:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231345AbiCEGWZ (ORCPT ); Sat, 5 Mar 2022 01:22:25 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A58C854BF7; Fri, 4 Mar 2022 22:21:35 -0800 (PST) Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxGs1pASNiBh4DAA--.2113S5; Sat, 05 Mar 2022 14:21:31 +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 v5 3/4] MIPS: Refactor early_parse_memmap() to fix memmap= parameter Date: Sat, 5 Mar 2022 14:21:28 +0800 Message-Id: <1646461289-31992-4-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1646461289-31992-1-git-send-email-yangtiezhu@loongson.cn> References: <1646461289-31992-1-git-send-email-yangtiezhu@loongson.cn> X-CM-TRANSID: AQAAf9AxGs1pASNiBh4DAA--.2113S5 X-Coremail-Antispam: 1UD129KBjvJXoWxCF17tw4rKFW8Ar18GrWkXrb_yoW5AF13pr 1furWSkr48tFnrJr1ftrn7u34Yyw1vkF4UGay2krn5Jwn8Jr18Aw1rWFW7KFyfJr1UA3Wj qFs8tFy09ws2kw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBv14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1l84 ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxVW8Jr0_Cr1U M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r106r15McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkIecxEwVAFwVW8AwCF04 k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18 MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr4 1lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1l IxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4 A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JU3kuxUUUUU= X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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() 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 --- 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