Skip to content

Commit 83b2d34

Browse files
rpptIngo Molnar
authored and
Ingo Molnar
committed
x86/e820: Discard high memory that can't be addressed by 32-bit systems
Dave Hansen reports the following crash on a 32-bit system with CONFIG_HIGHMEM=y and CONFIG_X86_PAE=y: > 0xf75fe000 is the mem_map[] entry for the first page >4GB. It > obviously wasn't allocated, thus the oops. BUG: unable to handle page fault for address: f75fe000 #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page *pdpt = 0000000002da2001 *pde = 000000000300c067 *pte = 0000000000000000 Oops: Oops: 0002 [#1] SMP NOPTI CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.15.0-rc1-00288-ge618ee89561b-dirty #311 PREEMPT(undef) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014 EIP: __free_pages_core+0x3c/0x74 ... Call Trace: memblock_free_pages+0x11/0x2c memblock_free_all+0x2ce/0x3a0 mm_core_init+0xf5/0x320 start_kernel+0x296/0x79c i386_start_kernel+0xad/0xb0 startup_32_smp+0x151/0x154 The mem_map[] is allocated up to the end of ZONE_HIGHMEM which is defined by max_pfn. The bug was introduced by this recent commit: 6faea34 ("arch, mm: streamline HIGHMEM freeing") Previously, freeing of high memory was also clamped to the end of ZONE_HIGHMEM but after this change, memblock_free_all() tries to free memory above the of ZONE_HIGHMEM as well and that causes access to mem_map[] entries beyond the end of the memory map. To fix this, discard the memory after max_pfn from memblock on 32-bit systems so that core MM would be aware only of actually usable memory. Fixes: 6faea34 ("arch, mm: streamline HIGHMEM freeing") Reported-by: Dave Hansen <[email protected]> Tested-by: Arnd Bergmann <[email protected]> Signed-off-by: Mike Rapoport (Microsoft) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Andy Shevchenko <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Davide Ciminaghi <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: Sean Christopherson <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] # discussion and submission
1 parent 8560697 commit 83b2d34

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

arch/x86/kernel/e820.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,14 @@ void __init e820__memblock_setup(void)
12991299
memblock_add(entry->addr, entry->size);
13001300
}
13011301

1302+
/*
1303+
* 32-bit systems are limited to 4BG of memory even with HIGHMEM and
1304+
* to even less without it.
1305+
* Discard memory after max_pfn - the actual limit detected at runtime.
1306+
*/
1307+
if (IS_ENABLED(CONFIG_X86_32))
1308+
memblock_remove(PFN_PHYS(max_pfn), -1);
1309+
13021310
/* Throw away partial pages: */
13031311
memblock_trim_memory(PAGE_SIZE);
13041312

0 commit comments

Comments
 (0)