From mboxrd@z Thu Jan 1 00:00:00 1970 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.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 2529EC433DB for ; Tue, 2 Feb 2021 08:27:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A22BD64ECB for ; Tue, 2 Feb 2021 08:27:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A22BD64ECB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C53F36B0005; Tue, 2 Feb 2021 03:27:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C04766B006C; Tue, 2 Feb 2021 03:27:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF3586B0070; Tue, 2 Feb 2021 03:27:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0036.hostedemail.com [216.40.44.36]) by kanga.kvack.org (Postfix) with ESMTP id 951C56B0005 for ; Tue, 2 Feb 2021 03:27:08 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5E8E73628 for ; Tue, 2 Feb 2021 08:27:08 +0000 (UTC) X-FDA: 77772647736.14.feast56_2e0bede275c9 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 3EBC318229818 for ; Tue, 2 Feb 2021 08:27:08 +0000 (UTC) X-HE-Tag: feast56_2e0bede275c9 X-Filterd-Recvd-Size: 5044 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Tue, 2 Feb 2021 08:27:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612254427; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7mTg2oMPOn40/ltsulP4d95N1N+NtkIehznJg+VXVl4=; b=GyZJH3VY+5lwbfbTa6yqLUGiN/s/eOU6jieDoyBu2cOAZIMPNnAtOikk/4n1GWBVhhCjmI 1pmC32OwOcX7uztrPt1ll//QtNeMs//ateORNtQUgEwMDQ3sTHziMNLjh0+Wk69gcJIRIm GgzrsrksOkuhHZB8S2UNb6F7v2MXgfA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-570-ssxtYByMNaumSNvBCcQfXg-1; Tue, 02 Feb 2021 03:27:03 -0500 X-MC-Unique: ssxtYByMNaumSNvBCcQfXg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 33081802B4E; Tue, 2 Feb 2021 08:27:01 +0000 (UTC) Received: from [10.36.114.148] (ovpn-114-148.ams2.redhat.com [10.36.114.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id 495A419717; Tue, 2 Feb 2021 08:26:58 +0000 (UTC) Subject: Re: [PATCH V2 2/2] arm64/mm: Reorganize pfn_valid() To: Anshuman Khandual , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Catalin Marinas , Will Deacon , Ard Biesheuvel , Mark Rutland , James Morse , Robin Murphy , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Dan Williams , Mike Rapoport References: <1612239114-28428-1-git-send-email-anshuman.khandual@arm.com> <1612239114-28428-3-git-send-email-anshuman.khandual@arm.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <5609cc64-317c-1517-0e90-027868bc9d4b@redhat.com> Date: Tue, 2 Feb 2021 09:26:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <1612239114-28428-3-git-send-email-anshuman.khandual@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: On 02.02.21 05:11, Anshuman Khandual wrote: > 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 > Signed-off-by: Anshuman Khandual > --- > arch/arm64/mm/init.c | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > > diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c > index 1141075e4d53..5d8fd5360a68 100644 > --- a/arch/arm64/mm/init.c > +++ b/arch/arm64/mm/init.c > @@ -219,16 +219,25 @@ 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 = __pfn_to_section(pfn); > + > if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS) > return 0; > > - if (!valid_section(__pfn_to_section(pfn))) > + if (!valid_section(ms)) > return 0; > > /* > @@ -240,8 +249,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); > } > Reviewed-by: David Hildenbrand -- Thanks, David / dhildenb