From 0db31d63f27e5b8ca84b9fd5a3cff5b12ac88abf Mon Sep 17 00:00:00 2001 From: Ma Wupeng Date: Wed, 2 Aug 2023 15:23:28 +0800 Subject: mm: disable kernelcore=mirror when no mirror memory For system with kernelcore=mirror enabled while no mirrored memory is reported by efi. This could lead to kernel OOM during startup since all memory beside zone DMA are in the movable zone and this prevents the kernel to use it. Zone DMA/DMA32 initialization is independent of mirrored memory and their max pfn is set in zone_sizes_init(). Since kernel can fallback to zone DMA/DMA32 if there is no memory in zone Normal, these zones are seen as mirrored memory no mather their memory attributes are. To solve this problem, disable kernelcore=mirror when there is no real mirrored memory exists. Link: https://lkml.kernel.org/r/20230802072328.2107981-1-mawupeng1@huawei.com Signed-off-by: Ma Wupeng Suggested-by: Kefeng Wang Suggested-by: Mike Rapoport Reviewed-by: Mike Rapoport (IBM) Reviewed-by: Kefeng Wang Cc: Levi Yun Signed-off-by: Andrew Morton --- mm/mm_init.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'mm/mm_init.c') diff --git a/mm/mm_init.c b/mm/mm_init.c index a2fbaa8d917f..2a19f3151661 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -376,6 +376,11 @@ static void __init find_zone_movable_pfns_for_nodes(void) if (mirrored_kernelcore) { bool mem_below_4gb_not_mirrored = false; + 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)) continue; -- cgit v1.2.3