Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Suseendran Bhaskaran <suseendranb@google.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Mike Rapoport <rppt@kernel.org>,  Dan Williams <djbw@kernel.org>,
	David Hildenbrand <david@kernel.org>
Cc: Alexander Graf <graf@amazon.com>,
	Alison Schofield <alison.schofield@intel.com>,
	 Andy Lutomirski <luto@kernel.org>,
	Borislav Petkov <bp@alien8.de>,
	 Catalin Marinas <catalin.marinas@arm.com>,
	Changyuan Lyu <changyuanl@google.com>,
	 Dave Hansen <dave.hansen@linux.intel.com>,
	Dave Jiang <dave.jiang@intel.com>,
	 David Rientjes <rientjes@google.com>,
	Frank van der Linden <fvdl@google.com>,
	"H. Peter Anvin" <hpa@zytor.com>,  Ingo Molnar <mingo@redhat.com>,
	Ira Weiny <iweiny@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
	 "Liam R. Howlett" <liam@infradead.org>,
	Mark Rutland <mark.rutland@arm.com>,
	 Michal Hocko <mhocko@suse.com>,
	Oscar Salvador <osalvador@suse.de>,
	 Pasha Tatashin <pasha.tatashin@soleen.com>,
	Peter Zijlstra <peterz@infradead.org>,
	 Pratyush Yadav <pratyush@kernel.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	 Shuah Khan <skhan@linuxfoundation.org>,
	Thomas Gleixner <tglx@kernel.org>,
	 Vishal Verma <vishal.l.verma@intel.com>,
	Vlastimil Babka <vbabka@kernel.org>,
	 Will Deacon <will@kernel.org>,
	kexec@lists.infradead.org,  linux-arm-kernel@lists.infradead.org,
	linux-cxl@vger.kernel.org,  linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	 nvdimm@lists.linux.dev, x86@kernel.org,
	 Suseendran Bhaskaran <suseendranb@google.com>
Subject: [RFC PATCH 10/11] x86/kaslr: avoid placing kernel in carvable high memory when extmem= is set
Date: Wed,  2 Dec 2026 00:19:45 +0000	[thread overview]
Message-ID: <20261202001946.1226273-11-suseendranb@google.com> (raw)
In-Reply-To: <20261202001946.1226273-1-suseendranb@google.com>

Cold-boot extmem= switches early memblock allocations bottom-up, placing
direct-map page tables right above the uncompressed kernel image.
Physical KASLR scans all RAM without checking extmem=, so placing the
kernel above 4 GiB lands the image and page tables inside carvable high
RAM -- breaking 1 GiB contiguity, preventing a clean max carve on
secondary nodes, or causing fixed-size carving to fail with -ENOMEM.

Prefer physical KASLR slots below SZ_4G on cold boot when CONFIG_EXTMEM
is enabled and extmem= is set, falling back to mem_limit if no slot
exists below 4 GiB. KHO bootmem placement and virtual KASLR are
unchanged.

Signed-off-by: Suseendran Bhaskaran <suseendranb@google.com>
---
 arch/x86/boot/compressed/kaslr.c | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 290153818d0f..73c672d6f2ae 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -33,6 +33,7 @@
 #undef _SETUP
 
 #include <asm/kexec_handover.h>
+#include <linux/sizes.h>
 
 extern unsigned long get_cmd_line_ptr(void);
 
@@ -74,6 +75,7 @@ static unsigned long get_boot_seed(void)
 #define MAX_MEMMAP_REGIONS	4
 
 static bool memmap_too_large;
+static bool extmem_cmdline;
 
 
 /*
@@ -271,6 +273,9 @@ static void handle_mem_options(void)
 
 			if (mem_size < mem_limit)
 				mem_limit = mem_size;
+		} else if (IS_ENABLED(CONFIG_EXTMEM) &&
+			   !strcmp(param, "extmem") && val && *val) {
+			extmem_cmdline = true;
 		}
 	}
 
@@ -823,11 +828,28 @@ static unsigned long find_random_phys_addr(unsigned long minimum,
 
 	/*
 	 * During kexec handover only process KHO bootmem areas that are known
-	 * not to contain any data that must be preserved.
+	 * not to contain any data that must be preserved. On cold boot with
+	 * extmem=, prefer slots below 4 GiB so neither the kernel image nor
+	 * bottom-up direct-map page tables land in carvable high RAM, falling
+	 * back to mem_limit if no usable slot exists below 4 GiB.
 	 */
-	if (!process_kho_entries(minimum, image_size) &&
-	    !process_efi_entries(minimum, image_size))
-		process_e820_entries(minimum, image_size);
+	if (!process_kho_entries(minimum, image_size)) {
+		unsigned long orig_gb_huge_pages = max_gb_huge_pages;
+		u64 orig_mem_limit = mem_limit;
+
+		if (extmem_cmdline && (u64)minimum + image_size <= SZ_4G)
+			mem_limit = min_t(u64, mem_limit, SZ_4G);
+
+		if (!process_efi_entries(minimum, image_size))
+			process_e820_entries(minimum, image_size);
+
+		if (!slot_max && mem_limit != orig_mem_limit) {
+			mem_limit = orig_mem_limit;
+			max_gb_huge_pages = orig_gb_huge_pages;
+			if (!process_efi_entries(minimum, image_size))
+				process_e820_entries(minimum, image_size);
+		}
+	}
 
 	phys_addr = slots_fetch_random();
 


  parent reply	other threads:[~2026-12-02  0:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  0:19 [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 01/11] mm/cma: clamp multi-range search to 4G and honor memblock flags Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 02/11] mm/memblock: factor out multi-range contiguous reservation helper from CMA Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 03/11] x86/mm: add early direct-map unmap helpers for boot carveouts Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 04/11] arm64/mm: support unmapping boot carveouts from the linear map Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 05/11] mm/extmem: add architecture-neutral external memory subsystem Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 06/11] dax/hmem: bind extmem platform devices with per-region alignment Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 07/11] nvdimm/ramdax: manage bus and DIMM allocations with devres Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 08/11] nvdimm/ramdax: harden probe checks and select NUMA_KEEP_MEMINFO Suseendran Bhaskaran
2026-12-02  0:19 ` [RFC PATCH 09/11] nvdimm/ramdax: support binding extmem platform devices Suseendran Bhaskaran
2026-12-02  0:19 ` Suseendran Bhaskaran [this message]
2026-12-02  0:19 ` [RFC PATCH 11/11] mm/extmem: preserve carved regions across KHO kexec Suseendran Bhaskaran

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=20261202001946.1226273-11-suseendranb@google.com \
    --to=suseendranb@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=alison.schofield@intel.com \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=changyuanl@google.com \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=dave.jiang@intel.com \
    --cc=david@kernel.org \
    --cc=djbw@kernel.org \
    --cc=fvdl@google.com \
    --cc=graf@amazon.com \
    --cc=hpa@zytor.com \
    --cc=iweiny@kernel.org \
    --cc=kexec@lists.infradead.org \
    --cc=liam@infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mhocko@suse.com \
    --cc=mingo@redhat.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=osalvador@suse.de \
    --cc=pasha.tatashin@soleen.com \
    --cc=peterz@infradead.org \
    --cc=pratyush@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=rientjes@google.com \
    --cc=rppt@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=tglx@kernel.org \
    --cc=vbabka@kernel.org \
    --cc=vishal.l.verma@intel.com \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    /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