Skip to content

Commit 600f6fa

Browse files
author
Marc Zyngier
committed
KVM: arm64: Let kvm_vcpu_read_pmcr() return an EL-dependent value for PMCR_EL0.N
When EL2 is present, PMCR_EL0.N is the effective value of MDCR_EL2.HPMN when accessed from EL1 or EL0. Make sure we honor this requirement. Reviewed-by: Oliver Upton <oliver.upton@linux.dev> Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent efff9dd commit 600f6fa

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

arch/arm64/kvm/pmu-emul.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,8 +1300,12 @@ u8 kvm_arm_pmu_get_pmuver_limit(void)
13001300
u64 kvm_vcpu_read_pmcr(struct kvm_vcpu *vcpu)
13011301
{
13021302
u64 pmcr = __vcpu_sys_reg(vcpu, PMCR_EL0);
1303+
u64 n = vcpu->kvm->arch.nr_pmu_counters;
13031304

1304-
return u64_replace_bits(pmcr, vcpu->kvm->arch.nr_pmu_counters, ARMV8_PMU_PMCR_N);
1305+
if (vcpu_has_nv(vcpu) && !vcpu_is_el2(vcpu))
1306+
n = FIELD_GET(MDCR_EL2_HPMN, __vcpu_sys_reg(vcpu, MDCR_EL2));
1307+
1308+
return u64_replace_bits(pmcr, n, ARMV8_PMU_PMCR_N);
13051309
}
13061310

13071311
void kvm_pmu_nested_transition(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)