From patchwork Sun Sep 11 14:38:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 75962 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp464155qgf; Sun, 11 Sep 2016 07:40:46 -0700 (PDT) X-Received: by 10.98.87.90 with SMTP id l87mr24863546pfb.133.1473604846709; Sun, 11 Sep 2016 07:40:46 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id n84si16158191pfj.215.2016.09.11.07.40.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Sep 2016 07:40:46 -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.85_2 #1 (Red Hat Linux)) id 1bj5uf-0004Sy-6Z; Sun, 11 Sep 2016 14:39:17 +0000 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bj5uZ-0004R5-7o for linux-arm-kernel@lists.infradead.org; Sun, 11 Sep 2016 14:39:13 +0000 Received: by mail-wm0-x22d.google.com with SMTP id 1so105395916wmz.1 for ; Sun, 11 Sep 2016 07:38:50 -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; bh=xwh4nTCZ69BNEf868rPz1Tda632nqRrun3I8RSUkjmQ=; b=POKfUbDQYOg9h2e6/31Q6ReKEPGbT3YMo4XU3k/899V+u01XG/7h/latWr1VssB+Yt pB3Hxt6nSHog4kkVxlQT9tENjPh6n9/fcXkZA3/7wwZ5YRbMoDaEa2vfRSyEFuXXyglT jI/5z0k6hrvRDzRiw0PBG6mya4YehyYNLuyEw= 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; bh=xwh4nTCZ69BNEf868rPz1Tda632nqRrun3I8RSUkjmQ=; b=ZOQmQUUoEsrlcHYqQeUeNxMMl3h+poPa3BL+Qv4PLFtBZlyKPvybXMbW6adpU6AJT3 nOgIZXAgeZ96On/63n7Cv+fK52zhf7tZMC7ePK55Pa/R2U0SulaTONGk9cFszh4hOP4z Jp+J7h4GNFZ0udoPBcT7kBkkc7dSKLWitsHs75DYc4eltkPgca23mbtjry0jjWCeNmFE pWBkfzhTgL3mJHj9CuQPyJx7KNUMVzNKa4E7IfBmyasMLvEHJbdoqj1Eqyu+7zjuLQVT nS4bNvjgF+iuuMLq0Dk4lSC8bYifi4qrTmszsAB9S2VhC6PyIHLozgANHSH2qZ2vUvXj Hj7w== X-Gm-Message-State: AE9vXwNoCiCCVAqXqfO1Tal5Xgh46wqzcujYyWwKHI1GjAi1gDFKMpGtCrjQF059ZZuGqmR/ X-Received: by 10.28.4.206 with SMTP id 197mr5299190wme.68.1473604729531; Sun, 11 Sep 2016 07:38:49 -0700 (PDT) Received: from localhost.localdomain ([196.68.26.72]) by smtp.gmail.com with ESMTPSA id j1sm13246331wju.9.2016.09.11.07.38.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 11 Sep 2016 07:38:48 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com Subject: [PATCH] arm64: mm: move zero page from .bss to right before swapper_pg_dir Date: Sun, 11 Sep 2016 15:38:34 +0100 Message-Id: <1473604714-5512-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160911_073911_629704_E2F66DA3 X-CRM114-Status: GOOD ( 12.00 ) 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:22d 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 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 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: Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Move the statically allocated zero page from the .bss section to right before swapper_pg_dir. This allows us to refer to its physical address by simply reading TTBR1_EL1 (which always points to swapper_pg_dir and always has its ASID field cleared), and subtracting PAGE_SIZE. Inspired-by: http://marc.info/?l=linux-arm-kernel&m=147282867511801 Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/mmu_context.h | 10 ++++++---- arch/arm64/kernel/head.S | 1 - arch/arm64/kernel/vmlinux.lds.S | 2 ++ arch/arm64/mm/mmu.c | 1 - 4 files changed, 8 insertions(+), 6 deletions(-) -- 2.7.4 _______________________________________________ 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/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index b1892a0dbcb0..94461ba5febd 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -49,13 +49,15 @@ static inline void contextidr_thread_switch(struct task_struct *next) */ static inline void cpu_set_reserved_ttbr0(void) { - unsigned long ttbr = virt_to_phys(empty_zero_page); + unsigned long dummy; - asm( + asm volatile( + " mrs %0, ttbr1_el1 // get TTBR1\n" + " sub %0, %0, %1 // subtract PAGE_SIZE\n" " msr ttbr0_el1, %0 // set TTBR0\n" " isb" - : - : "r" (ttbr)); + : "=&r" (dummy) + : "I" (PAGE_SIZE)); } /* diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 8bc9458f9add..6020b884b076 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -449,7 +449,6 @@ __primary_switched: adr_l x2, __bss_stop sub x2, x2, x0 bl __pi_memset - dsb ishst // Make zero page visible to PTW #ifdef CONFIG_KASAN bl kasan_early_init diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 659963d40bb4..a14eb8ff5144 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -193,6 +193,8 @@ SECTIONS . = ALIGN(PAGE_SIZE); idmap_pg_dir = .; . += IDMAP_DIR_SIZE; + empty_zero_page = .; + . += PAGE_SIZE; swapper_pg_dir = .; . += SWAPPER_DIR_SIZE; diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 4989948d1feb..539ce9d11325 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -53,7 +53,6 @@ EXPORT_SYMBOL(kimage_voffset); * Empty_zero_page is a special page that is used for zero-initialized data * and COW. */ -unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] __page_aligned_bss; EXPORT_SYMBOL(empty_zero_page); static pte_t bm_pte[PTRS_PER_PTE] __page_aligned_bss;