From patchwork Tue Feb 23 17:22:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 62749 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1950369lbl; Tue, 23 Feb 2016 09:24:14 -0800 (PST) X-Received: by 10.66.62.132 with SMTP id y4mr46759103par.55.1456248254725; Tue, 23 Feb 2016 09:24:14 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id 17si48466774pfr.69.2016.02.23.09.24.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Feb 2016 09:24:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aYGgA-0007Px-35; Tue, 23 Feb 2016 17:23:18 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aYGg7-0007Iu-3V for linux-arm-kernel@lists.infradead.org; Tue, 23 Feb 2016 17:23:15 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2543A49; Tue, 23 Feb 2016 09:22:01 -0800 (PST) Received: from e104818-lin.cambridge.arm.com (e104818-lin.cambridge.arm.com [10.1.203.148]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C42633F25E; Tue, 23 Feb 2016 09:22:52 -0800 (PST) Date: Tue, 23 Feb 2016 17:22:50 +0000 From: Catalin Marinas To: Ard Biesheuvel Subject: Re: [RFC PATCH 10/10] arm64: mm: restrict __pa() translations to linear virtual addresses Message-ID: <20160223172250.GF4777@e104818-lin.cambridge.arm.com> References: <1456174472-30028-1-git-send-email-ard.biesheuvel@linaro.org> <1456174472-30028-11-git-send-email-ard.biesheuvel@linaro.org> <20160223122615.GJ3966@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160223_092315_181880_FF3467CD X-CRM114-Status: GOOD ( 17.55 ) X-Spam-Score: -6.9 (------) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-6.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [217.140.101.70 listed in list.dnswl.org] -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Will Deacon , "linux-arm-kernel@lists.infradead.org" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org On Tue, Feb 23, 2016 at 01:29:21PM +0100, Ard Biesheuvel wrote: > On 23 February 2016 at 13:26, Will Deacon wrote: > > On Mon, Feb 22, 2016 at 09:54:32PM +0100, Ard Biesheuvel wrote: > >> Now that we have replaced all occurrences of __pa() translations > >> involving virtual addresses that are covered by the kernel text, > >> we can redefine __virt_to_phys and __pa() etc to only take virtual > >> address that are covered by the linear mapping. This means we can > >> remove the comparison with PAGE_OFFSET in the definition of > >> __virt_to_phys(). > >> > >> Signed-off-by: Ard Biesheuvel > >> --- > >> arch/arm64/include/asm/memory.h | 12 +++++++----- > >> 1 file changed, 7 insertions(+), 5 deletions(-) > >> > >> diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h > >> index 56d6739430f3..3b5dc5b243ac 100644 > >> --- a/arch/arm64/include/asm/memory.h > >> +++ b/arch/arm64/include/asm/memory.h > >> @@ -86,11 +86,14 @@ > >> * private definitions which should NOT be used outside memory.h > >> * files. Use virt_to_phys/phys_to_virt/__pa/__va instead. > >> */ > >> -#define __virt_to_phys(x) ({ \ > >> +#ifndef CONFIG_DEBUG_VM > >> +#define __virt_to_phys(x) (((phys_addr_t)(x) & ~PAGE_OFFSET) + PHYS_OFFSET) > >> +#else > >> +#define __virt_to_phys(x) ({ \ > >> phys_addr_t __x = (phys_addr_t)(x); \ > >> - __x & BIT(VA_BITS - 1) ? (__x & ~PAGE_OFFSET) + PHYS_OFFSET : \ > >> - (__x - kimage_voffset); }) > >> - > >> + BUG_ON(__x < PAGE_OFFSET); \ > >> + (((phys_addr_t)__x & ~PAGE_OFFSET) + PHYS_OFFSET); }) > > > > What's the #include-hell like if you try to use VM_BUG_ON instead? > > > > The #include hell would not change I think, since > > include/linux/mmdebug.h:18:#define VM_BUG_ON(cond) BUG_ON(cond) > > but it would certainly make this code look a lot cleaner. I just tried the fixup below on top of your PHYS_OFFSET patch from yesterday and it seems to work (I can fold it in once I finish testing more build configurations): -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index d862c62a33b8..e02bfef18552 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -132,14 +132,11 @@ #ifndef __ASSEMBLY__ #include +#include extern phys_addr_t memstart_addr; /* PHYS_OFFSET - the physical address of the start of memory. */ -#ifndef CONFIG_DEBUG_VM -#define PHYS_OFFSET ({ memstart_addr; }) -#else -#define PHYS_OFFSET ({ BUG_ON(memstart_addr & 1); memstart_addr; }) -#endif +#define PHYS_OFFSET ({ VM_BUG_ON(memstart_addr & 1); memstart_addr; }) /* the offset between the kernel virtual and physical mappings */ extern u64 kimage_voffset;