Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1752096pxb; Thu, 4 Mar 2021 21:26:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJwHq4+owd2Cl6q84Ey5zIQdlkKAcX7QVqpLAn/M4NhT791L4ACLqGYvgZch1HTIj/VbL4vs X-Received: by 2002:a05:6e02:1d88:: with SMTP id h8mr6469571ila.43.1614921996234; Thu, 04 Mar 2021 21:26:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614921996; cv=none; d=google.com; s=arc-20160816; b=rwX1/9RYzGgs8sX4YBSEx/lszuFBYTJbf23aOmxRYkB/8fFvn1O4R7/VcLVyTiWAYe HjYPySn4gnfrTWnCsgRrsSTbh0lWjjFsKxu4ASVkySXWsLrha8HzF08LkXlk2lcNdXSW P8oAdhAMszp1wYihg8Sawl4liINUu5mOmmLbFzqPeDNuh/XrAzJM8pr3TwaCnmUgDAcb YmklhNASMsHYV7lfQqpJemOKEOcJBP0kladBbJRFRYoe+s8NbT+R8Le4+1Sypn4glNBI r0yWtf0mrEwazfbyeTEi/Z+/TmBGDKxW1HURTSAB2KWO6mksTjbXAMtp7xiUsDYA1QCc /c9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=QiyYY4qRW1UVgE+5FbkBaV60rLkFNY4vSmUoDt84uao=; b=crWSnGJra6F5HuE9X+csinWrX4NSkcBhVpUTGJ/Ymqj75FU0Ap30jEksvn+DcUXKUd ywGxLobr13yRGecOyFPOszZUlbdae1uINXWvtCcQX40zkIV8Dop8RQMuJu7ImqgVroCr 9J8atATsz1cKX4Oyh77JRuEy5epaQvbdC8fmnBUzMls2NHNBdo/1zmdIjo2aB+uDNAzs glgpkz8EkytYYuaUdqAVs5RKyUM88rd47fC3l3d9cdvJRQswdt6qx4OejbkSSaSwgg9D UHnVq8P+MQJVBaAviyA4N2DutELVaZri3jQNVbWtNF+KtBRLfs/daQqFkztRY/NAtkHZ I2nw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a16si1609144iow.42.2021.03.04.21.26.22; Thu, 04 Mar 2021 21:26:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229573AbhCEFYt (ORCPT + 99 others); Fri, 5 Mar 2021 00:24:49 -0500 Received: from foss.arm.com ([217.140.110.172]:47988 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbhCEFYs (ORCPT ); Fri, 5 Mar 2021 00:24:48 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 61A87113E; Thu, 4 Mar 2021 21:24:48 -0800 (PST) Received: from p8cg001049571a15.arm.com (unknown [10.163.68.69]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3E9043F73B; Thu, 4 Mar 2021 21:24:42 -0800 (PST) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Anshuman Khandual , Catalin Marinas , Will Deacon , Ard Biesheuvel , Mark Rutland , James Morse , Robin Murphy , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Dan Williams , David Hildenbrand , Mike Rapoport , Veronika Kabatova Subject: [PATCH V3 2/2] arm64/mm: Reorganize pfn_valid() Date: Fri, 5 Mar 2021 10:54:58 +0530 Message-Id: <1614921898-4099-3-git-send-email-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1614921898-4099-1-git-send-email-anshuman.khandual@arm.com> References: <1614921898-4099-1-git-send-email-anshuman.khandual@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are multiple instances of pfn_to_section_nr() and __pfn_to_section() when CONFIG_SPARSEMEM is enabled. This can be optimized if memory section is fetched earlier. This replaces the open coded PFN and ADDR conversion with PFN_PHYS() and PHYS_PFN() helpers. While there, also add a comment. This does not cause any functional change. Cc: Catalin Marinas Cc: Will Deacon Cc: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Reviewed-by: David Hildenbrand Signed-off-by: Anshuman Khandual --- arch/arm64/mm/init.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 5920c527845a..3685e12aba9b 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -219,16 +219,26 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max) int pfn_valid(unsigned long pfn) { - phys_addr_t addr = pfn << PAGE_SHIFT; + phys_addr_t addr = PFN_PHYS(pfn); - if ((addr >> PAGE_SHIFT) != pfn) + /* + * Ensure the upper PAGE_SHIFT bits are clear in the + * pfn. Else it might lead to false positives when + * some of the upper bits are set, but the lower bits + * match a valid pfn. + */ + if (PHYS_PFN(addr) != pfn) return 0; #ifdef CONFIG_SPARSEMEM +{ + struct mem_section *ms; + if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS) return 0; - if (!valid_section(__pfn_to_section(pfn))) + ms = __pfn_to_section(pfn); + if (!valid_section(ms)) return 0; /* @@ -240,8 +250,9 @@ int pfn_valid(unsigned long pfn) * memory sections covering all of hotplug memory including * both normal and ZONE_DEVICE based. */ - if (!early_section(__pfn_to_section(pfn))) - return pfn_section_valid(__pfn_to_section(pfn), pfn); + if (!early_section(ms)) + return pfn_section_valid(ms, pfn); +} #endif return memblock_is_map_memory(addr); } -- 2.20.1