Add Armv8-R AArch64 support
v2 cover Add Armv8-R AArch64 support
Currently, we cannot boot Linux with boot-wrapper on Armv8-R AArch64:
1. The Armv8-R AArch64 profile does not support the EL3.
2. The Armv8-R AArch64 EL2 only supports a PMSA, which Linux does not support. So it's necessary to drop into EL1 before entering the kernel.
3. There is no EL2 booting code for Armv8-R AArch64 and no configuration for dropping to EL1 in boot-wrapper.
These patches enable boot-wrapper booting Linux with Armv8-R AArch64:
Patch 1 allows boot-wrapper to boot on more platforms. Patch 2 renames some labels as preparations for booting from lower EL. Patch 3 remove the redundant setup_stack.
Patch 4-5 does some preparations for lower EL booting. Patch 6 prepares for GICv3 initialization with EL2.
Patch 7 adds necessary EL2 registers.
Patch 8 adds auto-detection for Armv8-R AArch64 to drop into EL1 before entering the kernel.
Refs: Arm Architecture Reference Manual Supplement - Armv8, for Armv8-R AArch64 architecture profile.
[https://developer.arm.com/documentation/ddi0600/latest/]
---------
v1 -> v2:
1. Split Patch 2 to Patch 2,3,4.
2. Slightly refine some comments.
3. More checks on Armv8-R AArch64.
4. Force setting HCR_EL2 instead of modifying.
Jaxson Han (8):
Decouple V2M_SYS config by auto-detect dtb node
aarch64: Rename labels and prepare for lower EL booting
aarch64: Remove the redundant setup_stack
aarch64: Prepare for EL1 booting
aarch64: Prepare for lower EL booting
gic-v3: Prepare for gicv3 with EL2
aarch64: Prepare for booting with EL2
aarch64: Introduce EL2 boot code for Armv8-R AArch64
Makefile.am | 4 +- arch/aarch32/include/asm/gic-v3.h | 7 ++ arch/aarch64/boot.S | 146 +++++++++++++++++++++++++++--- arch/aarch64/include/asm/cpu.h | 3 + arch/aarch64/include/asm/gic-v3.h | 38 +++++++- arch/aarch64/psci.S | 13 +-- arch/aarch64/spin.S | 8 +- arch/aarch64/utils.S | 10 +- gic-v3.c | 2 +- platform.c | 4 + 10 files changed, 203 insertions(+), 32 deletions(-)
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 1/8 Decouple V2M_SYS config by auto-detect dtb node
An auto-detect switch is added to make it an option to enable/disable 'arm,vexpress-sysreg', because not all platforms support this feature.
But the auto-detection generates the side-effect of printing a warning message about the missing node:
No matching devices found at ./findbase.pl line 37.
In this case, to drop the warning message, add "2> /dev/null" at the end of the findbase.pl call.
--- Makefile.am | 4 ++-- platform.c | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-)
Makefile.am +2 -2
@@ -10,7 +10,7 @@ # VE PHYS_OFFSET := $(shell perl -I $(top_srcdir) $(top_srcdir)/findmem.pl $(KERNEL_DTB)) UART_BASE := $(shell perl -I $(top_srcdir) $(top_srcdir)/findbase.pl $(KERNEL_DTB) 0 'arm,pl011') -SYSREGS_BASE := $(shell perl -I $(top_srcdir) $(top_srcdir)/findbase.pl $(KERNEL_DTB) 0 'arm,vexpress-sysreg') +SYSREGS_BASE := $(shell perl -I $(top_srcdir) $(top_srcdir)/findbase.pl $(KERNEL_DTB) 0 'arm,vexpress-sysreg' 2> /dev/null) CNTFRQ := 0x01800000 # 24Mhz CPU_IDS := $(shell perl -I $(top_srcdir) $(top_srcdir)/findcpuids.pl $(KERNEL_DTB))
@@ -19,7 +19,7 @@ NR_CPUS := $(shell echo $(CPU_IDS) | tr ',' ' ' | wc -w) DEFINES = -DCNTFRQ=$(CNTFRQ) DEFINES += -DCPU_IDS=$(CPU_IDS) DEFINES += -DNR_CPUS=$(NR_CPUS) -DEFINES += -DSYSREGS_BASE=$(SYSREGS_BASE) +DEFINES += $(if $(SYSREGS_BASE), -DSYSREGS_BASE=$(SYSREGS_BASE), ) DEFINES += -DUART_BASE=$(UART_BASE) DEFINES += -DSTACK_SIZE=256
platform.c +4 -0
@@ -23,10 +23,12 @@#define PL011 (reg) ((void *)UART_BASE + PL011_##reg) +#ifdef SYSREGS_BASE #define V2M_SYS_CFGDATA 0xa0#define V2M_SYS_CFGCTRL 0xa4#define V2M_SYS (reg) ((void *)SYSREGS_BASE + V2M_SYS_##reg) +#endif static void print_string (const char *str) {
@@ -59,6 +61,7 @@ void init_platform(void)print_string ("Boot-wrapper v0.2\r\n\r\n" ); +#ifdef SYSREGS_BASE /* * CLCD output site MB */
@@ -66,4 +69,5 @@ void init_platform(void)/* START | WRITE | MUXFPGA | SITE_MB */ raw_writel ((1 <<31 ) | (1 <<30 ) | (7 <<20 ) | (0 <<16 ),V2M_SYS (CFGCTRL )); +#endif }
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 2/8 aarch64: Rename labels and prepare for lower EL booting
In reply to Jaxson HanPrepare 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.
--- arch/aarch64/boot.S | 33 ++++++++++++++++++++++----------- arch/aarch64/include/asm/cpu.h | 3 +++ arch/aarch64/psci.S | 13 +++++++------ arch/aarch64/spin.S | 8 ++++---- 4 files changed, 36 insertions(+), 21 deletions(-)
arch/aarch64/boot.S +22 -11
@@ -12,7 +12,7 @@ .section .init .globl _start - .globl jump_kernel + .globl jump_kernel _start: cpuid x0, x1
@@ -22,20 +22,31 @@ _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 - 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
@@ -114,7 +125,7 @@ _start: bl gic_secure_init - b start_el3 + b start_el_max err_invalid_id: b .
@@ -141,7 +152,7 @@ jump_kernel: 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
@@ -150,9 +161,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_KERNEL /* * If bit 0 of the kernel address is set, we're entering in AArch32
@@ -168,5 +179,5 @@ jump_kernel: .data .align 3 -flag_no_el3: +flag_keep_el: .long 0
arch/aarch64/include/asm/cpu.h +3 -0
@@ -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__
arch/aarch64/psci.S +7 -6
@@ -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
arch/aarch64/spin.S +4 -4
@@ -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
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [boot-wrapper PATCH v2 2/8] aarch64: Rename labels and prepare for lower EL booting
Quoted 5 lines · On Fri, 21 May 2021 18:48:01 +0800 Jaxson Han <[email protected]> wrote:
Prepare for booting from lower EL. Rename
*_el3relavant labels with*_el_maxand*_no_el3with*_keep_el. Since the original_no_el3means "We neither do init sequence at this highest EL nor drop to lower EL when entering to kernel", we rename it with_keep_elto make it more clear for lower EL initialisation.
Thanks for splitting out this patch, I verified that most of it is indeed just renames, apart from the things below:
Quoted 78 lines
Signed-off-by Jaxson Han <[email protected]>--- arch/aarch64/boot.S | 33 ++++++++++++++++++++++----------- arch/aarch64/include/asm/cpu.h | 3 +++ arch/aarch64/psci.S | 13 +++++++------ arch/aarch64/spin.S | 8 ++++---- 4 files changed, 36 insertions(+), 21 deletions(-)arch/aarch64/boot.S +19
-8@@ -12,7 +12,7 @@ .section .init .globl _start - .globl jump_kernel + .globl jump_kernel _start: cpuid x0, x1@@ -22,20 +22,31 @@ _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 - 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@@ -114,7 +125,7 @@ _start: bl gic_secure_init - b start_el3 + b start_el_max err_invalid_id: b .@@ -141,7 +152,7 @@ jump_kernel: 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
arch/aarch64/boot.S jump_kernel: · line 166
Quoted 8 lines
arch/aarch64/boot.S +2
-2@@ -150,9 +161,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_KERNEL
This looks both premature and wrong: The value of SPSR_KERNEL doesn't
change here, so doesn't need any change in this instruction. Plus: ldr
without '=' requires an address, not a value, and this in fact already
breaks compilation:arch/aarch64/boot.S:166: Error: immediate value must be a multiple of 4 at operand 2 -- `ldr w4,#((1<<8)|(1<<9)|(1<<7)|(1<<6)|(9<<0))'
So please remove this change, and also the changes in cpu.h below, and introduce them only when they are actually needed.
Apart from the rest is then really just renames.
Cheers,
Andre
Quoted 87 lines
arch/aarch64/boot.S +1
-1/* * If bit 0 of the kernel address is set, we're entering in AArch32@@ -168,5 +179,5 @@ jump_kernel: .data .align 3 -flag_no_el3: +flag_keep_el: .long 0arch/aarch64/include/asm/cpu.h +3
-0@@ -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__arch/aarch64/psci.S +7
-6@@ -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_spinarch/aarch64/spin.S +0
-2@@ -11,11 +11,11 @@ .text - .globl start_no_el3 - .globl start_el3
arch/aarch64/spin.S line 21
Quoted 10 lines
arch/aarch64/spin.S +4
-2+ .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
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
RE: [boot-wrapper PATCH v2 2/8] aarch64: Rename labels and prepare for lower EL booting
Hi Andre,
Quoted 115 lines
-----Original Message-----
From: Andre Przywara <[email protected]>
Sent: Monday, May 24, 2021 5:32 PM
To: Jaxson Han <[email protected]>
Cc: Mark Rutland <[email protected]>; linux-arm- [email protected]; Wei Chen <[email protected]>
Subject: Re: [boot-wrapper PATCH v2 2/8] aarch64: Rename labels and prepare for lower EL bootingQuoted 5 lines · On Fri, 21 May 2021 18:48:01 +0800 Jaxson Han <[email protected]> wrote:
Prepare for booting from lower EL. Rename
*_el3relavant labels with*_el_maxand*_no_el3with*_keep_el. Since the original_no_el3means "We neither do init sequence at this highest EL nor drop to lower EL when entering to kernel", we rename it with_keep_elto make it more clear for lower EL initialisation.Thanks for splitting out this patch, I verified that most of it is indeed just renames, apart from the things below:
Quoted 78 lines
Signed-off-by Jaxson Han <[email protected]>--- arch/aarch64/boot.S | 33 ++++++++++++++++++++++----------- arch/aarch64/include/asm/cpu.h | 3 +++ arch/aarch64/psci.S | 13 +++++++------ arch/aarch64/spin.S | 8 ++++---- 4 files changed, 36 insertions(+), 21 deletions(-)arch/aarch64/boot.S index renamed from arch/aarch64/boot.S +0
-0a9264de..e4f5f3d 100644
arch/aarch64/boot.S +19
-8@@ -12,7 +12,7 @@ .section .init .globl _start - .globl jump_kernel + .globl jump_kernel _start: cpuid x0, x1@@ -22,20 +22,31 @@ _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 - 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@@ -114,7 +125,7 @@ _start: bl gic_secure_init - b start_el3 + b start_el_max err_invalid_id: b .@@ -141,7 +152,7 @@ jump_kernel: 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, x20arch/aarch64/boot.S jump_kernel: · line 166
Quoted 8 lines
arch/aarch64/boot.S +2
-2@@ -150,9 +161,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_KERNELThis looks both premature and wrong: The value of
SPSR_KERNELdoesn't change here, so doesn't need any change in this instruction. Plus: ldr without '=' requires an address, not a value, and this in fact already breaks compilation:arch/aarch64/boot.S:166: Error: immediate value must be a multiple of 4 at operand 2 -- `ldr w4,#((1<<8)|(1<<9)|(1<<7)|(1<<6)|(9<<0))'
Quoted 4 lines
So please remove this change, and also the changes in
cpu.hbelow, and introduce them only when they are actually needed.Apart from the rest is then really just renames.
Right, I made a mistake. I will fix this and move them into patch 5.
Thanks,
Jaxson
Quoted 100 lines
Cheers,
AndreQuoted 23 lines
arch/aarch64/boot.S +1
-1/* * If bit 0 of the kernel address is set, we're entering in AArch32@@ -168,5 +179,5 @@ jump_kernel: .data .align 3 -flag_no_el3: +flag_keep_el: .long 0(quoted diff) +0
-0
b/arch/aarch64/include/asm/cpu.hindex ccb5397..2b3a0a4 100644arch/aarch64/include/asm/cpu.h +1
-0@@ -11,6 +11,7 @@#define MPIDR_ID_BITS 0xff00ffffff +#define CURRENTEL_EL2 (2 << 2)#define CURRENTEL_EL3 (3 << 2)/* arch/aarch64/include/asm/cpu.h line 30
Quoted 6 lines
arch/aarch64/include/asm/cpu.h +1
-0@@ -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 */
arch/aarch64/include/asm/cpu.h line 46
Quoted 5 lines
arch/aarch64/include/asm/cpu.h +0
-0@@ -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)arch/aarch64/include/asm/cpu.h line 47
Quoted 1 line
arch/aarch64/include/asm/cpu.h +1
-0+#define SPSR_KERNEL_EL1 (SPSR_A | SPSR_D | SPSR_I | SPSR_F |
SPSR_EL1H)Quoted 57 lines
arch/aarch64/include/asm/cpu.h +0
-0#endif #ifndef __ASSEMBLY__arch/aarch64/psci.S index renamed from arch/aarch64/psci.S +0
-001ebe7d..ae02fd6 100644
arch/aarch64/psci.S +3
-4@@ -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 bootthe
- * 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.
*/arch/aarch64/psci.S +1
-1-start_no_el3: +start_keep_el: cpuid x0, x1 bl find_logical_id cbz x0, psci_first_spinarch/aarch64/spin.S index renamed from arch/aarch64/spin.S +0
-072603cf..533177c 100644
arch/aarch64/spin.S +2
-2@@ -11,11 +11,11 @@ .text - .globl start_no_el3 - .globl start_el3 + .globl start_keep_el + .globl start_el_max
Quoted 7 lines
arch/aarch64/spin.S line 21
Quoted 7 lines
arch/aarch64/spin.S +2
-2-start_el3: -start_no_el3: +start_el_max: +start_keep_el: cpuid x0, x1 bl find_logical_id
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 3/8 aarch64: Remove the redundant setup_stack
In reply to Jaxson HanSince we already have set up a stack above, there is no need to do it again.
--- arch/aarch64/boot.S | 1 - 1 file changed, 1 deletion(-)
arch/aarch64/boot.S +0 -1
@@ -39,7 +39,6 @@ _start: ldr x1, =flag_keep_el str w0, [x1] - bl setup_stack b start_keep_el /*
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [boot-wrapper PATCH v2 3/8] aarch64: Remove the redundant setup_stack
Quoted 2 lines · On Fri, 21 May 2021 18:48:02 +0800 Jaxson Han <[email protected]> wrote:
Since we already have set up a stack above, there is no need to do it again.
Indeed, in fact it's a bug: setup_stack expects the logical CPU ID in w0, and here we always call it with w0 being 1.
Quoted 1 line
Signed-off-by Jaxson Han <[email protected]>
Thanks!
Andre
Quoted 9 lines
--- arch/aarch64/boot.S | 1 - 1 file changed, 1 deletion(-)arch/aarch64/boot.S +0
-0
arch/aarch64/boot.S _start: · line 44
Quoted 7 lines
arch/aarch64/boot.S +0
-1@@ -39,7 +39,6 @@ _start: ldr x1, =flag_keep_el str w0, [x1] - bl setup_stack b start_keep_el /*
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 4/8 aarch64: Prepare for EL1 booting
In reply to Jaxson HanWhen booting from EL1, add a check and skip the init of sctlr_el2 in jump_kernel
--- arch/aarch64/boot.S | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
arch/aarch64/boot.S +5 -1
@@ -144,10 +144,14 @@ jump_kernel: ldr x0, =SCTLR_EL1_RESET msr sctlr_el1, x0 + mrs x0, CurrentEL + cmp x0, #CURRENTEL_EL2 + b.lt 1f + 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
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [boot-wrapper PATCH v2 4/8] aarch64: Prepare for EL1 booting
Quoted 4 lines · On Fri, 21 May 2021 18:48:03 +0800 Jaxson Han <[email protected]> wrote:
When booting from EL1, add a check and skip the init of
sctlr_el2injump_kernelSigned-off-by Jaxson Han <[email protected]>
Cheers,
Andre
Quoted 14 lines
--- arch/aarch64/boot.S | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)arch/aarch64/boot.S +2
-0@@ -144,10 +144,14 @@ jump_kernel: ldr x0, =SCTLR_EL1_RESET msr sctlr_el1, x0 + mrs x0, CurrentEL + cmp x0, #CURRENTEL_EL2
arch/aarch64/boot.S jump_kernel: · line 157
Quoted 10 lines
arch/aarch64/boot.S +3
-1+ b.lt 1f + 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
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 5/8 aarch64: Prepare for lower EL booting
In reply to Jaxson HanSave SPSR_KERNEL into spsr_to_elx during el3_init. The jump_kernel will load spsr_to_elx into spsr_el3.
This change will make it easier to control whether drop to lower EL before jumping to the kernel.
--- arch/aarch64/boot.S | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
arch/aarch64/boot.S +13 -2
@@ -118,7 +118,16 @@ el3_init: 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 + +el_max_init: ldr x0, =CNTFRQ msr cntfrq_el0, x0
@@ -166,7 +175,7 @@ jump_kernel: b.eq 1f br x19 // Keep current EL -1: ldr w4, #SPSR_KERNEL +1: ldr w4, spsr_to_elx /* * If bit 0 of the kernel address is set, we're entering in AArch32
@@ -184,3 +193,5 @@ jump_kernel: .align 3 flag_keep_el: .long 0 +spsr_to_elx: + .long 0
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [boot-wrapper PATCH v2 5/8] aarch64: Prepare for lower EL booting
On Fri, 21 May 2021 18:48:04 +0800
Jaxson Han <[email protected]> wrote:
Hi,
Quoted 5 lines
Save
SPSR_KERNELintospsr_to_elxduringel3_init. Thejump_kernelwill loadspsr_to_elxintospsr_el3.This change will make it easier to control whether drop to lower EL before jumping to the kernel.
Looks good, but this needs some adaption after fixing patch 2/8:
Quoted 29 lines
Signed-off-by Jaxson Han <[email protected]>--- arch/aarch64/boot.S | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)arch/aarch64/boot.S +10
-1@@ -118,7 +118,16 @@ el3_init: 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 + +el_max_init: ldr x0, =CNTFRQ msr cntfrq_el0, x0
arch/aarch64/boot.S jump_kernel: · line 178
Quoted 5 lines
arch/aarch64/boot.S +1
-1@@ -166,7 +175,7 @@ jump_kernel: b.eq 1f br x19 // Keep current EL -1: ldr w4, #SPSR_KERNEL +1: ldr w4, spsr_to_elx
This would be the place where you change the original "mov x4, #SPSR_KERNEL" line into this one here (and not in patch 2).
With that fixed:
Cheers,
Andre
arch/aarch64/boot.S jump_kernel: · line 197
Quoted 9 lines
arch/aarch64/boot.S +2
-0/* * If bit 0 of the kernel address is set, we're entering in AArch32@@ -184,3 +193,5 @@ jump_kernel: .align 3 flag_keep_el: .long 0 +spsr_to_elx: + .long 0
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 6/8 gic-v3: Prepare for gicv3 with EL2
In reply to Jaxson HanThis is a preparation for allowing boot-wrapper configuring the gicv3 with EL2.
When confiuring with EL2, since there is no ICC_CTLR_EL2, the ICC_CTLR_EL3 cannot be replaced with ICC_CTLR_EL2 simply. See [https://developer.arm.com/documentation/ihi0069/latest/].
As the caller, gic_secure_init expects the ICC_CTLR to be written, we change the function into gic_init_icc_ctlr(). In the GIC spec, the r/w bits in this register ([6:0]) either affect EL3 IRQ routing (not applicable since no EL3), non-secure IRQ handling (not applicable since only secure state in Armv8-R aarch64), or are aliased to ICC_CTLR_EL1 bits.
So, based on this, the new gic_init_icc_ctlr() would be:
When currentEL is EL3, init ICC_CTLR_EL3 as before.
When currentEL is not EL3, init ICC_CTLR_EL1 with ICC_CTLR_EL1_RESET.
--- arch/aarch32/include/asm/gic-v3.h | 7 ++++++ arch/aarch64/include/asm/gic-v3.h | 38 ++++++++++++++++++++++++++++--- gic-v3.c | 2 +- 3 files changed, 43 insertions(+), 4 deletions(-)
arch/aarch32/include/asm/gic-v3.h +7 -0
@@ -9,6 +9,8 @@#ifndef __ASM_AARCH32_GICV3_H#define __ASM_AARCH32_GICV3_H +#define ICC_CTLR_RESET (0UL) +static inline uint32_t gic_read_icc_sre (void ) {uint32_t val;
@@ -26,4 +28,9 @@ static inline void gic_write_icc_ctlr(uint32_t val) asm volatile ("mcr p15, 6, %0, c12, c12, 4" : : "r" (val)); } +static inline void gic_init_icc_ctlr () +{ +gic_write_icc_ctlr (ICC_CTLR_RESET ); +} +#endif
arch/aarch64/include/asm/gic-v3.h +35 -3
@@ -15,21 +15,53 @@#define ICC_CTLR_EL3 "S3_6_C12_C12_4"#define ICC_PMR_EL1 "S3_0_C4_C6_0" +#define ICC_CTLR_EL3_RESET (0UL) +#define ICC_CTLR_EL1_RESET (0UL) + +static inline uint32_t current_el (void ) +{ +uint32_t val; + + asmvolatile ("mrs %0, CurrentEL" :"=r" (val)); +return val; +} +static inline uint32_t gic_read_icc_sre (void ) {uint32_t val; - asmvolatile ("mrs %0, " ICC_SRE_EL3 :"=r" (val)); + +if (current_el () ==CURRENTEL_EL3 ) + asmvolatile ("mrs %0, " ICC_SRE_EL3 :"=r" (val)); +else + asmvolatile ("mrs %0, " ICC_SRE_EL2 :"=r" (val)); +return val; }static inline void gic_write_icc_sre (uint32_t val) { - asmvolatile ("msr " ICC_SRE_EL3 ", %0" : :"r" (val)); +if (current_el () ==CURRENTEL_EL3 ) + asmvolatile ("msr " ICC_SRE_EL3 ", %0" : :"r" (val)); +else + asmvolatile ("msr " ICC_SRE_EL2 ", %0" : :"r" (val)); } -static inline void gic_write_icc_ctlr (uint32_t val) +static inline void gic_write_icc_ctlr_el3 (uint32_t val) { asmvolatile ("msr " ICC_CTLR_EL3 ", %0" : :"r" (val)); } +static inline void gic_write_icc_ctlr_el1 (uint32_t val) +{ + asmvolatile ("msr " ICC_CTLR_EL1 ", %0" : :"r" (val)); +} + +static inline void gic_init_icc_ctlr () +{ +if (current_el () ==CURRENTEL_EL3 ) +gic_write_icc_ctlr_el3 (ICC_CTLR_EL3_RESET ); +else +gic_write_icc_ctlr_el1 (ICC_CTLR_EL1_RESET ); +} +#endif
gic-v3.c +1 -1
@@ -121,6 +121,6 @@ void gic_secure_init(void)gic_write_icc_sre (sre);isb (); -gic_write_icc_ctlr (0 ); +gic_init_icc_ctlr ();isb (); }
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [boot-wrapper PATCH v2 6/8] gic-v3: Prepare for gicv3 with EL2
On Fri, 21 May 2021 18:48:05 +0800
Jaxson Han <[email protected]> wrote:
Hi,
Quoted 7 lines
This is a preparation for allowing boot-wrapper configuring the gicv3 with EL2.
When confiuring with EL2, since there is no
ICC_CTLR_EL2, theICC_CTLR_EL3cannot be replaced withICC_CTLR_EL2simply. See [https://developer.arm.com/documentation/ihi0069/latest/].
Quoted 9 lines
As the caller,
gic_secure_initexpects theICC_CTLRto be written, we change the function intogic_init_icc_ctlr(). In the GIC spec, the r/w bits in this register ([6:0]) either affect EL3 IRQ routing (not applicable since no EL3), non-secure IRQ handling (not applicable since only secure state in Armv8-R aarch64), or are aliased toICC_CTLR_EL1bits.
So, based on this, the newgic_init_icc_ctlr()would be:
When currentEL is EL3, initICC_CTLR_EL3as before.
When currentEL is not EL3, initICC_CTLR_EL1withICC_CTLR_EL1_RESET.
Looks good, thanks!
Quoted 2 lines
Signed-off-by Jaxson Han <[email protected]>
Cheers,
Andre
Quoted 95 lines
--- arch/aarch32/include/asm/gic-v3.h | 7 ++++++ arch/aarch64/include/asm/gic-v3.h | 38 ++++++++++++++++++++++++++++--- gic-v3.c | 2 +- 3 files changed, 43 insertions(+), 4 deletions(-)arch/aarch32/include/asm/gic-v3.h +7
-0@@ -9,6 +9,8 @@#ifndef __ASM_AARCH32_GICV3_H#define __ASM_AARCH32_GICV3_H +#define ICC_CTLR_RESET (0UL) +static inline uint32_t gic_read_icc_sre (void ) {uint32_t val;@@ -26,4 +28,9 @@ static inline void gic_write_icc_ctlr(uint32_t val) asm volatile ("mcr p15, 6, %0, c12, c12, 4" : : "r" (val)); } +static inline void gic_init_icc_ctlr () +{ +gic_write_icc_ctlr (ICC_CTLR_RESET ); +} +#endif arch/aarch64/include/asm/gic-v3.h +35
-3@@ -15,21 +15,53 @@#define ICC_CTLR_EL3 "S3_6_C12_C12_4"#define ICC_PMR_EL1 "S3_0_C4_C6_0" +#define ICC_CTLR_EL3_RESET (0UL) +#define ICC_CTLR_EL1_RESET (0UL) + +static inline uint32_t current_el (void ) +{ +uint32_t val; + + asmvolatile ("mrs %0, CurrentEL" :"=r" (val)); +return val; +} +static inline uint32_t gic_read_icc_sre (void ) {uint32_t val; - asmvolatile ("mrs %0, " ICC_SRE_EL3 :"=r" (val)); + +if (current_el () ==CURRENTEL_EL3 ) + asmvolatile ("mrs %0, " ICC_SRE_EL3 :"=r" (val)); +else + asmvolatile ("mrs %0, " ICC_SRE_EL2 :"=r" (val)); +return val; }static inline void gic_write_icc_sre (uint32_t val) { - asmvolatile ("msr " ICC_SRE_EL3 ", %0" : :"r" (val)); +if (current_el () ==CURRENTEL_EL3 ) + asmvolatile ("msr " ICC_SRE_EL3 ", %0" : :"r" (val)); +else + asmvolatile ("msr " ICC_SRE_EL2 ", %0" : :"r" (val)); } -static inline void gic_write_icc_ctlr (uint32_t val) +static inline void gic_write_icc_ctlr_el3 (uint32_t val) { asmvolatile ("msr " ICC_CTLR_EL3 ", %0" : :"r" (val)); } +static inline void gic_write_icc_ctlr_el1 (uint32_t val) +{ + asmvolatile ("msr " ICC_CTLR_EL1 ", %0" : :"r" (val)); +} + +static inline void gic_init_icc_ctlr () +{ +if (current_el () ==CURRENTEL_EL3 ) +gic_write_icc_ctlr_el3 (ICC_CTLR_EL3_RESET ); +else +gic_write_icc_ctlr_el1 (ICC_CTLR_EL1_RESET ); +} +#endif gic-v3.c +0
-0
gic-v3.c void gic_secure_init(void) · line 126
Quoted 7 lines
gic-v3.c +1
-1@@ -121,6 +121,6 @@ void gic_secure_init(void)gic_write_icc_sre (sre);isb (); -gic_write_icc_ctlr (0 ); +gic_init_icc_ctlr ();isb (); }
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 7/8 aarch64: Prepare for booting with EL2
In reply to Jaxson HanPrepare for allowing boot-wrapper to be entered in EL2. Detect current EL and set the corresponding EL registers.
--- arch/aarch64/boot.S | 8 ++++++++ arch/aarch64/utils.S | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-)
arch/aarch64/boot.S +8 -0
@@ -183,10 +183,18 @@ jump_kernel: */ bfi x4, x19, #5, #1 + mrs x5, CurrentEL + cmp x5, #CURRENTEL_EL2 + b.eq 1f + msr elr_el3, x19 msr spsr_el3, x4 eret +1: msr elr_el2, x19 + msr spsr_el2, x4 + eret + .ltorg .data
arch/aarch64/utils.S +9 -1
@@ -37,10 +37,18 @@ find_logical_id: ret /* - * Setup EL3 vectors + * Setup EL3/EL2 vectors * x0: vector address */ setup_vector: + mrs x1, CurrentEL + cmp x1, #CURRENTEL_EL2 + b.eq 1f + msr VBAR_EL3, x0 isb ret + +1: msr VBAR_EL2, x0 + isb + ret
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [boot-wrapper PATCH v2 7/8] aarch64: Prepare for booting with EL2
Quoted 4 lines · On Fri, 21 May 2021 18:48:06 +0800 Jaxson Han <[email protected]> wrote:
Prepare for allowing boot-wrapper to be entered in EL2. Detect current EL and set the corresponding EL registers.
Signed-off-by Jaxson Han <[email protected]>
Cheers,
Andre
Quoted 42 lines
--- arch/aarch64/boot.S | 8 ++++++++ arch/aarch64/utils.S | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-)arch/aarch64/boot.S +8
-0@@ -183,10 +183,18 @@ jump_kernel: */ bfi x4, x19, #5, #1 + mrs x5, CurrentEL + cmp x5, #CURRENTEL_EL2 + b.eq 1f + msr elr_el3, x19 msr spsr_el3, x4 eret +1: msr elr_el2, x19 + msr spsr_el2, x4 + eret + .ltorg .dataarch/aarch64/utils.S +2
-1@@ -37,10 +37,18 @@ find_logical_id: ret /* - * Setup EL3 vectors + * Setup EL3/EL2 vectors * x0: vector address */ setup_vector: + mrs x1, CurrentEL
arch/aarch64/utils.S find_logical_id: · line 54
Quoted 10 lines
arch/aarch64/utils.S +7
-0+ cmp x1, #CURRENTEL_EL2 + b.eq 1f + msr VBAR_EL3, x0 isb ret + +1: msr VBAR_EL2, x0 + isb + ret
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 8/8 aarch64: Introduce EL2 boot code for Armv8-R AArch64
In reply to Jaxson HanThe Armv8-R AArch64 profile does not support the EL3 exception level. The Armv8-R AArch64 profile allows for an (optional) VMSAv8-64 MMU at EL1, which allows to run off-the-shelf Linux. However EL2 only supports a PMSA, which is not supported by Linux, so we need to drop into EL1 before entering the kernel.
We add a new err_invalid_arch symbol as a dead loop. If we detect the current Armv8-R aarch64 only supports with PMSA, meaning we cannot boot Linux anymore, then we jump to err_invalid_arch.
During Armv8-R aarch64 init, to make sure nothing unexpected traps into EL2, we auto-detect and config FIEN and EnSCXT in HCR_EL2.
The boot sequence is:
If CurrentEL == EL3, then goto EL3 initialisation and drop to lower EL
before entering the kernel.
If CurrentEL == EL2 && id_aa64mmfr0_el1.MSA == 0xf (Armv8-R aarch64),
if id_aa64mmfr0_el1.MSA_frac == 0x2,
then goto Armv8-R AArch64 initialisation and drop to EL1 before entering the kernel.
else, which means VMSA unsupported and cannot boot Linux,
goto err_invalid_arch (dead loop).
Else, no initialisation and keep the current EL before entering the
kernel.
--- arch/aarch64/boot.S | 87 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-)
arch/aarch64/boot.S +85 -2
@@ -25,16 +25,24 @@ _start: * Boot sequence * If CurrentEL == EL3, then goto EL3 initialisation and drop to * lower EL before entering the kernel. + * If CurrentEL == EL2 && id_aa64mmfr0_el1.MSA == 0xf, then + * If id_aa64mmfr0_el1.MSA_frac == 0x2, then goto + * Armv8-R AArch64 initialisation and drop to EL1 before + * entering the kernel. + * Else, which means VMSA unsupported and cannot boot Linux, + * goto err_invalid_arch (dead loop). * Else, no initialisation and keep the current EL before * entering the kernel. */ mrs x0, CurrentEL - cmp x0, #CURRENTEL_EL3 - beq el3_init + cmp x0, #CURRENTEL_EL2 + bgt el3_init + beq el2_init /* * We stay in the current EL for entering the kernel */ +keep_el: mov w0, #1 ldr x1, =flag_keep_el str w0, [x1]
@@ -127,6 +135,80 @@ el3_init: str w0, [x1] b el_max_init + /* + * EL2 Armv8-R AArch64 initialisation + */ +el2_init: + /* Detect Armv8-R AArch64 */ + mrs x1, id_aa64mmfr0_el1 + /* + * Check MSA, bits [51:48]: + * 0xf means Armv8-R AArch64. + * If not 0xf, goto keep_el. + */ + ubfx x0, x1, #48, #4 // MSA + cmp x0, 0xf + bne keep_el + /* + * Check MSA_frac, bits [55:52]: + * 0x2 means EL1&0 translation regime also supports VMSAv8-64. + */ + ubfx x0, x1, #52, #4 // MSA_frac + cmp x0, 0x2 + /* If not 0x2, no VMSA, so cannot boot Linux and dead loop. */ + bne err_invalid_arch + + mrs x0, midr_el1 + msr vpidr_el2, x0 + + mrs x0, mpidr_el1 + msr vmpidr_el2, x0 + + mov x0, #(1 << 31) // VTCR_MSA: VMSAv8-64 support + msr vtcr_el2, x0 + + /* Init HCR_EL2 */ + mov x0, #(1 << 31) // RES1 + + mrs x1, id_aa64pfr0_el1 + ubfx x2, x1, #56, 4 + cmp x2, 0x2 + bne 1f + /* + * Disable trap when accessing SCTXNUM_EL0 or SCTXNUM_EL1 + * if FEAT_CSV2. + */ + orr x0, x0, #(1 << 53) // EnSCXT + +1: ubfx x2, x1, #28, 4 + cmp x2, 0x2 + bne 1f + /* Disable trap when accessing ERXPFGCDN_EL1 if FEAT_RASv1p1. */ + orr x0, x0, #(1 << 47) // FIEN + + /* Enable pointer authentication if present */ +1: mrs x1, id_aa64isar1_el1 + /* + * If ID_AA64ISAR1_EL1.{GPI, GPA, API, APA} == {0000, 0000, 0000, 0000} + * then HCR_EL2.APK and HCR_EL2.API are RES 0. + * Else + * set HCR_EL2.APK and HCR_EL2.API. + */ + ldr x2, =(((0xff) << 24) | (0xff << 4)) + and x1, x1, x2 + cbz x1, 1f + + orr x0, x0, #(1 << 40) // APK + orr x0, x0, #(1 << 41) // API + +1: msr hcr_el2, x0 + isb + + mov w0, #SPSR_KERNEL_EL1 + ldr x1, =spsr_to_elx + str w0, [x1] + // fall through + el_max_init: ldr x0, =CNTFRQ msr cntfrq_el0, x0
@@ -136,6 +218,7 @@ el_max_init: b start_el_max err_invalid_id: +err_invalid_arch: b . /*
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [boot-wrapper PATCH v2 8/8] aarch64: Introduce EL2 boot code for Armv8-R AArch64
On Fri, 21 May 2021 18:48:07 +0800
Jaxson Han <[email protected]> wrote:
Hi,
Quoted 13 lines
The Armv8-R AArch64 profile does not support the EL3 exception level. The Armv8-R AArch64 profile allows for an (optional) VMSAv8-64 MMU at EL1, which allows to run off-the-shelf Linux. However EL2 only supports a PMSA, which is not supported by Linux, so we need to drop into EL1 before entering the kernel.
We add a new
err_invalid_archsymbol as a dead loop. If we detect the current Armv8-R aarch64 only supports with PMSA, meaning we cannot boot Linux anymore, then we jump toerr_invalid_arch.During Armv8-R aarch64 init, to make sure nothing unexpected traps into EL2, we auto-detect and config FIEN and EnSCXT in
HCR_EL2.
Quoted 11 lines
The boot sequence is:
If CurrentEL == EL3, then goto EL3 initialisation and drop to lower EL
before entering the kernel.
If CurrentEL == EL2 && id_aa64mmfr0_el1.MSA ==0xf(Armv8-R aarch64),
if id_aa64mmfr0_el1.MSA_frac ==0x2,
then goto Armv8-R AArch64 initialisation and drop to EL1 before entering the kernel.
else, which means VMSA unsupported and cannot boot Linux,
gotoerr_invalid_arch(dead loop).
Else, no initialisation and keep the current EL before entering the
kernel.
This looks good in general, thanks for the commit message and the comments inline. Some smaller things below:
Quoted 41 lines
Signed-off-by Jaxson Han <[email protected]>--- arch/aarch64/boot.S | 87 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-)arch/aarch64/boot.S +10
-2@@ -25,16 +25,24 @@ _start: * Boot sequence * If CurrentEL == EL3, then goto EL3 initialisation and drop to * lower EL before entering the kernel. + * If CurrentEL == EL2 && id_aa64mmfr0_el1.MSA == 0xf, then + * If id_aa64mmfr0_el1.MSA_frac == 0x2, then goto + * Armv8-R AArch64 initialisation and drop to EL1 before + * entering the kernel. + * Else, which means VMSA unsupported and cannot boot Linux, + * goto err_invalid_arch (dead loop). * Else, no initialisation and keep the current EL before * entering the kernel. */ mrs x0, CurrentEL - cmp x0, #CURRENTEL_EL3 - beq el3_init + cmp x0, #CURRENTEL_EL2 + bgt el3_init + beq el2_init /* * We stay in the current EL for entering the kernel */ +keep_el: mov w0, #1 ldr x1, =flag_keep_el str w0, [x1]@@ -127,6 +135,80 @@ el3_init: str w0, [x1] b el_max_init
arch/aarch64/boot.S el3_init: · line 147
Quoted 10 lines
arch/aarch64/boot.S +10
-0+ /* + * EL2 Armv8-R AArch64 initialisation + */ +el2_init: + /* Detect Armv8-R AArch64 */ + mrs x1, id_aa64mmfr0_el1 + /* + * Check MSA, bits [51:48]: + * 0xf means Armv8-R AArch64. + * If not 0xf, goto keep_el.
Can you please change this last line to:
"If not 0xf, proceed in ARMv8-A EL2."
arch/aarch64/boot.S el3_init: · line 159
Quoted 12 lines
arch/aarch64/boot.S +12
-0+ */ + ubfx x0, x1, #48, #4 // MSA + cmp x0, 0xf + bne keep_el + /* + * Check MSA_frac, bits [55:52]: + * 0x2 means EL1&0 translation regime also supports VMSAv8-64. + */ + ubfx x0, x1, #52, #4 // MSA_frac + cmp x0, 0x2 + /* If not 0x2, no VMSA, so cannot boot Linux and dead loop. */ + bne err_invalid_arch
The architecture guarantees that those CPUID fields never lose features when the value in a field increases. So there might be some 0x3 feature addition in the future, which wouldn't be covered right now. So can you please change this branch to "b.lt" instead?
arch/aarch64/boot.S el3_init: · line 171
Quoted 12 lines
arch/aarch64/boot.S +12
-0+ + mrs x0, midr_el1 + msr vpidr_el2, x0 + + mrs x0, mpidr_el1 + msr vmpidr_el2, x0 + + mov x0, #(1 << 31) // VTCR_MSA: VMSAv8-64 support + msr vtcr_el2, x0 + + /* Init HCR_EL2 */ + mov x0, #(1 << 31) // RES1
Please add to the comment that it's RES1 in ARMv8-R64 only.
arch/aarch64/boot.S el3_init: · line 174
Quoted 3 lines
arch/aarch64/boot.S +3
-0+ + mrs x1, id_aa64pfr0_el1 + ubfx x2, x1, #56, 4
Can you please add the CSV2 name of the field as a comment here?
arch/aarch64/boot.S el3_init: · line 176
Quoted 2 lines
arch/aarch64/boot.S +2
-0+ cmp x2, 0x2 + bne 1f
To stay compatible with future additions to the CSV2 field, please use b.lt here.
arch/aarch64/boot.S el3_init: · line 185
Quoted 9 lines
arch/aarch64/boot.S +9
-0+ /* + * Disable trap when accessing SCTXNUM_EL0 or SCTXNUM_EL1 + * if FEAT_CSV2. + */ + orr x0, x0, #(1 << 53) // EnSCXT + +1: ubfx x2, x1, #28, 4 + cmp x2, 0x2 + bne 1f
As above: b.lt.
Rest looks fine to me, compared the bits and values to the manuals.
Thanks,
Andre
Quoted 30 lines
arch/aarch64/boot.S +26
-0+ /* Disable trap when accessing ERXPFGCDN_EL1 if FEAT_RASv1p1. */ + orr x0, x0, #(1 << 47) // FIEN + + /* Enable pointer authentication if present */ +1: mrs x1, id_aa64isar1_el1 + /* + * If ID_AA64ISAR1_EL1.{GPI, GPA, API, APA} == {0000, 0000, 0000, 0000} + * then HCR_EL2.APK and HCR_EL2.API are RES 0. + * Else + * set HCR_EL2.APK and HCR_EL2.API. + */ + ldr x2, =(((0xff) << 24) | (0xff << 4)) + and x1, x1, x2 + cbz x1, 1f + + orr x0, x0, #(1 << 40) // APK + orr x0, x0, #(1 << 41) // API + +1: msr hcr_el2, x0 + isb + + mov w0, #SPSR_KERNEL_EL1 + ldr x1, =spsr_to_elx + str w0, [x1] + // fall through + el_max_init: ldr x0, =CNTFRQ msr cntfrq_el0, x0
arch/aarch64/boot.S el_max_init: · line 224
Quoted 7 lines
arch/aarch64/boot.S +1
-0@@ -136,6 +218,7 @@ el_max_init: b start_el_max err_invalid_id: +err_invalid_arch: b . /*
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
RE: [boot-wrapper PATCH v2 8/8] aarch64: Introduce EL2 boot code for Armv8-R AArch64
Hi Andre,
Quoted 107 lines
-----Original Message-----
From: Andre Przywara <[email protected]>
Sent: Monday, May 24, 2021 6:20 PM
To: Jaxson Han <[email protected]>
Cc: Mark Rutland <[email protected]>; linux-arm- [email protected]; Wei Chen <[email protected]>
Subject: Re: [boot-wrapper PATCH v2 8/8] aarch64: Introduce EL2 boot code for Armv8-R AArch64On Fri, 21 May 2021 18:48:07 +0800
Jaxson Han <[email protected]> wrote:Hi,
Quoted 13 lines
The Armv8-R AArch64 profile does not support the EL3 exception level. The Armv8-R AArch64 profile allows for an (optional) VMSAv8-64 MMU at EL1, which allows to run off-the-shelf Linux. However EL2 only supports a PMSA, which is not supported by Linux, so we need to drop into EL1 before entering the kernel.
We add a new
err_invalid_archsymbol as a dead loop. If we detect the current Armv8-R aarch64 only supports with PMSA, meaning we cannot boot Linux anymore, then we jump toerr_invalid_arch.During Armv8-R aarch64 init, to make sure nothing unexpected traps into EL2, we auto-detect and config FIEN and EnSCXT in
HCR_EL2.Quoted 11 lines
The boot sequence is:
If CurrentEL == EL3, then goto EL3 initialisation and drop to lower EL
before entering the kernel.
If CurrentEL == EL2 && id_aa64mmfr0_el1.MSA ==0xf(Armv8-R aarch64),
if id_aa64mmfr0_el1.MSA_frac ==0x2,
then goto Armv8-R AArch64 initialisation and drop to EL1 before entering the kernel.
else, which means VMSA unsupported and cannot boot Linux,
gotoerr_invalid_arch(dead loop).
Else, no initialisation and keep the current EL before entering the
kernel.This looks good in general, thanks for the commit message and the comments inline. Some smaller things below:
Quoted 42 lines
Signed-off-by Jaxson Han <[email protected]>--- arch/aarch64/boot.S | 87 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-)arch/aarch64/boot.S index renamed from arch/aarch64/boot.S +0
-014fd9cf..0339e19 100644
arch/aarch64/boot.S +10
-2@@ -25,16 +25,24 @@ _start: * Boot sequence * If CurrentEL == EL3, then goto EL3 initialisation and drop to * lower EL before entering the kernel. + * If CurrentEL == EL2 && id_aa64mmfr0_el1.MSA == 0xf, then + * If id_aa64mmfr0_el1.MSA_frac == 0x2, then goto + * Armv8-R AArch64 initialisation and drop to EL1 before + * entering the kernel. + * Else, which means VMSA unsupported and cannot boot Linux, + * goto err_invalid_arch (dead loop). * Else, no initialisation and keep the current EL before * entering the kernel. */ mrs x0, CurrentEL - cmp x0, #CURRENTEL_EL3 - beq el3_init + cmp x0, #CURRENTEL_EL2 + bgt el3_init + beq el2_init /* * We stay in the current EL for entering the kernel */ +keep_el: mov w0, #1 ldr x1, =flag_keep_el str w0, [x1]@@ -127,6 +135,80 @@ el3_init: str w0, [x1] b el_max_initarch/aarch64/boot.S el3_init: · line 147
Quoted 10 lines
arch/aarch64/boot.S +10
-0+ /* + * EL2 Armv8-R AArch64 initialisation + */ +el2_init: + /* Detect Armv8-R AArch64 */ + mrs x1, id_aa64mmfr0_el1 + /* + * Check MSA, bits [51:48]: + * 0xf means Armv8-R AArch64. + * If not 0xf, goto keep_el.Can you please change this last line to:
"If not0xf, proceed in ARMv8-A EL2."Quoted 9 lines
arch/aarch64/boot.S +9
-0+ */ + ubfx x0, x1, #48, #4 // MSA + cmp x0, 0xf + bne keep_el + /* + * Check MSA_frac, bits [55:52]: + * 0x2 means EL1&0 translation regime also supports VMSAv8-64. + */ + ubfx x0, x1, #52, #4 // MSA_frac
Quoted 8 lines
arch/aarch64/boot.S el3_init: · line 159
Quoted 3 lines
arch/aarch64/boot.S +3
-0+ cmp x0, 0x2 + /* If not 0x2, no VMSA, so cannot boot Linux and dead loop. */ + bne err_invalid_archThe architecture guarantees that those CPUID fields never lose features when the value in a field increases. So there might be some
0x3feature addition in the future, which wouldn't be covered right now. So can you please change this branch to "b.lt" instead?
Yes, I will change it.
Quoted 10 lines
arch/aarch64/boot.S el3_init:
Quoted 9 lines
arch/aarch64/boot.S +8
-0+ + mrs x0, midr_el1 + msr vpidr_el2, x0 + + mrs x0, mpidr_el1 + msr vmpidr_el2, x0 + + mov x0, #(1 << 31) // VTCR_MSA: VMSAv8-64support
Quoted 6 lines
arch/aarch64/boot.S el3_init: · line 171
Quoted 4 lines
arch/aarch64/boot.S +4
-0+ msr vtcr_el2, x0 + + /* Init HCR_EL2 */ + mov x0, #(1 << 31) // RES1Please add to the comment that it's RES1 in ARMv8-R64 only.
Yes, no problem.
Quoted 6 lines
arch/aarch64/boot.S el3_init: · line 174
Quoted 4 lines
arch/aarch64/boot.S +3
-0+ + mrs x1, id_aa64pfr0_el1 + ubfx x2, x1, #56, 4Can you please add the CSV2 name of the field as a comment here?
Yes I will
Quoted 6 lines
arch/aarch64/boot.S el3_init: · line 176
Quoted 3 lines
arch/aarch64/boot.S +2
-0+ cmp x2, 0x2 + bne 1fTo stay compatible with future additions to the CSV2 field, please use b.lt here.
No problem
Quoted 12 lines
arch/aarch64/boot.S el3_init: · line 185
Quoted 10 lines
arch/aarch64/boot.S +9
-0+ /* + * Disable trap when accessing SCTXNUM_EL0 or SCTXNUM_EL1 + * if FEAT_CSV2. + */ + orr x0, x0, #(1 << 53) // EnSCXT + +1: ubfx x2, x1, #28, 4 + cmp x2, 0x2 + bne 1fAs above: b.lt.
Yes I will
Thanks,
Jaxson
Quoted 39 lines
Rest looks fine to me, compared the bits and values to the manuals.
Thanks,
Andrearch/aarch64/boot.S el3_init:
Quoted 7 lines
arch/aarch64/boot.S +7
-0+ /* Disable trap when accessing ERXPFGCDN_EL1 if FEAT_RASv1p1. */ + orr x0, x0, #(1 << 47) // FIEN + + /* Enable pointer authentication if present */ +1: mrs x1, id_aa64isar1_el1 + /* + * If ID_AA64ISAR1_EL1.{GPI, GPA, API, APA} == {0000, 0000, 0000,0000}
Quoted 25 lines
arch/aarch64/boot.S +19
-0+ * then HCR_EL2.APK and HCR_EL2.API are RES 0. + * Else + * set HCR_EL2.APK and HCR_EL2.API. + */ + ldr x2, =(((0xff) << 24) | (0xff << 4)) + and x1, x1, x2 + cbz x1, 1f + + orr x0, x0, #(1 << 40) // APK + orr x0, x0, #(1 << 41) // API + +1: msr hcr_el2, x0 + isb + + mov w0, #SPSR_KERNEL_EL1 + ldr x1, =spsr_to_elx + str w0, [x1] + // fall through + el_max_init: ldr x0, =CNTFRQ msr cntfrq_el0, x0@@ -136,6 +218,7 @@ el_max_init: b start_el_max
Quoted 5 lines
arch/aarch64/boot.S el_max_init: · line 224
Quoted 5 lines
arch/aarch64/boot.S +1
-0err_invalid_id: +err_invalid_arch: b . /*
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel