From patchwork Fri Jul 28 04:01:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13331132 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAF74C001DF for ; Fri, 28 Jul 2023 04:01:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7FB2D6B0074; Fri, 28 Jul 2023 00:01:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7AB726B0075; Fri, 28 Jul 2023 00:01:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69A806B0078; Fri, 28 Jul 2023 00:01:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5A94C6B0074 for ; Fri, 28 Jul 2023 00:01:37 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1D27880735 for ; Fri, 28 Jul 2023 04:01:37 +0000 (UTC) X-FDA: 81059671434.14.CC0FA57 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf26.hostedemail.com (Postfix) with ESMTP id B2FC2140014 for ; Fri, 28 Jul 2023 04:01:33 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690516895; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=ylWOmLlmtqGu3AzkaYNHixtYfYBTNgM7H3C7BAQc02E=; b=LKY0J+jbDuXjqzhacNJsX1bGxKhzbRvrwpOBtuB7JIkIGN1ct925C/p3DInVBYAzHazCqS gl52job2joyLLrlHHvhz5H4SVtofy3PkvSwYFbPxqwWkBHqUcKNiHGToHF+4gipMH6ZmHm zBcXMSWffeLDLvgOb0Nst2i7rpGIkns= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690516895; a=rsa-sha256; cv=none; b=7aTwE1mBSD6Hu9YnybOCzC2+QDcxRIaKc2OzXXk4/IWS4UWjyvxETQ1V2jOlusWepP26IM nrhNmXyRoZ/oelWYZMqzITRfgg5i+JJv4oG4wXc/6fv6dBCnmgJXeahgLjzdP6/1LajjlC 8lKfpdSI2/c8MNiznq+qVKE7FTBg9YE= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RBv4N5LkMztRdk; Fri, 28 Jul 2023 11:58:12 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 12:01:28 +0800 From: Wupeng Ma To: , CC: , Subject: [PATCH] mm: disable kernelcore=mirror when no mirror memory Date: Fri, 28 Jul 2023 12:01:24 +0800 Message-ID: <20230728040124.4093229-1-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: B2FC2140014 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 47eukrjkctcitunrnnzpjmgybzf753by X-HE-Tag: 1690516893-17600 X-HE-Meta: U2FsdGVkX1+Ky+VSIZheJQCH23xyLV6DZKqyC7OfQPMCxAkd0mC3oAt/mC/hiQxhTaT3ZeugEquuqtHjzn7qi4kQX+BuC4ayI+Wu/7twBgbAFPLB71/07R4F/tPlKx314RCUfvIOPtk+rUOhwNe9W8mM/8SxvHhMXM6X0uXbS67CxMI6EzxvGBu/hCQjJFjrw1gtt6MQ4+HWlSsC89GiQXA/Lx4X6K0qIvPKjPDxP47pfc+59aw/JxEF1c31nKVFlNcBX2jHBGEpRAzq/uAifs8KdeJVWVlSuBdY5SuDX4X79hczzPCF2/x7RCS7vRZLxIDR4VRmDAsKRbzU9Ro43ea6lPM9JWxnkFXx+y3CUHIXHewXIE5N1gmqgFZL/Km5A3jqKE6gnqlIHylWchwn6A9k3wWqON+omeqqZ0RpdkTJeMdsOfZhHM8KlWu089yhpVoX7Sj0XGpceLIkVVt/iWa+wJnZ1bdlS7XFiGf+Pw8ZyrsjQ/rGqbTuI/Lzh4SWGdQd1KVu/edteOxt/O8I4kVmQ+z0SLHHn6IBbB95C3P32zJ+t8gKuN99XFvXJJbqTQ+VpfQYs43cSBHbN7E8fx3E3QSX+ETqeDEtRfJ6yt6H9fukvT+j4m6QiCF9EGa0vLJLk8Ryirlk2MVSeYacCUvhZ7xlNwVCvEu3NttP6KxHMFs0VRp65zbe3cu3Msd/vgqgi7Sg7eaMk3yMlxTfwsnzbedJfBc0k6Jirm/fedgf2GOWLIbVV0srjlkbq/KbUsj2DFReX3RvtxKWK08k2SlEfeoPNWdBKAiTKFN+qH6t9WFbI/Gf1Xxuk5wlWqS1a5BJ/oRlpztiNseBdH6SacG4gz5xIQXHq2cE1Pao6HUmv1YmAbXwj/8phNne3mzLLmgU/l+8L622YO/KkI86p5WPRTdhdU56NqiKDH2Y8cPAvjQKzbM4wy6u7T8xBjIB3bU5V3UoJTE2qK5KRvD r0hZw/HA CYIBtB05w73u7m81dJwl3Sx4lyJCthdwqq8FnVIIz9hPmN+6dI6p1qSxum+DISUyEoCXAmA5NoJQtS8S6S6zrIREqp4USG7H6y7FAKojhTZh03bCz3w5H0qXZq6j3vjx3n6Z5odvVqVRQjGjz7OpEGkioYA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Ma Wupeng 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 --- 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; }