From patchwork Fri Jun 24 15:06:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12894750 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E14A8C433EF for ; Fri, 24 Jun 2022 15:11:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jQwZ70w+VibVCw/iNKkxqgste+SYj3ibtbpaxHPlp14=; b=nWiYfpwy5YH5kM y0NdY6Ck4Y8IegGFQEBIMUPbuqkWTHXAcJ0b2P2ukQIFPHXjUlgCwz70N/oWNhqd6wzlwehInYC3u hx9OfG3gl07TYP8BCTL/5cXQm8vHk/q1dYr5KCGDKPblOGpm2gwtV5J6o7p6rpspdzCf7YUIuH8N0 n4yHeGhF4mVTOZPbyZ1OxMaHVEJd/9BtrIFznGtdjtxq+0AxG8oQMX97XepP8DebKxnN5f5wKo7Sk NWvcb4DpplohNUarfHCS6FuG37ZW4ubc20XcoLLBNmZGMGyslFHJZhP50LReTL1WUCNJH7aI1KRgS GUysjlDzWYWFlM5yZc8A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o4kx0-002jol-Cb; Fri, 24 Jun 2022 15:10:26 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o4kuD-002iQn-IH for linux-arm-kernel@lists.infradead.org; Fri, 24 Jun 2022 15:07:35 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2CE5062183; Fri, 24 Jun 2022 15:07:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B28F5C3411C; Fri, 24 Jun 2022 15:07:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656083252; bh=0MsyA9t61JqcBmST0UVswIQsT/gQeOMoIkSz0EN+cIU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OIQ4A2s5yHsdi+5CnuVnGbEkMBeeRxJBN4va/KdSexQ1764/oCrIJw63f0zjnb40v A1GE70sb0p03b9dc+4GMZOnPX4torq2BNnO8p3yE6lMW24sRpsI731RKx/2JpkdCYT ABKrXRZHTPRzVA4apNs6FPcR4WA1kzZyKQ+ygPQQbo/oQbogGf5JWBReEV0QX6SuqR 3wnXx7mhgEpLnUxOE7AV48L1Ba05Cp69oxdc3bLcoXjdOor986fBTrkjPbPyVegr26 nOCJCmK+ryuc/VBMXhf9wQy5eoD86FBM1E3hcbFMDfOdLEHWHKUNpSSzWQm0I1pMO2 AgM/70y8jde+g== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Marc Zyngier , Will Deacon , Mark Rutland , Kees Cook , Catalin Marinas , Mark Brown , Anshuman Khandual Subject: [PATCH v5 10/21] arm64: mm: provide idmap pointer to cpu_replace_ttbr1() Date: Fri, 24 Jun 2022 17:06:40 +0200 Message-Id: <20220624150651.1358849-11-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220624150651.1358849-1-ardb@kernel.org> References: <20220624150651.1358849-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4222; h=from:subject; bh=0MsyA9t61JqcBmST0UVswIQsT/gQeOMoIkSz0EN+cIU=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBitdL3hRuqafL/xIoEuXNbg3LMdFomZyNHk/7vOkny tPHyWSWJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYrXS9wAKCRDDTyI5ktmPJBEkC/ 9LVoH7MZWY4khhOa14LtF8RYh/dUIBhQQgv2+rW0HbMgmfuyai3nLedczsIqs1JM2b1ZmHifQF5487 5UMGIcem/zTYBmLjJ083QUk2FqH4N6Xz88edMbFuVmEUtyyvTOXov/dyFK+c0WgPlnXZiqhhUsVEIQ vOSaVMSYZ06Naqg8yJY2iJL43BFvgQep8+GrNx1JBMM1APNtarYUiWoN47kZ1m/0sGfkaf4Nma4gSv B8iBip4YyUoczOoAMC/k5zUUZeJ3mvzDk/kJL9wA38CqwDBZH+ylSaGndL6K75gcG1YHZsWQSsvP5Y mcGublE3hP7DObFwayoGRlXEzD3cTf6yAQgrWLmaLcCkwfc/pq4oijgoKGOd7WBsHucfy0/7ElsBcx Sa4HQEJUSs1VwERt/qkMeH0eK4QInuaVMprNDZnOp3CPM0n9Zaa9Zdk/JZTRIf5if5q1ba3fG58hxs sKS8yn+FBV7zwjTWpbpr6pZEawiSieJ6X2yew2ur35iq0= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220624_080733_719972_9F95D900 X-CRM114-Status: GOOD ( 15.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In preparation for changing the way we initialize the permanent ID map, update cpu_replace_ttbr1() so we can use it with the initial ID map as well. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/mmu_context.h | 13 +++++++++---- arch/arm64/kernel/cpufeature.c | 2 +- arch/arm64/kernel/suspend.c | 2 +- arch/arm64/mm/kasan_init.c | 4 ++-- arch/arm64/mm/mmu.c | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index 7b387c3b312a..c7ccd82db1d2 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -105,13 +105,18 @@ static inline void cpu_uninstall_idmap(void) cpu_switch_mm(mm->pgd, mm); } -static inline void cpu_install_idmap(void) +static inline void __cpu_install_idmap(pgd_t *idmap) { cpu_set_reserved_ttbr0(); local_flush_tlb_all(); cpu_set_idmap_tcr_t0sz(); - cpu_switch_mm(lm_alias(idmap_pg_dir), &init_mm); + cpu_switch_mm(lm_alias(idmap), &init_mm); +} + +static inline void cpu_install_idmap(void) +{ + __cpu_install_idmap(idmap_pg_dir); } /* @@ -142,7 +147,7 @@ static inline void cpu_install_ttbr0(phys_addr_t ttbr0, unsigned long t0sz) * Atomically replaces the active TTBR1_EL1 PGD with a new VA-compatible PGD, * avoiding the possibility of conflicting TLB entries being allocated. */ -static inline void __nocfi cpu_replace_ttbr1(pgd_t *pgdp) +static inline void __nocfi cpu_replace_ttbr1(pgd_t *pgdp, pgd_t *idmap) { typedef void (ttbr_replace_func)(phys_addr_t); extern ttbr_replace_func idmap_cpu_replace_ttbr1; @@ -165,7 +170,7 @@ static inline void __nocfi cpu_replace_ttbr1(pgd_t *pgdp) replace_phys = (void *)__pa_symbol(function_nocfi(idmap_cpu_replace_ttbr1)); - cpu_install_idmap(); + __cpu_install_idmap(idmap); replace_phys(ttbr1); cpu_uninstall_idmap(); } diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 145b43c6c651..98b48d9069a7 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -3266,7 +3266,7 @@ subsys_initcall_sync(init_32bit_el0_mask); static void __maybe_unused cpu_enable_cnp(struct arm64_cpu_capabilities const *cap) { - cpu_replace_ttbr1(lm_alias(swapper_pg_dir)); + cpu_replace_ttbr1(lm_alias(swapper_pg_dir), idmap_pg_dir); } /* diff --git a/arch/arm64/kernel/suspend.c b/arch/arm64/kernel/suspend.c index 2b0887e58a7c..9135fe0f3df5 100644 --- a/arch/arm64/kernel/suspend.c +++ b/arch/arm64/kernel/suspend.c @@ -52,7 +52,7 @@ void notrace __cpu_suspend_exit(void) /* Restore CnP bit in TTBR1_EL1 */ if (system_supports_cnp()) - cpu_replace_ttbr1(lm_alias(swapper_pg_dir)); + cpu_replace_ttbr1(lm_alias(swapper_pg_dir), idmap_pg_dir); /* * PSTATE was not saved over suspend/resume, re-enable any detected diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index c12cd700598f..e969e68de005 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -236,7 +236,7 @@ static void __init kasan_init_shadow(void) */ memcpy(tmp_pg_dir, swapper_pg_dir, sizeof(tmp_pg_dir)); dsb(ishst); - cpu_replace_ttbr1(lm_alias(tmp_pg_dir)); + cpu_replace_ttbr1(lm_alias(tmp_pg_dir), idmap_pg_dir); clear_pgds(KASAN_SHADOW_START, KASAN_SHADOW_END); @@ -280,7 +280,7 @@ static void __init kasan_init_shadow(void) PAGE_KERNEL_RO)); memset(kasan_early_shadow_page, KASAN_SHADOW_INIT, PAGE_SIZE); - cpu_replace_ttbr1(lm_alias(swapper_pg_dir)); + cpu_replace_ttbr1(lm_alias(swapper_pg_dir), idmap_pg_dir); } static void __init kasan_init_depth(void) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 3be0e9f69406..488628f07b89 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -780,7 +780,7 @@ void __init paging_init(void) pgd_clear_fixmap(); - cpu_replace_ttbr1(lm_alias(swapper_pg_dir)); + cpu_replace_ttbr1(lm_alias(swapper_pg_dir), idmap_pg_dir); init_mm.pgd = swapper_pg_dir; memblock_phys_free(__pa_symbol(init_pg_dir),