@samitouri / QOSamiQemu / commits / d319978c29

hvf: gate ARM_FEATURE_PMU register emulation when using the Apple vGIC

From Apple documentation: > When EL2 is disabled, PMU register accesses trigger "Trapped MSR, MRS, or > System Instruction" exceptions. When this happens, hv_vcpu_run() returns, and the >  hv_vcpu_exit_t object contains the information about this exception. > When EL2 is enabled, the handling of PMU register accesses is determined by the PMUVer > field of ID_AA64DFR0_EL1 register. > If the PMUVer field value is zero or is invalid, PMU register accesses generate "Undefined" > exceptions, which are sent to the guest. > If the PMUVer field value is non-zero and valid, PMU register accesses are emulated by the framework. > The ID_AA64DFR0_EL1 register can be modified via hv_vcpu_set_sys_reg API. However, despite what that documentation says this is actually gated on using the Apple vGIC instead of nested virtualisation per se. Apple introduced both at the same time. Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr> Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Message-id: 20260429190532.26538-8-mohamed@unpredictable.fr Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Mohamed Mediouni committed May 5, 2026 at 09:25 UTC d319978c2911d6a734221b9250d84ebc58fbd574
1 file changed +2 -2
target/arm/hvf/hvf.c
+2 -2
@@ -1601,7 +1601,7 @@ static int hvf_sysreg_read(CPUState *cpu, uint32_t reg, uint64_t *val)
1601 ARMCPU *arm_cpu = ARM_CPU(cpu);
1602 CPUARMState *env = &arm_cpu->env;
1603
1604 - if (arm_feature(env, ARM_FEATURE_PMU)) {
1604 + if (!hvf_irqchip_in_kernel() && arm_feature(env, ARM_FEATURE_PMU)) {
1605 switch (reg) {
1606 case SYSREG_PMCR_EL0:
1607 *val = env->cp15.c9_pmcr;
@@ -1862,7 +1862,7 @@ static int hvf_sysreg_write(CPUState *cpu, uint32_t reg, uint64_t val)
1862 SYSREG_OP2(reg),
1863 val);
1864
1865 - if (arm_feature(env, ARM_FEATURE_PMU)) {
1865 + if (!hvf_irqchip_in_kernel() && arm_feature(env, ARM_FEATURE_PMU)) {
1866 switch (reg) {
1867 case SYSREG_PMCCNTR_EL0:
1868 pmu_op_start(env);