From patchwork Wed Mar 30 14: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: 64713 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2640741lbc; Wed, 30 Mar 2016 07:51:14 -0700 (PDT) X-Received: by 10.66.139.199 with SMTP id ra7mr13936959pab.74.1459349474562; Wed, 30 Mar 2016 07:51:14 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id h75si6995036pfh.96.2016.03.30.07.51.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Mar 2016 07:51:14 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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; dmarc=fail (p=NONE dis=NONE) header.from=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 1alHRb-0002SC-Iq; Wed, 30 Mar 2016 14:50:03 +0000 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1alHOX-0008K2-9p for linux-arm-kernel@lists.infradead.org; Wed, 30 Mar 2016 14:46:55 +0000 Received: by mail-wm0-x233.google.com with SMTP id r72so102922411wmg.0 for ; Wed, 30 Mar 2016 07:46:34 -0700 (PDT) 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=SRq8UicCXktmSa0UCvOveAm/Q/epmVBGQSkDt+UJTpQ=; b=D5y3ma45ucoowuYt25pEvV4kuXnA8mjbTZjfj8+u5HADIxJDpupJJ3oy3kcMefM1oS h/2Do09TRlCBiyboi40ShNUyg9HzCx9AxWpw8/NSgW7x1PbuGT38XiT3/r5jXuL3iyo7 bZUC7K0WAPRyKpntLp9m1ereDOEj2qHvZWFSc= 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=SRq8UicCXktmSa0UCvOveAm/Q/epmVBGQSkDt+UJTpQ=; b=fhdH77dt8uvDueHXE7sCK6gw0fLJkcvlxDhOENOK55bbt/vYIEm7vYHGrcy+oH0mm/ JsGKeDKrPo0tZBsZfzcR51k8AldU15pMoPXnet2eyAwb8KOu5ID8cAWtzhr7nlMCOE7f WAd20GnyDRiPg1+cVuWr5RhWlaBy7tDy+u9yeS6ObIi0bvCvzSA95O5YV/3nWTxg+HA7 Qf18ITHv8j5dhmJj6W1AbMJYtOA3Lz8GkbR+uRIti0UQ1yHsZ2aHwv4jkCmeVLsZ/XnB LiLcBd89wF1SHVLRwlLH3k4EwdLIibLbUGwq2GA36epNHND9FpJz7pKqrX3ri1pPxJ8o wJrQ== X-Gm-Message-State: AD7BkJIvoZZ6+8JCpFYu/7PA9rMEtnrI8tJb/N08QJaY9yjCExAcbKbbBFiM2rLXP1TSd76l X-Received: by 10.194.61.134 with SMTP id p6mr9541365wjr.67.1459349193191; Wed, 30 Mar 2016 07:46:33 -0700 (PDT) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id i5sm4325336wjx.15.2016.03.30.07.46.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Mar 2016 07:46:32 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, will.deacon@arm.com, linux-mm@kvack.org, akpm@linux-foundation.org, nios2-dev@lists.rocketboards.org, lftan@altera.com, jonas@southpole.se, linux@lists.openrisc.net Subject: [PATCH v2 9/9] mm: replace open coded page to virt conversion with page_to_virt() Date: Wed, 30 Mar 2016 16:46:04 +0200 Message-Id: <1459349164-27175-10-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1459349164-27175-1-git-send-email-ard.biesheuvel@linaro.org> References: <1459349164-27175-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160330_074653_625681_2DE9EDAD X-CRM114-Status: GOOD ( 15.24 ) 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:233 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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, steve.capper@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org The open coded conversion from struct page address to virtual address in lowmem_page_address() involves an intermediate conversion step to pfn number/physical address. Since the placement of the struct page array relative to the linear mapping may be completely independent from the placement of physical RAM (as is that case for arm64 after commit dfd55ad85e 'arm64: vmemmap: use virtual projection of linear region'), the conversion to physical address and back again should factor out of the equation, but unfortunately, the shifting and pointer arithmetic involved prevent this from happening, and the resulting calculation essentially subtracts the address of the start of physical memory and adds it back again, in a way that prevents the compiler from optimizing it away. Since the start of physical memory is not a build time constant on arm64, the resulting conversion involves an unnecessary memory access, which we would like to get rid of. So replace the open coded conversion with a call to page_to_virt(), and use the open coded conversion as its default definition, to be overriden by the architecture, if desired. The existing arch specific definitions of page_to_virt are all equivalent to this default definition, so by itself this patch is a no-op. Signed-off-by: Ard Biesheuvel --- include/linux/mm.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) -- 2.5.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel Acked-by: Will Deacon diff --git a/include/linux/mm.h b/include/linux/mm.h index ed6407d1b7b5..474c4625756e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -72,6 +72,10 @@ extern int mmap_rnd_compat_bits __read_mostly; #define __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0)) #endif +#ifndef page_to_virt +#define page_to_virt(x) __va(PFN_PHYS(page_to_pfn(x))) +#endif + /* * To prevent common memory management code establishing * a zero page mapping on a read fault. @@ -948,7 +952,7 @@ static inline struct mem_cgroup *page_memcg(struct page *page) static __always_inline void *lowmem_page_address(const struct page *page) { - return __va(PFN_PHYS(page_to_pfn(page))); + return page_to_virt(page); } #if defined(CONFIG_HIGHMEM) && !defined(WANT_PAGE_VIRTUAL)