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=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 19A50C433E0 for ; Fri, 29 Jan 2021 10:07:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8D22564E0F for ; Fri, 29 Jan 2021 10:07:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8D22564E0F 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 DBF796B0005; Fri, 29 Jan 2021 05:07:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D6E716B0006; Fri, 29 Jan 2021 05:07:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C35BF6B006C; Fri, 29 Jan 2021 05:07:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0040.hostedemail.com [216.40.44.40]) by kanga.kvack.org (Postfix) with ESMTP id AE6FA6B0005 for ; Fri, 29 Jan 2021 05:07:16 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 68B4933CD for ; Fri, 29 Jan 2021 10:07:16 +0000 (UTC) X-FDA: 77758384872.12.fold37_0b09630275a7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 45620180555C0 for ; Fri, 29 Jan 2021 10:07:16 +0000 (UTC) X-HE-Tag: fold37_0b09630275a7 X-Filterd-Recvd-Size: 6096 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Fri, 29 Jan 2021 10:07:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611914835; 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=shCP7p2ybm0NnC7dmsH87MLRPKEjgc5a0pPyuYDwMJg=; b=Ci6oxGNm/vXnsxF8P9zmX6alctLj3T5SUXILv01qt4AIFslKbau76EOsUFkMPKCSBirCNP 69MkmYtRXI9YLa/cYnWL35MWNbamPse+S/wH0jdQaev4qK8qAi2OBqJ438Y1vyTZhKRyV9 06/x8UA9OrwR8I+JO3a0gsZbAz04YEA= 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-494-GZ62zqW3MIOTlpn8gF6CTQ-1; Fri, 29 Jan 2021 05:07:10 -0500 X-MC-Unique: GZ62zqW3MIOTlpn8gF6CTQ-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 9B5CB107ACF7; Fri, 29 Jan 2021 10:07:08 +0000 (UTC) Received: from [10.36.113.219] (ovpn-113-219.ams2.redhat.com [10.36.113.219]) by smtp.corp.redhat.com (Postfix) with ESMTP id C053946; Fri, 29 Jan 2021 10:07:05 +0000 (UTC) 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: <1611905986-20155-1-git-send-email-anshuman.khandual@arm.com> <1611905986-20155-3-git-send-email-anshuman.khandual@arm.com> From: David Hildenbrand Organization: Red Hat GmbH Subject: Re: [PATCH 2/2] arm64/mm: Reorganize pfn_valid() Message-ID: <9050792c-feba-1b72-681e-ebc28fc1fcc5@redhat.com> Date: Fri, 29 Jan 2021 11:07:04 +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: <1611905986-20155-3-git-send-email-anshuman.khandual@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Content-Transfer-Encoding: quoted-printable 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 29.01.21 08:39, Anshuman Khandual wrote: > There are multiple instances of pfn_to_section_nr() and __pfn_to_sectio= n() > when CONFIG_SPARSEMEM is enabled. This can be just optimized if the mem= ory > section is fetched earlier. Hence bifurcate pfn_valid() into two differ= ent > definitions depending on whether CONFIG_SPARSEMEM is enabled. Also repl= ace > the open coded pfn <--> addr conversion with __[pfn|phys]_to_[phys|pfn]= (). > This does not cause any functional change. >=20 > 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 | 38 +++++++++++++++++++++++++++++++------- > 1 file changed, 31 insertions(+), 7 deletions(-) >=20 > diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c > index 1141075e4d53..09adca90c57a 100644 > --- a/arch/arm64/mm/init.c > +++ b/arch/arm64/mm/init.c > @@ -217,18 +217,25 @@ static void __init zone_sizes_init(unsigned long = min, unsigned long max) > free_area_init(max_zone_pfns); > } > =20 > +#ifdef CONFIG_SPARSEMEM > int pfn_valid(unsigned long pfn) > { > - phys_addr_t addr =3D pfn << PAGE_SHIFT; > + struct mem_section *ms =3D __pfn_to_section(pfn); > + phys_addr_t addr =3D __pfn_to_phys(pfn); I'd just use PFN_PHYS() here, which is more frequently used in the kernel= . > =20 > - if ((addr >> PAGE_SHIFT) !=3D 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_to_pfn(addr) !=3D pfn) and here PHYS_PFN(). Comment is helpful. :) > return 0; > =20 > -#ifdef CONFIG_SPARSEMEM > if (pfn_to_section_nr(pfn) >=3D NR_MEM_SECTIONS) > return 0; > =20 > - if (!valid_section(__pfn_to_section(pfn))) > + if (!valid_section(ms)) > return 0; > =20 > /* > @@ -240,11 +247,28 @@ 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); > -#endif > + if (!early_section(ms)) > + return pfn_section_valid(ms, pfn); > + > return memblock_is_map_memory(addr); > } > +#else > +int pfn_valid(unsigned long pfn) > +{ > + phys_addr_t addr =3D __pfn_to_phys(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_to_pfn(addr) !=3D pfn) > + return 0; > + > + return memblock_is_map_memory(addr); > +} I think you can avoid duplicating the code by doing something like: phys_addr_t addr =3D PFN_PHYS(pfn); if (PHYS_PFN(addr) !=3D pfn) return 0; #ifdef CONFIG_SPARSEMEM { struct mem_section *ms =3D __pfn_to_section(pfn); if (!valid_section(ms)) return 0; if (!early_section(ms)) return pfn_section_valid(ms, pfn); } #endif return memblock_is_map_memory(addr); --=20 Thanks, David / dhildenb