From mboxrd@z Thu Jan 1 00:00:00 1970 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 DE9D0C433F5 for ; Wed, 30 Mar 2022 15:51:51 +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=+EhXiJqCkpbj94tQ5BArL3RB1C83b1/U4wwxL6CFO8U=; b=WdIfFLmVTOOq8c JZQqikEAZCzHiyWR0bX/Av3eUAPrmIuAWNnOwe99fFpHaxuKjwedTiQyWh1GF3pogSM//Wix01zao Nvj/3JqoAd70wf3J9gFvcfP2lUlW855uLsLpMwF0SnlRMzUuiFa22KIOOqIr2WXDDJZ01rrjkc2up JY8NEkoA+yeDBR2B539HpGFRRzUZBss/x8LKwrEX7V1Izn6XqwaR6Rj+H2grUWHI796R2HRrdJz69 OTPwGMVJWMYDoweLj0C2uEuld7CMlIoPf+39nwA4Xgb5yVlXRH33r99oLHxmQpb2Nm776Hs6G/Lrb lFfeD+uE25kHom/uf0Og==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nZaaD-00GetQ-Lp; Wed, 30 Mar 2022 15:50:06 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nZaT3-00Gbmg-4J for linux-arm-kernel@lists.infradead.org; Wed, 30 Mar 2022 15:42:42 +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 ams.source.kernel.org (Postfix) with ESMTPS id C3FBAB81D6E; Wed, 30 Mar 2022 15:42:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AB97C3410F; Wed, 30 Mar 2022 15:42:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648654958; bh=z2EEihueXqWQnKubnMCy/H2MNFhOqik2plKlNjQa2t0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W6Ls0/O0zcOVxqn5rVk1Qf5ExrFXQoiDjih9YeXvdHGqHv2M5yd0k6v0qBQx3evsx mFVDfdirCQJG3AQpwA6lajAcFdsddFFGv99WaamDLG+QkbkRHHn8HkStfCZVHnJDoT d+isLIQSEqD2usd2sleaQTLXO3QWwufmqkgKHHHPXm9WJyDIoXr/j6nqCYjvUIb7C4 hjASIjx9wSySBFnv+vbUbMKcYt53oqt0zRrzvQifbe9GlK3mB84GDZDrpmnyokxH+j ZBb2nXQ4Cy0jvgOewrZZwErqv+wnHeUJmpgs6cMrU4dLDQIBYn0IsFQnw/VQRXzaV7 MRl7hlhCtEC0A== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, keescook@chromium.org, mark.rutland@arm.com, catalin.marinas@arm.com, Ard Biesheuvel Subject: [RFC PATCH v2 14/18] arm64: head: clean the ID map page to the PoC Date: Wed, 30 Mar 2022 17:42:01 +0200 Message-Id: <20220330154205.2483167-15-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220330154205.2483167-1-ardb@kernel.org> References: <20220330154205.2483167-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1638; h=from:subject; bh=z2EEihueXqWQnKubnMCy/H2MNFhOqik2plKlNjQa2t0=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBiRHpFIN68im7lXqsmgzMNBtRef/blT8WIX1vjAXlL 1E+XaeiJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYkR6RQAKCRDDTyI5ktmPJKEqDA CxvCDfbTBWBJwLdNYSXLyPbRU6LTg7TvbvWnRW0XsSZa2AR15so8kB+JZgi8O9ZA1N4B/NirqtedeP H9FFrcHhY2GoWAYOWg5TRMC2+5POwnIQZX2UGJmQBuzsyHsOkUSijOxbPGBsfpvh13b5PrX3e/wXwx wAEqiSIpy86dBZQK/M44xZfSsNJzg8wXJzPfgEWkJuLjoTJ3RJOgg6gaaS2cXnfjfc2dqRnXTPIQ+4 3jpqxT0MSnBLo6i9JZIhEH7RbR1/mSGJddw6pON+M3EfVdqlmXHznyB0VTAGDFaS7DwZnmMhUK2ppG d7gfg4EIniZo8NBQUKOjbw9Gm4g8jBY3QY3qxiATXTcIMiQicRoQ1jJdE7ZyFeN8sxsIUkhElEzplb dIvGR51JV/DbIIRGm9xg4R5FY/0QmuP73f41wCL8naOedGPAU10o9HihAJWQ8Q/PU1fY/uWUMWfbSv 8SIbx04sagJDUo3auIx78obYovXt9pxGXcCkzuH0fmPG0= 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-20220330_084241_534679_F7649FB5 X-CRM114-Status: GOOD ( 14.10 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If we enter with the MMU and caches enabled, the caller may not have performed any cache maintenance. So clean the ID mapped page to the PoC, and invalidate the I-cache so we can safely execute from it after disabling the MMU and caches. Note that this means primary_entry() itself needs to be moved into the ID map as well, as we will return from init_kernel_el() with the MMU and caches off. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/head.S | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index ec57a29f3f43..2f1dcc0c7594 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -75,7 +75,7 @@ __EFI_PE_HEADER - __INIT + .section ".idmap.text","awx" /* * The following callee saved general purpose registers are used on the @@ -91,6 +91,19 @@ SYM_CODE_START(primary_entry) bl record_mmu_state bl preserve_boot_args bl create_idmap + + /* + * If we entered with the MMU and caches on, clean the ID mapped part + * of the primary boot code to the PoC and invalidate it from the + * I-cache so we can safely turn them off. + */ + cbz x22, 0f + adrp x0, __idmap_text_start + adr_l x1, __idmap_text_end + sub x1, x1, x0 + bl dcache_clean_poc + ic ialluis +0: bl init_kernel_el // w0=cpu_boot_mode mov x20, x0 @@ -104,6 +117,7 @@ SYM_CODE_START(primary_entry) b __primary_switch SYM_CODE_END(primary_entry) + __INIT SYM_CODE_START_LOCAL(record_mmu_state) mrs x22, CurrentEL cmp x22, #CurrentEL_EL2 -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel