Received: by 10.223.185.116 with SMTP id b49csp5730807wrg; Tue, 27 Feb 2018 20:05:33 -0800 (PST) X-Google-Smtp-Source: AH8x2243DYNTCVJYlS65TEdomRfyPNciyiYVNJBl90YVO7HqdZQF3Bb3ctWNQXNKcuKYXdtrL8P7 X-Received: by 10.101.66.193 with SMTP id l1mr12962042pgp.57.1519790733649; Tue, 27 Feb 2018 20:05:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519790733; cv=none; d=google.com; s=arc-20160816; b=ET0++nbGI8FrjdsWS0yF85E0q7/tn+L1ltwtj3Zzmc6gucoyDmrDRuh1Bz8DETFkVN CsO60YP6WMUen/I76WaYM9300aJ9UkAqoiSA4TFafzHS/1WO7RWJN9Bpcn/sqkdr0par I2J+L1hA4YoYw1yuqhNqRjw0xMneMVQ462WPYwXHcOTjeEGP4cQ9/2CRKhZdT3YOQ8sk JS4WOFPq4AS7O2XmWjghSx+avPBChTVNujfF2HyYC/0pS68M6wEI57U5xP49kTXnhLo3 guSeBRNkjC0L3UInLMIN/2O0P7TJjHIK/S4k9akymZod8eH21DyUh4PMrIC9ZDpvwIWG 3uqg== 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 n5si455818pgu.568.2018.02.27.20.05.18; Tue, 27 Feb 2018 20:05:33 -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 S1752171AbeB1D6v (ORCPT + 99 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(-) 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. */ -- 2.7.4