Skip to content

Commit 87a1f06

Browse files
ionela-voinescuctmarinas
authored andcommitted
arm64: trap to EL1 accesses to AMU counters from EL0
The activity monitors extension is an optional extension introduced by the ARMv8.4 CPU architecture. In order to access the activity monitors counters safely, if desired, the kernel should detect the presence of the extension through the feature register, and mediate the access. Therefore, disable direct accesses to activity monitors counters from EL0 (userspace) and trap them to EL1 (kernel). To be noted that the ARM64_AMU_EXTN kernel config does not have an effect on this code. Given that the amuserenr_el0 resets to an UNKNOWN value, setting the trap of EL0 accesses to EL1 is always attempted for safety and security considerations. Therefore firmware should still ensure accesses to AMU registers are not trapped in EL2/EL3 as this code cannot be bypassed if the CPU implements the Activity Monitors Unit. Signed-off-by: Ionela Voinescu <[email protected]> Reviewed-by: James Morse <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Reviewed-by: Suzuki K Poulose <[email protected]> Cc: Steve Capper <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Will Deacon <[email protected]> Cc: Catalin Marinas <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent 2c9d45b commit 87a1f06

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

arch/arm64/include/asm/assembler.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,16 @@ USER(\label, ic ivau, \tmp2) // invalidate I line PoU
430430
9000:
431431
.endm
432432

433+
/*
434+
* reset_amuserenr_el0 - reset AMUSERENR_EL0 if AMUv1 present
435+
*/
436+
.macro reset_amuserenr_el0, tmpreg
437+
mrs \tmpreg, id_aa64pfr0_el1 // Check ID_AA64PFR0_EL1
438+
ubfx \tmpreg, \tmpreg, #ID_AA64PFR0_AMU_SHIFT, #4
439+
cbz \tmpreg, .Lskip_\@ // Skip if no AMU present
440+
msr_s SYS_AMUSERENR_EL0, xzr // Disable AMU access from EL0
441+
.Lskip_\@:
442+
.endm
433443
/*
434444
* copy_page - copy src to dest using temp registers t1-t8
435445
*/

arch/arm64/mm/proc.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ alternative_endif
131131
ubfx x11, x11, #1, #1
132132
msr oslar_el1, x11
133133
reset_pmuserenr_el0 x0 // Disable PMU access from EL0
134+
reset_amuserenr_el0 x0 // Disable AMU access from EL0
134135

135136
alternative_if ARM64_HAS_RAS_EXTN
136137
msr_s SYS_DISR_EL1, xzr
@@ -423,6 +424,8 @@ SYM_FUNC_START(__cpu_setup)
423424
isb // Unmask debug exceptions now,
424425
enable_dbg // since this is per-cpu
425426
reset_pmuserenr_el0 x0 // Disable PMU access from EL0
427+
reset_amuserenr_el0 x0 // Disable AMU access from EL0
428+
426429
/*
427430
* Memory region attributes
428431
*/

0 commit comments

Comments
 (0)