linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: disable kernelcore=mirror when no mirror memory
@ 2023-07-28  4:01 Wupeng Ma
  2023-07-29  8:12 ` Mike Rapoport
  0 siblings, 1 reply; 8+ messages in thread
From: Wupeng Ma @ 2023-07-28  4:01 UTC (permalink / raw)
  To: akpm, rppt; +Cc: linux-mm, mawupeng1

From: Ma Wupeng <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.

Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
---
 mm/internal.h | 2 ++
 mm/memblock.c | 2 +-
 mm/mm_init.c  | 6 +++++-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/mm/internal.h b/mm/internal.h
index a7d9e980429a..98a03ac74ca7 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -374,6 +374,8 @@ static inline void clear_zone_contiguous(struct zone *zone)
 	zone->contiguous = false;
 }
 
+extern bool system_has_some_mirror;
+
 extern int __isolate_free_page(struct page *page, unsigned int order);
 extern void __putback_isolated_page(struct page *page, unsigned int order,
 				    int mt);
diff --git a/mm/memblock.c b/mm/memblock.c
index f9e61e565a53..e7a7a65415fb 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -156,10 +156,10 @@ static __refdata struct memblock_type *memblock_memory = &memblock.memory;
 	} while (0)
 
 static int memblock_debug __initdata_memblock;
-static bool system_has_some_mirror __initdata_memblock;
 static int memblock_can_resize __initdata_memblock;
 static int memblock_memory_in_slab __initdata_memblock;
 static int memblock_reserved_in_slab __initdata_memblock;
+bool system_has_some_mirror __initdata_memblock;
 
 static enum memblock_flags __init_memblock choose_memblock_flags(void)
 {
diff --git a/mm/mm_init.c b/mm/mm_init.c
index a1963c3322af..6267b9f75927 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -269,7 +269,11 @@ static int __init cmdline_parse_kernelcore(char *p)
 {
 	/* parse kernelcore=mirror */
 	if (parse_option_str(p, "mirror")) {
-		mirrored_kernelcore = true;
+		if (system_has_some_mirror)
+			mirrored_kernelcore = true;
+		else
+			pr_warn("The system has no mirror memory, disable kernelcore=mirror.\n");
+
 		return 0;
 	}
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-08-01 17:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-28  4:01 [PATCH] mm: disable kernelcore=mirror when no mirror memory Wupeng Ma
2023-07-29  8:12 ` Mike Rapoport
2023-07-29  8:57   ` Kefeng Wang
2023-07-30  6:53     ` Mike Rapoport
2023-07-31  1:39       ` Kefeng Wang
2023-07-31  2:06         ` mawupeng
2023-08-01 14:05         ` Mike Rapoport
2023-07-31  1:39       ` mawupeng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).