From patchwork Mon Feb 29 14:44:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 63220 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1292387lbc; Mon, 29 Feb 2016 06:49:06 -0800 (PST) X-Received: by 10.98.75.79 with SMTP id y76mr22866926pfa.147.1456757345977; Mon, 29 Feb 2016 06:49:05 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id 66si43484371pfl.7.2016.02.29.06.49.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Feb 2016 06:49:05 -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 1aaP72-0004rU-Dd; Mon, 29 Feb 2016 14:47:52 +0000 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aaP5E-0003Qj-Iz for linux-arm-kernel@lists.infradead.org; Mon, 29 Feb 2016 14:46:02 +0000 Received: by mail-wm0-x22a.google.com with SMTP id n186so52752141wmn.1 for ; Mon, 29 Feb 2016 06:45:39 -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=18WVFpPI8PWesxiw4pXHMl3sLWrigmgri2VV2jz3uXI=; b=cf9/3xmA+WCpw0/VR9Uq7lo+GGmEijWpReMoKiQZ4CIOxsAeRWDAe5f6pLiuOJQvGb 3zPmVXyWmjzPENYpDeg4PTJfOKr6dbZm4QOZqtKKXPUpTDG9YLOcefsNXIe5znVMuFSN m1/83H91k9MoFQHnNdhJI5KlMpbqWIKAEobgg= 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=18WVFpPI8PWesxiw4pXHMl3sLWrigmgri2VV2jz3uXI=; b=aXnXQAhN5xyc+NJAPqxpIrhrCQdmdaNPtRBGHp0kc1nwqaV3Jgzv26vISDQvkdANE5 blctCa7C5EdnrnLPHabDnFuPVDNKyJW5SEN8budJCZZdEN0ly3kEKd9eEzzttIrMIK5U aDGgGEW7otBNTFzWwSOXiYvGv3HC0fNySpHWIvDeGHvINHlhV1m2poFBAWul6fUrtyfd 66pa5cSwz9MhqjrCrH+ZJioKD0+M7ymBGVyCpUrCsg+xPqYCUrEM0yiHQS6qn6UL6m6i 01v2Q3MtCwk2vmPilB2ctBqvgsGK64Cr4cRXHHOzVFDuGP42UGxkd6eANrch3kH9a7gN eE+g== X-Gm-Message-State: AD7BkJI2CrCWTOEiUNVxY740ZaqTytXceC0QKWbCGe0H75sGWeqAkUfkT59Sysni3SUoYo6L X-Received: by 10.28.129.194 with SMTP id c185mr12260467wmd.29.1456757137802; Mon, 29 Feb 2016 06:45:37 -0800 (PST) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id di1sm26196693wjc.3.2016.02.29.06.45.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Feb 2016 06:45:36 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, will.deacon@arm.com, mark.rutland@arm.com Subject: [PATCH v2 6/9] arm64: mm: restrict virt_to_page() to the linear mapping Date: Mon, 29 Feb 2016 15:44:41 +0100 Message-Id: <1456757084-1078-7-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456757084-1078-1-git-send-email-ard.biesheuvel@linaro.org> References: <1456757084-1078-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160229_064600_939188_6B0FFC6B X-CRM114-Status: GOOD ( 12.53 ) 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:22a 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_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 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: jonas@southpole.se, Ard Biesheuvel , linux-mm@kvack.org, nios2-dev@lists.rocketboards.org, linux@lists.openrisc.net, lftan@altera.com, akpm@linux-foundation.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org The mm layer makes heavy use of virt_to_page(), which translates from virtual addresses to offsets in the struct page array using an intermediate translation to physical addresses. However, these physical translations are based on the actual placement of physical memory, which can only be discovered at runtime. This means virt_to_page() translations involve a global PHYS_OFFSET variable, and hence a memory access. Now that the vmemmap region has been redefined to cover the linear region rather than the entire physical address space, we no longer need to perform a virtual-to-physical translation in the implementation of virt_to_page(), which means we can get rid of the memory access. Since VMEMMAP_START is guaranteed to be aligned to a power-of-two upper bound of the size of the vmemmap region, we can also treat VMEMMAP_START as a mask rather than an offset. This restricts virt_to_page() translations to the linear region, so redefine virt_addr_valid() as well. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/memory.h | 12 +++++++++++- 1 file changed, 11 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 diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 8a2ab195ca77..f412f502ccdd 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -208,9 +208,19 @@ static inline void *phys_to_virt(phys_addr_t x) */ #define ARCH_PFN_OFFSET ((unsigned long)PHYS_PFN_OFFSET) +#ifndef CONFIG_SPARSEMEM_VMEMMAP #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) -#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) +#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) +#else +#define __virt_to_pgoff(kaddr) (((u64)(kaddr) & ~PAGE_OFFSET) / PAGE_SIZE * sizeof(struct page)) +#define __page_to_voff(kaddr) (((u64)(page) & ~VMEMMAP_START) * PAGE_SIZE / sizeof(struct page)) + +#define page_to_virt(page) ((void *)((__page_to_voff(page)) | PAGE_OFFSET)) +#define virt_to_page(vaddr) ((struct page *)((__virt_to_pgoff(vaddr)) | VMEMMAP_START)) +#define virt_addr_valid(kaddr) pfn_valid((((u64)(kaddr) & ~PAGE_OFFSET) \ + + PHYS_OFFSET) >> PAGE_SHIFT) +#endif #endif #include