From patchwork Tue Jun 7 09:38:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 12871598 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 3BD05CCA47F for ; Tue, 7 Jun 2022 09:16:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B7FFB8D0003; Tue, 7 Jun 2022 05:16:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A904B8D0002; Tue, 7 Jun 2022 05:16:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90A1A8D0003; Tue, 7 Jun 2022 05:16:54 -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 82B958D0002 for ; Tue, 7 Jun 2022 05:16:54 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5C42A34B2D for ; Tue, 7 Jun 2022 09:16:54 +0000 (UTC) X-FDA: 79550885148.03.9FD42C4 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf28.hostedemail.com (Postfix) with ESMTP id 506CBC004F for ; Tue, 7 Jun 2022 09:16:09 +0000 (UTC) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4LHPqj4SWXzpXwZ; Tue, 7 Jun 2022 17:16:33 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 7 Jun 2022 17:16:51 +0800 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.2375.24; Tue, 7 Jun 2022 17:16:49 +0800 From: Wupeng Ma To: , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 5/6] mm: Add mirror flag back on initrd memory Date: Tue, 7 Jun 2022 17:38:04 +0800 Message-ID: <20220607093805.1354256-6-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220607093805.1354256-1-mawupeng1@huawei.com> References: <20220607093805.1354256-1-mawupeng1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected X-Stat-Signature: bu6ofsd1gtq9g9z588fj9efynu65d5d3 X-Rspam-User: Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 506CBC004F X-HE-Tag: 1654593369-925118 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 Initrd memory will be removed and then added in arm64_memblock_init() and this will cause it to lose all of its memblock flags. The lost of MEMBLOCK_MIRROR flag will lead to error log printed by find_zone_movable_pfns_for_nodes if the lower 4G range has some non-mirrored memory. In order to solve this problem, the lost MEMBLOCK_MIRROR flag will be reinstalled if the origin memblock has this flag. Signed-off-by: Ma Wupeng --- arch/arm64/mm/init.c | 9 +++++++++ include/linux/memblock.h | 1 + mm/memblock.c | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 339ee84e5a61..11641f924d08 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -350,9 +350,18 @@ void __init arm64_memblock_init(void) "initrd not fully accessible via the linear mapping -- please check your bootloader ...\n")) { phys_initrd_size = 0; } else { + int flags, ret; + + ret = memblock_get_flags(base, &flags); + if (ret) + flags = 0; + memblock_remove(base, size); /* clear MEMBLOCK_ flags */ memblock_add(base, size); memblock_reserve(base, size); + + if (flags & MEMBLOCK_MIRROR) + memblock_mark_mirror(base, size); } } diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 50ad19662a32..3d6a382ac9c8 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -487,6 +487,7 @@ bool memblock_is_map_memory(phys_addr_t addr); bool memblock_is_region_memory(phys_addr_t base, phys_addr_t size); bool memblock_is_reserved(phys_addr_t addr); bool memblock_is_region_reserved(phys_addr_t base, phys_addr_t size); +int memblock_get_flags(phys_addr_t base, int *flags); void memblock_dump_all(void); diff --git a/mm/memblock.c b/mm/memblock.c index b1d2a0009733..0c5b5699af6e 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1796,6 +1796,26 @@ int __init_memblock memblock_search_pfn_nid(unsigned long pfn, return memblock_get_region_node(&type->regions[mid]); } +/** + * memblock_get_flags - get a single memblock flags + * @base: base of memeblock to get + * + * Get the flags of memeblock with base: @base + * + * Return: + * 0 if ok, non-zero if fail + */ +int __init_memblock memblock_get_flags(phys_addr_t base, int *flags) +{ + int idx = memblock_search(&memblock.memory, base); + + if (idx == -1) + return -EINVAL; + + *flags = memblock.memory.regions[idx].flags; + return 0; +} + /** * memblock_is_region_memory - check if a region is a subset of memory * @base: base of region to check