From patchwork Wed Dec 9 21:43:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 11962709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8405C4361B for ; Wed, 9 Dec 2020 21:43:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6A28123C91 for ; Wed, 9 Dec 2020 21:43:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6A28123C91 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0FBEF8D0031; Wed, 9 Dec 2020 16:43:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 036066B013A; Wed, 9 Dec 2020 16:43:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E66298D0031; Wed, 9 Dec 2020 16:43:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0135.hostedemail.com [216.40.44.135]) by kanga.kvack.org (Postfix) with ESMTP id C35526B0139 for ; Wed, 9 Dec 2020 16:43:17 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 83DFE362D for ; Wed, 9 Dec 2020 21:43:17 +0000 (UTC) X-FDA: 77575070034.25.use30_4703e18273f3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 702721804E3A0 for ; Wed, 9 Dec 2020 21:43:17 +0000 (UTC) X-HE-Tag: use30_4703e18273f3 X-Filterd-Recvd-Size: 4472 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Wed, 9 Dec 2020 21:43:16 +0000 (UTC) From: Mike Rapoport Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: Andrew Morton Cc: Andrea Arcangeli , Baoquan He , David Hildenbrand , Mel Gorman , Michal Hocko , Mike Rapoport , Mike Rapoport , Qian Cai , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org Subject: [PATCH v2 1/2] mm: memblock: enforce overlap of memory.memblock and memory.reserved Date: Wed, 9 Dec 2020 23:43:03 +0200 Message-Id: <20201209214304.6812-2-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201209214304.6812-1-rppt@kernel.org> References: <20201209214304.6812-1-rppt@kernel.org> MIME-Version: 1.0 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: Mike Rapoport memblock does not require that the reserved memory ranges will be a subset of memblock.memory. As the result there maybe reserved pages that are not in the range of any zone or node because zone and node boundaries are detected based on memblock.memory and pages that only present in memblock.reserved are not taken into account during zone/node size detection. Make sure that all ranges in memblock.reserved are added to memblock.memory before calculating node and zone boundaries. Fixes: 73a6e474cb37 ("mm: memmap_init: iterate over memblock regions rather that check each PFN") Reported-by: Andrea Arcangeli Signed-off-by: Mike Rapoport --- include/linux/memblock.h | 1 + mm/memblock.c | 24 ++++++++++++++++++++++++ mm/page_alloc.c | 7 +++++++ 3 files changed, 32 insertions(+) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index ef131255cedc..e64dae2dd1ce 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -120,6 +120,7 @@ int memblock_clear_nomap(phys_addr_t base, phys_addr_t size); unsigned long memblock_free_all(void); void reset_node_managed_pages(pg_data_t *pgdat); void reset_all_zones_managed_pages(void); +void memblock_enforce_memory_reserved_overlap(void); /* Low level functions */ void __next_mem_range(u64 *idx, int nid, enum memblock_flags flags, diff --git a/mm/memblock.c b/mm/memblock.c index b68ee86788af..9277aca642b2 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1857,6 +1857,30 @@ void __init_memblock memblock_trim_memory(phys_addr_t align) } } +/** + * memblock_enforce_memory_reserved_overlap - make sure every range in + * @memblock.reserved is covered by @memblock.memory + * + * The data in @memblock.memory is used to detect zone and node boundaries + * during initialization of the memory map and the page allocator. Make + * sure that every memory range present in @memblock.reserved is also added + * to @memblock.memory even if the architecture specific memory + * initialization failed to do so + */ +void __init memblock_enforce_memory_reserved_overlap(void) +{ + phys_addr_t start, end; + int nid; + u64 i; + + __for_each_mem_range(i, &memblock.reserved, &memblock.memory, + NUMA_NO_NODE, MEMBLOCK_NONE, &start, &end, &nid) { + pr_warn("memblock: reserved range [%pa-%pa] is not in memory\n", + &start, &end); + memblock_add_node(start, (end - start), nid); + } +} + void __init_memblock memblock_set_current_limit(phys_addr_t limit) { memblock.current_limit = limit; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index eaa227a479e4..dbc57dbbacd8 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7436,6 +7436,13 @@ void __init free_area_init(unsigned long *max_zone_pfn) memset(arch_zone_highest_possible_pfn, 0, sizeof(arch_zone_highest_possible_pfn)); + /* + * Some architectures (e.g. x86) have reserved pages outside of + * memblock.memory. Make sure these pages are taken into account + * when detecting zone and node boundaries + */ + memblock_enforce_memory_reserved_overlap(); + start_pfn = find_min_pfn_with_active_regions(); descending = arch_has_descending_max_zone_pfns();