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] [day] [month] [year] [list]
Message-ID: <20250430084138.2287031-3-jaszczyk@chromium.org>
Date: Wed, 30 Apr 2025 08:41:38 +0000
From: Grzegorz Jaszczyk <jaszczyk@...omium.org>
To: tglx@...utronix.de,
	robh@...nel.org
Cc: mingo@...hat.com,
	bp@...en8.de,
	dave.hansen@...ux.intel.com,
	x86@...nel.org,
	hpa@...or.com,
	saravanak@...gle.com,
	dmaluka@...omium.org,
	bgrzesik@...gle.com,
	jaszczyk@...gle.com,
	ilpo.jarvinen@...ux.intel.com,
	usamaarif642@...il.com,
	linux-kernel@...r.kernel.org,
	devicetree@...r.kernel.org,
	tnowicki@...gle.com,
	mazurekm@...gle.com,
	vineethrp@...gle.com,
	rppt@...nel.org,
	agordeev@...ux.ibm.com,
	dyoung@...hat.com,
	myrrhperiwinkle@...labs.xyz,
	guoweikang.kernel@...il.com,
	kirill.shutemov@...ux.intel.com,
	akpm@...ux-foundation.org,
	joel.granados@...nel.org,
	sourabhjain@...ux.ibm.com
Subject: [PATCH v3 2/2] x86/e820: reserve corresponding to DT reserved-memory nomap region

From: Grzegorz Jaszczyk <jaszczyk@...gle.com>

The reserved-memory nomap region shouldn't be mapped and registered as an
IORESOURCE_SYSTEM_RAM resource. On the x86 platform the resource tree
map is built based on e820 entries (see e820__reserve_resources).
Aligning DT reserved-memory nomap region by adding corresponding e820
reserved range will allow x86 to build appropriate resource tree.
Similar thing is done during e.g. arm64 resource tree creation (see:
arm64's request_standard_resources()).

Adding a corresponding e820 entry also allows other parts of x86 early
kernel initialization to rely on it. E.g. e820__setup_pci_gap based on
the gap in the e820 memory table picks space and passes to the PCI
subsystem.  Without adding corresponding e820 reserved entry, DT
reserved memory nomap region could conflict with such region assigned
later to PCI subsystem.

Additionally updating e820_table in this stage of the x86 setup seems
safe since it is performed before mentioned e820__reserve_resources and
e820__setup_pci_gap and there are also other functions, which updates
e820 table on the later stage of early x86 setup such as early_quirks()
and efi_arch_mem_reserve() (used by efi_esrt_init).

Signed-off-by: Grzegorz Jaszczyk <jaszczyk@...gle.com>
---
 arch/x86/include/asm/e820/api.h |  1 +
 arch/x86/kernel/e820.c          | 19 +++++++++++++++++++
 arch/x86/kernel/setup.c         |  2 ++
 3 files changed, 22 insertions(+)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index c83645d5b2a8..a3b39ec6c3b4 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -28,6 +28,7 @@ extern unsigned long e820__end_of_low_ram_pfn(void);
 
 extern u64  e820__memblock_alloc_reserved(u64 size, u64 align);
 extern void e820__memblock_setup(void);
+extern void e820__reserve_nomap_region(void);
 
 extern void e820__finish_early_params(void);
 extern void e820__reserve_resources(void);
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 9920122018a0..1179ab538d20 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -1312,3 +1312,22 @@ void __init e820__memblock_setup(void)
 
 	memblock_dump_all();
 }
+
+void __init e820__reserve_nomap_region(void)
+{
+	struct memblock_region *region;
+	resource_size_t start;
+
+	for_each_mem_region(region) {
+		if (memblock_is_nomap(region)) {
+			start = __pfn_to_phys(memblock_region_reserved_base_pfn(region));
+
+			/*
+			 * Add corresponding e820 region and let
+			 * e820__update_table sanitize e820 map
+			 */
+			e820__range_add(start, region->size, E820_TYPE_RESERVED);
+			e820__update_table_print();
+		}
+	}
+}
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 6f4eddc11560..7fe09f4ea16e 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1049,6 +1049,8 @@ void __init setup_arch(char **cmdline_p)
 
 	x86_flattree_get_config();
 
+	e820__reserve_nomap_region();
+
 	/*
 	 * Needs to run after memblock setup because it needs the physical
 	 * memory size.
-- 
2.49.0.901.g37484f566f-goog


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ