Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13906847pxu; Mon, 4 Jan 2021 07:39:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHeGC2U8Iged6OFO3f7z1TLlNwYtnfVYNuLZqDWNUGDBmNXMJCBwMZ+uhLKGfZZ9cmierc X-Received: by 2002:a17:906:1a5a:: with SMTP id j26mr67576107ejf.225.1609774754397; Mon, 04 Jan 2021 07:39:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609774754; cv=none; d=google.com; s=arc-20160816; b=PocQJAS3O65sfc4Ehn8/hsSGY/8XZk9aM+hpE5rgnuagmFX5oRgec4bY3Ar03Mc2T6 wSwSEwDLPD9yff0GaY+VxEPFqkEbRUqMTPAo/PiS9xWxTU7GOU1STNJIEKYp99Mhb16d JYXN7XjdJSC8jMeKhTonUPlF6dQcl8U5mY4+t3U+MwU0bunFJYHde9uRRjPXqtpNKWAS cCFFuG6banBsZH1Z+NVnuvk4iTNksTZNDzU8W564W6NtOItr2R61p6Vm70iUozCNlSpj EEZSc4l+rmPNC1S8IhGT0Qyde7Dfp4gMdj9MnXjffC1FCORdY9qsmVSQfIlrufDpe09E m30w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=8R6XMKFBMMrwextS6anpSFiferwHxnIohtnagBzV0Cg=; b=DmSkYw3qSdY4oF3xOdxXYSM6wmS+zuyft+8LavXX66R9wpLEo4IXM+S94fTCIH/1OT 3oB4Ol6YWX7Z4vJBBVo1lokHsBtfIkx8tUELl6p+1GUT2MJgj2XdBdw0FkdkIifOnpjf dkcxmwS8VAkdSuNjTe84J6JUzrvlSGa9ChKf/TlDOIDXKnaEWD+/rcugpX+hpMjOwD48 5oeEektmun3lJ2vbRxBttMXIvrS4q1v0kH1zDUyzdJlDjjQMPzyhpDxRpaJe9WIyrBf2 zaXKyh6FABZ+Ca+LUyabWHvLRjud3XtXCT5gg6K2Y00GMykT51drqwZ0eOeOT87wSvJh nbIA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i8si18851605edu.515.2021.01.04.07.38.51; Mon, 04 Jan 2021 07:39:14 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726969AbhADPhv (ORCPT + 99 others); Mon, 4 Jan 2021 10:37:51 -0500 Received: from frasgout.his.huawei.com ([185.176.79.56]:2288 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726434AbhADPhu (ORCPT ); Mon, 4 Jan 2021 10:37:50 -0500 Received: from fraeml744-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4D8fl03Lbpz67WRx; Mon, 4 Jan 2021 23:32:28 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml744-chm.china.huawei.com (10.206.15.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Mon, 4 Jan 2021 16:37:09 +0100 Received: from localhost (10.47.65.160) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2106.2; Mon, 4 Jan 2021 15:37:08 +0000 Date: Mon, 4 Jan 2021 15:36:33 +0000 From: Jonathan Cameron To: Anshuman Khandual CC: , , Mark Rutland , , "David Hildenbrand" , Robin Murphy , =?ISO-8859-1?Q?J?= =?ISO-8859-1?Q?=E9r=F4me?= Glisse , James Morse , Dan Williams , , Subject: Re: [RFC 1/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory Message-ID: <20210104153633.00003288@Huawei.com> In-Reply-To: <1608621144-4001-2-git-send-email-anshuman.khandual@arm.com> References: <1608621144-4001-1-git-send-email-anshuman.khandual@arm.com> <1608621144-4001-2-git-send-email-anshuman.khandual@arm.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.47.65.160] X-ClientProxiedBy: lhreml703-chm.china.huawei.com (10.201.108.52) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 22 Dec 2020 12:42:23 +0530 Anshuman Khandual wrote: > pfn_valid() validates a pfn but basically it checks for a valid struct page > backing for that pfn. It should always return positive for memory ranges > backed with struct page mapping. But currently pfn_valid() fails for all > ZONE_DEVICE based memory types even though they have struct page mapping. > > pfn_valid() asserts that there is a memblock entry for a given pfn without > MEMBLOCK_NOMAP flag being set. The problem with ZONE_DEVICE based memory is > that they do not have memblock entries. Hence memblock_is_map_memory() will > invariably fail via memblock_search() for a ZONE_DEVICE based address. This > eventually fails pfn_valid() which is wrong. memblock_is_map_memory() needs > to be skipped for such memory ranges. As ZONE_DEVICE memory gets hotplugged > into the system via memremap_pages() called from a driver, their respective > memory sections will not have SECTION_IS_EARLY set. > > Normal hotplug memory will never have MEMBLOCK_NOMAP set in their memblock > regions. Because the flag MEMBLOCK_NOMAP was specifically designed and set > for firmware reserved memory regions. memblock_is_map_memory() can just be > skipped as its always going to be positive and that will be an optimization > for the normal hotplug memory. Like ZONE_DEVIE based memory, all hotplugged typo: ZONE_DEVIE > normal memory too will not have SECTION_IS_EARLY set for their sections. > > Skipping memblock_is_map_memory() for all non early memory sections would > fix pfn_valid() problem for ZONE_DEVICE based memory and also improve its > performance for normal hotplug memory as well. > > Cc: Catalin Marinas > Cc: Will Deacon > Cc: Ard Biesheuvel > Cc: Robin Murphy > Cc: linux-arm-kernel@lists.infradead.org > Cc: linux-kernel@vger.kernel.org > Fixes: 73b20c84d42d ("arm64: mm: implement pte_devmap support") > Signed-off-by: Anshuman Khandual > --- > arch/arm64/mm/init.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c > index 75addb36354a..ee23bda00c28 100644 > --- a/arch/arm64/mm/init.c > +++ b/arch/arm64/mm/init.c > @@ -225,6 +225,18 @@ int pfn_valid(unsigned long pfn) > > if (!valid_section(__pfn_to_section(pfn))) > return 0; > + > + /* > + * ZONE_DEVICE memory does not have the memblock entries. > + * memblock_is_map_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 > + * memory sections covering all of hotplug memory including > + * both normal and ZONE_DEVIE based. Here as well + the cover letter title. > + */ > + if (!early_section(__pfn_to_section(pfn))) > + return 1; > #endif > return memblock_is_map_memory(addr); > }