From patchwork Mon Jul 29 16:14:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13745260 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 133E7C3DA61 for ; Mon, 29 Jul 2024 16:16:13 +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=apfw54rnp4ri5sKGInijz4bMSlwUtQtGLjxNlDWrtMU=; b=3WbSlOI9K5iKIQVUsC2IHVtmAH 5bPVcmEybrAIzj6g1F70A9q+N8y3p62lN6/njmysB57zfyYrD0YQHa2HD1qJRmrU3jAEGPESk16NW SYJAmsSBWzy4ULpXnisuVkFCW9KmkNq39hj0sezn+Bz2nIodgD4bU5s8y4iTVkvtD7aT1EJ1BKcxq SuqUn4VoJu9/K3BN5kuwqFrbMQpt+KmWRlojfFm+CGQ14JMpHuLAHOyYt4dECUXGuXcbfEphkVlcM x8PXSp5OGs2YZxPm3IQYLl2Fb4skmXkoXWyAj1DuRGdvwUn5lktMFjouviH0CLHdkzMTGF3wV4VR8 RzQQ9YWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYT2X-0000000ByVA-34VH; Mon, 29 Jul 2024 16:16:01 +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 1sYT1l-0000000ByKT-47qh for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 16:15:15 +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 7179E143D; Mon, 29 Jul 2024 09:15:37 -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 08FD13F766; Mon, 29 Jul 2024 09:15:10 -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 01/11] Always enter AArch32 kernels in ARM mode Date: Mon, 29 Jul 2024 17:14:51 +0100 Message-Id: <20240729161501.1806271-2-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_091514_148699_1C8061D6 X-CRM114-Status: GOOD ( 13.64 ) 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 Currnetly we try to support entering AArch32 kernels, but this is unnecessary, and the code is never exercised. Per Linux's Documentation/arch/arm/booting.txt, AArch32 kernels supported by the AArch64 boot-wrapper should always be entered in ARM mode: | The boot loader is expected to call the kernel image by jumping | directly to the first instruction of the kernel image. | | On CPUs supporting the ARM instruction set, the entry must be | made in ARM state, even for a Thumb-2 kernel. | | On CPUs supporting only the Thumb instruction set such as | Cortex-M class CPUs, the entry must be made in Thumb state. Additionally, the kernel__start symbol that we use as the kernel entrypoint is always PHYS_OFFSET + KERNEL_OFFSET, which doesn't take into account any ARM/Thumb distinction in the AArch32 kernel image, and hence we'll never try to set the Thumb bit in the SPSR. Remove the redundant code. Signed-off-by: Mark Rutland Cc: Akos Denke Cc: Andre Przywara Cc: Luca Fancellu Cc: Marc Zyngier --- arch/aarch32/boot.S | 4 ---- arch/aarch64/boot.S | 7 ------- 2 files changed, 11 deletions(-) diff --git a/arch/aarch32/boot.S b/arch/aarch32/boot.S index 4d16c9c..5c2a183 100644 --- a/arch/aarch32/boot.S +++ b/arch/aarch32/boot.S @@ -105,10 +105,6 @@ ASM_FUNC(jump_kernel) bxeq lr @ no EL3 ldr r4, =SPSR_KERNEL - /* Return in thumb2 mode when bit 0 of address is 1 */ - tst lr, #1 - orrne r4, #PSR_T - msr spsr_cxf, r4 movs pc, lr diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index da5fa65..b889137 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -136,13 +136,6 @@ ASM_FUNC(jump_kernel) br x19 // No EL3 1: mov x4, #SPSR_KERNEL - - /* - * If bit 0 of the kernel address is set, we're entering in AArch32 - * thumb mode. Set SPSR.T accordingly. - */ - bfi x4, x19, #5, #1 - msr elr_el3, x19 msr spsr_el3, x4 eret From patchwork Mon Jul 29 16:14:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13745261 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 03B9AC3DA4A for ; Mon, 29 Jul 2024 16:16:35 +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=J6T97nShCpcFoHrVaJFzqsWMr3k0A7XqgoskZqG+0II=; b=fDIH2JZrS+tSoiI3BF9J5Wnm1i SnRtnTDC6imf4iULMtI3S+uoqCdmOXgcvoNF0wpo2mmOQHlIprKrWKnqO0KSWuKVDz+sh0C3k5TvP TjE90wGqPyoi0D5M92m8/OpVkVYfP7X+zRoWh+iRAGm0uSVTpHkUS3FEIfyKjP1hGLcQ9OvbapbZ6 voW4rHNOVOUqqLeiXyuqPWhcxyaizs0RzeFrlknMIHINnn32KhYBsBBMU8l+Y+0NbbrjVNkotBZDY FD9+59H2xv+YgR8XHzdaP81u1sO2MsQiR4O7lhPhCpqpgMMH6brQlZmZ6ovrnMzlL4LhULFg6jxOl LkIeidEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYT2w-0000000Byaa-1Grb; Mon, 29 Jul 2024 16:16:26 +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 1sYT1l-0000000ByKR-3uYq for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 16:15:15 +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 10C781007; Mon, 29 Jul 2024 09:15:39 -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 93AB83F766; Mon, 29 Jul 2024 09:15:12 -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 02/11] aarch64: Remove redundant EL1 entry logic Date: Mon, 29 Jul 2024 17:14:52 +0100 Message-Id: <20240729161501.1806271-3-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_091514_041746_9E5F9C8F X-CRM114-Status: UNSURE ( 9.71 ) X-CRM114-Notice: Please train this message. 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 For historical reasons the boot-wrapper has code to handle being entered at Non-secure EL1, but currently this is unsupported and cannot be used to boot a kernel as jump_kernel() unconditionally writes to SCTLR_EL2, which will UNDEF. Remove the logic for handling Non-secure EL1. Signed-off-by: Mark Rutland Cc: Akos Denke Cc: Andre Przywara Cc: Luca Fancellu Cc: Marc Zyngier --- arch/aarch64/boot.S | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index b889137..51ef41b 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -31,10 +31,8 @@ ASM_FUNC(_start) b.eq reset_at_el3 cmp x0, #CURRENTEL_EL2 b.eq reset_at_el2 - cmp x0, #CURRENTEL_EL1 - b.eq reset_at_el1 - /* Booting at EL0 is not supported */ + /* Booting at EL1 or EL0 is not supported */ b . /* @@ -72,19 +70,6 @@ reset_at_el2: msr sctlr_el2, x0 isb - b reset_no_el3 - - /* - * EL1 initialization - */ -reset_at_el1: - mov_64 x0, SCTLR_EL1_RESET - msr sctlr_el1, x0 - isb - - b reset_no_el3 - -reset_no_el3: cpuid x0, x1 bl find_logical_id cmp x0, #MPIDR_INVALID From patchwork Mon Jul 29 16:14:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13745387 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 535C3C3DA61 for ; Mon, 29 Jul 2024 16:20:32 +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=JSkr6pa7Oy8WmGb1MBkWW6G/d3jkP4/ph+RUfTKhCIc=; b=tAxQXZxO6OmS+m0PsvYwIwu8b+ ajf4hiS8TanxALJIo0NyZiJY3DOVOunEtkwswbvorWkF2eXlTpkxE1lqEp8QcHB/tU9NKbQrEIRL8 r3am7jMirqNgkpfCi8OLqnVPwkmxAMxyghT8J9Q7uRjyTbIWOZxy9BNM2K6xQVFud00qzKk6he1wD +tod6niwlkmzbg5msrWkaEs7TXszbTCJz8fsyCntfeFhks83vALuzLfsWcluH29H1843omXi4rUqL lUh2OxwvB74w3pdN33lE+QwQO5PN+LkQHiDgWRM/2QkLHaHb13TsY2GcKJ6+nF4dY7SCTjMJNLcxD DJRRI/0Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYT6m-0000000BzVI-1cr1; Mon, 29 Jul 2024 16:20:24 +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 1sYT1n-0000000ByL3-1KHv for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 16:15:16 +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 808B91477; Mon, 29 Jul 2024 09:15:40 -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 13C223F766; Mon, 29 Jul 2024 09:15:13 -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 03/11] aarch64: Implement cpu_init_arch() Date: Mon, 29 Jul 2024 17:14:53 +0100 Message-Id: <20240729161501.1806271-4-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_091515_571797_64ACE1A5 X-CRM114-Status: GOOD ( 10.60 ) 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 EL2 it does not initialise CNTFRQ_EL0, and in future it may need to initialize other CPU state regardless of the exeption level it was entered at. Use a common cpu_init_arch() function to initialize CPU state regardless of the exception level the boot-wrapper was entered at. Signed-off-by: Mark Rutland Cc: Akos Denke Cc: Andre Przywara Cc: Luca Fancellu Cc: Marc Zyngier Acked-by: Marc Zyngier --- arch/aarch64/boot.S | 4 +++- arch/aarch64/init.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index 51ef41b..d8d38dd 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -51,7 +51,7 @@ reset_at_el3: bl cpu_init_bootwrapper - bl cpu_init_el3 + bl cpu_init_arch bl gic_secure_init @@ -82,6 +82,8 @@ reset_at_el2: bl cpu_init_bootwrapper + bl cpu_init_arch + b start_bootmethod err_invalid_id: diff --git a/arch/aarch64/init.c b/arch/aarch64/init.c index c9fc7f1..49abdf7 100644 --- a/arch/aarch64/init.c +++ b/arch/aarch64/init.c @@ -52,7 +52,7 @@ static inline bool cpu_has_permission_indirection(void) return mrs(ID_AA64MMFR3_EL1) & mask; } -void cpu_init_el3(void) +static void cpu_init_el3(void) { unsigned long scr = SCR_EL3_RES1 | SCR_EL3_NS | SCR_EL3_HCE; unsigned long mdcr = 0; @@ -153,8 +153,6 @@ void cpu_init_el3(void) msr(SMCR_EL3, smcr); } - - msr(CNTFRQ_EL0, COUNTER_FREQ); } #ifdef PSCI @@ -171,3 +169,11 @@ bool cpu_init_psci_arch(void) return true; } #endif + +void cpu_init_arch(void) +{ + if (mrs(CurrentEL) == CURRENTEL_EL3) + cpu_init_el3(); + + msr(CNTFRQ_EL0, COUNTER_FREQ); +} 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 From patchwork Mon Jul 29 16:14:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13745263 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 7D91EC3DA4A for ; Mon, 29 Jul 2024 16:17:45 +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=J9jGTOOU4uQ/29L4c1MQlO8xEvGbkoT0FEq5nJPp48Q=; b=bKM2XCA+aLQR0k4HP1esJxUw7s eSwHPk9j0PAN2ynsMT3hPXwAWZ71AewlHc/HXXv3UT2FBmOpkwEgkt0Ljr2HkSVSUB9z7fwYWR+ra JYfkX7zFoDHNGA1pHgKSupvy1mxPnf7QHXyD2HrKERO78Du0R9r0loGKX4yWwrGP0jsE9BHQXp7ZB frfNbfJg3JL/ghMERfqneHNMSOTqKIRPtcIZiwbb2qus/+9kMLWHXFvIQwvHvkwMh1Nyxl2o6AKf0 Uek3FXXXXgaL3pyaMVYWHeoB+AWsszf1sAY6I133NPHvoq//4dIOPokHt/K1mwXwWrkYAAm1eLX9n Y0ZGKKOw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYT43-0000000Bytp-22A9; Mon, 29 Jul 2024 16:17:35 +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 1sYT1q-0000000ByM4-17AB for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 16:15:19 +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 56A31143D; Mon, 29 Jul 2024 09:15:43 -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 E2A0E3F766; Mon, 29 Jul 2024 09:15:16 -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 05/11] aarch32: Refactor inital entry Date: Mon, 29 Jul 2024 17:14:55 +0100 Message-Id: <20240729161501.1806271-6-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_091518_374057_43431C47 X-CRM114-Status: GOOD ( 11.30 ) 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 For historical reasons the early AArch32 code is structured differently from the early AArch64 code, with some common code (including stack setup) performed before we identify the mode we were entered in. Align the structure of the early AArch32 code with that of the early AArch64 code. This will make subsequent refactoring easier. Signed-off-by: Mark Rutland Cc: Akos Denke Cc: Andre Przywara Cc: Luca Fancellu Cc: Marc Zyngier --- arch/aarch32/boot.S | 55 ++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/arch/aarch32/boot.S b/arch/aarch32/boot.S index 5c2a183..43dce75 100644 --- a/arch/aarch32/boot.S +++ b/arch/aarch32/boot.S @@ -31,7 +31,28 @@ * PSCI is not supported when entered in this mode. */ ASM_FUNC(_start) - /* Stack initialisation */ + mrs r0, cpsr + and r0, #PSR_MODE_MASK + cmp r0, #PSR_SVC + beq reset_at_svc + cmp r0, #PSR_HYP + beq reset_at_hyp + + /* Booting at other modes is not supported */ + b . + +reset_at_svc: + /* + * When entered in Secure SVC mode we must switch to monitor mode to + * configure SCR.NS. Switch to monitor mode ASAP to simplify later + * code. + */ + adr lr, reset_at_mon + ldr r0, =(PSR_A | PSR_I | PSR_F | PSR_MON) + msr spsr, r0 + movs pc, lr + +reset_at_mon: cpuid r0, r1 bl find_logical_id cmp r0, #MPIDR_INVALID @@ -39,36 +60,28 @@ ASM_FUNC(_start) bl setup_stack - mrs r0, cpsr - and r0, #PSR_MODE_MASK - - cmp r0, #PSR_HYP - bne _switch_monitor + bl cpu_init_bootwrapper - mov r0, #1 - ldr r1, =flag_no_el3 - str r0, [r1] + bl cpu_init_secure_pl1 - bl cpu_init_bootwrapper + bl gic_secure_init b start_bootmethod -_switch_monitor: - adr lr, _monitor - ldr r0, =(PSR_A | PSR_I | PSR_F | PSR_MON) - msr spsr, r0 - movs pc, lr +reset_at_hyp: + cpuid r0, r1 + bl find_logical_id + cmp r0, #MPIDR_INVALID + beq err_invalid_id -_monitor: - /* Move the stack to Monitor mode*/ - mrs sp, sp_svc + bl setup_stack - bl cpu_init_secure_pl1 + mov r0, #1 + ldr r1, =flag_no_el3 + str r0, [r1] bl cpu_init_bootwrapper - bl gic_secure_init - b start_bootmethod err_invalid_id: From patchwork Mon Jul 29 16:14:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13745381 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 3E995C3DA61 for ; Mon, 29 Jul 2024 16:18:08 +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=UDYDx4DalxW/4nSqnb+RZjQRsE/6XRQnDD/JdL5aVm4=; b=qye7qIOqIBYCptLqy9V2WThq0o l3dzoM89dD+vYyiagYWiDaBhmzdbuQ4uakPy/WWi1Slw5BDRbpVbZepw/EdjXh4iKuHQo2vxULO9A hrgwl3DlIQJ9Rhpm+o/fXyFhJyf/F5USPRGbJNMXc6SyCvzVJfueMRw10zdQwJzwxT+1uFvG7mTi6 jLt/ezRl4FuykxAy3ullMK9+MW3m7FFYom8jpkZI8BvAF1RFrHB4cTtJqX8IvXYJFfgBsJscrgD9u uMbogoLVbpYg048AOy3NVMeY2CAsRav3BbzWaYkh3CFaNzCyHEMX/W1RxNb6MFRGF6i+Z1oVnqH/Z Tk0+0NWw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYT4R-0000000Byz8-35pP; Mon, 29 Jul 2024 16:17:59 +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 1sYT1u-0000000ByMf-34qx for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 16:15:24 +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 8F5AB1007; Mon, 29 Jul 2024 09:15:44 -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 271513F766; Mon, 29 Jul 2024 09:15:18 -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 06/11] aarch32: Implement cpu_init_arch() Date: Mon, 29 Jul 2024 17:14:56 +0100 Message-Id: <20240729161501.1806271-7-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_091522_844389_29963440 X-CRM114-Status: GOOD ( 10.75 ) 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 EL2/Hyp it does not initialise CNTFRQ, and in future it may need to initialize other CPU state regardless of the exeption level it was entered at. Use a common cpu_init_arch() function to initialize CPU state regardless of the exception level the boot-wrapper was entered at. For clarity cpu_init_secure_pl1() is renamed to cpu_init_monitor(), which better matches PSR_MON and will allow for the addition of cppu_init_hyp() and cpu_init_svc() in future. Signed-off-by: Mark Rutland Cc: Akos Denke Cc: Andre Przywara Cc: Luca Fancellu Cc: Marc Zyngier --- arch/aarch32/boot.S | 4 +++- arch/aarch32/init.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/aarch32/boot.S b/arch/aarch32/boot.S index 43dce75..a6f0751 100644 --- a/arch/aarch32/boot.S +++ b/arch/aarch32/boot.S @@ -62,7 +62,7 @@ reset_at_mon: bl cpu_init_bootwrapper - bl cpu_init_secure_pl1 + bl cpu_init_arch bl gic_secure_init @@ -82,6 +82,8 @@ reset_at_hyp: bl cpu_init_bootwrapper + bl cpu_init_arch + b start_bootmethod err_invalid_id: diff --git a/arch/aarch32/init.c b/arch/aarch32/init.c index e25f0c7..35da37c 100644 --- a/arch/aarch32/init.c +++ b/arch/aarch32/init.c @@ -29,7 +29,7 @@ void announce_arch(void) print_string("\r\n"); } -void cpu_init_secure_pl1(void) +static void cpu_init_monitor(void) { unsigned long scr = SCR_NS | SCR_HCE; unsigned long nsacr = NSACR_CP10 | NSACR_CP11; @@ -37,8 +37,6 @@ void cpu_init_secure_pl1(void) mcr(SCR, scr); mcr(NSACR, nsacr); - - mcr(CNTFRQ, COUNTER_FREQ); } #ifdef PSCI @@ -55,3 +53,11 @@ bool cpu_init_psci_arch(void) return true; } #endif + +void cpu_init_arch(void) +{ + if (read_cpsr_mode() == PSR_MON) + cpu_init_monitor(); + + mcr(CNTFRQ, COUNTER_FREQ); +} From patchwork Mon Jul 29 16:14:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13745382 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 828FBC3DA61 for ; Mon, 29 Jul 2024 16:18:33 +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=BU270ZpBBvm8aDrMqeF/b8RFoPUdF2MZtueBl4qmaSs=; b=oEvHPpfsWEhnekvzfaOh+AY5aG tNHJtt6MxHqavkaYLOBmjrJ8mgokcKt7ldixJLhzP4hjtT/arxKf9lwmvlJcgfDjXMDgM6ekeVQW/ KTTwJqG2E43W4IhAQdU8S8Vd4D3fnipSDIdTrSSMwGDAMsE2nXTCbEEOy/wBhqLLcJKxzfU6cQQO1 6RMnFCvzRXniSTizf2UlSVzaotCrlPwuZM7mGlseeUpN/8oFJ3N+c9eeHIWilRN3o/i3zBCkLoyTd +2moAP9Hpt8BtWMZoiyLIsP7MaWs3HPKBP2kztC7IKMZK8ohVlVMqTxXf/BfxRKlFCv6Bm6G+cq2B PZkSqeUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYT4o-0000000Bz3U-3hVZ; Mon, 29 Jul 2024 16:18:22 +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 1sYT1w-0000000ByMz-0mfl for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 16:15:25 +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 ED05F143D; Mon, 29 Jul 2024 09:15:48 -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 84A1A3F766; Mon, 29 Jul 2024 09:15:22 -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 07/11] aarch32: Always enter kernel via exception return Date: Mon, 29 Jul 2024 17:14:57 +0100 Message-Id: <20240729161501.1806271-8-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_091524_325706_7D8B2E66 X-CRM114-Status: GOOD ( 11.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 Seculre PL1 it will enter the kernel via an exception return, ERET, and when entered at Hyp 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 an exception return so that PSTATE is always initialized to a known-good value. Rework jump_kernel() to always enter the kernel via ERET, matching the stype of the AArch64 version of jump_kernel() Signed-off-by: Mark Rutland Cc: Akos Denke Cc: Andre Przywara Cc: Luca Fancellu Cc: Marc Zyngier --- arch/aarch32/boot.S | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/arch/aarch32/boot.S b/arch/aarch32/boot.S index a6f0751..11fd7aa 100644 --- a/arch/aarch32/boot.S +++ b/arch/aarch32/boot.S @@ -76,10 +76,6 @@ reset_at_hyp: bl setup_stack - mov r0, #1 - ldr r1, =flag_no_el3 - str r0, [r1] - bl cpu_init_bootwrapper bl cpu_init_arch @@ -96,9 +92,10 @@ err_invalid_id: * r1-r3, sp[0]: kernel arguments */ ASM_FUNC(jump_kernel) - sub sp, #4 @ Ignore fourth argument - push {r0 - r3} - mov r5, sp + mov r4, r0 + mov r5, r1 + mov r6, r2 + mov r7, r3 ldr r0, =HSCTLR_KERNEL mcr p15, 4, r0, c1, c0, 0 @ HSCTLR @@ -111,19 +108,24 @@ ASM_FUNC(jump_kernel) bl find_logical_id bl setup_stack - ldr lr, [r5], #4 - ldm r5, {r0 - r2} - - ldr r4, =flag_no_el3 - ldr r4, [r4] - cmp r4, #1 - bxeq lr @ no EL3 + mov r0, r5 + mov r1, r6 + mov r2, r7 + ldr r3, =SPSR_KERNEL + + mrs r5, cpsr + and r5, #PSR_MODE_MASK + cmp r5, #PSR_MON + beq eret_at_mon + cmp r5, #PSR_HYP + beq eret_at_hyp + b . - ldr r4, =SPSR_KERNEL - msr spsr_cxf, r4 +eret_at_mon: + mov lr, r4 + msr spsr_cxf, r3 movs pc, lr - - .section .data - .align 2 -flag_no_el3: - .long 0 +eret_at_hyp: + msr elr_hyp, r4 + msr spsr_cxf, r3 + eret From patchwork Mon Jul 29 16:14:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13745383 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 79BB6C3DA61 for ; Mon, 29 Jul 2024 16:18:56 +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=V7yQdnmdaeeokbadRqR33rBUZDru+OCTUXw9qig999I=; b=FHvK2sjcUvRbCQBOUDQysVJLSF RNIqTMdOwVcwQEfMFfPLhY5PZ/0ODD89vjdojvnEdP4h/uKV90/2G7AtIK5f3FG3D4TAMRTFD54oA YMld1InNr6C+NNEqJhcfg6iJxTon6Cn4kufILt6RZlfbJ9+Wj/nC9vTP7HsO8Z7R/LBU5Mkb5sWen xNpBHV+Yagu6ABwC1ry/0VYEcoE7A6QUJgyhORl3YAMYOMzeR8UVYzoSaZmnA89oN2Ku4gx4vAav2 ATclz9NHmLt7N97rUMViOKVDiTMouX7qo0psGJoWzNM2qOcBAGJhDuIGkzUb0AZUwhCrcMSIWmrTB fEhbZIDw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYT5D-0000000Bz7T-0WO2; Mon, 29 Jul 2024 16:18:47 +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 1sYT1x-0000000ByMf-0vnk for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 16:15:26 +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 8C8A71007; Mon, 29 Jul 2024 09:15:50 -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 246533F766; Mon, 29 Jul 2024 09:15:24 -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 08/11] Unify assembly setup paths Date: Mon, 29 Jul 2024 17:14:58 +0100 Message-Id: <20240729161501.1806271-9-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_091525_387075_BADDA328 X-CRM114-Status: GOOD ( 16.90 ) 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 The early assembly paths for EL3/Secure-PL1 and EL2/Hyp are almost identical aside from the EL3/Secure-PL1 paths calling gic_secure_init(). Simplify the easlery assembly paths by conditionally calling gic_secure_init() from cpu_init_arch(), allowing the EL3/Secure-PL1 and EL2/Hyp paths to be unified. In order to call gic_secure_init() from C code we need to expose a prototype for gic_secure_init(), requiring a new header. For clarity the existing headers are renamed to and are included through the common header. Signed-off-by: Mark Rutland Cc: Akos Denke Cc: Andre Przywara Cc: Luca Fancellu Cc: Marc Zyngier --- arch/aarch32/boot.S | 20 ++++++-------------- arch/aarch32/include/asm/{gic-v3.h => gic.h} | 2 +- arch/aarch32/init.c | 5 ++++- arch/aarch64/boot.S | 17 ++++------------- arch/aarch64/include/asm/{gic-v3.h => gic.h} | 2 +- arch/aarch64/init.c | 5 ++++- common/gic-v3.c | 2 +- common/gic.c | 2 +- include/gic.h | 16 ++++++++++++++++ 9 files changed, 38 insertions(+), 33 deletions(-) rename arch/aarch32/include/asm/{gic-v3.h => gic.h} (91%) rename arch/aarch64/include/asm/{gic-v3.h => gic.h} (92%) create mode 100644 include/gic.h diff --git a/arch/aarch32/boot.S b/arch/aarch32/boot.S index 11fd7aa..3a51cb0 100644 --- a/arch/aarch32/boot.S +++ b/arch/aarch32/boot.S @@ -53,22 +53,14 @@ reset_at_svc: movs pc, lr reset_at_mon: - cpuid r0, r1 - bl find_logical_id - cmp r0, #MPIDR_INVALID - beq err_invalid_id - - bl setup_stack - - bl cpu_init_bootwrapper - - bl cpu_init_arch - - bl gic_secure_init - - b start_bootmethod + // TODO initialise monitor state + b reset_common reset_at_hyp: + // TODO initialise hyp state + b reset_common + +reset_common: cpuid r0, r1 bl find_logical_id cmp r0, #MPIDR_INVALID diff --git a/arch/aarch32/include/asm/gic-v3.h b/arch/aarch32/include/asm/gic.h similarity index 91% rename from arch/aarch32/include/asm/gic-v3.h rename to arch/aarch32/include/asm/gic.h index b28136a..0b9425d 100644 --- a/arch/aarch32/include/asm/gic-v3.h +++ b/arch/aarch32/include/asm/gic.h @@ -1,5 +1,5 @@ /* - * arch/aarch32/include/asm/gic-v3.h + * arch/aarch32/include/asm/gic.h * * Copyright (C) 2015 ARM Limited. All rights reserved. * diff --git a/arch/aarch32/init.c b/arch/aarch32/init.c index 35da37c..cb67bf6 100644 --- a/arch/aarch32/init.c +++ b/arch/aarch32/init.c @@ -7,6 +7,7 @@ * found in the LICENSE.txt file. */ #include +#include #include #include @@ -56,8 +57,10 @@ bool cpu_init_psci_arch(void) void cpu_init_arch(void) { - if (read_cpsr_mode() == PSR_MON) + if (read_cpsr_mode() == PSR_MON) { cpu_init_monitor(); + gic_secure_init(); + } mcr(CNTFRQ, COUNTER_FREQ); } diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index 3dbf85a..4cc41bb 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -43,19 +43,7 @@ reset_at_el3: msr sctlr_el3, x0 isb - cpuid x0, x1 - bl find_logical_id - cmp x0, #MPIDR_INVALID - b.eq err_invalid_id - bl setup_stack - - bl cpu_init_bootwrapper - - bl cpu_init_arch - - bl gic_secure_init - - b start_bootmethod + b reset_common /* * EL2 initialization @@ -70,6 +58,9 @@ reset_at_el2: msr sctlr_el2, x0 isb + b reset_common + +reset_common: cpuid x0, x1 bl find_logical_id cmp x0, #MPIDR_INVALID diff --git a/arch/aarch64/include/asm/gic-v3.h b/arch/aarch64/include/asm/gic.h similarity index 92% rename from arch/aarch64/include/asm/gic-v3.h rename to arch/aarch64/include/asm/gic.h index 2447480..9d716f6 100644 --- a/arch/aarch64/include/asm/gic-v3.h +++ b/arch/aarch64/include/asm/gic.h @@ -1,5 +1,5 @@ /* - * arch/aarch64/include/asm/gic-v3.h + * arch/aarch64/include/asm/gic.h * * Copyright (C) 2015 ARM Limited. All rights reserved. * diff --git a/arch/aarch64/init.c b/arch/aarch64/init.c index 49abdf7..68c220b 100644 --- a/arch/aarch64/init.c +++ b/arch/aarch64/init.c @@ -7,6 +7,7 @@ * found in the LICENSE.txt file. */ #include +#include #include #include @@ -172,8 +173,10 @@ bool cpu_init_psci_arch(void) void cpu_init_arch(void) { - if (mrs(CurrentEL) == CURRENTEL_EL3) + if (mrs(CurrentEL) == CURRENTEL_EL3) { cpu_init_el3(); + gic_secure_init(); + } msr(CNTFRQ_EL0, COUNTER_FREQ); } diff --git a/common/gic-v3.c b/common/gic-v3.c index 6207007..4d8e620 100644 --- a/common/gic-v3.c +++ b/common/gic-v3.c @@ -10,7 +10,7 @@ #include #include -#include +#include #include #define GICD_CTLR 0x0 diff --git a/common/gic.c b/common/gic.c index 04d4289..15a3410 100644 --- a/common/gic.c +++ b/common/gic.c @@ -10,7 +10,7 @@ #include #include -#include +#include #include #define GICD_CTLR 0x0 diff --git a/include/gic.h b/include/gic.h new file mode 100644 index 0000000..127f82b --- /dev/null +++ b/include/gic.h @@ -0,0 +1,16 @@ +/* + * include/gic.h + * + * Copyright (C) 2024 ARM Limited. All rights reserved. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE.txt file. + */ +#ifndef __GIC_H +#define __GIC_H + +#include + +void gic_secure_init(void); + +#endif From patchwork Mon Jul 29 16:14:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13745384 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 9CB95C3DA7E for ; Mon, 29 Jul 2024 16:19:21 +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=eP7hNuQUMm53L8DEGKmQh+mExQx+1vMOlG4PtNmVVss=; b=Ywk0Pc/CPFi7NRXxQzEosd6JpL XFjTN0LouvTKPjJYXAWdiv0F2WyfEBINE6Mw+yEbBmo6gNQo02zaFTW6iaU1hufgLRtExBp5eaAqP t5eYgZUzTZMpk0193x1CpU+g8gu95fMa07fFqjG3aDwps3C3SPO7y+g80H7BO2JbtFVtEwgsNEjPX rtmBWwI3UfEB+4m6FgVyH0s/eoXgDxL1kXhgvVWYAWDDfmWbtnmMXACp3zGqIEXf8tnEugpU/0A6y moqQuhyzoC0756AgVjuWhl5T5jm/0HuZC8l5XWdirLl8lrT6VOKkTd77jFhrsFG60uoD652HQaIGC eb1bD2mg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYT5b-0000000BzCU-1Ov8; Mon, 29 Jul 2024 16:19: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 1sYT1z-0000000ByMz-1Dx9 for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 16:15:28 +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 24B86143D; Mon, 29 Jul 2024 09:15:52 -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 B06E63F766; Mon, 29 Jul 2024 09:15:25 -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 09/11] Simplify spin logic Date: Mon, 29 Jul 2024 17:14:59 +0100 Message-Id: <20240729161501.1806271-10-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_091527_507498_DB754727 X-CRM114-Status: GOOD ( 14.26 ) 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 The logic for initial boot is more complicated than it needs to be, with both first_spin() having a special case for CPU0 that requires an additional argument to be passed to spin(). Simplify this by moving the special-case logic for CPU0 into first_spin(). This removes the need to provide a dummy mailbox for CPU0 to spin on, simplfiies callers of first_spin() and spin(), which no longer need to pass a dummy mailbox or 'is_entry' for CPU0. Signed-off-by: Mark Rutland Cc: Akos Denke Cc: Andre Przywara Cc: Luca Fancellu Cc: Marc Zyngier --- arch/aarch64/spin.S | 11 +---------- common/boot.c | 20 ++++++++------------ common/psci.c | 2 +- include/boot.h | 2 +- 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/arch/aarch64/spin.S b/arch/aarch64/spin.S index 375f732..a7879d4 100644 --- a/arch/aarch64/spin.S +++ b/arch/aarch64/spin.S @@ -23,15 +23,6 @@ ASM_FUNC(start_bootmethod) * Primary CPU (x0 = 0) jumps to kernel, the other ones wait for an * address to appear in mbox */ - adr x3, mbox - adr x4, kernel_address - cmp x0, #0 - csel x1, x3, x4, ne + adr x1, mbox mov x2, #0 bl first_spin - - .align 3 -kernel_address: - .long 0 - - .ltorg diff --git a/common/boot.c b/common/boot.c index 29d53a4..4417649 100644 --- a/common/boot.c +++ b/common/boot.c @@ -27,7 +27,7 @@ const unsigned long id_table[] = { CPU_IDS }; * @invalid: value of an invalid address, 0 or -1 depending on the boot method * @is_entry: when true, pass boot parameters to the kernel, instead of 0 */ -void __noreturn spin(unsigned long *mbox, unsigned long invalid, int is_entry) +void __noreturn spin(unsigned long *mbox, unsigned long invalid) { unsigned long addr = invalid; @@ -36,13 +36,6 @@ void __noreturn spin(unsigned long *mbox, unsigned long invalid, int is_entry) addr = *mbox; } - if (is_entry) -#ifdef KERNEL_32 - jump_kernel(addr, 0, ~0, (unsigned long)&dtb, 0); -#else - jump_kernel(addr, (unsigned long)&dtb, 0, 0, 0); -#endif - jump_kernel(addr, 0, 0, 0, 0); unreachable(); @@ -60,12 +53,15 @@ void __noreturn first_spin(unsigned int cpu, unsigned long *mbox, unsigned long invalid) { if (cpu == 0) { - *mbox = (unsigned long)&entrypoint; - sevl(); - spin(mbox, invalid, 1); + unsigned long addr = (unsigned long)&entrypoint; +#ifdef KERNEL_32 + jump_kernel(addr, 0, ~0, (unsigned long)&dtb, 0); +#else + jump_kernel(addr, (unsigned long)&dtb, 0, 0, 0); +#endif } else { *mbox = invalid; - spin(mbox, invalid, 0); + spin(mbox, invalid); } unreachable(); diff --git a/common/psci.c b/common/psci.c index 5ae4255..19cc315 100644 --- a/common/psci.c +++ b/common/psci.c @@ -57,7 +57,7 @@ static int psci_cpu_off(void) branch_table[cpu] = PSCI_ADDR_INVALID; - spin(branch_table + cpu, PSCI_ADDR_INVALID, 0); + spin(branch_table + cpu, PSCI_ADDR_INVALID); unreachable(); } diff --git a/include/boot.h b/include/boot.h index 459d1d5..18b805d 100644 --- a/include/boot.h +++ b/include/boot.h @@ -12,7 +12,7 @@ #include #include -void __noreturn spin(unsigned long *mbox, unsigned long invalid, int is_entry); +void __noreturn spin(unsigned long *mbox, unsigned long invalid); void __noreturn first_spin(unsigned int cpu, unsigned long *mbox, unsigned long invalid_addr); From patchwork Mon Jul 29 16:15:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13745385 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 2A96DC3DA61 for ; Mon, 29 Jul 2024 16:19:44 +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=jokuWTwaFYOVzvfadJXTX9S1vMD3x58sH57W8zf6Uas=; b=glA+D5vlbFnXV1lz9fgcEwQN1A hRGtYjviqHHywAQ2dbTcMCVdY4XPfOWTl1kJp7L7TiuKX9Myo/uw9ZNGyHA8AqjHunvwJ1dxiECF3 VMXzc+QQaWk2eGhhYN0uy/mgB0cp/Mi3l++cjziLXXkliZIhrbsIzI5hKAOI3zjdEedTjR6BEa0AU BZxFizkFdzjdw4+FBSizn72Cnw1a74/m4B0TLBWVLM0T0lI6bISJWrmUUHvXDuUAAEL/EH1qsR8YH rfAS9B4ok7OtXPl9UUaFiAMpWNfHJ2FmZL1ziU628m1M33gR7GUXlFC3mWo9dyDfEw3KYYtWAJv4f /2Lndhmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYT5z-0000000BzIU-2h3p; Mon, 29 Jul 2024 16:19:35 +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 1sYT20-0000000ByOS-3bUO for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 16:15:30 +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 A86351007; Mon, 29 Jul 2024 09:15:53 -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 403A93F766; Mon, 29 Jul 2024 09:15:27 -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 10/11] Add printing functions Date: Mon, 29 Jul 2024 17:15:00 +0100 Message-Id: <20240729161501.1806271-11-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_091529_029103_AAB7E21E X-CRM114-Status: UNSURE ( 9.89 ) X-CRM114-Notice: Please train this message. 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 subsequent patches we'll want to log messages from specific CPUs. Add helpers to make this simpler. Signed-off-by: Mark Rutland Cc: Akos Denke Cc: Andre Przywara Cc: Luca Fancellu Cc: Marc Zyngier --- common/platform.c | 35 +++++++++++++++++++++++++++++++++++ include/platform.h | 4 ++++ 2 files changed, 39 insertions(+) diff --git a/common/platform.c b/common/platform.c index 1607ee6..4e390e1 100644 --- a/common/platform.c +++ b/common/platform.c @@ -65,6 +65,41 @@ void print_ulong_hex(unsigned long val) } } +// 2^32 is 4,294,967,296 +#define DEC_CHARS_PER_UINT 10 + +void print_uint_dec(unsigned int val) +{ + char digits[DEC_CHARS_PER_UINT]; + int d = 0; + + do { + digits[d] = val % 10; + val /= 10; + d++; + } while (val); + + while (d--) { + print_char('0' + digits[d]); + } +} + +void print_cpu_warn(unsigned int cpu, const char *str) +{ + print_string("CPU"); + print_uint_dec(cpu); + print_string(" WARNING: "); + print_string(str); +} + +void print_cpu_msg(unsigned int cpu, const char *str) +{ + print_string("CPU"); + print_uint_dec(cpu); + print_string(": "); + print_string(str); +} + void init_uart(void) { /* diff --git a/include/platform.h b/include/platform.h index c88e124..09712b1 100644 --- a/include/platform.h +++ b/include/platform.h @@ -12,6 +12,10 @@ void print_char(char c); void print_string(const char *str); void print_ulong_hex(unsigned long val); +void print_uint_dec(unsigned int val); + +void print_cpu_warn(unsigned int cpu, const char *str); +void print_cpu_msg(unsigned int cpu, const char *str); void init_uart(void); From patchwork Mon Jul 29 16:15:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13745386 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 F3EC9C3DA4A for ; Mon, 29 Jul 2024 16:20:10 +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=GsLPw2Y7ZVO2WEI/w30ZJrjTmzpxn98rsBOD0VfzonA=; b=LyHtrLqJmSZgaYJilOoVdfXm3m LaINg3BXFPuolIoijVF1YHx2dlmNWUWQqfBIJ70TUI1Yb1AB+cMYkkKykTbEj8vSy1cF/GXxiJTGo Kk1BbBnzTm0IOattRxkogS1Bzf34rtzLpOMN7mnH6lIvKDyQphKcHqq+z4n98qYtLzZ/OHq75GzuK 6CthaxN55MsjLNRC3Kg8c5RZR67HzDwt+EkpBfnc+BC7y/mjzHJNPLDOhn58cySFYQkXrG+q8f8GU yOTcm03E6zHNisXaxc+hi6HHTctrAZP2QJPeL2HR2JRCFj414ArcZ2XDm6Q+Q0d0hdAuGlLWRQf04 I+eqrlBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYT6N-0000000BzOs-3ykd; Mon, 29 Jul 2024 16:19:59 +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 1sYT22-0000000ByMz-03SQ for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 16:15:31 +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 15F9F143D; Mon, 29 Jul 2024 09:15:55 -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 A1F3D3F766; Mon, 29 Jul 2024 09:15:28 -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 11/11] Boot CPUs sequentially Date: Mon, 29 Jul 2024 17:15:01 +0100 Message-Id: <20240729161501.1806271-12-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_091530_212925_45BBAD40 X-CRM114-Status: GOOD ( 16.43 ) 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 Currently the boot-wrapper initializes all CPUs in parallel. This means that we cannot log errors as they happen, as this would mean multiple CPUs concurrently writing to the UART, producing garbled output. To produce meaningful output we have to special-case errors on the boot CPU and hope CPUs have been configured consistently. To make it easier to handle errors, boot CPUs sequentially so that errors can be logged as they happen. With this change it's pretty clear that the cpu_init_bootmethod() abstraction isn't helpful, and so this is removed with cpu_init_arch() directly initializing PSCI where necessary. When things go well this looks like: | Boot-wrapper v0.2 | Entered at EL3 | Memory layout: | [0000000080000000..0000000080001f90] => boot-wrapper | [000000008000fff8..0000000080010000] => mbox | [0000000080200000..0000000082cbaa00] => kernel | [0000000088000000..0000000088002df1] => dtb | CPU0: (MPIDR 0000000000000000) initializing... | CPU0: Done | CPU1: (MPIDR 0000000000000100) initializing... | CPU1: Done | CPU2: (MPIDR 0000000000000200) initializing... | CPU2: Done | CPU3: (MPIDR 0000000000000300) initializing... | CPU3: Done | CPU4: (MPIDR 0000000000010000) initializing... | CPU4: Done | CPU5: (MPIDR 0000000000010100) initializing... | CPU5: Done | CPU6: (MPIDR 0000000000010200) initializing... | CPU6: Done | CPU7: (MPIDR 0000000000010300) initializing... | CPU7: Done | All CPUs initialized. Entering kernel... | | [ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd0f0] Signed-off-by: Mark Rutland Cc: Akos Denke Cc: Andre Przywara Cc: Luca Fancellu Cc: Marc Zyngier --- arch/aarch32/boot.S | 2 -- arch/aarch32/init.c | 17 +++++++++------ arch/aarch64/boot.S | 2 -- arch/aarch64/init.c | 17 +++++++++------ arch/aarch64/spin.S | 3 --- common/init.c | 50 +++++++++++++++++++++++++++++++++++++-------- common/psci.c | 14 ------------- include/boot.h | 6 +----- 8 files changed, 64 insertions(+), 47 deletions(-) diff --git a/arch/aarch32/boot.S b/arch/aarch32/boot.S index 3a51cb0..679e28a 100644 --- a/arch/aarch32/boot.S +++ b/arch/aarch32/boot.S @@ -70,8 +70,6 @@ reset_common: bl cpu_init_bootwrapper - bl cpu_init_arch - b start_bootmethod err_invalid_id: diff --git a/arch/aarch32/init.c b/arch/aarch32/init.c index cb67bf6..d08ac83 100644 --- a/arch/aarch32/init.c +++ b/arch/aarch32/init.c @@ -6,6 +6,7 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE.txt file. */ +#include #include #include #include @@ -43,24 +44,28 @@ static void cpu_init_monitor(void) #ifdef PSCI extern char psci_vectors[]; -bool cpu_init_psci_arch(void) +static void cpu_init_psci_arch(unsigned int cpu) { - if (read_cpsr_mode() != PSR_MON) - return false; + if (read_cpsr_mode() != PSR_MON) { + print_cpu_warn(cpu, "PSCI could not be initialized (not booted at PL1).\r\n"); + return; + } mcr(MVBAR, (unsigned long)psci_vectors); isb(); - - return true; } +#else +static static void cpu_init_psci_arch(unsigned int cpu) { } #endif -void cpu_init_arch(void) +void cpu_init_arch(unsigned int cpu) { if (read_cpsr_mode() == PSR_MON) { cpu_init_monitor(); gic_secure_init(); } + cpu_init_psci_arch(cpu); + mcr(CNTFRQ, COUNTER_FREQ); } diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index 4cc41bb..f8fc808 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -69,8 +69,6 @@ reset_common: bl cpu_init_bootwrapper - bl cpu_init_arch - b start_bootmethod err_invalid_id: diff --git a/arch/aarch64/init.c b/arch/aarch64/init.c index 68c220b..81fe33a 100644 --- a/arch/aarch64/init.c +++ b/arch/aarch64/init.c @@ -6,6 +6,7 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE.txt file. */ +#include #include #include #include @@ -159,24 +160,28 @@ static void cpu_init_el3(void) #ifdef PSCI extern char psci_vectors[]; -bool cpu_init_psci_arch(void) +static void cpu_init_psci_arch(unsigned int cpu) { - if (mrs(CurrentEL) != CURRENTEL_EL3) - return false; + if (mrs(CurrentEL) != CURRENTEL_EL3) { + print_cpu_warn(cpu, "PSCI could not be initialized (not booted at EL3).\r\n"); + return; + } msr(VBAR_EL3, (unsigned long)psci_vectors); isb(); - - return true; } +#else +static void cpu_init_psci_arch(unsigned int cpu); #endif -void cpu_init_arch(void) +void cpu_init_arch(unsigned int cpu) { if (mrs(CurrentEL) == CURRENTEL_EL3) { cpu_init_el3(); gic_secure_init(); } + cpu_init_psci_arch(cpu); + msr(CNTFRQ_EL0, COUNTER_FREQ); } diff --git a/arch/aarch64/spin.S b/arch/aarch64/spin.S index a7879d4..81d7ee4 100644 --- a/arch/aarch64/spin.S +++ b/arch/aarch64/spin.S @@ -12,9 +12,6 @@ .text -ASM_FUNC(cpu_init_bootmethod) - ret - ASM_FUNC(start_bootmethod) cpuid x0, x1 bl find_logical_id diff --git a/common/init.c b/common/init.c index 3c05ac3..6197ead 100644 --- a/common/init.c +++ b/common/init.c @@ -43,18 +43,50 @@ static void announce_objects(void) void announce_arch(void); +static void init_bootwrapper(void) +{ + init_uart(); + announce_bootwrapper(); + announce_arch(); + announce_objects(); + init_platform(); +} + +static void cpu_init_self(unsigned int cpu) +{ + print_string("CPU"); + print_uint_dec(cpu); + print_string(": (MPIDR "); + print_ulong_hex(read_mpidr()); + print_string(") initializing...\r\n"); + + cpu_init_arch(cpu); + + print_cpu_msg(cpu, "Done\r\n"); +} + void cpu_init_bootwrapper(void) { + static volatile unsigned int cpu_next = 0; unsigned int cpu = this_cpu_logical_id(); - if (cpu == 0) { - init_uart(); - announce_bootwrapper(); - announce_arch(); - announce_objects(); - print_string("\r\n"); - init_platform(); - } + if (cpu == 0) + init_bootwrapper(); + + while (cpu_next != cpu) + wfe(); + + cpu_init_self(cpu); + + cpu_next = cpu + 1; + dsb(sy); + sev(); + + if (cpu != 0) + return; + + while (cpu_next != NR_CPUS) + wfe(); - cpu_init_bootmethod(cpu); + print_string("All CPUs initialized. Entering kernel...\r\n\r\n"); } diff --git a/common/psci.c b/common/psci.c index 19cc315..5fe8999 100644 --- a/common/psci.c +++ b/common/psci.c @@ -87,17 +87,3 @@ void __noreturn psci_first_spin(void) unreachable(); } - -void cpu_init_bootmethod(unsigned int cpu) -{ - if (cpu_init_psci_arch()) - return; - - if (cpu == 0) { - print_string("WARNING: PSCI could not be initialized. Boot may fail\r\n\r\n"); - return; - } - - while (1) - wfe(); -} diff --git a/include/boot.h b/include/boot.h index 18b805d..12c9c5c 100644 --- a/include/boot.h +++ b/include/boot.h @@ -17,10 +17,6 @@ void __noreturn spin(unsigned long *mbox, unsigned long invalid); void __noreturn first_spin(unsigned int cpu, unsigned long *mbox, unsigned long invalid_addr); -void cpu_init_bootmethod(unsigned int cpu); - -#ifdef PSCI -bool cpu_init_psci_arch(void); -#endif +void cpu_init_arch(unsigned int cpu); #endif