From patchwork Thu Jun 30 14:42:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12901951 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 5C5C4C43334 for ; Thu, 30 Jun 2022 14:45:12 +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=eO1hu8t3KX4GjBmvIy0qVV3fvhRLQSR6uB9r+RKpr7Q=; b=MuYwxSv/Ltfbvp V1wQJm//X7yYo3WLw7qo8+t3vjlM2Rnjn4QjXmpXoPaVJm5zx4bbdjaxbgV2dKIlBFLKjOarp4RaN yGhpL5y4eV0Rsz22KPM+EBOFexTqf7dlKosUqxm5eNnodVBznoDAZNGXjOImWjribf6HaargUO0ta U+512SK+vQGGV2/mWC8afsQ7EFcmikGiiADI2TB4FYj58CIxt1rTSfZbTolkt9S/PXWEa5y7XpEEE jLRI9ofpBC+3RR7niAfa7hPAe98zBLP5tjT1zWTOlqbIJBZDymLen7haoUsX5OwW+/oVTV4d6v39y gTBKdGw1oudolE7yoqyg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o6vOi-00085h-Vw; Thu, 30 Jun 2022 14:44:01 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o6vNW-0007gX-4m for linux-arm-kernel@lists.infradead.org; Thu, 30 Jun 2022 14:42:47 +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 BC9F66232A; Thu, 30 Jun 2022 14:42:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E039C341CD; Thu, 30 Jun 2022 14:42:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656600165; bh=eLBbBu42Eait2R2zKHPQ835md1AWZ1nnjes6vvOLsBw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kCmh/vzM9NMISZkzCeyPGvHCc7Xdtnu/+qvWTRjFlh6lEWvQ2PZpR9lVGIwHB6nzV f3pMAWqE1gSiJ4wW9bTB8leOiCzTUdC6+N+Uv908jd30ByqR6r/iEcgkj4zcZNMC7T BHkQFvL3PZwu5w6i/k2cTaPr9RXaeoj708/PiVPk2ijDgJrLmON31SVeBsbKq1z0BO 4XOdZDfqUDAoa7hDm+nSlddnSbSPkIGKxjF92G5rryB2v2hPHs2yYiEybf8C1Hcuro 7giQ/Ec8X6y7/aAwI89C6R3HnxmOt46CkolBJ13qqUIsu4ERCs97r1Jwv2pYel4cHl ff0QGIObmYFqg== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Will Deacon , Marc Zyngier , =?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?= , Quentin Perret , Mark Rutland Subject: [PATCH 5/6] arm64: head: clean the ID map page to the PoC Date: Thu, 30 Jun 2022 16:42:29 +0200 Message-Id: <20220630144230.2332555-6-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220630144230.2332555-1-ardb@kernel.org> References: <20220630144230.2332555-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1571; h=from:subject; bh=eLBbBu42Eait2R2zKHPQ835md1AWZ1nnjes6vvOLsBw=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBivbZR8GLSCJM4bY9wu1I1X6SWBFAudWgpLwK0tor4 myoC44CJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYr22UQAKCRDDTyI5ktmPJJNqC/ 0Zz0YIqADhEaDGi0kLMok1DsZjuWiYg1l46T/gOdnROnZUMsEaXv/TbjYFoXYGpRd2rnSInn9K74wl vy16UEt5CPZVPC4LhgaNPJesmwCKSz0Xb0UxQiRwQVPR2ZY6lJoBCDr5achwvkaEIOj46U6m0E7ZcB rQkDbmMySE3tOyvyRcLT9VUfhnFOSGxWsdU/QMZnbvAulClqiKojSJjKzgvgH9YxIWITyqoh6Sh2GN pS6dWWU/10SZ/az057wpKed3DNKHGy14FBmGyCM2lYa9SLi5qnOBLe5ttl/IFlZWzsfPnGW1rOHPNI CPCUCVOWa3qxgYZMJvUHxvhHP2dDjG2oUtYGgTPvwp4SR71Ph7f48TsDHu9kQCjOHrWGEWKERxqXbG x1e/SbxCK1mhRKgY/2eRRhwripER6GhmV0mm1Nf3cpLOC0JEb27KqtBX+xkLmM8oJFO+XVCiDbEwl9 jH57/nKZnLRnDK7FdEr1RoLpClMQecxw3R6v8PE5QGmpg= 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-20220630_074246_305071_F8F8EF04 X-CRM114-Status: GOOD ( 15.97 ) 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 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, to ensure that instruction and data accesses with the MMU off see the correct data. 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 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 42fc7e980b35..4ca4d66b418f 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -70,7 +70,7 @@ __EFI_PE_HEADER - __INIT + .section ".idmap.text","awx" /* * The following callee saved general purpose registers are used on the @@ -89,6 +89,17 @@ 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 so we can safely execute it with + * the MMU off. + */ + cbz x19, 0f + adrp x0, __idmap_text_start + adr_l x1, __idmap_text_end + bl dcache_clean_poc +0: bl init_kernel_el // w0=cpu_boot_mode mov x20, x0 @@ -109,6 +120,7 @@ SYM_CODE_START(primary_entry) b __primary_switch SYM_CODE_END(primary_entry) + __INIT SYM_CODE_START_LOCAL(record_mmu_state) mrs x19, CurrentEL cmp x19, #CurrentEL_EL2