From patchwork Mon Feb 22 17:46:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 62615 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1381736lbl; Mon, 22 Feb 2016 09:48:21 -0800 (PST) X-Received: by 10.66.97.101 with SMTP id dz5mr30615326pab.61.1456163299546; Mon, 22 Feb 2016 09:48:19 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id o5si40969579pfi.36.2016.02.22.09.48.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Feb 2016 09:48:19 -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; dkim=neutral (body hash did not verify) header.i=@linaro.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 1aXuZR-0003i3-AI; Mon, 22 Feb 2016 17:46:53 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aXuZD-0003Yd-Hq for linux-arm-kernel@lists.infradead.org; Mon, 22 Feb 2016 17:46:40 +0000 Received: by mail-wm0-x22b.google.com with SMTP id g62so185137745wme.1 for ; Mon, 22 Feb 2016 09:46:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AFrqsnTvWmw+1a6/ia08Wyn/a//LeixVc3g8pTZqnlk=; b=OHpj8dY8sKG+a4PbaO76sciPvMWpimInC3FhARSeuDivlD4ubh4JBfSqQiE6NqqAwG csijOa2nzFiPS5BgPZIKW+y3ReITwj3pJdqUn5HvJltORf49dN0J4NpsKzJROuSilgo5 b/C/cEV3GuuuqWJlwtj977TpZzIuTMcEeqew8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AFrqsnTvWmw+1a6/ia08Wyn/a//LeixVc3g8pTZqnlk=; b=Fh/3vcdvFX41vv+DGmWROD8hfOpb0UddnlahE3LnKzQDHLDNfTYfOt0KjBD3NQF6Op 5kYC6Ma4HpXu7eH+1FFYsDy88iaq2HeiovDoJSkyYVlZy2aS0gdoSftwr2/dDUsRt8+f uEdzbo8DZDOJVz+Gnd4JBKrAVU6oSgd7nbqTQzK08KgO4vVP6+xadwoRmrHYHCPfCpze uQJkQxgu7tzYN0NlAsydc2yp1UwPo1UCq51wN1fnXW6tepUOCZW6AKafQFRfn3NhvbDo ipdNC6K6rhYVMGmN8+fGVdg1cXE6JkD8GO9XfGt8OlNrd0LvwmMnv0dBwgXvXTxnSRkA YLvw== X-Gm-Message-State: AG10YOQvhxFJYMWpUtzu+qK3i6FTceUBVwGg8rDCca0m+OE8akOhTbdfoczHP8H+ZOeiTSgo X-Received: by 10.194.185.144 with SMTP id fc16mr29039363wjc.123.1456163177092; Mon, 22 Feb 2016 09:46:17 -0800 (PST) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id v1sm25561611wjf.49.2016.02.22.09.46.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Feb 2016 09:46:16 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, will.deacon@arm.com Subject: [PATCH 2/2] arm64: mm: use bit ops rather than arithmetic in pa/va translations Date: Mon, 22 Feb 2016 18:46:04 +0100 Message-Id: <1456163164-23251-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456163164-23251-1-git-send-email-ard.biesheuvel@linaro.org> References: <1456163164-23251-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160222_094639_924523_26D1835B X-CRM114-Status: GOOD ( 12.25 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:22b listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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@arm.com, Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Since PAGE_OFFSET is chosen such that it cuts the kernel VA space right in half, and since the size of the kernel VA space itself is always a power of 2, we can treat PAGE_OFFSET as a bitmask and replace the additions/subtractions with 'or' and 'and-not' operations. For the comparison against PAGE_OFFSET, a mov/cmp/branch sequence ends up getting replaced with a single tbz instruction. For the additions and subtractions, we save a mov instruction since the mask is folded into the instruction's immediate field. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/memory.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- 2.5.0 _______________________________________________ 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 771d0b506e4b..2296b32130a1 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -88,10 +88,10 @@ */ #define __virt_to_phys(x) ({ \ phys_addr_t __x = (phys_addr_t)(x); \ - __x >= PAGE_OFFSET ? (__x - PAGE_OFFSET + PHYS_OFFSET) : \ - (__x - kimage_voffset); }) + __x & BIT(VA_BITS - 1) ? (__x & ~PAGE_OFFSET) + PHYS_OFFSET : \ + (__x - kimage_voffset); }) -#define __phys_to_virt(x) ((unsigned long)((x) - PHYS_OFFSET + PAGE_OFFSET)) +#define __phys_to_virt(x) ((unsigned long)((x) - PHYS_OFFSET) | PAGE_OFFSET) #define __phys_to_kimg(x) ((unsigned long)((x) + kimage_voffset)) /* @@ -131,6 +131,7 @@ #endif #ifndef __ASSEMBLY__ +#include extern phys_addr_t memstart_addr; /* PHYS_OFFSET - the physical address of the start of memory. */