All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: Andre Przywara <andre.przywara@arm.com>
Cc: linux-arm-kernel@lists.infradead.org, Jaxson.Han@arm.com,
	Wei.Chen@arm.com
Subject: Re: [boot-wrapper PATCH 04/12] Remove `flag_no_el3`
Date: Fri, 30 Jul 2021 17:43:33 +0100	[thread overview]
Message-ID: <20210730164333.GF19569@C02TD0UTHF1T.local> (raw)
In-Reply-To: <20210730161305.4064f576@slackpad.fritz.box>

On Fri, Jul 30, 2021 at 04:13:05PM +0100, Andre Przywara wrote:
> On Thu, 29 Jul 2021 16:20:42 +0100
> Mark Rutland <mark.rutland@arm.com> wrote:
> 
> Hi,
> 
> > We set `flag_no_el3` when not booted at EL3 / monitor mode, and
> > subsequently we use this to determine whether we need to drop exception
> > level before entering Linux. As this can be derived from CurrentEL or
> > CPSR, the flag itself is redundant, and we can defer the check until
> > we're about to enter Linux.
> > 
> > In future this will allow more logic to be converted into C, where it
> > will be easier to handle architectural variants.
> > 
> > Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> > ---
> >  arch/aarch32/boot.S | 14 +++-----------
> >  arch/aarch64/boot.S | 13 ++-----------
> >  2 files changed, 5 insertions(+), 22 deletions(-)
> > 
> > diff --git a/arch/aarch32/boot.S b/arch/aarch32/boot.S
> > index 2a85ad5..0bd1ca2 100644
> > --- a/arch/aarch32/boot.S
> > +++ b/arch/aarch32/boot.S
> > @@ -31,9 +31,6 @@ ENTRY(_start)
> >  	cmp	r0, #PSR_HYP
> >  	bne	_switch_monitor
> 
> Can't this become "beq start_no_el3" now?

I'm working to *remove* the el3/no_el3 labels, and handle the specific
exception levels as required, so I don't want to introduce that.

This says exactly what it does (i.e. switch to monitor mode), so I'd
rather leave it as-is.

> > -	mov	r0, #1
> > -	ldr	r1, =flag_no_el3
> > -	str	r0, [r1]
> >  	b	start_no_el3
> >  
> >  _switch_monitor:
> > @@ -89,9 +86,9 @@ ENTRY(jump_kernel)
> >  	ldr	lr, [r5], #4
> >  	ldm	r5, {r0 - r2}
> >  
> > -	ldr	r4, =flag_no_el3
> > -	ldr	r4, [r4]
> > -	cmp	r4, #1
> > +	mrs	r4, cpsr
> > +	and	r4, #PSR_MODE_MASK
> > +	cmp	r4, #PSR_MON
> 
> Is comparing explicitly against monitor mode the right thing? IIRC
> normally we come out of reset in secure SVC, and this *is* EL3 (the
> highest implemented exception level), from an ARMv8 perspective.

I agree it's not quite right, but the situation is more complicated:
It's more complicated than that. For details see:

* G1.4.1 "About the AArch32 PE modes"
* G1.9.1 "AArch32 state PE mode descriptions"
* G1.17 "Reset into AArch32 state" says:

The summary is:

* AArch32 doesn't necessarily reset into EL3. EL3 an EL2 are OPTIONAL.

* Supervisor mode can exist in EL3, Secure EL1, and Non-Secure EL1, and
  the PSR doesn't tell you which of the three you're in.

The boot-wrapper currently assumes we reset into EL3 or Non-Secure EL2,
and this is after the switch, where we should be in monitor mode
(otherwise PSCI cannot work, since we can't write to MVBAR). I'm not
changing that assumption. 

We should be able to rework that to *try* to switch to monitor mode, and
if that fails stick to S/NS EL1. I'm happy to tackle that as a follow
up, organising the logic so we can rely on:

* MON being EL3
* HYP being NS EL2
* SVC being S EL1 or NS EL1

> The old code did compare against HYP, which is probably what we want
> and is also one of the few modes we are sure of being not EL3.

That maches EL2 specifically (and I have left that as-is), but not about
EL3/EL1.

> 
> >  	bxeq	lr				@ no EL3
> >  
> >  	ldr	r4, =SPSR_KERNEL
> > @@ -113,8 +110,3 @@ boot_vectors:
> >  	b	.
> >  	b	.
> >  	b	.
> > -
> > -	.section .data
> > -	.align 2
> > -flag_no_el3:
> > -	.long 0
> > diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S
> > index 37759ce..fae0188 100644
> > --- a/arch/aarch64/boot.S
> > +++ b/arch/aarch64/boot.S
> > @@ -28,10 +28,6 @@ _start:
> >  	cmp	x0, #CURRENTEL_EL3
> >  	b.eq	1f
> 
> Can't this become "b.ne start_no_el3" now?

As above, I'm working towards removing those labels, and having a single
boot path, so I'd prefer to leave that as-is for now.

Thanks,
Mark.

> 
> Cheers,
> Andre
> 
> >  
> > -	mov	w0, #1
> > -	ldr	x1, =flag_no_el3
> > -	str	w0, [x1]
> > -
> >  	b	start_no_el3
> >  
> >  1:	mov	x0, #0x30			// RES1
> > @@ -140,8 +136,8 @@ jump_kernel:
> >  	bl	find_logical_id
> >  	bl	setup_stack		// Reset stack pointer
> >  
> > -	ldr	w0, flag_no_el3
> > -	cmp	w0, #0			// Prepare Z flag
> > +	mrs	x0, CurrentEl
> > +	cmp	w0, #CURRENTEL_EL3	// Prepare Z flag
> >  
> >  	mov	x0, x20
> >  	mov	x1, x21
> > @@ -164,8 +160,3 @@ jump_kernel:
> >  	eret
> >  
> >  	.ltorg
> > -
> > -	.data
> > -	.align 3
> > -flag_no_el3:
> > -	.long 0
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-07-30 16:45 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-29 15:20 [boot-wrapper PATCH 00/12] Preparatory fixes and cleanup Mark Rutland
2021-07-29 15:20 ` [boot-wrapper PATCH 01/12] Ensure `kernel_address` is aligned Mark Rutland
2021-07-30 15:11   ` Andre Przywara
2021-07-29 15:20 ` [boot-wrapper PATCH 02/12] Output text separately from data Mark Rutland
2021-07-29 15:20 ` [boot-wrapper PATCH 03/12] Remove cache maintenance Mark Rutland
2021-07-30 15:12   ` Andre Przywara
2021-07-30 15:43     ` Mark Rutland
2021-07-29 15:20 ` [boot-wrapper PATCH 04/12] Remove `flag_no_el3` Mark Rutland
2021-07-30 15:13   ` Andre Przywara
2021-07-30 16:43     ` Mark Rutland [this message]
2021-08-02 14:43       ` Mark Rutland
2021-07-29 15:20 ` [boot-wrapper PATCH 05/12] Move PSCI triage to C Mark Rutland
2021-07-29 15:20 ` [boot-wrapper PATCH 06/12] Move scripts to a `scripts` directory Mark Rutland
2021-07-30 15:13   ` Andre Przywara
2021-07-29 15:20 ` [boot-wrapper PATCH 07/12] aarch64: respect text offset Mark Rutland
2021-07-30 15:13   ` Andre Przywara
2021-07-30 15:43     ` Mark Rutland
2021-07-29 15:20 ` [boot-wrapper PATCH 08/12] Consistently use logical CPU IDs Mark Rutland
2021-07-30 17:38   ` Andre Przywara
2021-07-29 15:20 ` [boot-wrapper PATCH 09/12] Cleanup `.globl` usage Mark Rutland
2021-07-30 17:39   ` Andre Przywara
2021-07-29 15:20 ` [boot-wrapper PATCH 10/12] aarch32: rename `_spin_dead` -> `err_invalid_id` Mark Rutland
2021-07-30 17:39   ` Andre Przywara
2021-07-29 15:20 ` [boot-wrapper PATCH 11/12] Rename `spin.h` -> `boot.h` Mark Rutland
2021-07-30 17:39   ` Andre Przywara
2021-07-29 15:20 ` [boot-wrapper PATCH 12/12] Move common source files to `common` directory Mark Rutland
2021-07-30 17:40   ` Andre Przywara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210730164333.GF19569@C02TD0UTHF1T.local \
    --to=mark.rutland@arm.com \
    --cc=Jaxson.Han@arm.com \
    --cc=Wei.Chen@arm.com \
    --cc=andre.przywara@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.