From: Ma Wupeng mawupeng1@huawei.com
maillist inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I7QV2C CVE: NA
Reference: https://lkml.kernel.org/r/20230802072328.2107981-1-mawupeng1@huawei.com
--------------------------------
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 mawupeng1@huawei.com Suggested-by: Kefeng Wang wangkefeng.wang@huawei.com Suggested-by: Mike Rapoport rppt@kernel.org Reviewed-by: Mike Rapoport (IBM) rppt@kernel.org Reviewed-by: Kefeng Wang wangkefeng.wang@huawei.com Cc: Levi Yun ppbuk5246@gmail.com Signed-off-by: Andrew Morton akpm@linux-foundation.org Signed-off-by: Ma Wupeng mawupeng1@huawei.com --- include/linux/mm.h | 1 + mm/memblock.c | 5 +++++ mm/page_alloc.c | 5 +++++ 3 files changed, 11 insertions(+)
diff --git a/include/linux/mm.h b/include/linux/mm.h index 58d7a59b5b65..34400f909335 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 b7744ae2ce3d..94008ef55a82 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 12da70f39e0c..d797bbac809d 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;
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/1650 邮件列表地址:https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/Q...
FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/1650 Mailing list address: https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/Q...