From: Yanteng Si <si.yanteng@linux.dev>
To: Ming Wang <wangming01@loongson.cn>,
Huacai Chen <chenhuacai@kernel.org>,
WANG Xuerui <kernel@xen0n.name>,
Andrew Morton <akpm@linux-foundation.org>,
Bibo Mao <maobibo@loongson.cn>,
Hari Bathini <hbathini@linux.ibm.com>,
Guo Weikang <guoweikang.kernel@gmail.com>,
Sourabh Jain <sourabhjain@linux.ibm.com>,
Usama Arif <usamaarif642@gmail.com>,
loongarch@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: lixuefeng@loongson.cn, chenhuacai@loongson.cn, gaojuxin@loongson.cn
Subject: Re: [PATCH] LoongArch: Support mem=SIZE kernel parameter
Date: Wed, 2 Jul 2025 10:11:48 +0800 [thread overview]
Message-ID: <0561da2c-a4d7-49bb-8394-930f10880610@linux.dev> (raw)
In-Reply-To: <20250701090449.2426151-1-wangming01@loongson.cn>
在 7/1/25 5:04 PM, Ming Wang 写道:
> The LoongArch mem= parameter parser was previously limited to the
> mem=SIZE@START format. This was inconvenient for the common use case
> of simply capping the total system memory, as it forced users to
> manually specify a start address. It was also inconsistent with the
> behavior on other architectures.
>
> This patch enhances the parser in early_parse_mem() to also support the
> more user-friendly mem=SIZE format. The implementation now checks for
> the presence of the '@' symbol to determine the user's intent:
>
> - If mem=SIZE is provided (no '@'), the kernel now calls
> memblock_enforce_memory_limit(). This trims memory from the top down
> to the specified size.
> - If mem=SIZE@START is used, the original behavior is retained for
> backward compatibility. This allows for defining specific memory
> banks.
>
> This change introduces an important usage rule reflected in the code's
> comments: the mem=SIZE format should only be specified once on the
> kernel command line. It acts as a single, global cap on total memory. In
> contrast, the mem=SIZE@START format can be used multiple times to
> define several distinct memory regions.
>
> Signed-off-by: Ming Wang <wangming01@loongson.cn>
> ---
> arch/loongarch/kernel/setup.c | 18 ++++++++++--------
> 1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c
> index b99fbb388fe0..af59ba180dc2 100644
> --- a/arch/loongarch/kernel/setup.c
> +++ b/arch/loongarch/kernel/setup.c
> @@ -191,6 +191,16 @@ static int __init early_parse_mem(char *p)
> return -EINVAL;
> }
>
> + start = 0;
> + size = memparse(p, &p);
> + if (*p == '@') /* Every mem=... should contain '@' */
> + start = memparse(p + 1, &p);
> + else { /* Only one mem=... is allowed if no '@' */
> + usermem = 1;
> + memblock_enforce_memory_limit(size);
> + return 0;
> + }
> +
> /*
> * If a user specifies memory size, we
> * blow away any automatically generated
> @@ -201,14 +211,6 @@ static int __init early_parse_mem(char *p)
> 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);
> - else {
> - pr_err("Invalid format!\n");
> - return -EINVAL;
> - }
I don't understand. Isn't it better to modify the else{} directly here?
Thanks,
Yanteng
next prev parent reply other threads:[~2025-07-02 2:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-01 9:04 Ming Wang
2025-07-02 2:11 ` Yanteng Si [this message]
2025-07-03 1:36 ` Ming Wang
2025-07-07 2:33 ` Yanteng Si
2025-07-07 10:02 ` Ming Wang
2025-07-10 4:28 ` Huacai Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0561da2c-a4d7-49bb-8394-930f10880610@linux.dev \
--to=si.yanteng@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=chenhuacai@kernel.org \
--cc=chenhuacai@loongson.cn \
--cc=gaojuxin@loongson.cn \
--cc=guoweikang.kernel@gmail.com \
--cc=hbathini@linux.ibm.com \
--cc=kernel@xen0n.name \
--cc=linux-kernel@vger.kernel.org \
--cc=lixuefeng@loongson.cn \
--cc=loongarch@lists.linux.dev \
--cc=maobibo@loongson.cn \
--cc=sourabhjain@linux.ibm.com \
--cc=usamaarif642@gmail.com \
--cc=wangming01@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®