Skip to content
  • Qian Cai's avatar
    Revert "mm: use early_pfn_to_nid in page_ext_init" · 2f1ee091
    Qian Cai authored
    This reverts commit fe53ca54 ("mm: use early_pfn_to_nid in
    page_ext_init").
    
    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.
    
      UBSAN: Undefined behaviour in ./include/linux/mm.h:1104:50
      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...
    2f1ee091