Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: arm64: PMU: Reload when resetting

Replace kvm_pmu_vcpu_reset() with the generic PMU reloading mechanism to
ensure the consistency with system registers and to reduce code size.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20250315-pmc-v5-5-ecee87dab216@daynix.com
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>

authored by

Akihiko Odaki and committed by
Oliver Upton
fe535380 1db4aaa0

+3 -19
-14
arch/arm64/kvm/pmu-emul.c
··· 255 255 } 256 256 257 257 /** 258 - * kvm_pmu_vcpu_reset - reset pmu state for cpu 259 - * @vcpu: The vcpu pointer 260 - * 261 - */ 262 - void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu) 263 - { 264 - unsigned long mask = kvm_pmu_implemented_counter_mask(vcpu); 265 - int i; 266 - 267 - for_each_set_bit(i, &mask, 32) 268 - kvm_pmu_stop_counter(kvm_vcpu_idx_to_pmc(vcpu, i)); 269 - } 270 - 271 - /** 272 258 * kvm_pmu_vcpu_destroy - free perf event of PMU for cpu 273 259 * @vcpu: The vcpu pointer 274 260 *
-3
arch/arm64/kvm/reset.c
··· 196 196 vcpu->arch.reset_state.reset = false; 197 197 spin_unlock(&vcpu->arch.mp_state_lock); 198 198 199 - /* Reset PMU outside of the non-preemptible section */ 200 - kvm_pmu_vcpu_reset(vcpu); 201 - 202 199 preempt_disable(); 203 200 loaded = (vcpu->cpu != -1); 204 201 if (loaded)
+3
arch/arm64/kvm/sys_regs.c
··· 4480 4480 } 4481 4481 4482 4482 set_bit(KVM_ARCH_FLAG_ID_REGS_INITIALIZED, &kvm->arch.flags); 4483 + 4484 + if (kvm_vcpu_has_pmu(vcpu)) 4485 + kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu); 4483 4486 } 4484 4487 4485 4488 /**
-2
include/kvm/arm_pmu.h
··· 52 52 u64 kvm_pmu_accessible_counter_mask(struct kvm_vcpu *vcpu); 53 53 u64 kvm_pmu_get_pmceid(struct kvm_vcpu *vcpu, bool pmceid1); 54 54 void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu); 55 - void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu); 56 55 void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu); 57 56 void kvm_pmu_reprogram_counter_mask(struct kvm_vcpu *vcpu, u64 val); 58 57 void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu); ··· 126 127 return 0; 127 128 } 128 129 static inline void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu) {} 129 - static inline void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu) {} 130 130 static inline void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu) {} 131 131 static inline void kvm_pmu_reprogram_counter_mask(struct kvm_vcpu *vcpu, u64 val) {} 132 132 static inline void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu) {}