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.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 732F9C4338F for ; Mon, 2 Aug 2021 12:20:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5724F60FC2 for ; Mon, 2 Aug 2021 12:20:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233679AbhHBMUT (ORCPT ); Mon, 2 Aug 2021 08:20:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:34934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233631AbhHBMUD (ORCPT ); Mon, 2 Aug 2021 08:20:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1B12660FC2; Mon, 2 Aug 2021 12:19:50 +0000 (UTC) Date: Mon, 2 Aug 2021 13:19:48 +0100 From: Catalin Marinas To: Oleksandr Tyshchenko Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Oleksandr Tyshchenko , Will Deacon , Andrey Konovalov , Ard Biesheuvel , Vincenzo Frascino , Joey Gouly , Sami Tolvanen , Mark Rutland , Juergen Gross , Julien Grall , Wei Chen , Stefano Stabellini , Anshuman Khandual , Mike Rapoport Subject: Re: [RFC PATCH 1/2] arm64: mm: Make virt_addr_valid to check for pfn_valid again Message-ID: <20210802121947.GF18685@arm.com> References: <1627490656-1267-1-git-send-email-olekstysh@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1627490656-1267-1-git-send-email-olekstysh@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding Mike and Anshuman, On Wed, Jul 28, 2021 at 07:44:15PM +0300, Oleksandr Tyshchenko wrote: > From: Oleksandr Tyshchenko > > The problem is that Arm's implementation of virt_addr_valid() > leads to memblock_is_map_memory() check, which will fail for > ZONE_DEVICE based addresses. But, the pfn_valid() check in turn > is able to cope with ZONE_DEVICE based memory. > > You can find a good explanation of that problem at: > https://lore.kernel.org/lkml/1614921898-4099-2-git-send-email-anshuman.khandual@arm.com > > Signed-off-by: Oleksandr Tyshchenko > --- > I am not quite sure whether it is a "correct" place and > the change itself, I just partially restored a behaviour before: > https://lore.kernel.org/lkml/20210511100550.28178-4-rppt@kernel.org > So, the target of this patch is to get a feedback how to resolve > this properly if, of course, this really needs to be resolved > (I might miss important bits here). > > It is worth mentioning that patch doesn't fix the current code base > (if I am not mistaken, no one calls virt_addr_valid() on Arm64 for > ZONE_DEVICE based addresses at the moment, so it seems that nothing > is broken), the fix is intended for the subsequent patch in this > series that will try to enable Xen's "unpopulated-alloc" usage > on Arm (it was enabled on x86 so far). > Please see: > [RFC PATCH 2/2] xen/unpopulated-alloc: Query hypervisor to provide > unallocated space > > The subsequent patch will enable the code where virt_addr_valid() > is used in drivers/xen/unpopulated-alloc.c:fill_list() to check that > a virtual address returned by memremap_pages() is valid. I wonder what the point of calling virt_addr_valid() in fill_list() is? If memremap_pages() succeeded, the pages were mapped at the returned vaddr, there's no need for an additional virt_addr_valid() check. > --- > arch/arm64/include/asm/memory.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h > index 824a365..1a35a44 100644 > --- a/arch/arm64/include/asm/memory.h > +++ b/arch/arm64/include/asm/memory.h > @@ -351,7 +351,7 @@ static inline void *phys_to_virt(phys_addr_t x) > > #define virt_addr_valid(addr) ({ \ > __typeof__(addr) __addr = __tag_reset(addr); \ > - __is_lm_address(__addr) && pfn_is_map_memory(virt_to_pfn(__addr)); \ > + __is_lm_address(__addr) && pfn_valid(virt_to_pfn(__addr)); \ > }) pfn_valid() only guarantees the presence of a struct page but not necessarily that the virtual address is accessible (valid). So this change would break the NOMAP ranges case. -- Catalin 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.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable 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 2DDBDC4338F for ; Mon, 2 Aug 2021 12:21:46 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E1D24600D4 for ; Mon, 2 Aug 2021 12:21:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E1D24600D4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Fim41DvgFtYRMkuXc1dYvQe7BUvuEy5z4Lt2m4QlFZk=; b=rgvn49bs6aQAu2 zHifmeqSIP5F+3mjtvfOGV6o30Lvdng0oyqZkH1XnaUVH/Xc6nydH4liR6KSblB9d6eof1kAIaCof GRUIJOg8jA/Z0iYcg1DsZtMHzIpF5Z39qxTTIiZUDK6VD0nuZDK2Zfof1xLdnwBgzFOCHUiuxGKfS LfXeLIaVrgdSg5i4MN+KD29VJj1cXoxrZGPRjmRiAWjPCESd5LEothmdPDjPbBu0XLGwzAV3ha3nD 0bBdKLU2JG5zSrE96zM0lHecYfOOdsLZwOIZdlonsp8aDzsDyaqsHXqfZNyObfmTMXTMs5uQPPell rFJ5LtGGKQgHMBa6yj4g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mAWvF-00GBBl-LE; Mon, 02 Aug 2021 12:19:57 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mAWvC-00GBAn-1g for linux-arm-kernel@lists.infradead.org; Mon, 02 Aug 2021 12:19:55 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1B12660FC2; Mon, 2 Aug 2021 12:19:50 +0000 (UTC) Date: Mon, 2 Aug 2021 13:19:48 +0100 From: Catalin Marinas To: Oleksandr Tyshchenko Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Oleksandr Tyshchenko , Will Deacon , Andrey Konovalov , Ard Biesheuvel , Vincenzo Frascino , Joey Gouly , Sami Tolvanen , Mark Rutland , Juergen Gross , Julien Grall , Wei Chen , Stefano Stabellini , Anshuman Khandual , Mike Rapoport Subject: Re: [RFC PATCH 1/2] arm64: mm: Make virt_addr_valid to check for pfn_valid again Message-ID: <20210802121947.GF18685@arm.com> References: <1627490656-1267-1-git-send-email-olekstysh@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1627490656-1267-1-git-send-email-olekstysh@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210802_051954_189148_44E4B1EC X-CRM114-Status: GOOD ( 30.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Adding Mike and Anshuman, On Wed, Jul 28, 2021 at 07:44:15PM +0300, Oleksandr Tyshchenko wrote: > From: Oleksandr Tyshchenko > > The problem is that Arm's implementation of virt_addr_valid() > leads to memblock_is_map_memory() check, which will fail for > ZONE_DEVICE based addresses. But, the pfn_valid() check in turn > is able to cope with ZONE_DEVICE based memory. > > You can find a good explanation of that problem at: > https://lore.kernel.org/lkml/1614921898-4099-2-git-send-email-anshuman.khandual@arm.com > > Signed-off-by: Oleksandr Tyshchenko > --- > I am not quite sure whether it is a "correct" place and > the change itself, I just partially restored a behaviour before: > https://lore.kernel.org/lkml/20210511100550.28178-4-rppt@kernel.org > So, the target of this patch is to get a feedback how to resolve > this properly if, of course, this really needs to be resolved > (I might miss important bits here). > > It is worth mentioning that patch doesn't fix the current code base > (if I am not mistaken, no one calls virt_addr_valid() on Arm64 for > ZONE_DEVICE based addresses at the moment, so it seems that nothing > is broken), the fix is intended for the subsequent patch in this > series that will try to enable Xen's "unpopulated-alloc" usage > on Arm (it was enabled on x86 so far). > Please see: > [RFC PATCH 2/2] xen/unpopulated-alloc: Query hypervisor to provide > unallocated space > > The subsequent patch will enable the code where virt_addr_valid() > is used in drivers/xen/unpopulated-alloc.c:fill_list() to check that > a virtual address returned by memremap_pages() is valid. I wonder what the point of calling virt_addr_valid() in fill_list() is? If memremap_pages() succeeded, the pages were mapped at the returned vaddr, there's no need for an additional virt_addr_valid() check. > --- > arch/arm64/include/asm/memory.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h > index 824a365..1a35a44 100644 > --- a/arch/arm64/include/asm/memory.h > +++ b/arch/arm64/include/asm/memory.h > @@ -351,7 +351,7 @@ static inline void *phys_to_virt(phys_addr_t x) > > #define virt_addr_valid(addr) ({ \ > __typeof__(addr) __addr = __tag_reset(addr); \ > - __is_lm_address(__addr) && pfn_is_map_memory(virt_to_pfn(__addr)); \ > + __is_lm_address(__addr) && pfn_valid(virt_to_pfn(__addr)); \ > }) pfn_valid() only guarantees the presence of a struct page but not necessarily that the virtual address is accessible (valid). So this change would break the NOMAP ranges case. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel