Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp14288050pxu; Mon, 4 Jan 2021 19:27:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJaHhRbUWYPUvf+AhufcGrRbOJ/ePLbxoArnFO5SH0HipF3mCHU3Tg18yyEMDk08z6rIhQ X-Received: by 2002:a17:906:c83b:: with SMTP id dd27mr70171795ejb.356.1609817261691; Mon, 04 Jan 2021 19:27:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609817261; cv=none; d=google.com; s=arc-20160816; b=ct27ur4wap/P3TCAHcM40EujlHMd0+2dUbfG82i2CS6zgIsZ0/TNH8mqCm6FXI8UdX f8++e37zmX/ODtLyjz8Y9zKLZKYEvT0x0igRWlRYqLQXAu6qtRGbadi8Mu+w6SWnu4ez p68FhzBD6pnfOiSzF8meW33WgM6VG3ksd2BlpbYr07rcNgiNLtv3zWSY+PDR7h1xRcA2 CjWsXzaphTTd9vxlfLwuTTN/URNYAP/++XfFmhR4oXqH3KsxnaevJLNQcdxcPA45usP5 iCE74evt+mDK0oD1q5MUupBVykFmKznErxmKwkqfr3wj1QPnVY6BOKn91EOaMoiy8Ar3 LQYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=7tmvZllkNr3dycEyzMrUcXpmcNgi6y44wA6ZlckxDY4=; b=f9QG6JCZyahm4sUzTTwXRuhKLIYVTomxHT1Sit20UkIUu6C0UsVnxE4vNM4pyTI4FW VkD47uMno+4XMUGilgQ5phs7rvw9/rhwe0NSYCWr4DfWshD+Lb/4ag6WZarmFCJ9wfuF mW4SiBYLLCrqT2/0Yc1Hce9hDC9Z9w6e6RYSpT8bkSru8TGCS7rN12/r34BFfZPWDxlF CE6fQH0RY6JDX4umMrmzCzjmXKJnXnvpDpqOdLLVNoTywfKDfGDhpyBBojLFfAoLKhNn xu1XyXPZK4oDzApFJeujplG3qUeN1RDk0tbUnPp2WX54M0I7p0WhZo7FlsyYdVSUfA3b VBtQ== 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 p11si29400263eja.213.2021.01.04.19.27.17; Mon, 04 Jan 2021 19:27:41 -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 S1726683AbhAED0U (ORCPT + 99 others); Mon, 4 Jan 2021 22:26:20 -0500 Received: from foss.arm.com ([217.140.110.172]:48756 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726163AbhAED0T (ORCPT ); Mon, 4 Jan 2021 22:26:19 -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 8B2751FB; Mon, 4 Jan 2021 19:25:33 -0800 (PST) Received: from [192.168.0.130] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 863513F66E; Mon, 4 Jan 2021 19:25:29 -0800 (PST) Subject: Re: [RFC 1/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory To: Jonathan Cameron Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mark Rutland , catalin.marinas@arm.com, David Hildenbrand , Robin Murphy , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , James Morse , Dan Williams , will@kernel.org, ardb@kernel.org References: <1608621144-4001-1-git-send-email-anshuman.khandual@arm.com> <1608621144-4001-2-git-send-email-anshuman.khandual@arm.com> <20210104153633.00003288@Huawei.com> From: Anshuman Khandual Message-ID: <72ad70de-a282-7136-ddea-4157e835c8aa@arm.com> Date: Tue, 5 Jan 2021 08:55:48 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210104153633.00003288@Huawei.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/4/21 9:06 PM, Jonathan Cameron wrote: > 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. My bad, will fix all the three instances.