Skip to content

Commit 882f784

Browse files
Anshuman Khandualgregkh
authored andcommitted
arm64/boot: Enable EL2 requirements for FEAT_PMUv3p9
commit 858c7bf upstream. FEAT_PMUv3p9 registers such as PMICNTR_EL0, PMICFILTR_EL0, and PMUACR_EL1 access from EL1 requires appropriate EL2 fine grained trap configuration via FEAT_FGT2 based trap control registers HDFGRTR2_EL2 and HDFGWTR2_EL2. Otherwise such register accesses will result in traps into EL2. Add a new helper __init_el2_fgt2() which initializes FEAT_FGT2 based fine grained trap control registers HDFGRTR2_EL2 and HDFGWTR2_EL2 (setting the bits nPMICNTR_EL0, nPMICFILTR_EL0 and nPMUACR_EL1) to enable access into PMICNTR_EL0, PMICFILTR_EL0, and PMUACR_EL1 registers. Also update booting.rst with SCR_EL3.FGTEn2 requirement for all FEAT_FGT2 based registers to be accessible in EL2. Cc: Will Deacon <will@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Rob Herring <robh@kernel.org> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Marc Zyngier <maz@kernel.org> Cc: Oliver Upton <oliver.upton@linux.dev> Cc: linux-arm-kernel@lists.infradead.org Cc: linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: kvmarm@lists.linux.dev Fixes: 0bbff9e ("perf/arm_pmuv3: Add PMUv3.9 per counter EL0 access control") Fixes: d8226d8 ("perf: arm_pmuv3: Add support for Armv9.4 PMU instruction counter") Tested-by: Rob Herring (Arm) <robh@kernel.org> Reviewed-by: Rob Herring (Arm) <robh@kernel.org> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> Link: https://lore.kernel.org/r/20250227035119.2025171-1-anshuman.khandual@arm.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent eebba39 commit 882f784

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

Documentation/arch/arm64/booting.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ Before jumping into the kernel, the following conditions must be met:
288288

289289
- SCR_EL3.FGTEn (bit 27) must be initialised to 0b1.
290290

291+
For CPUs with the Fine Grained Traps 2 (FEAT_FGT2) extension present:
292+
293+
- If EL3 is present and the kernel is entered at EL2:
294+
295+
- SCR_EL3.FGTEn2 (bit 59) must be initialised to 0b1.
296+
291297
For CPUs with support for HCRX_EL2 (FEAT_HCX) present:
292298

293299
- If EL3 is present and the kernel is entered at EL2:
@@ -382,6 +388,22 @@ Before jumping into the kernel, the following conditions must be met:
382388

383389
- SMCR_EL2.EZT0 (bit 30) must be initialised to 0b1.
384390

391+
For CPUs with the Performance Monitors Extension (FEAT_PMUv3p9):
392+
393+
- If EL3 is present:
394+
395+
- MDCR_EL3.EnPM2 (bit 7) must be initialised to 0b1.
396+
397+
- If the kernel is entered at EL1 and EL2 is present:
398+
399+
- HDFGRTR2_EL2.nPMICNTR_EL0 (bit 2) must be initialised to 0b1.
400+
- HDFGRTR2_EL2.nPMICFILTR_EL0 (bit 3) must be initialised to 0b1.
401+
- HDFGRTR2_EL2.nPMUACR_EL1 (bit 4) must be initialised to 0b1.
402+
403+
- HDFGWTR2_EL2.nPMICNTR_EL0 (bit 2) must be initialised to 0b1.
404+
- HDFGWTR2_EL2.nPMICFILTR_EL0 (bit 3) must be initialised to 0b1.
405+
- HDFGWTR2_EL2.nPMUACR_EL1 (bit 4) must be initialised to 0b1.
406+
385407
For CPUs with Memory Copy and Memory Set instructions (FEAT_MOPS):
386408

387409
- If the kernel is entered at EL1 and EL2 is present:

arch/arm64/include/asm/el2_setup.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,30 @@
259259
.Lskip_fgt_\@:
260260
.endm
261261

262+
.macro __init_el2_fgt2
263+
mrs x1, id_aa64mmfr0_el1
264+
ubfx x1, x1, #ID_AA64MMFR0_EL1_FGT_SHIFT, #4
265+
cmp x1, #ID_AA64MMFR0_EL1_FGT_FGT2
266+
b.lt .Lskip_fgt2_\@
267+
268+
mov x0, xzr
269+
mrs x1, id_aa64dfr0_el1
270+
ubfx x1, x1, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4
271+
cmp x1, #ID_AA64DFR0_EL1_PMUVer_V3P9
272+
b.lt .Lskip_pmuv3p9_\@
273+
274+
orr x0, x0, #HDFGRTR2_EL2_nPMICNTR_EL0
275+
orr x0, x0, #HDFGRTR2_EL2_nPMICFILTR_EL0
276+
orr x0, x0, #HDFGRTR2_EL2_nPMUACR_EL1
277+
.Lskip_pmuv3p9_\@:
278+
msr_s SYS_HDFGRTR2_EL2, x0
279+
msr_s SYS_HDFGWTR2_EL2, x0
280+
msr_s SYS_HFGRTR2_EL2, xzr
281+
msr_s SYS_HFGWTR2_EL2, xzr
282+
msr_s SYS_HFGITR2_EL2, xzr
283+
.Lskip_fgt2_\@:
284+
.endm
285+
262286
.macro __init_el2_gcs
263287
mrs_s x1, SYS_ID_AA64PFR1_EL1
264288
ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4
@@ -304,6 +328,7 @@
304328
__init_el2_nvhe_idregs
305329
__init_el2_cptr
306330
__init_el2_fgt
331+
__init_el2_fgt2
307332
__init_el2_gcs
308333
.endm
309334

0 commit comments

Comments
 (0)