From patchwork Thu Apr 22 06:18:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12217703 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,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 7CC32C433B4 for ; Thu, 22 Apr 2021 06:21:32 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 2A39260FD7 for ; Thu, 22 Apr 2021 06:21:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2A39260FD7 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=desiato.20200630; 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=f4gb9TwJVpIAPsNcnHvSSF/5/OQUB07PYjbMiQfggl0=; b=SYWMh8GMCa98HtROKh+J6cz1Y g56viZKk0ju74ShHM0kqw/4nUDTeXrVGcezZJRB/sudjCct4PIbykxSyHZmzheV7bkGf88qPp4CQP BnR+ai1S6B0NCCQW1CxHShKQfJ0Et/W03UWhcKxwnxTZZN6JlZrzw6L1he4nXTh58gml6Q46KMgtU VDm8a4Ug9KGod++YuohhE20U7AcUJ4Z55JLP5IOAqerEBvMSspcMLWmrzEYkaxSgpbc0XquqbeiBQ lNbXg/mD1vskLRc0wd5ciMJLWCWWRn9jTYhgT7QuQrKh1WrpZNLSCvI7FpgxNLQO1fHpdu1bOEqza O8g+9YWBQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZSgW-00FyLr-0Q; Thu, 22 Apr 2021 06:19:32 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZSgI-00FyK6-FI for linux-arm-kernel@desiato.infradead.org; Thu, 22 Apr 2021 06:19:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=3ulNwrU85zrE10Xr//2x6C328KKH8Itb2ZqL71DkfwI=; b=rsH7FeID3PCIa9UNlAPCTIViVH E9OtC6soMOyzOku2Go8P5tpZNEX/F94H4zGFCFDQlSA7wpGgXGtugg8uxWgBHZeHrBqyAE3/nVZN+ qK8GULfHZPcDzMWAPIN0a+pZ4FSPk3lg4YijNemVDcj1ivYxy1SpOwZzSWeJ/eYcDvhay8c8al8zN Weo6iXVo22mBa89BBOOIESyzcXOq5VjOkFGKGPJ819kiKB49a45B9fqu32CB7eYfXyDQi+GQluDLs g5AuMQJWH0eYZlAd/ETCY5yQFVJote5+VtaahhXjLMBWO5qVNpRBTD/DrRTuLPoXi91zPYMU6uzWp uIwQkefA==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZSgG-00DPCM-1T for linux-arm-kernel@lists.infradead.org; Thu, 22 Apr 2021 06:19:17 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 15B886113C; Thu, 22 Apr 2021 06:19:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619072355; bh=E81akF1BinjHKMvNozvRyjwjqZ1X1qBHHvRxS2i48PI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uhF/ObuaXIspDxBYAAvqiR9bZWwB6AgoMlH014SLQhtOLankdq4B/GD3Yo0udRpVN V4O7zfQeYj3d3MsrkeqVdql8uSygos1lTLK7EI4LL+45XgG1WXnQAKKoqc+MSynyv8 RPTss4obNwjyO+I1nhKkRsUpm+BVzxRIOv8H69n8pyGU9MgJmnC8MVR812ygWZw88d IMPinfocfipp01RqC8gTj6sHqEEC14mHm4WBMVnRmpjfqnBGjgfwVLky+NEAH/sLGz ymht+5Lg6VmPoy5sPouM6ey44RYSp1fUy1r+DOgpc2ZVwQZt/vzKXsMWS96M//CVtD HCIHPVRr+SEcQ== From: Mike Rapoport To: linux-arm-kernel@lists.infradead.org Cc: Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Catalin Marinas , David Hildenbrand , Marc Zyngier , Mark Rutland , Mike Rapoport , Mike Rapoport , Will Deacon , kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 1/4] include/linux/mmzone.h: add documentation for pfn_valid() Date: Thu, 22 Apr 2021 09:18:59 +0300 Message-Id: <20210422061902.21614-2-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210422061902.21614-1-rppt@kernel.org> References: <20210422061902.21614-1-rppt@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210421_231916_143695_606538D2 X-CRM114-Status: GOOD ( 12.81 ) 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 Add comment describing the semantics of pfn_valid() that clarifies that pfn_valid() only checks for availability of a memory map entry (i.e. struct page) for a PFN rather than availability of usable memory backing that PFN. The most "generic" version of pfn_valid() used by the configurations with SPARSEMEM enabled resides in include/linux/mmzone.h so this is the most suitable place for documentation about semantics of pfn_valid(). Suggested-by: Anshuman Khandual Signed-off-by: Mike Rapoport Reviewed-by: Anshuman Khandual --- include/linux/mmzone.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 47946cec7584..961f0eeefb62 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1410,6 +1410,17 @@ static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn) #endif #ifndef CONFIG_HAVE_ARCH_PFN_VALID +/** + * pfn_valid - check if there is a valid memory map entry for a PFN + * @pfn: the page frame number to check + * + * Check if there is a valid memory map entry aka struct page for the @pfn. + * Note, that availability of the memory map entry does not imply that + * there is actual usable memory at that @pfn. The struct page may + * represent a hole or an unusable page frame. + * + * Return: 1 for PFNs that have memory map entries and 0 otherwise + */ static inline int pfn_valid(unsigned long pfn) { struct mem_section *ms; From patchwork Thu Apr 22 06:19:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12217705 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,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,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 541CFC433B4 for ; Thu, 22 Apr 2021 06:21:41 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 AD358613B0 for ; Thu, 22 Apr 2021 06:21:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD358613B0 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=desiato.20200630; 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=B4Cuj2bmy2FqOYlOmcQotjVttvPlYcDGDlf8it2Bpr4=; b=SRR+XcQILeM7JoPoBIQNh4zTI rfpgvFzfp5m0/iTxC14rIatu0vjvd3Nhb5tNs4ClLueGDVhC/FjhQ/YWLpw8l1sKiRwn/Rlb5gLhE gJv+SEk4wAAxtB5RWc5PDkb321BtejxsgFOUEEU51V+eTt7APHDAp0cK33yAYrnqmgXe+G97gu2x/ F2YTy9mQOscytmcC4WEjOp8Nzh4Eaqw117gFKbR+eDaBVUWyIwlukrA14ijVMYEn0qOAkMnHVEhvr +bE/1vhXRn8MC+FeMA112bcLKY42MiNHN6rY2Jo53u8+dG9bMCx+FzTJkd/wjFMdDt4W8MaNDGHd+ YzCpuzzyg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZSgi-00FyMl-2a; Thu, 22 Apr 2021 06:19:44 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZSgM-00FyKd-Ol for linux-arm-kernel@desiato.infradead.org; Thu, 22 Apr 2021 06:19:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=GwIyU4uWGMghtaAeEW6PJ47LFDrwjpKYkGlLssBTYlU=; b=XgbvfPPhIA59ZhkV+qSWd1DIqp SX7V3QRQtJIFPQoEaXoBiGHFYG868bUqZ0fMSpRkaDl5STaL4x8gjcJEwUQsd6+fzN72Jwr5rEhtV JTCA278DCn5ucKjNa/Vy1vOom8O1/zMBiXu66TQbjlZ5ec85wKywlozc2yuvetBcD9DNt7788YJEp +IRJFgUdTZuRTaHuLbV/Xw2Nq21u6azNPbi/RS2JTct4zw21sgt/eG62GI0Wbw+0+NVxgUM5FqN/3 qex1Vpwu3g8NKyYfarcBAA61Cy+LkDRBin1xGVIcEReale5A2/rfbhZ7EYftwMstBV0lORD8MMDCW 3RGj8a6g==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZSgK-00DPDG-4E for linux-arm-kernel@lists.infradead.org; Thu, 22 Apr 2021 06:19:21 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 275BD60E0C; Thu, 22 Apr 2021 06:19:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619072359; bh=uAcQCKfynNirKrVcKn7BUZtb4Q7z7Znh4i0ynZdq9kE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bzfnTm3Z1pasiEH1lFZ42vt8BpmmNbt8U4aNZDs48SNuYcBU/Xdl4S/HQPLYNPYjN ZdRUVwu+uSRJY+41MYKZluiy9qQuuIn7q9LE/GyHMIbISznQ2oWPWxC9Qz7N1eKu8N 9jzEZvri+Lio8jIA6hZawhZU7qVjD6bUoxTribnLNM6fd/BIp3gMFODASulbMWHtOq re+OJ1tv+B49WL1NU+QPHkzjrdACu9GLk9d5KWrIMEQJzR4GJKXwvmCl3M9YHcf2yW zLiUPmbqfOx6PWakTZ2fDBSMKaiZ7ex8/8mUw6yo6le9C7ULIJZw4L3ci5ZLsI7ryO 34jeQUkYTpUXQ== From: Mike Rapoport To: linux-arm-kernel@lists.infradead.org Cc: Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Catalin Marinas , David Hildenbrand , Marc Zyngier , Mark Rutland , Mike Rapoport , Mike Rapoport , Will Deacon , kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 2/4] memblock: update initialization of reserved pages Date: Thu, 22 Apr 2021 09:19:00 +0300 Message-Id: <20210422061902.21614-3-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210422061902.21614-1-rppt@kernel.org> References: <20210422061902.21614-1-rppt@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210421_231920_267837_1293B744 X-CRM114-Status: GOOD ( 18.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 The struct pages representing a reserved memory region are initialized using reserve_bootmem_range() function. This function is called for each reserved region just before the memory is freed from memblock to the buddy page allocator. The struct pages for MEMBLOCK_NOMAP regions are kept with the default values set by the memory map initialization which makes it necessary to have a special treatment for such pages in pfn_valid() and pfn_valid_within(). Split out initialization of the reserved pages to a function with a meaningful name and treat the MEMBLOCK_NOMAP regions the same way as the reserved regions and mark struct pages for the NOMAP regions as PageReserved. Signed-off-by: Mike Rapoport Reviewed-by: David Hildenbrand Reviewed-by: Anshuman Khandual --- include/linux/memblock.h | 4 +++- mm/memblock.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 5984fff3f175..1b4c97c151ae 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -30,7 +30,9 @@ extern unsigned long long max_possible_pfn; * @MEMBLOCK_NONE: no special request * @MEMBLOCK_HOTPLUG: hotpluggable region * @MEMBLOCK_MIRROR: mirrored region - * @MEMBLOCK_NOMAP: don't add to kernel direct mapping + * @MEMBLOCK_NOMAP: don't add to kernel direct mapping and treat as + * reserved in the memory map; refer to memblock_mark_nomap() description + * for further details */ enum memblock_flags { MEMBLOCK_NONE = 0x0, /* No special request */ diff --git a/mm/memblock.c b/mm/memblock.c index afaefa8fc6ab..3abf2c3fea7f 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -906,6 +906,11 @@ int __init_memblock memblock_mark_mirror(phys_addr_t base, phys_addr_t size) * @base: the base phys addr of the region * @size: the size of the region * + * The memory regions marked with %MEMBLOCK_NOMAP will not be added to the + * direct mapping of the physical memory. These regions will still be + * covered by the memory map. The struct page representing NOMAP memory + * frames in the memory map will be PageReserved() + * * Return: 0 on success, -errno on failure. */ int __init_memblock memblock_mark_nomap(phys_addr_t base, phys_addr_t size) @@ -2002,6 +2007,26 @@ static unsigned long __init __free_memory_core(phys_addr_t start, return end_pfn - start_pfn; } +static void __init memmap_init_reserved_pages(void) +{ + struct memblock_region *region; + phys_addr_t start, end; + u64 i; + + /* initialize struct pages for the reserved regions */ + for_each_reserved_mem_range(i, &start, &end) + reserve_bootmem_region(start, end); + + /* and also treat struct pages for the NOMAP regions as PageReserved */ + for_each_mem_region(region) { + if (memblock_is_nomap(region)) { + start = region->base; + end = start + region->size; + reserve_bootmem_region(start, end); + } + } +} + static unsigned long __init free_low_memory_core_early(void) { unsigned long count = 0; @@ -2010,8 +2035,7 @@ static unsigned long __init free_low_memory_core_early(void) memblock_clear_hotplug(0, -1); - for_each_reserved_mem_range(i, &start, &end) - reserve_bootmem_region(start, end); + memmap_init_reserved_pages(); /* * We need to use NUMA_NO_NODE instead of NODE_DATA(0)->node_id From patchwork Thu Apr 22 06:19:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12217707 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,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,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 3F3A7C433ED for ; Thu, 22 Apr 2021 06:21:46 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 B46D4613CE for ; Thu, 22 Apr 2021 06:21:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B46D4613CE 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=desiato.20200630; 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=Cd+YETNRmLeZCgN3H2iNkhfapQzQ+Jz08M76+QvefYo=; b=NNz0+6Y+tVl/bO/caSOmJoSfE fPlhuzwIRYspoNsv+rxBs6Zso5wVqGE8GNaKZoNIS4RW7lcmj42p4Hs1iiaZ9oL1+GAhg2kSH1Ldq 4bRiiwqWDo0u+TGdAFmI/r7UKFq1SLvsO4b+A6KQPFuxU8S1m1VtxSLUJcQznrxgmTdFLRO7zXnUL KI4ov94ftoReyCA5QqHkKSDZw2Q2/qeEGguxihoGK4nR0ynYpZg1vZTS7aa9Z9/NwcJr9B/kgibIc UKLPF3P21nW55J2p67jseHDn7DWtt5Vje+B2mHBXUPsMsnMmsV22HTGlacXSH6hrSDwjGyOu1+QhQ UuYq4qWcQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZSgs-00FyON-Fo; Thu, 22 Apr 2021 06:19:54 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZSgQ-00FyKw-Uh for linux-arm-kernel@desiato.infradead.org; Thu, 22 Apr 2021 06:19:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=IxpNaIC8neDzxbmBb8/w/64TRws/ZQxYG1TLANkr4gE=; b=Uxz+c/zZc5t9R9uTw7tqEDIhmc NzbV6z3gASf0pIccARAY+fQWxr0jyr89vsXiNubf+F1q+Clo5dY9N39cRCfbfTbSZ3nEOdJOAyq9b yJpKJ2Tv+sr61at5fKUfJWyrBAPqqNg29js9lL6gJHnvZFROVytuEdpJuMyr//E/Q+Ln7Rx74HRTQ HUe98liwiQXgSrIia7n3F8TWcNlhBTfnJbmPxoe2cCpCGf/lBAuuZhCQPRZztrLBIlEafH/urpEgb KWw0qxCi+n/DE6CZuHhSEWzZX2uCHjd4Ovf9BXMAfrUTEArSOMMmquPyBg+wZyO7f6cz3U+8i01uy 7fpm0DdA==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZSgO-00DPE7-7T for linux-arm-kernel@lists.infradead.org; Thu, 22 Apr 2021 06:19:25 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 33D1F61435; Thu, 22 Apr 2021 06:19:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619072363; bh=9kfzC5zo0v7akEEAeoirtWTk7ku+3GeuiJKcxC8sMNE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bQF3qbFGi5hXQBVvbuNSirl3raBF5dajpQyIONh8J7jNTSbBrcc97/YaHzw1oM6In UgyU3X3TBuGIyVal/JeXJ6SZ4f4oDgkevVVdRumQNap2mxBgKKuJMN6o+cp+hxYvab T1QJozEsOSvuYGsCB6SWM+w+odj/lxPNQ2qhZz+4Rpc6sXntSQHB8o/Bu12+9OudP/ r6OAWRc+xBBTXMsanhDbLIyZfn4LSnkvJxEm8kv38/7bqACs8ZfYJbE14XXmRdw/UV kiJkogCyXZH/92oTenQnv2DMzg07CRzwBCRCpCNS30vCTzsZ5BtqQ0hyV2dTmQ2snf jl4aziuCXeIXw== From: Mike Rapoport To: linux-arm-kernel@lists.infradead.org Cc: Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Catalin Marinas , David Hildenbrand , Marc Zyngier , Mark Rutland , Mike Rapoport , Mike Rapoport , Will Deacon , kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 3/4] arm64: decouple check whether pfn is in linear map from pfn_valid() Date: Thu, 22 Apr 2021 09:19:01 +0300 Message-Id: <20210422061902.21614-4-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210422061902.21614-1-rppt@kernel.org> References: <20210422061902.21614-1-rppt@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210421_231924_346962_5DCC736B X-CRM114-Status: GOOD ( 19.45 ) 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 intended semantics of pfn_valid() is to verify whether there is a struct page for the pfn in question and nothing else. Yet, on arm64 it is used to distinguish memory areas that are mapped in the linear map vs those that require ioremap() to access them. Introduce a dedicated pfn_is_map_memory() wrapper for memblock_is_map_memory() to perform such check and use it where appropriate. Using a wrapper allows to avoid cyclic include dependencies. While here also update style of pfn_valid() so that both pfn_valid() and pfn_is_map_memory() declarations will be consistent. Signed-off-by: Mike Rapoport Acked-by: David Hildenbrand --- arch/arm64/include/asm/memory.h | 2 +- arch/arm64/include/asm/page.h | 3 ++- arch/arm64/kvm/mmu.c | 2 +- arch/arm64/mm/init.c | 12 ++++++++++++ arch/arm64/mm/ioremap.c | 4 ++-- arch/arm64/mm/mmu.c | 2 +- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 0aabc3be9a75..194f9f993d30 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -351,7 +351,7 @@ static inline void *phys_to_virt(phys_addr_t x) #define virt_addr_valid(addr) ({ \ __typeof__(addr) __addr = __tag_reset(addr); \ - __is_lm_address(__addr) && pfn_valid(virt_to_pfn(__addr)); \ + __is_lm_address(__addr) && pfn_is_map_memory(virt_to_pfn(__addr)); \ }) void dump_mem_limit(void); diff --git a/arch/arm64/include/asm/page.h b/arch/arm64/include/asm/page.h index 012cffc574e8..75ddfe671393 100644 --- a/arch/arm64/include/asm/page.h +++ b/arch/arm64/include/asm/page.h @@ -37,7 +37,8 @@ void copy_highpage(struct page *to, struct page *from); typedef struct page *pgtable_t; -extern int pfn_valid(unsigned long); +int pfn_valid(unsigned long pfn); +int pfn_is_map_memory(unsigned long pfn); #include diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 8711894db8c2..23dd99e29b23 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -85,7 +85,7 @@ void kvm_flush_remote_tlbs(struct kvm *kvm) static bool kvm_is_device_pfn(unsigned long pfn) { - return !pfn_valid(pfn); + return !pfn_is_map_memory(pfn); } /* diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 3685e12aba9b..966a7a18d528 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -258,6 +258,18 @@ int pfn_valid(unsigned long pfn) } EXPORT_SYMBOL(pfn_valid); +int pfn_is_map_memory(unsigned long pfn) +{ + phys_addr_t addr = PFN_PHYS(pfn); + + /* avoid false positives for bogus PFNs, see comment in pfn_valid() */ + if (PHYS_PFN(addr) != pfn) + return 0; + + return memblock_is_map_memory(addr); +} +EXPORT_SYMBOL(pfn_is_map_memory); + static phys_addr_t memory_limit = PHYS_ADDR_MAX; /* diff --git a/arch/arm64/mm/ioremap.c b/arch/arm64/mm/ioremap.c index b5e83c46b23e..b7c81dacabf0 100644 --- a/arch/arm64/mm/ioremap.c +++ b/arch/arm64/mm/ioremap.c @@ -43,7 +43,7 @@ static void __iomem *__ioremap_caller(phys_addr_t phys_addr, size_t size, /* * Don't allow RAM to be mapped. */ - if (WARN_ON(pfn_valid(__phys_to_pfn(phys_addr)))) + if (WARN_ON(pfn_is_map_memory(__phys_to_pfn(phys_addr)))) return NULL; area = get_vm_area_caller(size, VM_IOREMAP, caller); @@ -84,7 +84,7 @@ EXPORT_SYMBOL(iounmap); void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size) { /* For normal memory we already have a cacheable mapping. */ - if (pfn_valid(__phys_to_pfn(phys_addr))) + if (pfn_is_map_memory(__phys_to_pfn(phys_addr))) return (void __iomem *)__phys_to_virt(phys_addr); return __ioremap_caller(phys_addr, size, __pgprot(PROT_NORMAL), diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 5d9550fdb9cf..26045e9adbd7 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -81,7 +81,7 @@ void set_swapper_pgd(pgd_t *pgdp, pgd_t pgd) pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, unsigned long size, pgprot_t vma_prot) { - if (!pfn_valid(pfn)) + if (!pfn_is_map_memory(pfn)) return pgprot_noncached(vma_prot); else if (file->f_flags & O_SYNC) return pgprot_writecombine(vma_prot); From patchwork Thu Apr 22 06:19:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12217709 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,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,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 63E6AC433B4 for ; Thu, 22 Apr 2021 06:21:52 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 DB474613B0 for ; Thu, 22 Apr 2021 06:21:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB474613B0 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=desiato.20200630; 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=QqAHBh1o+bjkLyHf/U+P1FYF6jcHZIx/3McArpFxTJU=; b=HKk95keWBB2LtdLi/4dxLisAE Wy5eqAnXlyDZbSk0aDVyvpRKMhsu5ApzZNtiB8uHDFLBhBLW/bYoHrG55NoXcagMfqNxDmI03m06B akLuzOlFvOEEZTXIaETVKDmSCiQhgb5L6ZdGbgoNR+UL2/Shji85ufMHzZXA/WE+nPtc/y0dxC7Cg m3m8spvXJjiERpquzXed0ckECCUd01l9lwSUAW1/8ZWOAwFbwl1IQLDo/t6hiCCTxoFgyaFppn9uw oQCvvuwx1Pao2a74kIr6aasIv8RKKJjREjiqBMLFM6VtcbHqE5TZWRKFtah1ptVR1Jn3HErWHWGgz lPZlDx4mA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZSh5-00FyQF-MO; Thu, 22 Apr 2021 06:20:07 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZSgU-00FyLi-Oq for linux-arm-kernel@desiato.infradead.org; Thu, 22 Apr 2021 06:19:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=RUcoxw0ewvkDgLnrI7Af5RTtX8kxOht7a+fLSvrb02s=; b=epXL4DVmOSuOaKkuk1ZPAOLHid W24fIh9J8GWfQb1uTZOIrHMWwrXtLB5eHCht3IBi4N/XGLs2GYti5er4uUMYcviSRyHqtSdF9rae6 b22mQMC+84Un9KyKaeGZHbVm/kkugh2Hl7ytm/EPQrsOa+UDJmNKkpzTtEINSx3pwta8FTNHWyL+D xcAXH7flhfNEaGMI/ZVAVF2GdK8NbXyzAgCnc4QHaCc/xfyfFyix2z0JMvtEiKQ2IXMy4UGCICIY6 MUsc0W35fTKYisKq7H5B81UTxE1mD0QX2ZSMCMdeadnnHzZwyQenaQWdrzdhl/hF/UKpvNTLOAoQB Yh/IbqZw==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZSgS-00DPEj-7h for linux-arm-kernel@lists.infradead.org; Thu, 22 Apr 2021 06:19:29 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4CDF86145A; Thu, 22 Apr 2021 06:19:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619072367; bh=5pv19/zw6k97y2VFoD7tQZ9uQemSm8OSk2DzdouBBz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lRqB+e3jDktyHVncSv2EVQ7vnSkGOi8MCTVL1PoGUfGbpMvYA/EF9yl6xQDYcIM81 jivV+9fC8+krtFB7qJqeN2qoLwABPCk8lp2L6Ng6FEVG35NPRMkd5yj4rF/Egqwrg4 Dr84oFWd0BnfPcFD/QQWJaBm7tj3EbMKhpKu/oPfC3CEWX0RJSseTwqkb8XV08pm7T NSK/zDggVENJVpjJI0FqoTgHmQh4N/4j6XT9eUzghketH0zek7du2QBJlzoSGMTHDY JrLT07j4mPVTO9xZnnDueXjmXuGmP11FZ7RI8uvBILUSmJRGfVahjmRG7dZ6OIWzTo VS1h3VMV3f0ww== From: Mike Rapoport To: linux-arm-kernel@lists.infradead.org Cc: Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Catalin Marinas , David Hildenbrand , Marc Zyngier , Mark Rutland , Mike Rapoport , Mike Rapoport , Will Deacon , kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 4/4] arm64: drop pfn_valid_within() and simplify pfn_valid() Date: Thu, 22 Apr 2021 09:19:02 +0300 Message-Id: <20210422061902.21614-5-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210422061902.21614-1-rppt@kernel.org> References: <20210422061902.21614-1-rppt@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210421_231928_360536_E5295491 X-CRM114-Status: GOOD ( 17.45 ) 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 arm64's version of pfn_valid() differs from the generic because of two reasons: * Parts of the memory map are freed during boot. This makes it necessary to verify that there is actual physical memory that corresponds to a pfn which is done by querying memblock. * There are NOMAP memory regions. These regions are not mapped in the linear map and until the previous commit the struct pages representing these areas had default values. As the consequence of absence of the special treatment of NOMAP regions in the memory map it was necessary to use memblock_is_map_memory() in pfn_valid() and to have pfn_valid_within() aliased to pfn_valid() so that generic mm functionality would not treat a NOMAP page as a normal page. Since the NOMAP regions are now marked as PageReserved(), pfn walkers and the rest of core mm will treat them as unusable memory and thus pfn_valid_within() is no longer required at all and can be disabled by removing CONFIG_HOLES_IN_ZONE on arm64. pfn_valid() can be slightly simplified by replacing memblock_is_map_memory() with memblock_is_memory(). Signed-off-by: Mike Rapoport Acked-by: David Hildenbrand --- arch/arm64/Kconfig | 3 --- arch/arm64/mm/init.c | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index e4e1b6550115..58e439046d05 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1040,9 +1040,6 @@ config NEED_PER_CPU_EMBED_FIRST_CHUNK def_bool y depends on NUMA -config HOLES_IN_ZONE - def_bool y - source "kernel/Kconfig.hz" config ARCH_SPARSEMEM_ENABLE diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 966a7a18d528..f431b38d0837 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -243,7 +243,7 @@ int pfn_valid(unsigned long pfn) /* * ZONE_DEVICE memory does not have the memblock entries. - * memblock_is_map_memory() check for ZONE_DEVICE based + * memblock_is_memory() check for ZONE_DEVICE based * addresses will always fail. Even the normal hotplugged * memory will never have MEMBLOCK_NOMAP flag set in their * memblock entries. Skip memblock search for all non early @@ -254,7 +254,7 @@ int pfn_valid(unsigned long pfn) return pfn_section_valid(ms, pfn); } #endif - return memblock_is_map_memory(addr); + return memblock_is_memory(addr); } EXPORT_SYMBOL(pfn_valid);