Re: [PATCH] mm/page_owner: fix for deferred struct page init

From: Michal Hocko
Date: Thu Dec 20 2018 - 04:44:05 EST


On Thu 20-12-18 01:03:03, Qian Cai wrote:
> When booting a system with "page_owner=on",
>
> start_kernel
> page_ext_init
> invoke_init_callbacks
> init_section_page_ext
> init_page_owner
> init_early_allocated_pages
> init_zones_in_node
> init_pages_in_zone
> lookup_page_ext
> page_to_nid
>
> The issue here is that page_to_nid() will not work since some page
> flags have no node information until later in page_alloc_init_late() due
> to DEFERRED_STRUCT_PAGE_INIT. Hence, it could trigger an out-of-bounds
> access with an invalid nid.
>
> [ 8.666047] UBSAN: Undefined behaviour in ./include/linux/mm.h:1104:50
> [ 8.672603] index 7 is out of range for type 'zone [5]'
>
> Also, kernel will panic since flags were poisoned earlier with,
>
> CONFIG_DEBUG_VM_PGFLAGS=y
> CONFIG_NODE_NOT_IN_PAGE_FLAGS=n
>
> start_kernel
> setup_arch
> pagetable_init
> paging_init
> sparse_init
> sparse_init_nid
> memblock_alloc_try_nid_raw
>
> Although later it tries to set page flags for pages in reserved bootmem
> regions,
>
> mm_init
> mem_init
> memblock_free_all
> free_low_memory_core_early
> reserve_bootmem_region
>
> there could still have some freed pages from the page allocator but yet
> to be initialized due to DEFERRED_STRUCT_PAGE_INIT. It have already been
> dealt with a bit in page_ext_init().

Is there any reason why we cannot postpone page_ext initialization to
after all the memory is initialized?
--
Michal Hocko
SUSE Labs