From patchwork Fri Mar 5 05:24:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 12117775 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,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,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 BE35EC433DB for ; Fri, 5 Mar 2021 05:27:43 +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 5007464F2C for ; Fri, 5 Mar 2021 05:27:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5007464F2C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com 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:MIME-Version:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id: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=Qa+hsVOsCJdI91F/xnHgimG/GA0G0v5PO1zq+sfounU=; b=fpqU7Wcq7BRgVsY5k7bxTsDQEh Q+GcQ5lIKL02PWvR6jmEU3M+Oc7/JdzPh7OUMuoEDUCFQeLB7yLohtvoycoIHZYvol2ZO6AoMPSKx FVAXZkZi93KKRfd7Mp+3mqGctcV8c6Gnfq5FOxQHzHV8KIODRGya/DZP01k4qN2PUzJqHp8XuyosQ WPqfvrLR4TDHwghVwZqJY+BYQLjH8OWbeI79o3qUMxFmEGUMlA7V/AktonhoQzomOlA8QCFJCbuXu LsYBhUAneyrhqowNaQrJCjuL4Q8wnUGDa/L8bPTAhyH/hKRyyEuH4AZs+7qErxMYE+9VvDJDqqggU 7t79+Bmg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lI2yJ-00CnOi-8o; Fri, 05 Mar 2021 05:25:55 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lI2yG-00CnNY-P6 for linux-arm-kernel@desiato.infradead.org; Fri, 05 Mar 2021 05:25:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=QiyYY4qRW1UVgE+5FbkBaV60rLkFNY4vSmUoDt84uao=; b=A5MvQjOezVRGt3ml14uELcVG1l gx0x2hBp6/qRSTHp94O3ADmCEhEaLezA04oSACt9gwedJJW41BC6BU9wvuHWG2VNFDjpXByVsP+yN 2fKh9aMlDCd9VK5z/kVhC0zJL/YlR6ijp+W4m+YvwcxJlrGfwYJeG0r0cvWkba1X/nhmW+B1mmIv4 cMZ17/uzKar4/oIo7U4iEAxhHnD5VWYNdZDZYtOvhuLEoN0m0Za5XtMxUllNh1HCIoo1vtjw50ZZ/ 1MTenj6Vcu5esYfr1FoUqmwzTVQcxL2VED9HKw9KSdAjeMLBVLxyJ5RF21Fqb9IPxxmHc+bc4r/v3 8YkHkAww==; Received: from foss.arm.com ([217.140.110.172]) by casper.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lI2xJ-00AGdY-SN for linux-arm-kernel@lists.infradead.org; Fri, 05 Mar 2021 05:25:28 +0000 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?b?SsOpcsO0bWUgR2xpc3Nl?= , 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210305_052502_018196_DA816E76 X-CRM114-Status: GOOD ( 16.06 ) 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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 Acked-by: Catalin Marinas --- 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); }