Skip to content

Commit d0c94c4

Browse files
author
Marc Zyngier
committed
KVM: arm64: Restore PMU configuration on first run
Restoring a guest with an active virtual PMU results in no perf counters being instanciated on the host side. Not quite what you'd expect from a restore. In order to fix this, force a writeback of PMCR_EL0 on the first run of a vcpu (using a new request so that it happens once the vcpu has been loaded). This will in turn create all the host-side counters that were missing. Reported-by: Jinank Jain <jinankj@amazon.de> Tested-by: Jinank Jain <jinankj@amazon.de> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/87wnrbylxv.wl-maz@kernel.org Link: https://lore.kernel.org/r/b53dfcf9bbc4db7f96154b1cd5188d72b9766358.camel@amazon.de
1 parent 2a71fab commit d0c94c4

3 files changed

Lines changed: 8 additions & 0 deletions

File tree

arch/arm64/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#define KVM_REQ_VCPU_RESET KVM_ARCH_REQ(2)
4747
#define KVM_REQ_RECORD_STEAL KVM_ARCH_REQ(3)
4848
#define KVM_REQ_RELOAD_GICv4 KVM_ARCH_REQ(4)
49+
#define KVM_REQ_RELOAD_PMU KVM_ARCH_REQ(5)
4950

5051
#define KVM_DIRTY_LOG_MANUAL_CAPS (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \
5152
KVM_DIRTY_LOG_INITIALLY_SET)

arch/arm64/kvm/arm.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,10 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu)
689689
vgic_v4_load(vcpu);
690690
preempt_enable();
691691
}
692+
693+
if (kvm_check_request(KVM_REQ_RELOAD_PMU, vcpu))
694+
kvm_pmu_handle_pmcr(vcpu,
695+
__vcpu_sys_reg(vcpu, PMCR_EL0));
692696
}
693697
}
694698

arch/arm64/kvm/pmu-emul.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,9 @@ int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu)
851851
return -EINVAL;
852852
}
853853

854+
/* One-off reload of the PMU on first run */
855+
kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
856+
854857
return 0;
855858
}
856859

0 commit comments

Comments
 (0)