Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp495210pxb; Wed, 27 Jan 2021 13:00:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJwh8i8gTMZ28UMJu1qenSjqFhUSB5A3pZqRYMNzUeFW3HQZ7Wj4X0/KlpYLbWOLUbSH98qZ X-Received: by 2002:a17:906:6bca:: with SMTP id t10mr8035840ejs.35.1611781210957; Wed, 27 Jan 2021 13:00:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611781210; cv=none; d=google.com; s=arc-20160816; b=UzNsS/rDCoBhBIyhh13hHfYyXuDVg9vIYbsSDRhajktVp/VXAKAgkau4iaHzhz954n ZAnOM28iXYi//FFbGrNJIfz1SFkfeNRE/xixfX4ycEhiGee0pU5BA+5/hpLE+Ymz4nVD KK/gixWQWP4NlvAbL3mmyFj4+jg3NWkfQ3VFiWWs6RSVxTsGZQgZt4AeT9AWMLlFmHbO SswMa82Zdgxw5aT0La8RjGLZXRonUw9w1vUFRKp+kA1W5QBJy/Hkvp9SyfUJ0F3Wi5Oh Iw9ux+WJBgQLrn8adMTTSsoLtAWtTZYgzLUQlXlXWKUzqztpUpuqBCKTPkT/Oc1qdSxL bQXQ== 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=KHtoStQLgfHQAcFRp8IPuA3tGxNpvO4McMXQ0f/l7Sg=; b=bqhMAFZV+JOBI0I5Gy+SsKeZJNQPQcCx05o2Tp4xLpf04czvW1auMGcIxnqLqHB3gu FCFxvZ+zFggAcqVKk9RLtJeF15YNHX6XwAuKH0FtbVmOpmihSFFAWtG9iiDUZUKg4ZqC ankmAHGlnlV/lrBmVj8/FIlmnWOXQBH3iwxFtxsKOp9eI/iWMnmfUeNTtOhXRryaI/pI Xvz/OI+uIYwXxEhkNT7tAY4g13CRiYo6iraDFMSfe1DJsJbM8KwlhAFj++hTu2yKY+Zr cTKhipWk79jkt5q8z0VWYCBVnxcSxQKWbquFV8nlRy0p6Oz4WX7nXaV+aYJX8Sb6eV8T btMQ== 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 e13si1444599edz.214.2021.01.27.12.59.45; Wed, 27 Jan 2021 13:00:10 -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 S238335AbhA0EMn (ORCPT + 99 others); Tue, 26 Jan 2021 23:12:43 -0500 Received: from foss.arm.com ([217.140.110.172]:47828 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238124AbhA0EGx (ORCPT ); Tue, 26 Jan 2021 23:06:53 -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 3586C1042; Tue, 26 Jan 2021 20:06:07 -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 999403F66B; Tue, 26 Jan 2021 20:06:03 -0800 (PST) Subject: Re: [RFC 1/2] arm64/mm: Fix pfn_valid() for ZONE_DEVICE based memory To: David Hildenbrand , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: catalin.marinas@arm.com, will@kernel.org, ardb@kernel.org, Mark Rutland , James Morse , Robin Murphy , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Dan Williams , Mike Rapoport References: <1608621144-4001-1-git-send-email-anshuman.khandual@arm.com> <1608621144-4001-2-git-send-email-anshuman.khandual@arm.com> From: Anshuman Khandual Message-ID: <4c7a92f3-4c5a-c3c6-7fed-befed2f3d3cb@arm.com> Date: Wed, 27 Jan 2021 09:36:20 +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: 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/25/21 2:43 PM, David Hildenbrand wrote: > On 25.01.21 07:22, Anshuman Khandual wrote: >> >> On 12/22/20 12:42 PM, Anshuman Khandual wrote: >>> 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 >>> 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 >> >> Hello David/Mike, >> >> Given that we would need to rework early sections, memblock semantics via a >> new config i.e EARLY_SECTION_MEMMAP_HOLES and also some possible changes to >> ARCH_KEEP_MEMBLOCK and HAVE_ARCH_PFN_VALID, wondering if these patches here >> which fixes a problem (and improves performance) can be merged first. After >> that, I could start working on the proposed rework. Could you please let me >> know your thoughts on this. Thank you. > > As I said, we might have to throw in an pfn_section_valid() check, to > catch not-section-aligned ZONE_DEVICE ranges (I assume this is possible > on arm64 as well, no?). pfn_section_valid() should be called only for !early_section() i.e normal hotplug and ZONE_DEVICE memory ? Because early boot memory should always be section aligned. > > Apart from that, I'm fine with a simple fix upfront, that can be more > easily backported if needed. (Q: do we? is this stable material?) > Right, an upfront fix here would help in backporting. AFAICS it should be backported to the stable as pte_devmap and ZONE_DEVICE have been around for some time now. Do you have a particular stable version which needs to be tagged in the patch ?