Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1650155pxm; Thu, 24 Feb 2022 07:04:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJz9zb+mQXhgZ372sZQ6qvenKDsz6kdrEXy5w4O/WoPI0MsZAoZXB8eE0gcLFHOYVtU3m/i+ X-Received: by 2002:a17:90a:29c4:b0:1b8:cc9c:134e with SMTP id h62-20020a17090a29c400b001b8cc9c134emr3216662pjd.134.1645715054898; Thu, 24 Feb 2022 07:04:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645715054; cv=none; d=google.com; s=arc-20160816; b=ydtMGvAfzGQ6kTPngfNZYWGcCk1q/bZrQKiVzCQc/zSLsbi3ByvuM2qXdiVk2VnmHf GnA2IRXZsCL7BFfVFxsPFNUvi7RJB7begaM+0yejmpeo9s427vqLZRnJaTEl/AsGIyeq eJqVOWLJ2e1rcoV1Tzs9Rp4Wh2X7w5/tR6RAoRWl7nYyM5iekuCkkL7I2AAsrW7939lF CFanDJvUoumI+KyLvX/zNuX33gnFdLoTCH4+8+P7//ag7j2M1GxVuKnZXzdorrQnHSxx tE8qSl4UBemqp/u1k9nFhszKaG4i6sKtTvonmXSZswGsmZOE1n5BoxHCDJysunJsZRWO KH+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=Z2oTxzdN0yWHQ7j8eHPdHsbUT4/VvET5TZMjkyM9pvE=; b=lgldNhu9s+J8AOsNJsx2GNpnNuM17PiBy2bWTRK7sd2TuMCjlTXoztmLTt4tXj4KAt ePSsYPkX6H+B7lWt7dqP2331burO99hjGkLPszYObSsLXG6Vc9ozY+4t7qtNKX3hu4Wi 9U8pVMOrprGfbqYazBPGaM0PpLs3zxiDzfw9Z+IKjAa0uUZxybq3Pw+q3Sx5BKZky9lb XM3AjMI5LXMWqaLbFjwHtryvxrseLTnUXOXzZl8DnSMiM8kN0gYKV4OtDCkI959Ez879 mgqI30o9SX2bLmaCZYe9/llizm+OY4F8DTmo/OJlziPgrd/NIr79+k5o0uBfV7Y3VzfK aGeA== 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 r33si2539856pgm.351.2022.02.24.07.03.53; Thu, 24 Feb 2022 07:04:14 -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 S234577AbiBXMwt (ORCPT + 99 others); Thu, 24 Feb 2022 07:52:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234489AbiBXMwr (ORCPT ); Thu, 24 Feb 2022 07:52:47 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 900AA20D527 for ; Thu, 24 Feb 2022 04:52:15 -0800 (PST) Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9DxSMl8fxdizHIGAA--.7452S2; Thu, 24 Feb 2022 20:52:13 +0800 (CST) From: Tiezhu Yang To: Thomas Bogendoerfer Cc: Xuefeng Li , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] MIPS: Refactor early_parse_mem() to fix mem= parameter Date: Thu, 24 Feb 2022 20:52:12 +0800 Message-Id: <1645707132-10121-1-git-send-email-y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jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7VUUJ733UUUUU== 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 mem= means "Force usage of a specific amount of memory", but when add "mem=3G" to the command-line, kernel boot hangs in sparse_init(). This commit is similar with the implementation of the other archs such as arm64, powerpc and riscv, refactor the function early_parse_mem() and then use memblock_enforce_memory_limit() to limit the memory size. With this patch, when add "mem=3G" to the command-line, the kernel boots successfully, we can see the following messages: [ 0.000000] Memory limited to 3072MB ... [ 0.000000] Memory: 2991952K/3145728K available (...) After login, the output of free command is consistent with the above log. Signed-off-by: Tiezhu Yang --- arch/mips/kernel/setup.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index f979adf..2917412 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -339,27 +339,15 @@ static void __init bootmem_init(void) #endif /* CONFIG_SGI_IP27 */ static int usermem __initdata; +static phys_addr_t memory_limit; static int __init early_parse_mem(char *p) { - phys_addr_t start, size; - - /* - * If a user specifies memory size, we - * blow away any automatically generated - * size. - */ - if (usermem == 0) { - usermem = 1; - memblock_remove(memblock_start_of_DRAM(), - memblock_end_of_DRAM() - memblock_start_of_DRAM()); - } - start = 0; - size = memparse(p, &p); - if (*p == '@') - start = memparse(p + 1, &p); + if (!p) + return 1; - memblock_add(start, size); + memory_limit = memparse(p, &p) & PAGE_MASK; + pr_notice("Memory limited to %lldMB\n", memory_limit >> 20); return 0; } @@ -633,6 +621,9 @@ static void __init arch_mem_init(char **cmdline_p) parse_early_param(); + /* Limit the memory size via mem= command-line parameter */ + memblock_enforce_memory_limit(memory_limit); + if (usermem) pr_info("User-defined physical RAM map overwrite\n"); -- 2.1.0