Re: [RFC PATCH 0/2] KVM: x86/pmu: Let userspace disable SW accounting of emulated instructions
From: Sean Christopherson
Date: Tue Jul 21 2026 - 14:07:10 EST
On Tue, Jul 21, 2026, Luka Absandze wrote:
> 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
Ya, I was envisioning a knob.
> with <0 meaning no reprogram?
Eh, I don't see a need to assign special meaning to <0. Make it a u32 (or u64),
and then a large value will provide the same behavior in practice, without needing
special handling in KVM.
> 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.