From: Wupeng Ma <mawupeng1@huawei.com>
To: <akpm@linux-foundation.org>, <rppt@kernel.org>,
<wangkefeng.wang@huawei.com>
Cc: <linux-mm@kvack.org>, <mawupeng1@huawei.com>
Subject: [PATCH v2] mm: disable kernelcore=mirror when no mirror memory
Date: Wed, 2 Aug 2023 15:23:28 +0800 [thread overview]
Message-ID: <20230802072328.2107981-1-mawupeng1@huawei.com> (raw)
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.
Suggested-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Suggested-by: Mike Rapoport <rppt@kernel.org>
Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
---
mm/internal.h | 1 +
mm/memblock.c | 5 +++++
mm/mm_init.c | 5 +++++
3 files changed, 11 insertions(+)
diff --git a/mm/internal.h b/mm/internal.h
index a7d9e980429a..b8aaf9cac87e 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -1005,6 +1005,7 @@ static inline bool gup_must_unshare(struct vm_area_struct *vma,
}
extern bool mirrored_kernelcore;
+extern bool memblock_has_mirror(void);
static inline bool vma_soft_dirty_enabled(struct vm_area_struct *vma)
{
diff --git a/mm/memblock.c b/mm/memblock.c
index f9e61e565a53..913b2520a9a0 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;
static int memblock_reserved_in_slab __initdata_memblock;
+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/mm_init.c b/mm/mm_init.c
index a1963c3322af..e8af1b628430 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -377,6 +377,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;
--
2.25.1
next reply other threads:[~2023-08-02 7:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-02 7:23 Wupeng Ma [this message]
2023-08-02 18:44 ` Mike Rapoport
2023-08-03 3:06 ` Kefeng Wang
2023-08-03 17:53 ` Andrew Morton
2023-08-04 1:44 ` Kefeng Wang
2023-08-06 18:55 ` Yun Levi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230802072328.2107981-1-mawupeng1@huawei.com \
--to=mawupeng1@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.org \
--cc=rppt@kernel.org \
--cc=wangkefeng.wang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox