Skip to content

Commit 5f0a714

Browse files
Shannon ZhaoMarc Zyngier
authored andcommitted
arm64: KVM: Free perf event of PMU when destroying vcpu
When KVM frees VCPU, it needs to free the perf_event of PMU. Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org> Reviewed-by: Marc Zyngier <marc.zyngier@arm.com> Reviewed-by: Andrew Jones <drjones@redhat.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent 2aa36e9 commit 5f0a714

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎arch/arm/kvm/arm.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
266266
kvm_mmu_free_memory_caches(vcpu);
267267
kvm_timer_vcpu_terminate(vcpu);
268268
kvm_vgic_vcpu_destroy(vcpu);
269+
kvm_pmu_vcpu_destroy(vcpu);
269270
kmem_cache_free(kvm_vcpu_cache, vcpu);
270271
}
271272

‎include/kvm/arm_pmu.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ u64 kvm_pmu_get_counter_value(struct kvm_vcpu *vcpu, u64 select_idx);
4343
void kvm_pmu_set_counter_value(struct kvm_vcpu *vcpu, u64 select_idx, u64 val);
4444
u64 kvm_pmu_valid_counter_mask(struct kvm_vcpu *vcpu);
4545
void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu);
46+
void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu);
4647
void kvm_pmu_disable_counter(struct kvm_vcpu *vcpu, u64 val);
4748
void kvm_pmu_enable_counter(struct kvm_vcpu *vcpu, u64 val);
4849
void kvm_pmu_overflow_set(struct kvm_vcpu *vcpu, u64 val);
@@ -69,6 +70,7 @@ static inline u64 kvm_pmu_valid_counter_mask(struct kvm_vcpu *vcpu)
6970
return 0;
7071
}
7172
static inline void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu) {}
73+
static inline void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu) {}
7274
static inline void kvm_pmu_disable_counter(struct kvm_vcpu *vcpu, u64 val) {}
7375
static inline void kvm_pmu_enable_counter(struct kvm_vcpu *vcpu, u64 val) {}
7476
static inline void kvm_pmu_overflow_set(struct kvm_vcpu *vcpu, u64 val) {}

‎virt/kvm/arm/pmu.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,27 @@ void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu)
101101
}
102102
}
103103

104+
/**
105+
* kvm_pmu_vcpu_destroy - free perf event of PMU for cpu
106+
* @vcpu: The vcpu pointer
107+
*
108+
*/
109+
void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu)
110+
{
111+
int i;
112+
struct kvm_pmu *pmu = &vcpu->arch.pmu;
113+
114+
for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) {
115+
struct kvm_pmc *pmc = &pmu->pmc[i];
116+
117+
if (pmc->perf_event) {
118+
perf_event_disable(pmc->perf_event);
119+
perf_event_release_kernel(pmc->perf_event);
120+
pmc->perf_event = NULL;
121+
}
122+
}
123+
}
124+
104125
u64 kvm_pmu_valid_counter_mask(struct kvm_vcpu *vcpu)
105126
{
106127
u64 val = vcpu_sys_reg(vcpu, PMCR_EL0) >> ARMV8_PMU_PMCR_N_SHIFT;

0 commit comments

Comments
 (0)