From patchwork Wed Feb 28 03:56:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 129894 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp568110lja; Tue, 27 Feb 2018 19:58:57 -0800 (PST) X-Google-Smtp-Source: AH8x226kD6BUICA0Z6qzFnZ7Uz+ZPoHwgZBGRjtEzIZyLiaBq+bG3xPDLcqb2BCt4W18NFq4P4VC X-Received: by 10.98.19.146 with SMTP id 18mr16418681pft.3.1519790337457; Tue, 27 Feb 2018 19:58:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519790337; cv=none; d=google.com; s=arc-20160816; b=QLhAwGI8uboV7xiXvvNm8f1lCz5/VzxgWDRv9ZcW0pVRKkZqmO+Ul1Fjjed0Phc50y Y1t3lawQGGtEYobU8XEbj+aCjanXoPfhLwVweq8fgOJGTyf/mFLgeDkFlkJiXs6PaH9G 20BMk41OHlWL798LeUF/xZhYcg0iVQKF6qJ5N8X7kG+mlaGtDIW/gqfJlPh3Gr8EgqnH QJAlXotLTqPoORteetgPWsKd5hUiQIgX69IwDB/zUCnuQibW3QQ9bo4KohwL38xv9+Mu 1Qs96u5OlbjTQvCplu5Ccjb8mhnVoXVP1nAd4jl+09YsItwrM5/OSoT1Cwpl2RChuJHY GT/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Dc0kkeu44UfOi1EiXBfePyqu3iL2CZsHYUa6WCie3uU=; b=XUwJHHPW+pinwXJd+SGYEKxahLzZLDDYqhoR08QsJMaFgO0jJSDxMIC88XglTt3PS4 K0DiInG1/fMPA/HRowQfg3CJ33IC/pzbjByzQPV3j/RvAMlW5q76S75f+OTY7NxIl+3+ 3V80OQkhR4tQXOrk5YP2DupB5ienyBWPpN2ieR4mE83447RMlgHcuMBjQmmEN74vp8HM PHYHagLer8T+/G61KfQYbm+q8ID9FWlVSZ6U3lQjuotyonDVY11cVS7UY2bNFZOLModO 09NBgwThXpUHSP7x4CMUXhZ0+LxvpLBJ09PpFkXpRGZEmYLLqt9c4q4SzoRWytVgH9h0 aziQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I2x2yCrd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e13si457384pgt.481.2018.02.27.19.58.57; Tue, 27 Feb 2018 19:58:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I2x2yCrd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752175AbeB1D6v (ORCPT + 28 others); Tue, 27 Feb 2018 22:58:51 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:35663 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752110AbeB1D6r (ORCPT ); Tue, 27 Feb 2018 22:58:47 -0500 Received: by mail-pf0-f195.google.com with SMTP id y186so514075pfb.2 for ; Tue, 27 Feb 2018 19:58:47 -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=Dc0kkeu44UfOi1EiXBfePyqu3iL2CZsHYUa6WCie3uU=; b=I2x2yCrdloDJsDzGky18ImiprE3074QmGs0w/bU6KgN4DSY09E0MdREcIWl0Ltbmgl LJo4BMEz9o89GiWf/2NedS+MvCaCGozBaJRgQ2P72Xj7UV5zmMwtdfM5EQfrCfleOE+T 24Nca5qIOMRKqx65mKx9mfNLA+rd2DzLkGWis= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Dc0kkeu44UfOi1EiXBfePyqu3iL2CZsHYUa6WCie3uU=; b=qtq6T0IGYjWbi/NSKNHDjbveMIi4iUfoqtSBB+U7RX0t1fUDomUDskRH2h5zeDoRN3 yXaOuIeU4RCYLQD4F9sjhiCtfkksge5ek6JCOrKChp2tAsWC0DSAgDX+/Olx7Yb+wZOU F2tWJVHk3TZy63umB169sTU0358JZKgCS8JJaFJnELvnCoiXcmUhUqoUceqimWnR+5A+ bu9uN1fXJyQqWW3p5smK3GFZuhIeqto9HZAmg6gy+0TYOnwZyfC9MYUFY+UDjKcr9IKR vmOaKgpNK/4wmkzNPR6VtjQRXpcEA23S7CU7L+jCt6hDG0ehvUvXVXiD72cdfcNRKNCm rpFA== X-Gm-Message-State: APf1xPA5u1/p3Nst01uJK207cJKNr2emydD+ozUPL73PUKdFAPytsdLt S4x2PEFGqHp+IJ9NrmqXROUC6w== X-Received: by 10.101.66.196 with SMTP id l4mr13030606pgp.66.1519790326774; Tue, 27 Feb 2018 19:58:46 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id q17sm739911pgt.7.2018.02.27.19.58.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Feb 2018 19:58:46 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alex Shi Subject: [PATCH 10/29] arm64: mm: Map entry trampoline into trampoline and kernel page tables Date: Wed, 28 Feb 2018 11:56:32 +0800 Message-Id: <1519790211-16582-11-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519790211-16582-1-git-send-email-alex.shi@linaro.org> References: <1519790211-16582-1-git-send-email-alex.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Will Deacon commit 51a0048beb44 upstream. The exception entry trampoline needs to be mapped at the same virtual address in both the trampoline page table (which maps nothing else) and also the kernel page table, so that we can swizzle TTBR1_EL1 on exceptions from and return to EL0. This patch maps the trampoline at a fixed virtual address in the fixmap area of the kernel virtual address space, which allows the kernel proper to be randomized with respect to the trampoline when KASLR is enabled. Reviewed-by: Mark Rutland Tested-by: Laura Abbott Tested-by: Shanker Donthineni Signed-off-by: Will Deacon Signed-off-by: Alex Shi Conflicts: no acpi apei in arch/arm64/include/asm/fixmap.h no rodata in arch/arm64/mm/mmu.c --- arch/arm64/include/asm/fixmap.h | 5 +++++ arch/arm64/include/asm/pgtable.h | 1 + arch/arm64/kernel/asm-offsets.c | 6 +++++- arch/arm64/mm/mmu.c | 23 +++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/arch/arm64/include/asm/fixmap.h b/arch/arm64/include/asm/fixmap.h index caf86be..7b1d88c 100644 --- a/arch/arm64/include/asm/fixmap.h +++ b/arch/arm64/include/asm/fixmap.h @@ -51,6 +51,11 @@ enum fixed_addresses { FIX_EARLYCON_MEM_BASE, FIX_TEXT_POKE0, + +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 + FIX_ENTRY_TRAMP_TEXT, +#define TRAMP_VALIAS (__fix_to_virt(FIX_ENTRY_TRAMP_TEXT)) +#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ __end_of_permanent_fixed_addresses, /* diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 7acd3c5..3a30a39 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -692,6 +692,7 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm, extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; extern pgd_t idmap_pg_dir[PTRS_PER_PGD]; +extern pgd_t tramp_pg_dir[PTRS_PER_PGD]; /* * Encode and decode a swap entry: diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index c58ddf8..5f4bf3c 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -144,11 +145,14 @@ int main(void) DEFINE(ARM_SMCCC_RES_X2_OFFS, offsetof(struct arm_smccc_res, a2)); DEFINE(ARM_SMCCC_QUIRK_ID_OFFS, offsetof(struct arm_smccc_quirk, id)); DEFINE(ARM_SMCCC_QUIRK_STATE_OFFS, offsetof(struct arm_smccc_quirk, state)); - BLANK(); DEFINE(HIBERN_PBE_ORIG, offsetof(struct pbe, orig_address)); DEFINE(HIBERN_PBE_ADDR, offsetof(struct pbe, address)); DEFINE(HIBERN_PBE_NEXT, offsetof(struct pbe, next)); DEFINE(ARM64_FTR_SYSVAL, offsetof(struct arm64_ftr_reg, sys_val)); + BLANK(); +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 + DEFINE(TRAMP_VALIAS, TRAMP_VALIAS); +#endif return 0; } diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index d5cc6d7..84945c9 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -419,6 +419,29 @@ static void __init map_kernel_segment(pgd_t *pgd, void *va_start, void *va_end, vm_area_add_early(vma); } +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +static int __init map_entry_trampoline(void) +{ + extern char __entry_tramp_text_start[]; + + pgprot_t prot = rodata_enabled ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC; + phys_addr_t pa_start = __pa_symbol(__entry_tramp_text_start); + + /* The trampoline is always mapped and can therefore be global */ + pgprot_val(prot) &= ~PTE_NG; + + /* Map only the text into the trampoline page table */ + memset(tramp_pg_dir, 0, PGD_SIZE); + __create_pgd_mapping(tramp_pg_dir, pa_start, TRAMP_VALIAS, PAGE_SIZE, + prot, pgd_pgtable_alloc, 0); + + /* ...as well as the kernel page table */ + __set_fixmap(FIX_ENTRY_TRAMP_TEXT, pa_start, prot); + return 0; +} +core_initcall(map_entry_trampoline); +#endif + /* * Create fine-grained mappings for the kernel. */