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: 12351347 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.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 BC7AEC11F65 for ; Wed, 30 Jun 2021 07:14:23 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8095861C75 for ; Wed, 30 Jun 2021 07:14:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8095861C75 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CPF2QRU5r/ED7+oUgvGknDWDO6TsWDNVEVxh82JSHcg=; b=mH6ci71a5RmH8h /eZODJkoD8ggV5yGVlJPuaxYoObU8FFL4tRXJOaU+P2sUUQhtb4Jj2HtSM7IMijYVwAl/BrgUqFoI XHlYHdsnufT4DYzViSUNyeqPawjXvd3/1GMKB/8g/HWS16iwxMVMSUVfECAdWQco2OpbNKYhTDGGr j9V61GCyUWM4iLWz8afE3paTQYLv/IMTBu59BjO4EvBNqf5w8wHxWsebTkMjSOuZGAdChOrwGFVoe IGwS4HWb7zH3Y7D/KQM+MWvNm4U6KUKxtMI6Jtae7/FFj9CuKZGN8J9CKOE8dhlVgOry4FvVF4HUp sbPNsQKJJxe4EYfejubg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUOf-00D03G-BZ; Wed, 30 Jun 2021 07:12:33 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUOT-00Czzo-Em for linux-arm-kernel@lists.infradead.org; Wed, 30 Jun 2021 07:12:22 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210630_001221_553972_49FF0AF6 X-CRM114-Status: GOOD ( 13.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 12351349 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.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 6BFBDC11F65 for ; Wed, 30 Jun 2021 07:14:26 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 33CE961CC0 for ; Wed, 30 Jun 2021 07:14:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 33CE961CC0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vs+Yh1aq2QkIEuYeYYuKKx2R5/pDLmOe9MCxJRpJ3cM=; b=Y/e3r5GT5T0gb1 s4uKs4qKUgH0lUG27Bvg4gx6+Ux/lAds8DwqRp6vLwivlj2Y2FMPLcOOddMUAcZ0PIcBRx4VKkvbj 1gXC+3h837AU9Na35I6fEkPQCANUcMwhRCJS0bB8soA5sfBYMe3ySaoSrKmvClFPqUhFFiyM0hskN mY1lRgyCOy212JKo2V6RJUjAgJN7AGwDr/yulbLdWzyW6sgiTf9UX934F0vGBsgMUj+sbJgmAc+ZC 31SziQ6y+IC4oqrQU/maVhA4IVxp23yApO8Mr6zKfPROG1qBsB8GH52Ako+kfYxxgC27IyoJ2BF2A ER9162Myv0ouVnUeePbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUOp-00D04V-Pz; Wed, 30 Jun 2021 07:12:44 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUOW-00D00o-9l for linux-arm-kernel@lists.infradead.org; Wed, 30 Jun 2021 07:12:25 +0000 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210630_001224_403534_D4B1981F X-CRM114-Status: GOOD ( 13.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 12351351 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.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 1BB14C11F69 for ; Wed, 30 Jun 2021 07:14:27 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D9F6461CC0 for ; Wed, 30 Jun 2021 07:14:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9F6461CC0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bc0xVC0W8FMrC7DKUx7762tsP3MKrFk2ciorKJQsUpg=; b=HNww6SJ4B+EqQi oJOzDaTW3tb5mb6HDwkAxhQs8xAnS2QkMKUSST0tXG4O9hy5jLlW87UkeVTG98YMJMPss48wMW2Ld kiV6E0E7wNGZLxXfAbuuF58Lvz0OAzUOqNZyGK2zmWh1IwNygQP+NONRlA17AVJmn/FAkuY4bqocT 57glq5CoCQCLFO/PgW7XYpHlmkQdcxW8k36TTZoX/wMdgPeGGLoOQW+p9Ehbb+Nx2saSxFDIUmP6w 3m/U85Q+eXAFQQV3zWK2L0uTX2+vcg5Mvg3Ud4KhZkbZKM8DK0GjiXrPHYFjJ9PdxAel9N1NjgsLa VBSFTgn5Cd5EMO8rCbVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUP0-00D06W-SN; Wed, 30 Jun 2021 07:12:55 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUOZ-00D01q-40 for linux-arm-kernel@lists.infradead.org; Wed, 30 Jun 2021 07:12:28 +0000 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210630_001227_228668_0AE5192B X-CRM114-Status: GOOD ( 11.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 12351353 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.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 51534C11F68 for ; Wed, 30 Jun 2021 07:14:41 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1C1DB61CC1 for ; Wed, 30 Jun 2021 07:14:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1C1DB61CC1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HsI+qw8pp9h+yny3vHqogoVUwa8Orny6hglXqZiGta0=; b=opknuhkT/9FeIm w923WwSMX73xFIwgWnoFaASdYM3OaZ/F1TyLnuzYfzuIahDG14L4z1nemmZOsOKdCCSjX3ng0ONCZ 5WFVZGPBoZu8rDwgccQAuphhnedkSIpBi4EVxhb73iiDJbryVGBSy7iA23ux/gGQBHFAf706Q2M69 +WNAHl96bel86hiTsrNxM/IL5d0zdU8Z8BZ5hRxJrpf8RiwoIdoDGVwYpseZ76UB+GpkgEnnJ0hbl wyBOumaHBSdk1xtaHEuclqNMWoeCJ8m/5JjgKuifSlcS9KMB6dwWVuOZ5d5+XFzDQK1nTJoUVdcPU /Wtvp8zQ2QWaXBREpJAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUPC-00D08u-56; Wed, 30 Jun 2021 07:13:06 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUOc-00D02Y-0o for linux-arm-kernel@lists.infradead.org; Wed, 30 Jun 2021 07:12:31 +0000 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210630_001230_119528_9B1B6D00 X-CRM114-Status: GOOD ( 15.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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