memblock: fix crash when reserved memory is not added to memory
authorYajun Deng <yajun.deng@linux.dev>
Thu, 18 Jan 2024 06:18:53 +0000 (14:18 +0800)
committerMike Rapoport (IBM) <rppt@kernel.org>
Fri, 19 Jan 2024 08:53:59 +0000 (10:53 +0200)
After commit 61167ad5fecd ("mm: pass nid to reserve_bootmem_region()")
nid of a reserved region is used by init_reserved_page() (with
CONFIG_DEFERRED_STRUCT_PAGE_INIT=y) to access node strucure.
In many cases the nid of the reserved memory is not set and this causes
a crash.

When the nid of a reserved region is not set, fall back to
early_pfn_to_nid(), so that nid of the first_online_node will be passed
to init_reserved_page().

Fixes: 61167ad5fecd ("mm: pass nid to reserve_bootmem_region()")
Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
Link: https://lore.kernel.org/r/20240118061853.2652295-1-yajun.deng@linux.dev
[rppt: massaged the commit message]
Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org>
mm/memblock.c

index 5a88d6d24d793807803139254b5804827251adf1..4823ad979b72f5b9df9a93a2a58b4f807b873a61 100644 (file)
@@ -2141,6 +2141,9 @@ static void __init memmap_init_reserved_pages(void)
                        start = region->base;
                        end = start + region->size;
 
+                       if (nid == NUMA_NO_NODE || nid >= MAX_NUMNODES)
+                               nid = early_pfn_to_nid(PFN_DOWN(start));
+
                        reserve_bootmem_region(start, end, nid);
                }
        }