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=-2.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=no 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 E0B28C433FF for ; Wed, 14 Aug 2019 12:02:34 +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 B560C2083B for ; Wed, 14 Aug 2019 12:02:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="i0sD49bY"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="G2XQwKko" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B560C2083B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject: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=RP1wPPYSrUgDqXWkcYLTlRf9E1HK37UXqc1jeBpjNYU=; b=i0sD49bYFZdWX0 vaDvgmqLGyO07euDuCy5JewI6Sm3tGzRNFiEtA/FgAgwl8sHcAycHqnsZ0C8chuHsHZzwwoseewBY qbq6U8yEvNcRLBtBceo+TtrABJl8LBZ5VKs5NTxSsZR4YU1HLSKaX7hMRh72umleIOp/yFEV9gy49 W0Y5b6Hbh5e1W6W4ckb1JpOObbQ3ox9EBmX/luTAIwoNozLoMQVwU64I6DpIDlKZ6CNnDRm7jFQNV iRwcm4yczH3Yz7pIbEbKhwacvVdAj20ZcOMvi9QUnMP0zulQjP0mrYSubFCkM4MaPI46w1i9cpATr jSozi3B82VGb1hQbqbKA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hxrz6-0003i8-Uq; Wed, 14 Aug 2019 12:02:33 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hxrz0-0003hf-7M for linux-arm-kernel@lists.infradead.org; Wed, 14 Aug 2019 12:02:27 +0000 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 95D952083B; Wed, 14 Aug 2019 12:02:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565784145; bh=72va8Gi4pOhpfpzk4mD/PEMy0g/X9+kT34ErtIuy8tk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=G2XQwKkoFQ+dHKhkM27CpkipH3QuNPy3M4HOS9YTLhxJuVx8C07ZaWAuA3XvddCGq lPLdUa4SYFD2pa/3fW9Q3lvtEmSeXjhwdwr6GkDlNbln05wjZlcZplcbbxxFEZgVYi Iu2157btaNV3646VMQRfJOCMmPiDjjufAAY3mGR8= Date: Wed, 14 Aug 2019 13:02:21 +0100 From: Will Deacon To: Catalin Marinas Subject: Re: [PATCH 1/8] arm64: memory: Fix virt_addr_valid() using __is_lm_address() Message-ID: <20190814120221.zuguyh6tpku3nvtt@willie-the-truck> References: <20190813170149.26037-1-will@kernel.org> <20190813170149.26037-2-will@kernel.org> <20190814091942.GA50688@arrakis.emea.arm.com> <20190814094819.4bdqaubqmbcm3zax@willie-the-truck> <20190814104022.GI50688@arrakis.emea.arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190814104022.GI50688@arrakis.emea.arm.com> User-Agent: NeoMutt/20170113 (1.7.2) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190814_050226_377859_3C7993F6 X-CRM114-Status: GOOD ( 21.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Steve Capper , Andrey Konovalov , Geert Uytterhoeven , Qian Cai , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Aug 14, 2019 at 11:40:23AM +0100, Catalin Marinas wrote: > On Wed, Aug 14, 2019 at 10:48:20AM +0100, Will Deacon wrote: > > On Wed, Aug 14, 2019 at 10:19:42AM +0100, Catalin Marinas wrote: > > > On Tue, Aug 13, 2019 at 06:01:42PM +0100, Will Deacon wrote: > > > > -#define _virt_addr_is_linear(kaddr) \ > > > > - (__tag_reset((u64)(kaddr)) >= PAGE_OFFSET) > > > > +#define virt_addr_valid(addr) ({ \ > > > > + __typeof__(addr) __addr = addr; \ > > > > + __is_lm_address(__addr) && pfn_valid(virt_to_pfn(__addr)); \ > > > > +}) > > > > > > There is a slight change of semantics here but I don't think it's an > > > issue currently. __is_lm_address() is true even for a user address, so > > > at least the first part of virt_addr_valid() now accepts such addresses. > > > The pfn would be wrong eventually because of the virt-to-phys offsetting > > > and pfn_valid() false but we rely on this rather than checking it's a > > > kernel address. Slight concern as this macro is called from drivers. > > > > > > Should we keep the PAGE_OFFSET check as well? > > > > In virt_addr_valid() or __is_lm_address()? > > > > To be honest with you, I'm not even sure what virt_addr_valid() is supposed > > to do with non-linear kernel addresses: look at powerpc and riscv, who > > appear to convert the address straight to a pfn. Many callers check against > > is_vmalloc_addr() first, but not all of them. > > Even if they call is_vmalloc_addr(), it would return false for user > address. Anyway, at a quick look, I couldn't find any virt_addr_valid() > where it would be an issue. Sure, but my point was more that it would be crazy to have a macro that accepted user and linear addresses, but not vmalloc addresses! > > I think passing in a *user* address would be a huge bug in the caller, > > just like it would be if you called virt_to_phys() on a user address. > > If we care about that, then I think __is_lm_address() should be the one > > doing the check against PAGE_OFFSET. > > > > Thoughts? I'd be inclined to leave this patch as it is. > > Leave it as it is. The way pfn_valid() is written it wouldn't return > true for a user address due to the fact that virt_to_phys() cannot > return the same physical address for a user and linear map one. > > For this patch: > > Reviewed-by: Catalin Marinas Ta, Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel