Skip to content

Commit f6da81f

Browse files
reijiw-kvmoupton
authored andcommitted
KVM: arm64: PMU: Don't save PMCR_EL0.{C,P} for the vCPU
Presently, when a guest writes 1 to PMCR_EL0.{C,P}, which is WO/RAZ, KVM saves the register value, including these bits. When userspace reads the register using KVM_GET_ONE_REG, KVM returns the saved register value as it is (the saved value might have these bits set). This could result in userspace setting these bits on the destination during migration. Consequently, KVM may end up resetting the vPMU counter registers (PMCCNTR_EL0 and/or PMEVCNTR<n>_EL0) to zero on the first KVM_RUN after migration. Fix this by not saving those bits when a guest writes 1 to those bits. Fixes: ab94683 ("arm64: KVM: Add access handler for PMCR register") Cc: [email protected] Reviewed-by: Marc Zyngier <[email protected]> Signed-off-by: Reiji Watanabe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 9228b26 commit f6da81f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

arch/arm64/kvm/pmu-emul.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val)
538538
if (!kvm_pmu_is_3p5(vcpu))
539539
val &= ~ARMV8_PMU_PMCR_LP;
540540

541-
__vcpu_sys_reg(vcpu, PMCR_EL0) = val;
541+
/* The reset bits don't indicate any state, and shouldn't be saved. */
542+
__vcpu_sys_reg(vcpu, PMCR_EL0) = val & ~(ARMV8_PMU_PMCR_C | ARMV8_PMU_PMCR_P);
542543

543544
if (val & ARMV8_PMU_PMCR_E) {
544545
kvm_pmu_enable_counter_mask(vcpu,

0 commit comments

Comments
 (0)