I tried using the method and referring document by arm Official documents,but an exception appears in the kernel log
checked for the path without "/sys/bus/event_source/devices/arm_spe_XX."
The hardware is arm-cortex x3
Exception Message from above link:
> [ 0.774345] swapper/0: arm_spe_pmu spe-x3: [name:arm_spe_pmu&]profiling buffer owned by higher exception level
I don't know what causes this exception,
I've confirmed some things
bits[13:12] is ob11 and its meaning is as follows
Profiling Buffer uses Non-secure Virtual Addresses. Statistical Profiling enabled in Non-secure state and disabled in Secure state. Accesses to Statistical Profiling and Profiling Buffer control registers at EL2 and EL1 in Secure state generate Trap exceptions to EL3.
Please provide me with more Information ?
Please check if the target system you are working on supports Statistical Profiling Extension(SPE). This is reflected in the register ID_AA64DFR0_EL1, PMSVer, bits [35:32]:
https://developer.arm.com/documentation/ddi0595/2021-03/AArch64-Registers/ID-AA64DFR0-EL1--AArch64-Debug-Feature-Register-0
Please check and ensure the target system setup for enabling SPE is correct: https://developer.arm.com/documentation/101814/0801/Target-Setup/System-requirements-for-SPE-support
Ensure the latest Linux kernel and latest SPE driver with all relevant patches are applied (Patches if any/all applicable depending upon the Linux version you are using)
The error message,
"profiling buffer is owned by a higher exception level"
is observed when PMBIDR_EL1 register read from the driver code reflects that the P-bit is set to 1.
From the driver code, https://github.com/torvalds/linux/blob/master/drivers/perf/arm_spe_pmu.c
"
As per the PMBIDR register details (please refer to details when P-bit is read as one, copied below for quick reference): https://developer.arm.com/documentation/ddi0601/2020-12/AArch64-Registers/PMBIDR-EL1--Profiling-Buffer-ID-Register
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Programming not allowed. The Profiling Buffer is owned by a higher Exception level or the other Security state.
Profiling Buffer is owned by the current or a lower Exception level in the current Security state.
Profiling Buffer is owned by a higher Exception level or the other Security state.
The value read from this field depends on the current Exception level and the Effective values of MDCR_EL3.NSPB and MDCR_EL2.E2PB:
0b00
0b01
0b10
0b11
Please check when PMBIDR_EL1 is read by the SPE driver code, what are the values observed in MDCR_EL2 and MDCR_EL3 registers. When in non-secure EL1, if MDCR_EL3.NSPB bits [13:12] = 0b11, and MDCR_EL2.E2PB, bits [13:12] = 0b11, PMBIDR_EL1.P should read 0 and you should not observe the error message "profiling buffer is owned by a higher exception level".
Note that, if you are booting the Linux Kernel at EL1 directly it should work. However, not as a Virtual machine. The KVM does not support SPE for a guest OS. In this case you might see the error message "profiling buffer is owned by a higher exception level" as the guest OS will read PMBIDR.P bit as one.