Re: [RFC PATCH 0/2] KVM: x86/pmu: Let userspace disable SW accounting of emulated instructions
From: Absandze, Luka
Date: Tue Jul 21 2026 - 13:57:58 EST
On 2026-07-21 09:47, Sean Christopherson wrote:
> Hmm, yeah, that'd be better than ignoring emulated instruction entirely, and
> would give userspace far better control over how shoddy KVM's emulation is. Off
> the cuff, the change would be fairly trivial too? E.g.
>
> diff --git arch/x86/kvm/pmu.c arch/x86/kvm/pmu.c
> index 7f777049d328..c5f436c6f83f 100644
> --- arch/x86/kvm/pmu.c
> +++ arch/x86/kvm/pmu.c
> @@ -1084,7 +1084,8 @@ static void kvm_pmu_incr_counter(struct kvm_pmc *pmc)
> */
> if (!kvm_vcpu_has_mediated_pmu(vcpu)) {
> pmc->emulated_counter++;
> - kvm_pmu_request_counter_reprogram(pmc);
> + if (pmc->emulated_counter > pmu_something_something_tolerance)
> + kvm_pmu_request_counter_reprogram(pmc);
> return;
> }
I believe this is fine, but perhaps the tolerance itself could be a knob
with <0 meaning no reprogram? While the contention on this path will be
much lower, we are still introducing more steal time, and the added
accuracy is probably not worth even that for guests who really only care
for the rate of change, rather than exact instruction counts.