diff --git a/include/linux/mm.h b/include/linux/mm.h index 0b5ce84212d787c334684d3dfec042ac5ce7c301..5807be4c375cae44d6890403952e053143799b5f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2493,6 +2493,7 @@ extern void get_pfn_range_for_nid(unsigned int nid, extern unsigned long find_min_pfn_with_active_regions(void); extern bool mirrored_kernelcore; +extern bool memblock_has_mirror(void); #ifndef CONFIG_NEED_MULTIPLE_NODES static inline int early_pfn_to_nid(unsigned long pfn) diff --git a/mm/memblock.c b/mm/memblock.c index b7744ae2ce3dc2012dd7eedd25364357fbbc0c2d..94008ef55a827eff8f864d6f45ac7da3e48a19e1 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -161,6 +161,11 @@ static int memblock_can_resize __initdata_memblock; static int memblock_memory_in_slab __initdata_memblock = 0; static int memblock_reserved_in_slab __initdata_memblock = 0; +bool __init_memblock memblock_has_mirror(void) +{ + return system_has_some_mirror; +} + static enum memblock_flags __init_memblock choose_memblock_flags(void) { return system_has_some_mirror ? MEMBLOCK_MIRROR : MEMBLOCK_NONE; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 12da70f39e0cbb6fb2d5a0ea5190448c5482fca7..d797bbac809d7f52c190a1697da2bc26bb73f5ae 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7741,6 +7741,11 @@ static void __init find_zone_movable_pfns_for_nodes(void) bool has_unmirrored_mem = false; unsigned long mirrored_sz = 0; + if (!memblock_has_mirror()) { + pr_warn("The system has no mirror memory, ignore kernelcore=mirror.\n"); + goto out; + } + for_each_mem_region(r) { if (memblock_is_mirror(r)) { mirrored_sz += r->size;