From patchwork Wed Aug 2 07:23:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13337754 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 72C11C001DF for ; Wed, 2 Aug 2023 07:23:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12E0C280131; Wed, 2 Aug 2023 03:23:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DEAD280112; Wed, 2 Aug 2023 03:23:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0F47280131; Wed, 2 Aug 2023 03:23:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E211C280112 for ; Wed, 2 Aug 2023 03:23:44 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BD38BC05F8 for ; Wed, 2 Aug 2023 07:23:44 +0000 (UTC) X-FDA: 81078324768.17.A96863F Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf10.hostedemail.com (Postfix) with ESMTP id 42EBCC0010 for ; Wed, 2 Aug 2023 07:23:41 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.188 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=1690961023; 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=URN7cjzFKQmRgo7NLz+ectfP+VBWtwKjlqjm4gXAEqo=; b=FVoVxiJJR2EdKdlCgmaHTUiJ3oNU1waZtzF+db7wWm4gQrfybd3Azclw8+IfSWXuXycykB Lst6UitrrpNv1IUHwV0CWQMg4yRXqmMO6NiwnZwIMnTsPqKAFJOX/ktan7zrSFLHpB1c2s mYo3RF1e81BKs7HPKGeuwlMto6uKtKg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690961023; a=rsa-sha256; cv=none; b=lc+ddkcA2XUoaHpZrRGdQd+2Uw2a/+6oLH6F/uXwnN48DHX5d3F33NV++dkffwNeIIYARU 3Q0JGEXBLMf1HI7amk+ttGXLmtzsxTjMIaCqRuDghxZ65MCaZQgy/BsHF5CCP1+HCJQtlr Dr7n9mqIXLIuFbcX4Qu88myCGR33J4k= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.188 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.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RG3K66FXgzNmj4; Wed, 2 Aug 2023 15:20:10 +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; Wed, 2 Aug 2023 15:23:36 +0800 From: Wupeng Ma To: , , CC: , Subject: [PATCH v2] mm: disable kernelcore=mirror when no mirror memory Date: Wed, 2 Aug 2023 15:23:28 +0800 Message-ID: <20230802072328.2107981-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: 42EBCC0010 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: cqsyeizx7cqm1kz9naissfz6j6mjhda9 X-HE-Tag: 1690961021-749993 X-HE-Meta: U2FsdGVkX19d4qFQIOueRXa+hln1gBCg1HZyJauzbYuwwaq5Ove+J6Keh4s38p8VeFVjCLhepdDFyIgWerLjEVG5aXifX2mgUhj7BuNUpiiRxtGJtKeO9nfcEFLqwk5wdlrR04qEEX26fpJasRwK95Oinb/QggRWWzHxFRgvKlZJtuYEfDqB1iA6lY9ouZS9vt4P5Av4gZEPsQXEfR/QFTyvr48E0gWPaW50dYG4kFgyAC6uC/jXQGvMUR8hLd/T1+KHyUCitCfC0RdkF07A1YJAiU/kKa1Hptc+ujQLAQYBl/aG9q3IxsxqPuWu6FB0mQGMVKn2nkVbQTg//uNSSpnW8wZ0F44ZgGpcRa/siV2oWrLye7NjGuJK7/14FPD+WJesWC6jXXHtzdg6xfnKRxp7azk9vcnCgi9y4LkNoa1cmiXreZa4tCOBN5i8j7rHK6mfrYmSB69voMmUBr5GhBuMMt9WX1rdP/m9lQiVS7WL8CqWgOIujB69oeK4DtWfQC9UkY8T7VFh8MfJ7BW/4poTzonTmdA7A03fehwEHFjD5lAeSdd1hRGUze4k2fz2nKA2xb+hihHY+7wWYca8c2w6xtCS9XzmUptscmdsUKjnKSTzgOEl4PsvFTtNL6zpQJwfL1PptulMilOopZiyJ+SJYNkpnyetfmGRsAsZ1ssbBFFxZRilKEmSC4j1WiVuTsh8o41Yocbi7GCoJ96iOc8NfFSbO8FQh5KI405ZUhHkUuloy3S00jpRQXX/wv2ltUp8JWh2bOpuYt99WY2T/z8A1ZhOuBg5bjzTk1mJvpBQ7flg7gJuPdogDv1SEcvUMTGYWk5UYCsWfrOcWutZ/rXNiTXl9vbjSPcHxzmOHr8l14VihwXpE4Dh//aFwRdquH3AFS4NO++zTet7mYZdAqgc9Gqb8gNWOx37sJr7Q0c2Gx5oHzk7hDiaypO02yIaix/FSvJ56b+NfflJBlg I4ObcV8X RC9Ppkz5yNSwe+D3/OCVOOdIWXMB9mIuohAjnaK/waMUaqr+WntqHGtz1xzGxFCbaZzTs9NSccz7aQJBu3ELgEbEPzcBcnL5Ilmiq+XVbbVYnhcjEPd8N1iX+WFlq1nahrF+GLG3pH5S4hfMqRtAW6kjmMDWhaZsOxZJX+ft02GBm2kAZyF+rySj7uY83rVE9FVpMX2J0yo/sv6g= 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. Suggested-by: Kefeng Wang Suggested-by: Mike Rapoport Signed-off-by: Ma Wupeng Reviewed-by: Mike Rapoport (IBM) Reviewed-by: Kefeng Wang --- 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;