Re: [PATCH v3 2/4] KVM: LAPIC: lapic timer interrupt is injected by posted interrupt

From: Marcelo Tosatti
Date: Thu Jun 13 2019 - 19:00:00 EST


On Wed, Jun 12, 2019 at 05:22:31PM +0200, Radim KrÄmÃÅ wrote:
> 2019-06-12 09:48+0800, Wanpeng Li:
> > On Wed, 12 Jun 2019 at 04:39, Marcelo Tosatti <mtosatti@xxxxxxxxxx> wrote:
> > > On Tue, Jun 11, 2019 at 08:17:07PM +0800, Wanpeng Li wrote:
> > > > From: Wanpeng Li <wanpengli@xxxxxxxxxxx>
> > > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> > > > @@ -133,6 +133,12 @@ inline bool posted_interrupt_inject_timer_enabled(struct kvm_vcpu *vcpu)
> > > > }
> > > > EXPORT_SYMBOL_GPL(posted_interrupt_inject_timer_enabled);
> > > >
> > > > +static inline bool can_posted_interrupt_inject_timer(struct kvm_vcpu *vcpu)
> > > > +{
> > > > + return posted_interrupt_inject_timer_enabled(vcpu) &&
> > > > + kvm_hlt_in_guest(vcpu->kvm);
> > > > +}
> > >
> > > Hi Li,
> >
> > Hi Marcelo,
> >
> > >
> > > Don't think its necessary to depend on kvm_hlt_in_guest: Can also use
> > > exitless injection if the guest is running (think DPDK style workloads
> > > that busy-spin on network card).
>
> I agree.
>
> > There are some discussions here.
> >
> > https://lkml.org/lkml/2019/6/11/424
> > https://lkml.org/lkml/2019/6/5/436
>
> Paolo wants to disable the APF synthetic halt first, which I think is
> unrelated to the timer implementation.
> The synthetic halt happens when the VCPU cannot progress because the
> host swapped out its memory and any asynchronous event should unhalt it,
> because we assume that the interrupt path wasn't swapped out.
>
> The posted interrupt does a swake_up_one (part of vcpu kick), which is
> everything what the non-posted path does after setting a KVM request --
> it's a bug if we later handle the PIR differently from the KVM request,
> so the guest is going to be woken up on any halt blocking in KVM (even
> synthetic APF halt).
>
> Paolo, have I missed the point?
>
> Thanks.

"Here you need to check kvm_halt_in_guest, not kvm_mwait_in_guest,
because you need to go through kvm_apic_expired if the guest needs to be
woken up from kvm_vcpu_block."

Note: VMX preemption timer is disabled by Li's patch.