From patchwork Mon Jul 29 16:14:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13745262 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 ACAA8C3DA61 for ; Mon, 29 Jul 2024 16:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=BxcdtdOFUfH1RwZTzv0ky0PWvMcKKzBEG7nqCvWB2ws=; b=FqWKs6EqdFNI/usZs8SAO6cF59 eDb8uNv73UgqfsiSfL3rvpqDbrz+qYtgtK6MNhSmdp9FDW1Rat19U+r/Q23CgVAx0idpuJpKJtpf+ oksIqKHBXBncTHEs3z2r+gjfZj2uOweilqOj2WZRKDe/OBMoGeg/OwlxjF2VAu0Hpoav0pyAlaVsQ NboSLKudmCUHU12grSvFy5yZQBtOYNl+XZicq01GhxdUToEM4UuOP0CdMQiPA1twiJD7MUGtRh4r2 wYP5K/lLNf9aEmylplPtyrE7xcWpHejy4UU+MJukfNk3SogNA7fZJDlpP1aFzKGJ+ZaLA32H/w0F/ PBlvRoaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYT3f-0000000Bypm-0oA4; Mon, 29 Jul 2024 16:17:11 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYT1o-0000000ByLX-3HF4 for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 16:15:18 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E75DF1007; Mon, 29 Jul 2024 09:15:41 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7EF0B3F766; Mon, 29 Jul 2024 09:15:15 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: akos.denke@arm.com, andre.przywara@arm.com, luca.fancellu@arm.com, mark.rutland@arm.com, maz@kernel.org Subject: [BOOT-WRAPPER 04/11] aarch64: Always enter kernel via exception return Date: Mon, 29 Jul 2024 17:14:54 +0100 Message-Id: <20240729161501.1806271-5-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240729161501.1806271-1-mark.rutland@arm.com> References: <20240729161501.1806271-1-mark.rutland@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240729_091516_899099_E4F0A2C8 X-CRM114-Status: GOOD ( 10.03 ) 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 When the boot-wrapper is entered at EL3 it will enter the kernel via ERET, and when entered at EL2 it will branch to the kernel directly. This is an artifact of the way the boot-wrapper was originally written in assembly, and it would be preferable to always enter the kernel via ERET so that PSTATE is always initialized to a known-good value. Rework jump_kernel() to always enter the kernel via ERET. Signed-off-by: Mark Rutland Cc: Akos Denke Cc: Andre Przywara Cc: Luca Fancellu Cc: Marc Zyngier --- arch/aarch64/boot.S | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index d8d38dd..3dbf85a 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -76,10 +76,6 @@ reset_at_el2: b.eq err_invalid_id bl setup_stack - mov w0, #1 - ldr x1, =flag_no_el3 - str w0, [x1] - bl cpu_init_bootwrapper bl cpu_init_arch @@ -111,25 +107,26 @@ ASM_FUNC(jump_kernel) bl find_logical_id bl setup_stack // Reset stack pointer - ldr w0, flag_no_el3 - cmp w0, #0 // Prepare Z flag - mov x0, x20 mov x1, x21 mov x2, x22 mov x3, x23 + mov x4, #SPSR_KERNEL - b.eq 1f - br x19 // No EL3 + mrs x5, CurrentEL + cmp x5, #CURRENTEL_EL3 + b.eq eret_at_el3 + cmp x5, #CURRENTEL_EL2 + b.eq eret_at_el2 + b . // Not possible -1: mov x4, #SPSR_KERNEL +eret_at_el3: msr elr_el3, x19 msr spsr_el3, x4 eret +eret_at_el2: + msr elr_el2, x19 + msr spsr_el2, x4 + eret .ltorg - - .data - .align 3 -flag_no_el3: - .long 0