Re: [PATCH v4 3/6] KVM: x86/pmu: Disable counters based on Host-Only/Guest-Only bits in SVM
From: Yosry Ahmed
Date: Mon Apr 27 2026 - 19:20:32 EST
> We can have our cake and eat it too. Add svm_pmu_handle_nested_transition(),
> but then also rename and rework reprogram_counters() to support both deferred and
> synchronous operation, e.g. something like so:
>
> ---
> static inline void __kvm_pmu_reprogram_counters(struct kvm_pmu *pmu, u64 diff,
I don't like 'diff', I think just 'unsigned long *bitmap' and pass a
bitmap in here like most PMU code?
> bool defer)
> {
> struct kvm_vcpu *vcpu = pmu_to_vcpu(pmu);
>
> lockdep_assert_once(defer || kvm_get_running_vcpu() == vcpu);
Hmm why do we need this? Why not just pass in a vcpu? All callers have
the vcpu and it should always be the running vcpu whether we are
deferring or not.
>
> if (!diff)
Then this becomes bitmap_empty(bitmap)
> return;
>
> atomic64_or(diff, &pmu->__reprogram_pmi);
and this unfortunately becomes aatomic64_or(*(s64 *)bitmap,
&pmu->__reprogram_pmi);
>
> if (defer)
> kvm_make_request(KVM_REQ_PMU, vcpu);
> else
> kvm_pmu_handle_event(pmu_to_vcpu(pmu));
> }
>
> static inline void kvm_pmu_reprogram_counters(struct kvm_pmu *pmu, u64 diff)
> {
> __kvm_pmu_reprogram_counters(pmu, diff, true);
> }
> ---
>
> and then have SVM code pass in the reprogram_on_nested_transition or whatever.