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-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 15 Dec 2021 14:45:59 +0800
From:   "Peng Fan (OSS)" <peng.fan@....nxp.com>
To:     catalin.marinas@....com, will@...nel.org, rppt@...nel.org
Cc:     akpm@...ux-foundation.org, david@...hat.com,
        anshuman.khandual@....com, geert+renesas@...der.be,
        linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
        linux-imx@....com, Peng Fan <peng.fan@....com>
Subject: [PATCH 2/2] arm64: mm: support bootparam max_addr

From: Peng Fan <peng.fan@....com>

There is a "mem=[x]" boot parameter, but when there is a whole reserved
by secure TEE, the continuous DRAM area is split with two memblocks.

For example, DRAM area [0x40000000, 0xffffffff], when TEE uses
[0x50000000, 0x51000000), the memblock will be split into
[0x40000000, 0x50000000) and [0x51000000, 0xffffffff].

If pass "mem=1024MB", the actually max addr will be 0x81000000.
However if need the max addr be 0x80000000, mem=1008MB should be used.

There also might be multiple other holes that no visible to Linux, when
we wanna to limit the max addr usable by Linux, using "max_addr=[X]" is
much easier than "mem=[X]"

Signed-off-by: Peng Fan <peng.fan@....com>
---
 arch/arm64/mm/init.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index db63cc885771..3364b5e7a7fe 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -173,6 +173,7 @@ int pfn_is_map_memory(unsigned long pfn)
 EXPORT_SYMBOL(pfn_is_map_memory);
 
 static phys_addr_t memory_limit __ro_after_init = PHYS_ADDR_MAX;
+static phys_addr_t max_addr __ro_after_init = PHYS_ADDR_MAX;
 
 /*
  * Limit the memory size that was specified via FDT.
@@ -189,6 +190,18 @@ static int __init early_mem(char *p)
 }
 early_param("mem", early_mem);
 
+static int __init set_max_addr(char *p)
+{
+	if (!p)
+		return 1;
+
+	max_addr = memparse(p, &p) & PAGE_MASK;
+	pr_notice("Memory max addr set to 0x%llx\n", max_addr);
+
+	return 0;
+}
+early_param("max_addr", set_max_addr);
+
 void __init arm64_memblock_init(void)
 {
 	s64 linear_region_size = PAGE_END - _PAGE_OFFSET(vabits_actual);
@@ -253,6 +266,9 @@ void __init arm64_memblock_init(void)
 		memblock_add(__pa_symbol(_text), (u64)(_end - _text));
 	}
 
+	if (max_addr != PHYS_ADDR_MAX)
+		memblock_cap_memory_range(0, max_addr);
+
 	if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && phys_initrd_size) {
 		/*
 		 * Add back the memory we just removed if it results in the
@@ -427,4 +443,9 @@ void dump_mem_limit(void)
 	} else {
 		pr_emerg("Memory Limit: none\n");
 	}
+
+	if (max_addr != PHYS_ADDR_MAX)
+		pr_emerg("Max addr: 0x%llx\n", max_addr);
+	else
+		pr_emerg("Max addr: none\n");
 }
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ