Enable new Arm architecture features
cover Enable new Arm architecture features
Some new Arm architecture features introduce new system registers, access to which is guarded by SCR_EL3 bits. Since the boot-wrapper has no interest in trapping those accesses or deny them, just unconditionally enable them during initialisation.
Please have a look!
Cheers,
Andre
Andre Przywara (4):
aarch64: do not trap MPAM register accesses
aarch64: enable access to FEAT_AIE and FEAT_PFAR features
aarch64: enable access to HACDBS and HDBSS system registers
aarch64: enable access to FEAT_RASv1p1 system registers
arch/aarch64/include/asm/cpu.h | 15 +++++++++++++++ arch/aarch64/init.c | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+)
Signature · 1 line
2.25.1
PATCH 1/4 aarch64: do not trap MPAM register accesses
The architectural MPAM system registers in lower ELs are controlled by an EL3 control bit. To allow access to registers like MPAM2_EL2 or MPAM_EL1, clear the TRAPLOWER bit in the MPAM3_EL3 system register, to avoid an unhandled trap into the boot-wrapper code.
--- arch/aarch64/include/asm/cpu.h | 4 ++++ arch/aarch64/init.c | 3 +++ 2 files changed, 7 insertions(+)
arch/aarch64/include/asm/cpu.h +4 -0
@@ -29,6 +29,9 @@#define HFGWTR2_EL2 s3_4_c3_c1_3#define HFGITR2_EL2 s3_4_c3_c1_7 +#define MPAM3_EL3 s3_6_c10_c5_0 +#define MPAM3_EL3_TRAPLOWER BIT(62) +/* * RES1 bit definitions definitions as of ARM DDI 0487G.b *
@@ -120,6 +123,7 @@#define ID_AA64PFR0_EL1_RAS BITS(31, 28)#define ID_AA64PFR0_EL1_SVE BITS(35, 32) +#define ID_AA64PFR0_EL1_MPAM BITS(43, 40)#define ID_AA64PFR0_EL1_CSV2 BITS(59, 56)#define ID_AA64PFR1_EL1_MTE BITS(11, 8)
arch/aarch64/init.c +3 -0
@@ -198,6 +198,9 @@ static void cpu_init_el3(void)msr (SMCR_EL3 , smcr); } + +if (mrs_field (ID_AA64PFR0_EL1 ,MPAM )) +msr (MPAM3_EL3 ,mrs (MPAM3_EL3 ) & ~MPAM3_EL3_TRAPLOWER ); }void cpu_init_el2_armv8r (void )
Signature · 1 line
2.25.1
Re: [boot-wrapper PATCH 1/4] aarch64: do not trap MPAM register accesses
Hi Andre,
Quoted 38 lines · Andre Przywara
The architectural MPAM system registers in lower ELs are controlled by an EL3 control bit. To allow access to registers like
MPAM2_EL2orMPAM_EL1, clear the TRAPLOWER bit in theMPAM3_EL3system register, to avoid an unhandled trap into the boot-wrapper code.Signed-off-by Andre Przywara <[email protected]>--- arch/aarch64/include/asm/cpu.h | 4 ++++ arch/aarch64/init.c | 3 +++ 2 files changed, 7 insertions(+)arch/aarch64/include/asm/cpu.h +4
-0@@ -29,6 +29,9 @@#define HFGWTR2_EL2 s3_4_c3_c1_3#define HFGITR2_EL2 s3_4_c3_c1_7 +#define MPAM3_EL3 s3_6_c10_c5_0 +#define MPAM3_EL3_TRAPLOWER BIT(62) +/* * RES1 bit definitions definitions as of ARM DDI 0487G.b * @@ -120,6 +123,7 @@#define ID_AA64PFR0_EL1_RAS BITS(31, 28)#define ID_AA64PFR0_EL1_SVE BITS(35, 32) +#define ID_AA64PFR0_EL1_MPAM BITS(43, 40)#define ID_AA64PFR0_EL1_CSV2 BITS(59, 56)#define ID_AA64PFR1_EL1_MTE BITS(11, 8)arch/aarch64/init.c +0
-0
arch/aarch64/init.c static void cpu_init_el3(void) · line 204
Quoted 7 lines
arch/aarch64/init.c +3
-0@@ -198,6 +198,9 @@ static void cpu_init_el3(void)msr (SMCR_EL3 , smcr); } + +if (mrs_field (ID_AA64PFR0_EL1 ,MPAM )) +msr (MPAM3_EL3 ,mrs (MPAM3_EL3 ) & ~MPAM3_EL3_TRAPLOWER ); }
This enables register access to the MPAM-related CPU regs for lower ELs, but doesn't fully enable MPAM.
There is a global switch to turn MPAM on (MPAMn_ELn.MPAMEN, where ELn is the highest implemented EL). It defaults to off, and lower ELs can't turn it on. Because it's off by default, most other CPU state relating to MPAM is not in a defined state out of reset.
...So, I suspect we may need more steps here if we want MPAM to be usable.
The platform should initialise resource controls in the memory system for PARTID 0 in a sensible way without software having to do anything, but we have to make sure that EL3 uses this PARTID and not something random, and make lower ELs start out using it. So, probably:
MPAM3_EL3.{PARTID,PMG}_{I,D} should be initialised to 0. MPAM2_EL2.{PARTID,PMG}_{I,D} should be initialised to 0.
(Do we ever run the payload directly at EL1? Hopefully not, but tf so then we would need to initialise the IDs in MPAM1_EL1 also, and initialise trap controls in MPAM2_EL2 and MPAMHCR_EL2 and make sure that PARTID virtualisation controls are off in MPAMHCR_EL2.)
Many other controls require platform-specific knowledge in order to know how to initialise them sensibly, even though the architecture resets them to junk.
Since the bootwrapper is not attempting to define a security boundary, it is probably reasonable to hand everything over to Non-secure, so far as possible, so in MPAM3_EL3:
SDEFLT should probably be 0. (*)
FORCE_NS should probably be 0. (*)
ALTSP_HEN should probably be 1. (*; James might have a view.) ALTSP_EL3 should probably by 0, or left untouched (*)(+)
(*) Feature-dependent -- in some cases the features that they depend on have already been declared obsolete, but hopefully we can trust the architects not to recycle the bits for other purposes. I'm not sure what the usual policy is on that.
(+) Architectural reset is IMP DEF. So maybe it's something sane and appropriate for the platform but then again, maybe not.
Then:
ISB
and
Initialise MPAM3_EL3.MPAMEN to 1.
(This is a global control. Lower ELs can't turn it on for themselves, but without it, IDs that they specify in MPAMx_ELx are ignored and squashed to 0.)
The architecture says that MCSs out in the system will be initialised with a sensible resource control configuration for PARTID 0. We probably just have to trust that, otherwise we're in a world of pain.
I can't promise that I haven't missed some stuff, here!
Cheers
---Dave
PATCH 2/4 aarch64: enable access to FEAT_AIE and FEAT_PFAR features
In reply to Andre PrzywaraARMv8.9 introduced FEAT_AIE and FEAT_PFAR, both of which introduce system registers accessible from EL1 and EL2. Access to them is guarded by SCR_EL3 control bits AIEn and PFAREn.
Since boot-wrapper has no business in limiting those features or trapping access to those register, set the no-trap bits in SCR_EL3, if we detect the respective CPU feature bits.
--- arch/aarch64/include/asm/cpu.h | 4 ++++ arch/aarch64/init.c | 6 ++++++ 2 files changed, 10 insertions(+)
arch/aarch64/include/asm/cpu.h +4 -0
@@ -78,8 +78,10 @@#define SCR_EL3_TCR2EN BIT(43)#define SCR_EL3_SCTLR2En BIT(44)#define SCR_EL3_PIEN BIT(45) +#define SCR_EL3_AIEn BIT(46)#define SCR_EL3_D128En BIT(47)#define SCR_EL3_EnFPM BIT(50) +#define SCR_EL3_PFAREn BIT(53)#define SCR_EL3_FGTEN2 BIT(59)#define VTCR_EL2_MSA BIT(31)
@@ -119,6 +121,7 @@#define ID_AA64MMFR3_EL1_S2PIE BITS(15, 12)#define ID_AA64MMFR3_EL1_S1POE BITS(19, 16)#define ID_AA64MMFR3_EL1_S2POE BITS(23, 20) +#define ID_AA64MMFR3_EL1_AIE BITS(27, 24)#define ID_AA64MMFR3_EL1_D128 BITS(35, 32)#define ID_AA64PFR0_EL1_RAS BITS(31, 28)
@@ -130,6 +133,7 @@#define ID_AA64PFR1_EL1_SME BITS(27, 24)#define ID_AA64PFR1_EL1_CSV2_frac BITS(35, 32)#define ID_AA64PFR1_EL1_THE BITS(51, 48) +#define ID_AA64PFR1_EL1_PFAR BITS(63, 60)#define ID_AA64PFR2_EL1 s3_0_c0_c4_2#define ID_AA64PFR2_EL1_FPMR BITS(35, 32)
arch/aarch64/init.c +6 -0
@@ -136,6 +136,12 @@ static void cpu_init_el3(void)if (mrs_field (ID_AA64PFR2_EL1 ,FPMR )) scr |= SCR_EL3_EnFPM; +if (mrs_field (ID_AA64MMFR3_EL1 ,AIE )) + scr |= SCR_EL3_AIEn; + +if (mrs_field (ID_AA64PFR1_EL1 ,PFAR )) + scr |= SCR_EL3_PFAREn; +msr (SCR_EL3 , scr);msr (CPTR_EL3 , cptr);
Signature · 1 line
2.25.1
PATCH 3/4 aarch64: enable access to HACDBS and HDBSS system registers
In reply to Andre PrzywaraARMv9.5 introduced FEAT_HAFDBS and FEAT_HACBDS, both of which introduce system registers accessible from EL1 and EL2. Access to them is guarded by SCR_EL3 control bits HDBSSEn and HACDBSEn.
Since boot-wrapper has no business in limiting those features or trapping access to those register, set the no-trap bits in SCR_EL3, if we detect the respective CPU feature bits.
--- arch/aarch64/include/asm/cpu.h | 6 ++++++ arch/aarch64/init.c | 6 ++++++ 2 files changed, 12 insertions(+)
arch/aarch64/include/asm/cpu.h +6 -0
@@ -83,6 +83,8 @@#define SCR_EL3_EnFPM BIT(50)#define SCR_EL3_PFAREn BIT(53)#define SCR_EL3_FGTEN2 BIT(59) +#define SCR_EL3_HDBSSEn BIT(60) +#define SCR_EL3_HACDBSEn BIT(61)#define VTCR_EL2_MSA BIT(31)
@@ -113,6 +115,7 @@#define ID_AA64MMFR0_EL1_FGT BITS(59, 56)#define ID_AA64MMFR0_EL1_ECV BITS(63, 60) +#define ID_AA64MMFR1_EL1_HAFDBS BITS(3, 0)#define ID_AA64MMFR1_EL1_HCX BITS(43, 40)#define ID_AA64MMFR3_EL1_TCRX BITS(3, 0)
@@ -124,6 +127,9 @@#define ID_AA64MMFR3_EL1_AIE BITS(27, 24)#define ID_AA64MMFR3_EL1_D128 BITS(35, 32) +#define ID_AA64MMFR4_EL1 s3_0_c0_c7_4 +#define ID_AA64MMFR4_EL1_HACDBS BITS(15, 12) +#define ID_AA64PFR0_EL1_RAS BITS(31, 28)#define ID_AA64PFR0_EL1_SVE BITS(35, 32)#define ID_AA64PFR0_EL1_MPAM BITS(43, 40)
arch/aarch64/init.c +6 -0
@@ -142,6 +142,12 @@ static void cpu_init_el3(void)if (mrs_field (ID_AA64PFR1_EL1 ,PFAR )) scr |= SCR_EL3_PFAREn; +if (mrs_field (ID_AA64MMFR4_EL1 ,HACDBS )) + scr |= SCR_EL3_HACDBSEn; + +if (mrs_field (ID_AA64MMFR1_EL1 ,HAFDBS ) >=4 ) + scr |= SCR_EL3_HDBSSEn; +msr (SCR_EL3 , scr);msr (CPTR_EL3 , cptr);
Signature · 1 line
2.25.1
PATCH 4/4 aarch64: enable access to FEAT_RASv1p1 system registers
In reply to Andre PrzywaraFEAT_RASv1p1 introduces RAS error injection system registers, access to which is protected by an SCR_EL3 bit.
Since boot-wrapper has no business in limiting those features or trapping access to those register, set the no-trap bit in SCR_EL3, if we detect the respective CPU feature bit.
--- arch/aarch64/include/asm/cpu.h | 1 + arch/aarch64/init.c | 3 +++ 2 files changed, 4 insertions(+)
arch/aarch64/include/asm/cpu.h +1 -0
@@ -68,6 +68,7 @@#define SCR_EL3_RW BIT(10)#define SCR_EL3_APK BIT(16)#define SCR_EL3_API BIT(17) +#define SCR_EL3_FIEN BIT(21)#define SCR_EL3_ATA BIT(26)#define SCR_EL3_FGTEN BIT(27)#define SCR_EL3_ECVEN BIT(28)
arch/aarch64/init.c +3 -0
@@ -133,6 +133,9 @@ static void cpu_init_el3(void)if (mrs_field (ID_AA64PFR1_EL1 ,THE )) scr |= SCR_EL3_RCWMASKEn; +if (mrs_field (ID_AA64PFR0_EL1 ,RAS ) >=0b0010 ) + scr |=SCR_EL3_FIEN ; +if (mrs_field (ID_AA64PFR2_EL1 ,FPMR )) scr |= SCR_EL3_EnFPM;
Signature · 1 line
2.25.1