From patchwork Wed Jun 30 07:12:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12351359 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=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 4C8C8C11F65 for ; Wed, 30 Jun 2021 07:12:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EAE1761D0E for ; Wed, 30 Jun 2021 07:12:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EAE1761D0E 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 642748D0187; Wed, 30 Jun 2021 03:12:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 618EC8D017A; Wed, 30 Jun 2021 03:12:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E1158D0187; Wed, 30 Jun 2021 03:12:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0207.hostedemail.com [216.40.44.207]) by kanga.kvack.org (Postfix) with ESMTP id 2CB348D017A for ; Wed, 30 Jun 2021 03:12:22 -0400 (EDT) Received: from smtpin34.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1B77923E46 for ; Wed, 30 Jun 2021 07:12:22 +0000 (UTC) X-FDA: 78309521724.34.C6E18A5 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf09.hostedemail.com (Postfix) with ESMTP id C4C3D3000351 for ; Wed, 30 Jun 2021 07:12:21 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id B769161D0D; Wed, 30 Jun 2021 07:12:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625037141; bh=qrNdjflpUvLivu9UtSwHedId14adKJHrYDNOU0/V3Hs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KUqE6XNSw7dk8e2ZILlvfQq1B44GHU4kBesWjirZ6covpZVFA40ua/1O47D6jqxSB iuO138aUwA+rxwY6m0o/pbHv4c8JpG3aY0jES2YDxV5hvX+//xHdMbMWnwwWqShJKM R01ukn142OFPS2qQRvllI/9k5GTkVukP7Mg40e1LHJkrmfnNk9FQoxHby/K8ck19NP CW2W3061j+8wpglgwGYglAj9DAhdB5hjUifUibLsMXrsJTaAy9l77cznRzv5hgFS5t hmLS3L+wmYYXh1XovlmRz8Fvb8cagnxWeEA0/Q4RqhTiTNzLRAS2U6y6J3gc0GR6E6 ZHOo2z4dndf5g== From: Mike Rapoport To: linux-arm-kernel@lists.infradead.org Cc: Andrew Morton , Kefeng Wang , Mike Rapoport , Mike Rapoport , Russell King , Tony Lindgren , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 1/4] memblock: free_unused_memmap: use pageblock units instead of MAX_ORDER Date: Wed, 30 Jun 2021 10:12:08 +0300 Message-Id: <20210630071211.21011-2-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210630071211.21011-1-rppt@kernel.org> References: <20210630071211.21011-1-rppt@kernel.org> MIME-Version: 1.0 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KUqE6XNS; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf09.hostedemail.com: domain of rppt@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=rppt@kernel.org X-Stat-Signature: ob611r7mjgsgdsuiy873bayt1scidcr4 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: C4C3D3000351 X-HE-Tag: 1625037141-389339 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 The code that frees unused memory map uses rounds start and end of the holes that are freed to MAX_ORDER_NR_PAGES to preserve continuity of the memory map for MAX_ORDER regions. Lots of core memory management functionality relies on homogeneity of the memory map within each pageblock which size may differ from MAX_ORDER in certain configurations. Although currently, for the architectures that use free_unused_memmap(), pageblock_order and MAX_ORDER are equivalent, it is cleaner to have common notation thought mm code. Replace MAX_ORDER_NR_PAGES with pageblock_nr_pages and update the comments to make it more clear why the alignment to pageblock boundaries is required. Signed-off-by: Mike Rapoport --- mm/memblock.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index afaefa8fc6ab..97fa87541b5f 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1943,11 +1943,11 @@ static void __init free_unused_memmap(void) start = min(start, ALIGN(prev_end, PAGES_PER_SECTION)); #else /* - * Align down here since the VM subsystem insists that the - * memmap entries are valid from the bank start aligned to - * MAX_ORDER_NR_PAGES. + * Align down here since many operations in VM subsystem + * presume that there are no holes in the memory map inside + * a pageblock */ - start = round_down(start, MAX_ORDER_NR_PAGES); + start = round_down(start, pageblock_nr_pages); #endif /* @@ -1958,11 +1958,11 @@ static void __init free_unused_memmap(void) free_memmap(prev_end, start); /* - * Align up here since the VM subsystem insists that the - * memmap entries are valid from the bank end aligned to - * MAX_ORDER_NR_PAGES. + * Align up here since many operations in VM subsystem + * presume that there are no holes in the memory map inside + * a pageblock */ - prev_end = ALIGN(end, MAX_ORDER_NR_PAGES); + prev_end = ALIGN(end, pageblock_nr_pages); } #ifdef CONFIG_SPARSEMEM From patchwork Wed Jun 30 07:12:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12351361 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=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 77BD5C11F65 for ; Wed, 30 Jun 2021 07:12:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 25B9D61CC0 for ; Wed, 30 Jun 2021 07:12:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 25B9D61CC0 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 950148D0188; Wed, 30 Jun 2021 03:12:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 926578D017A; Wed, 30 Jun 2021 03:12:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EEEB8D0188; Wed, 30 Jun 2021 03:12:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0033.hostedemail.com [216.40.44.33]) by kanga.kvack.org (Postfix) with ESMTP id 5E4C18D017A for ; Wed, 30 Jun 2021 03:12:25 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 35F9318232A12 for ; Wed, 30 Jun 2021 07:12:25 +0000 (UTC) X-FDA: 78309521850.02.E62181F Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf02.hostedemail.com (Postfix) with ESMTP id C09AD7001BBC for ; Wed, 30 Jun 2021 07:12:24 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 9BFC561CA1; Wed, 30 Jun 2021 07:12:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625037144; bh=8S/jBfuQqPw5Y9SjeyOmElG9wuJ/AnCGL+Y38mTgWSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jPrqJ9elwiUu59yUGzRWjwOqgtiryjCb9+I5hv0C5j8k0p9IbjMiakMIRlbPyYp3M /eBXKjSoVvmhBcvGuxQx7dKJAl1EGWEUDvPQkRw4uZ1X/zfuJgYUtSXtthBFYzKiW7 OsK5uPqD0oOympl8T5XsctK3n+P29CWS4/YG6H4g6rtHVeX/XlRUeI3yCUsOjzcbTI FC0auyRdjEwMgTDhjtV3Z44n5ZOyCDG8a6ChugD2F6/9VNHEvPHfrmLaZfIQhQJMtb 3memoizj4Vyi1/0dYabvlMpCVZHo96iXPoWCdSfoKulVyvz3efbjCBgmtjrRDeSsQ/ zx5ssEZaHhsNw== From: Mike Rapoport To: linux-arm-kernel@lists.infradead.org Cc: Andrew Morton , Kefeng Wang , Mike Rapoport , Mike Rapoport , Russell King , Tony Lindgren , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 2/4] memblock: align freed memory map on pageblock boundaries with SPARSEMEM Date: Wed, 30 Jun 2021 10:12:09 +0300 Message-Id: <20210630071211.21011-3-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210630071211.21011-1-rppt@kernel.org> References: <20210630071211.21011-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C09AD7001BBC Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jPrqJ9el; spf=pass (imf02.hostedemail.com: domain of rppt@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Stat-Signature: wcsfresf1xrqn683zxbmnwq893g65q46 X-HE-Tag: 1625037144-113739 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 When CONFIG_SPARSEMEM=y the ranges of the memory map that are freed are not aligned to the pageblock boundaries which breaks assumptions about homogeneity of the memory map throughout core mm code. Make sure that the freed memory map is always aligned on pageblock boundaries regardless of the memory model selection. Signed-off-by: Mike Rapoport --- mm/memblock.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index 97fa87541b5f..2e25d69739e0 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1941,14 +1941,13 @@ static void __init free_unused_memmap(void) * due to SPARSEMEM sections which aren't present. */ start = min(start, ALIGN(prev_end, PAGES_PER_SECTION)); -#else +#endif /* * Align down here since many operations in VM subsystem * presume that there are no holes in the memory map inside * a pageblock */ start = round_down(start, pageblock_nr_pages); -#endif /* * If we had a previous bank, and there is a space @@ -1966,8 +1965,10 @@ static void __init free_unused_memmap(void) } #ifdef CONFIG_SPARSEMEM - if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION)) + if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION)) { + prev_end = ALIGN(end, pageblock_nr_pages); free_memmap(prev_end, ALIGN(prev_end, PAGES_PER_SECTION)); + } #endif } From patchwork Wed Jun 30 07:12:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12351363 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=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 2B626C11F65 for ; Wed, 30 Jun 2021 07:12:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D27C161CA1 for ; Wed, 30 Jun 2021 07:12:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D27C161CA1 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 4E2CA8D0189; Wed, 30 Jun 2021 03:12:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4BA5C8D017A; Wed, 30 Jun 2021 03:12:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A8638D0189; Wed, 30 Jun 2021 03:12:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0134.hostedemail.com [216.40.44.134]) by kanga.kvack.org (Postfix) with ESMTP id 0EEEF8D017A for ; Wed, 30 Jun 2021 03:12:28 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E2A178249980 for ; Wed, 30 Jun 2021 07:12:27 +0000 (UTC) X-FDA: 78309521934.22.C4120F8 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf22.hostedemail.com (Postfix) with ESMTP id 8ECE417E4 for ; Wed, 30 Jun 2021 07:12:27 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 7E83961C8D; Wed, 30 Jun 2021 07:12:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625037146; bh=UYXA0kQV/AwFpjI1/LxwK1KTy94Uxqh1rAP3oKcin5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ew/tukz+Z7GwlvQVFx7D/8kpQR7lebc9n3EiMj4QhF14U1zai38mvLjCr2Vy/RyTc YLtrZ+zFteQ0ZArsndyKDFuldXfWEYyEVz++jNr8622DIWCGRww+9k40E1qIrz7dWv T/bLBeh2gICo9HPMQR9vg/Xxt+QDBsgkxqXlT8XjEpfXWI6DFtG+3qUoqX1ipAoLbX AWQkdHuaA2zt88oS2H5MCIK4uo1UhElfVljNlYT+Ml5rl7c4F5O2RECVuGfqS9tzKv U5ztTH6hmM2uUMj/98xA1WQ+9DeXAr2Q57bEa93MhvvaIH6vkCEHVhplMTfX+0WDix 5/RdkymPa1sBA== From: Mike Rapoport To: linux-arm-kernel@lists.infradead.org Cc: Andrew Morton , Kefeng Wang , Mike Rapoport , Mike Rapoport , Russell King , Tony Lindgren , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 3/4] memblock: ensure there is no overflow in memblock_overlaps_region() Date: Wed, 30 Jun 2021 10:12:10 +0300 Message-Id: <20210630071211.21011-4-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210630071211.21011-1-rppt@kernel.org> References: <20210630071211.21011-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 8ECE417E4 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Ew/tukz+"; spf=pass (imf22.hostedemail.com: domain of rppt@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Stat-Signature: 5mf7h14mj1eii1sk9zf3sazi3wgnemtn X-HE-Tag: 1625037147-984489 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 There maybe an overflow in memblock_overlaps_region() if it is called with base and size such that base + size > PHYS_ADDR_MAX Make sure that memblock_overlaps_region() caps the size to prevent such overflow and remove now duplicated call to memblock_cap_size() from memblock_is_region_reserved(). Signed-off-by: Mike Rapoport --- mm/memblock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/memblock.c b/mm/memblock.c index 2e25d69739e0..67e0e24f8cc9 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -182,6 +182,8 @@ bool __init_memblock memblock_overlaps_region(struct memblock_type *type, { unsigned long i; + memblock_cap_size(base, &size); + for (i = 0; i < type->cnt; i++) if (memblock_addrs_overlap(base, size, type->regions[i].base, type->regions[i].size)) @@ -1794,7 +1796,6 @@ bool __init_memblock memblock_is_region_memory(phys_addr_t base, phys_addr_t siz */ bool __init_memblock memblock_is_region_reserved(phys_addr_t base, phys_addr_t size) { - memblock_cap_size(base, &size); return memblock_overlaps_region(&memblock.reserved, base, size); } From patchwork Wed Jun 30 07:12:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12351365 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=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 093F3C11F65 for ; Wed, 30 Jun 2021 07:12:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B3D7761C8D for ; Wed, 30 Jun 2021 07:12:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B3D7761C8D 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 2E6978D018A; Wed, 30 Jun 2021 03:12:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 296478D017A; Wed, 30 Jun 2021 03:12:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15E578D018A; Wed, 30 Jun 2021 03:12:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0088.hostedemail.com [216.40.44.88]) by kanga.kvack.org (Postfix) with ESMTP id E841F8D017A for ; Wed, 30 Jun 2021 03:12:30 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C1A471808894D for ; Wed, 30 Jun 2021 07:12:30 +0000 (UTC) X-FDA: 78309522060.16.2197715 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf09.hostedemail.com (Postfix) with ESMTP id 7CD3E3000349 for ; Wed, 30 Jun 2021 07:12:30 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 6071461CC0; Wed, 30 Jun 2021 07:12:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625037149; bh=4lZi2ByWBD8jlDCnRUevXMAgObek5/VFvTH3/bPm2EU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZBvVmkTL7uSEHD2WwVlJBNvtGcC3Nz2xDzvqmK6ZcNj5hRA6FngfMVPlL0aibIm8u uEPDLDjmIIdw9FQn+/aU0YvjiLRUNocqpEEDIuwSwldZsMnTaU8lVtEUR5JvU0zEcG nObX//WWjwB6evvr3tDnXVSsyH0pe5ZY2IO8HR9NCxuaHy1RYl2xrk9PaQGSfCdVxE +qmmiZf0i7VDXIlUsNYq67zVblQV30eInCyDmURwF+PeAlq2IHi8y6PGm9Co7K/MtZ +NREM9+ObdR7OyR+ZAPwk+7ltrC5w2qxCIRvSEpsFkG9NZ3y34h8MPqmFlUu7T+89T IWQQ7Mh5z9itw== From: Mike Rapoport To: linux-arm-kernel@lists.infradead.org Cc: Andrew Morton , Kefeng Wang , Mike Rapoport , Mike Rapoport , Russell King , Tony Lindgren , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 4/4] arm: extend pfn_valid to take into account freed memory map alignment Date: Wed, 30 Jun 2021 10:12:11 +0300 Message-Id: <20210630071211.21011-5-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210630071211.21011-1-rppt@kernel.org> References: <20210630071211.21011-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7CD3E3000349 X-Stat-Signature: cfhn1p7f864r9cshtbjk11r7q7fs371c Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZBvVmkTL; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf09.hostedemail.com: domain of rppt@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=rppt@kernel.org X-HE-Tag: 1625037150-239105 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 When unused memory map is freed the preserved part of the memory map is extended to match pageblock boundaries because lots of core mm functionality relies on homogeneity of the memory map within pageblock boundaries. Since pfn_valid() is used to check whether there is a valid memory map entry for a PFN, make it return true also for PFNs that have memory map entries even if there is no actual memory populated there. Signed-off-by: Mike Rapoport Tested-by: Kefeng Wang Reported-by: Guenter Roeck Signed-off-by: Mike Rapoport Tested-by: Guenter Roeck --- arch/arm/mm/init.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index 9d4744a632c6..6162a070a410 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -125,11 +125,22 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max_low, int pfn_valid(unsigned long pfn) { phys_addr_t addr = __pfn_to_phys(pfn); + unsigned long pageblock_size = PAGE_SIZE * pageblock_nr_pages; if (__phys_to_pfn(addr) != pfn) return 0; - return memblock_is_map_memory(addr); + /* + * If address less than pageblock_size bytes away from a present + * memory chunk there still will be a memory map entry for it + * because we round freed memory map to the pageblock boundaries. + */ + if (memblock_overlaps_region(&memblock.memory, + ALIGN_DOWN(addr, pageblock_size), + pageblock_size)) + return 1; + + return 0; } EXPORT_SYMBOL(pfn_valid); #endif