lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250701090449.2426151-1-wangming01@loongson.cn>
Date: Tue,  1 Jul 2025 17:04:49 +0800
From: Ming Wang <wangming01@...ngson.cn>
To: Huacai Chen <chenhuacai@...nel.org>,
	WANG Xuerui <kernel@...0n.name>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Bibo Mao <maobibo@...ngson.cn>,
	Hari Bathini <hbathini@...ux.ibm.com>,
	Guo Weikang <guoweikang.kernel@...il.com>,
	Ming Wang <wangming01@...ngson.cn>,
	Sourabh Jain <sourabhjain@...ux.ibm.com>,
	Usama Arif <usamaarif642@...il.com>,
	loongarch@...ts.linux.dev,
	linux-kernel@...r.kernel.org
Cc: lixuefeng@...ngson.cn,
	chenhuacai@...ngson.cn,
	gaojuxin@...ngson.cn
Subject: [PATCH] LoongArch: Support mem=SIZE kernel parameter

The LoongArch mem= parameter parser was previously limited to the
mem=SIZE@...RT 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@...RT 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@...RT format can be used multiple times to
define several distinct memory regions.

Signed-off-by: Ming Wang <wangming01@...ngson.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;
-	}
 
 	if (!IS_ENABLED(CONFIG_NUMA))
 		memblock_add(start, size);
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ