Skip to content

Commit 952bb32

Browse files
committed
lkl: initialize mm constants before mem_init()
max_mapnr is accessed through the following call chain: mem_init() -> memblock_free_all() -> free_low_memory_core_early() -> memmap_init_reserved_pages() -> reserve_bootmem_region() -> pfn_valid() -> (pfn - ARCH_PFN_OFFSET) < max_mapnr In lkl, max_mapnr is currently initialized in mem_init(), but only after memblock_free_all() runs. This means pfn_valid() can see an uninitialized max_mapnr and incorrectly return false for pfns that should be valid. For example, reserve_bootmem_region() should mark such pages as reserved, but due to this bug it does not. Other architectures, such as riscv, x86, and arm64, initialize mm constants before mem_init() from setup_arch(). Do the equivalent for lkl by initializing max_pfn, max_low_pfn, min_low_pfn, and max_mapnr in bootmem_init(). Signed-off-by: Ruihan Li <lrh2000@pku.edu.cn>
1 parent 34d8dc9 commit 952bb32

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

arch/lkl/mm/bootmem.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ void __init bootmem_init(unsigned long mem_sz)
4646
* Give all the memory to the bootmap allocator, tell it to put the
4747
* boot mem_map at the start of memory.
4848
*/
49-
max_low_pfn = virt_to_pfn((void *)memory_end);
50-
min_low_pfn = virt_to_pfn((void *)memory_start);
5149
memblock_add(__pa(memory_start), mem_size);
5250

51+
max_pfn = max_low_pfn = virt_to_pfn((void *)memory_end);
52+
min_low_pfn = virt_to_pfn((void *)memory_start);
53+
set_max_mapnr(max_pfn - ARCH_PFN_OFFSET);
54+
5355
empty_zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
5456
memset(empty_zero_page, 0, PAGE_SIZE);
5557

@@ -60,9 +62,6 @@ void __init bootmem_init(unsigned long mem_sz)
6062
void __init mem_init(void)
6163
{
6264
memblock_free_all();
63-
max_mapnr = totalram_pages();
64-
max_low_pfn = max_mapnr + ARCH_PFN_OFFSET;
65-
max_pfn = max_mapnr + ARCH_PFN_OFFSET;
6665
}
6766

6867
/*

0 commit comments

Comments
 (0)