Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/e820: temporarily enable KHO scratch for memory below 1M

KHO kernels are special and use only scratch memory for memblock
allocations, but memory below 1M is ignored by kernel after early boot and
cannot be naturally marked as scratch.

To allow allocation of the real-mode trampoline and a few (if any) other
very early allocations from below 1M forcibly mark the memory below 1M as
scratch.

After real mode trampoline is allocated, clear that scratch marking.

Link: https://lkml.kernel.org/r/20250509074635.3187114-13-changyuanl@google.com
Signed-off-by: Alexander Graf <graf@amazon.com>
Co-developed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Co-developed-by: Changyuan Lyu <changyuanl@google.com>
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Anthony Yznaga <anthony.yznaga@oracle.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Ashish Kalra <ashish.kalra@amd.com>
Cc: Ben Herrenschmidt <benh@kernel.crashing.org>
Cc: Borislav Betkov <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Gowans <jgowans@amazon.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Krzysztof Kozlowski <krzk@kernel.org>
Cc: Marc Rutland <mark.rutland@arm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Pratyush Yadav <ptyadav@amazon.de>
Cc: Rob Herring <robh@kernel.org>
Cc: Saravana Kannan <saravanak@google.com>
Cc: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleinxer <tglx@linutronix.de>
Cc: Thomas Lendacky <thomas.lendacky@amd.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Alexander Graf and committed by
Andrew Morton
a2daf83e 65a5d727

+20
+18
arch/x86/kernel/e820.c
··· 1300 1300 } 1301 1301 1302 1302 /* 1303 + * At this point memblock is only allowed to allocate from memory 1304 + * below 1M (aka ISA_END_ADDRESS) up until direct map is completely set 1305 + * up in init_mem_mapping(). 1306 + * 1307 + * KHO kernels are special and use only scratch memory for memblock 1308 + * allocations, but memory below 1M is ignored by kernel after early 1309 + * boot and cannot be naturally marked as scratch. 1310 + * 1311 + * To allow allocation of the real-mode trampoline and a few (if any) 1312 + * other very early allocations from below 1M forcibly mark the memory 1313 + * below 1M as scratch. 1314 + * 1315 + * After real mode trampoline is allocated, we clear that scratch 1316 + * marking. 1317 + */ 1318 + memblock_mark_kho_scratch(0, SZ_1M); 1319 + 1320 + /* 1303 1321 * 32-bit systems are limited to 4BG of memory even with HIGHMEM and 1304 1322 * to even less without it. 1305 1323 * Discard memory after max_pfn - the actual limit detected at runtime.
+2
arch/x86/realmode/init.c
··· 65 65 * setup_arch(). 66 66 */ 67 67 memblock_reserve(0, SZ_1M); 68 + 69 + memblock_clear_kho_scratch(0, SZ_1M); 68 70 } 69 71 70 72 static void __init sme_sev_setup_real_mode(struct trampoline_header *th)