Li RongQing <lirongqing@xxxxxxxxx> writes: > clear pv eoi pending bit only when it is set, to avoid calling > pv_eoi_put_user() > > and this can speed pv_eoi_clr_pending about 300 nsec on AMD EPYC > most of the time > > Signed-off-by: Li RongQing <lirongqing@xxxxxxxxx> > --- > arch/x86/kvm/lapic.c | 7 ++++--- > 1 files changed, 4 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > index 76fb009..c434f70 100644 > --- a/arch/x86/kvm/lapic.c > +++ b/arch/x86/kvm/lapic.c > @@ -694,9 +694,9 @@ static void pv_eoi_set_pending(struct kvm_vcpu *vcpu) > __set_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention); > } > > -static void pv_eoi_clr_pending(struct kvm_vcpu *vcpu) > +static void pv_eoi_clr_pending(struct kvm_vcpu *vcpu, bool pending) Nitpick (and probably a matter of personal taste): pv_eoi_clr_pending() has only one user and the change doesn't make its interface much nicer, I'd suggest we just inline in instead. (we can probably do the same to pv_eoi_get_pending()/pv_eoi_set_pending() too). > { > - if (pv_eoi_put_user(vcpu, KVM_PV_EOI_DISABLED) < 0) { > + if (pending && pv_eoi_put_user(vcpu, KVM_PV_EOI_DISABLED) < 0) { > printk(KERN_WARNING "Can't clear EOI MSR value: 0x%llx\n", > (unsigned long long)vcpu->arch.pv_eoi.msr_val); > return; > @@ -2693,7 +2693,8 @@ static void apic_sync_pv_eoi_from_guest(struct kvm_vcpu *vcpu, > * While this might not be ideal from performance point of view, > * this makes sure pv eoi is only enabled when we know it's safe. > */ > - pv_eoi_clr_pending(vcpu); > + pv_eoi_clr_pending(vcpu, pending); > + > if (pending) > return; > vector = apic_set_eoi(apic); Could you probably elaborate a bit (probably by enhancing the comment above pv_eoi_clr_pending()) why the race we have here (even before the patch) doesn't matter? As far as I understand it, the guest can change PV EOI status from a different CPU (it shouldn't do it but it still can) at any time: e.g. between pv_eoi_get_pending() and pv_eoi_clr_pending() but also right after we do pv_eoi_clr_pending() so the patch doesn't really change much in this regard. -- Vitaly