Skip to content

Commit b782e8d

Browse files
Yicong Yangwilldeacon
authored andcommitted
arm64: arm_pmuv3: Correctly extract and check the PMUVer
Currently we're using "sbfx" to extract the PMUVer from ID_AA64DFR0_EL1 and skip the init/reset if no PMU present when the extracted PMUVer is negative or is zero. However for PMUv3p8 the PMUVer will be 0b1000 and PMUVer extracted by "sbfx" will always be negative and we'll skip the init/reset in __init_el2_debug/reset_pmuserenr_el0 unexpectedly. So this patch use "ubfx" instead of "sbfx" to extract the PMUVer. If the PMUVer is implementation defined (0b1111) or not implemented(0b0000) then skip the reset/init. Previously we'll also skip the init/reset if the PMUVer is higher than the version we known (currently PMUv3p9), with this patch we'll only skip if the PMU is not implemented or implementation defined. This keeps consistence with how we probe the PMU in the driver with pmuv3_implemented(). Signed-off-by: Yicong Yang <yangyicong@hisilicon.com> Link: https://lore.kernel.org/r/20240411123030.7201-1-yangyicong@huawei.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 8f9f504 commit b782e8d

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

arch/arm64/include/asm/assembler.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,10 @@ alternative_endif
480480
*/
481481
.macro reset_pmuserenr_el0, tmpreg
482482
mrs \tmpreg, id_aa64dfr0_el1
483-
sbfx \tmpreg, \tmpreg, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4
484-
cmp \tmpreg, #1 // Skip if no PMU present
485-
b.lt 9000f
483+
ubfx \tmpreg, \tmpreg, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4
484+
cmp \tmpreg, #ID_AA64DFR0_EL1_PMUVer_NI
485+
ccmp \tmpreg, #ID_AA64DFR0_EL1_PMUVer_IMP_DEF, #4, ne
486+
b.eq 9000f // Skip if no PMU present or IMP_DEF
486487
msr pmuserenr_el0, xzr // Disable PMU access from EL0
487488
9000:
488489
.endm

arch/arm64/include/asm/el2_setup.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@
5959

6060
.macro __init_el2_debug
6161
mrs x1, id_aa64dfr0_el1
62-
sbfx x0, x1, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4
63-
cmp x0, #1
64-
b.lt .Lskip_pmu_\@ // Skip if no PMU present
62+
ubfx x0, x1, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4
63+
cmp x0, #ID_AA64DFR0_EL1_PMUVer_NI
64+
ccmp x0, #ID_AA64DFR0_EL1_PMUVer_IMP_DEF, #4, ne
65+
b.eq .Lskip_pmu_\@ // Skip if no PMU present or IMP_DEF
6566
mrs x0, pmcr_el0 // Disable debug access traps
6667
ubfx x0, x0, #11, #5 // to EL2 and allow access to
6768
.Lskip_pmu_\@:
68-
csel x2, xzr, x0, lt // all PMU counters from EL1
69+
csel x2, xzr, x0, eq // all PMU counters from EL1
6970

7071
/* Statistical profiling */
7172
ubfx x0, x1, #ID_AA64DFR0_EL1_PMSVer_SHIFT, #4

0 commit comments

Comments
 (0)