On Thu, Jun 01, 2023, Jim Mattson wrote: > On Thu, Jun 1, 2023 at 12:28 PM Jon Kohler <jon@xxxxxxxxxxx> wrote: > > > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h > > > index c544602d07a3..454bcbf5b543 100644 > > > --- a/arch/x86/kvm/x86.h > > > +++ b/arch/x86/kvm/x86.h > > > @@ -492,7 +492,31 @@ static inline void kvm_machine_check(void) > > > > > > void kvm_load_guest_xsave_state(struct kvm_vcpu *vcpu); > > > void kvm_load_host_xsave_state(struct kvm_vcpu *vcpu); > > > + > > > int kvm_spec_ctrl_test_value(u64 value); > > > + > > > +static inline bool kvm_account_msr_spec_ctrl_write(struct kvm_vcpu *vcpu) > > > +{ > > > + if ((vcpu->stat.exits - vcpu->arch.spec_ctrl_nr_exits_snapshot) < 20) > > I think you mean 200 here. If it's bad to have more than 1 > WRMSR(IA32_SPEC_CTRL) VM-exit in 20 VM-exits, then more than 10 such > VM-exits in 200 VM-exits represents sustained badness. No? The snapshot is updated on every write, i.e. this check is whether or not the last wrmsr(SPEC_CTRL) was less than 20 cycles ago. if ((vcpu->stat.exits - vcpu->arch.spec_ctrl_nr_exits_snapshot) < 20) vcpu->arch.nr_quick_spec_ctrl_writes++; else vcpu->arch.nr_quick_spec_ctrl_writes = 0; vcpu->arch.spec_ctrl_nr_exits_snapshot = vcpu->stat.exits; <= new snapshot return vcpu->arch.nr_quick_spec_ctrl_writes >= 10; > (Although, as Sean noted, these numbers are just placeholders.) And the logic is very off-the-cuff, e.g. it may be better to have a rolling 200-exit window instead of 10 somewhat independent 20-exit windows.