Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57E18C433ED for ; Mon, 26 Apr 2021 11:43:09 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A47AA61027 for ; Mon, 26 Apr 2021 11:43:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A47AA61027 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IlANRHg4XZFlUn8tRQzvPNyMLmEI1ZbI1dviOhsK5Lg=; b=bmTdZ77X74o/xycKpFIRbvYJ5 OAAXMR8ISmugtg6YLgrclx3qt8TnErneGJC7zpo9A+Vg7CwefsPX/Txw4IgSufAlQaviT7vU8viuE YZMRxyx4fkqK4XIErjqqMSt9p4DDUW09w8S83/dPO1G+NlEtpGI1cb9VoZxGhT3TUABdgavnlQzTg 1y8I1GI1Lxdfw4cEgi1lphkkL5WmXk1/XMjxqy+n1/cJ0aFE0BapkVD0YzPQ3CNYJLOFQJqDPiaXs YluYktn7gWWg2PKHfVFq/xBhwhP5ICoDM/0UijVISYxHVcY3raxJ/Q5Yo0CPVf17FwP6V0dCwkErM sdnvFK+kg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lazcN-007W5E-5p; Mon, 26 Apr 2021 11:41:35 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lazcK-007W52-8s for linux-arm-kernel@desiato.infradead.org; Mon, 26 Apr 2021 11:41:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To: From:Date:Sender:Reply-To:Content-ID:Content-Description; bh=Di7RE0RsX9lADNomsZw3L0VXWjI3UfcSQUclyfef220=; b=gc9gClQANaVyeuv6lvvDIuDQvm 6ROkKS+F9T+BLKydbrY79V8fkneKgKNtr27nMJQgpqRZEfzelUQ/Cave0Xo7GnFPzH5S8sDHrF4wo JKDLs+Clfrl1w3VrSjd/H1kCAB4PmdTlxFV/59+I6dD/Y27HI+MJcqzkb5ep0qf4y81ehf8YcpRXe +5OC062GPZG+I07K3VFaSAfFySKU5fjwdH3708LtVS1EFlFwMvBkwgMnIsAk6kXIdNgjHRgp3Ug0v dHDs2h29IkXOxADoizOVZzVBS5GSWUI+oplYVSggAbKb0etFTn7cNUV9O+JUIIxtHc8U3oqhVX9U0 4s4cCekg==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lazcH-00Fvom-0Y for linux-arm-kernel@lists.infradead.org; Mon, 26 Apr 2021 11:41: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 F07851FB; Mon, 26 Apr 2021 04:41:23 -0700 (PDT) Received: from slackpad.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 355283F73B; Mon, 26 Apr 2021 04:41:23 -0700 (PDT) Date: Mon, 26 Apr 2021 12:40:54 +0100 From: Andre Przywara To: Jaxson Han Cc: mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org, wei.chen@arm.com Subject: Re: [boot-wrapper PATCH 2/5] aarch64: Rename labels and prepare for lower EL booting Message-ID: <20210426124055.20253825@slackpad.fritz.box> In-Reply-To: <20210420072438.183086-3-jaxson.han@arm.com> References: <20210420072438.183086-1-jaxson.han@arm.com> <20210420072438.183086-3-jaxson.han@arm.com> Organization: Arm Ltd. X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.31; x86_64-slackware-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210426_044129_191588_78B3F021 X-CRM114-Status: GOOD ( 30.39 ) 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 On Tue, 20 Apr 2021 15:24:35 +0800 Jaxson Han wrote: > Prepare for booting from lower EL. Rename *_el3 relavant labels with > *_el_max and *_no_el3 with *_keep_el. Since the original _no_el3 means > "We neither do init sequence at this highest EL nor drop to lower EL > when entering to kernel", we rename it with _keep_el to make it more > clear for lower EL initialisation. So this cleanup and rename is fine, however the patch is hard to read since various other changes are mixed in. Can you try to isolate this more? If this patch would just rename the labels, and wouldn't carry any functional change, it might be easier to reason about. At least the SPSR value change should be separate. Some more below: > Also in jump_kernel, skip sctlr_el2 initialisation when CurrentEL < EL2. > > Signed-off-by: Jaxson Han > --- > arch/aarch64/boot.S | 54 +++++++++++++++++++++++++--------- > arch/aarch64/include/asm/cpu.h | 3 ++ > arch/aarch64/psci.S | 13 ++++---- > arch/aarch64/spin.S | 8 ++--- > 4 files changed, 54 insertions(+), 24 deletions(-) > > diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S > index e47cf59..f7dbf3f 100644 > --- a/arch/aarch64/boot.S > +++ b/arch/aarch64/boot.S > @@ -12,7 +12,7 @@ > .section .init > > .globl _start > - .globl jump_kernel > + .globl jump_kernel > > _start: > cpuid x0, x1 > @@ -22,20 +22,30 @@ _start: > bl setup_stack > > /* > - * EL3 initialisation > + * Boot sequence > + * If CurrentEL == EL3, then goto EL3 initialisation and drop to > + * lower EL before entering the kernel. > + * Else, no initialisation and keep the current EL before > + * entering the kernel. > */ > mrs x0, CurrentEL > cmp x0, #CURRENTEL_EL3 > - b.eq 1f > + beq el3_init > > + /* > + * We stay in the current EL for entering the kernel > + */ > mov w0, #1 > - ldr x1, =flag_no_el3 > + ldr x1, =flag_keep_el > str w0, [x1] > > - bl setup_stack I think this is indeed redundant, but can you either make this a separate patch or at least mention it in the commit message? > - b start_no_el3 > + b start_keep_el > > -1: mov x0, #0x30 // RES1 > + /* > + * EL3 initialisation > + */ > +el3_init: > + mov x0, #0x30 // RES1 > orr x0, x0, #(1 << 0) // Non-secure EL1 > orr x0, x0, #(1 << 8) // HVC enable > > @@ -93,13 +103,23 @@ _start: > mov x0, #ZCR_EL3_LEN_MASK // SVE: Enable full vector len > msr ZCR_EL3, x0 // for EL2. > > -1: > + /* > + * Save SPSR_KERNEL into spsr_to_elx. > + * The jump_kernel will load spsr_to_elx into spsr_el3 > + */ > +1: mov w0, #SPSR_KERNEL > + ldr x1, =spsr_to_elx > + str w0, [x1] > + b el_max_init This (and the other SPSR related changes below) should be in a separate patch. > + > +el_max_init: > ldr x0, =CNTFRQ > msr cntfrq_el0, x0 > + isb Why this isb here? I don't see that we would require this? > bl gic_secure_init > > - b start_el3 > + b start_el_max > > err_invalid_id: > b . > @@ -119,14 +139,18 @@ jump_kernel: > ldr x0, =SCTLR_EL1_RESET > msr sctlr_el1, x0 > > + mrs x0, CurrentEL > + cmp x0, #CURRENTEL_EL2 > + b.lt 1f > + This is also a change which might be separate. Cheers, Andre > ldr x0, =SCTLR_EL2_RESET > msr sctlr_el2, x0 > > - cpuid x0, x1 > +1: cpuid x0, x1 > bl find_logical_id > bl setup_stack // Reset stack pointer > > - ldr w0, flag_no_el3 > + ldr w0, flag_keep_el > cmp w0, #0 // Prepare Z flag > > mov x0, x20 > @@ -135,9 +159,9 @@ jump_kernel: > mov x3, x23 > > b.eq 1f > - br x19 // No EL3 > + br x19 // Keep current EL > > -1: mov x4, #SPSR_KERNEL > +1: ldr w4, spsr_to_elx > > /* > * If bit 0 of the kernel address is set, we're entering in AArch32 > @@ -153,5 +177,7 @@ jump_kernel: > > .data > .align 3 > -flag_no_el3: > +flag_keep_el: > + .long 0 > +spsr_to_elx: > .long 0 > diff --git a/arch/aarch64/include/asm/cpu.h b/arch/aarch64/include/asm/cpu.h > index ccb5397..2b3a0a4 100644 > --- a/arch/aarch64/include/asm/cpu.h > +++ b/arch/aarch64/include/asm/cpu.h > @@ -11,6 +11,7 @@ > > #define MPIDR_ID_BITS 0xff00ffffff > > +#define CURRENTEL_EL2 (2 << 2) > #define CURRENTEL_EL3 (3 << 2) > > /* > @@ -24,6 +25,7 @@ > #define SPSR_I (1 << 7) /* IRQ masked */ > #define SPSR_F (1 << 6) /* FIQ masked */ > #define SPSR_T (1 << 5) /* Thumb */ > +#define SPSR_EL1H (5 << 0) /* EL1 Handler mode */ > #define SPSR_EL2H (9 << 0) /* EL2 Handler mode */ > #define SPSR_HYP (0x1a << 0) /* M[3:0] = hyp, M[4] = AArch32 */ > > @@ -42,6 +44,7 @@ > #else > #define SCTLR_EL1_RESET SCTLR_EL1_RES1 > #define SPSR_KERNEL (SPSR_A | SPSR_D | SPSR_I | SPSR_F | SPSR_EL2H) > +#define SPSR_KERNEL_EL1 (SPSR_A | SPSR_D | SPSR_I | SPSR_F | SPSR_EL1H) > #endif > > #ifndef __ASSEMBLY__ > diff --git a/arch/aarch64/psci.S b/arch/aarch64/psci.S > index 01ebe7d..ae02fd6 100644 > --- a/arch/aarch64/psci.S > +++ b/arch/aarch64/psci.S > @@ -45,8 +45,8 @@ vector: > > .text > > - .globl start_no_el3 > - .globl start_el3 > + .globl start_keep_el > + .globl start_el_max > > err_exception: > b err_exception > @@ -101,7 +101,7 @@ smc_exit: > eret > > > -start_el3: > +start_el_max: > ldr x0, =vector > bl setup_vector > > @@ -111,10 +111,11 @@ start_el3: > b psci_first_spin > > /* > - * This PSCI implementation requires EL3. Without EL3 we'll only boot the > - * primary cpu, all others will be trapped in an infinite loop. > + * This PSCI implementation requires the highest EL(EL3 or Armv8-R EL2). > + * Without the highest EL, we'll only boot the primary cpu, all others > + * will be trapped in an infinite loop. > */ > -start_no_el3: > +start_keep_el: > cpuid x0, x1 > bl find_logical_id > cbz x0, psci_first_spin > diff --git a/arch/aarch64/spin.S b/arch/aarch64/spin.S > index 72603cf..533177c 100644 > --- a/arch/aarch64/spin.S > +++ b/arch/aarch64/spin.S > @@ -11,11 +11,11 @@ > > .text > > - .globl start_no_el3 > - .globl start_el3 > + .globl start_keep_el > + .globl start_el_max > > -start_el3: > -start_no_el3: > +start_el_max: > +start_keep_el: > cpuid x0, x1 > bl find_logical_id > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel