Skip to content

lkl: initialize mm constants before mem_init()#622

Open
lrh2000 wants to merge 1 commit intolkl:masterfrom
lrh2000:mm-init-const
Open

lkl: initialize mm constants before mem_init()#622
lrh2000 wants to merge 1 commit intolkl:masterfrom
lrh2000:mm-init-const

Conversation

@lrh2000
Copy link
Copy Markdown

@lrh2000 lrh2000 commented Apr 8, 2026

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().

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant