Re: [PATCHv4 3/5] kvm: host side for eoi optimization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


On Wed, May 16, 2012 at 09:38:22PM +0300, Gleb Natapov wrote:
> On Wed, May 16, 2012 at 09:29:49PM +0300, Michael S. Tsirkin wrote:
> > On Wed, May 16, 2012 at 09:25:20PM +0300, Gleb Natapov wrote:
> > > On Wed, May 16, 2012 at 03:15:00PM -0300, Marcelo Tosatti wrote:
> > > > On Wed, May 16, 2012 at 08:58:57PM +0300, Michael S. Tsirkin wrote:
> > > > > On Wed, May 16, 2012 at 02:20:58PM -0300, Marcelo Tosatti wrote:
> > > > > > On Wed, May 16, 2012 at 07:22:47PM +0300, Michael S. Tsirkin wrote:
> > > > > > > On Wed, May 16, 2012 at 12:49:40PM -0300, Marcelo Tosatti wrote:
> > > > > > > > > @@ -1245,9 +1306,20 @@ int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu)
> > > > > > > > >  	int vector = kvm_apic_has_interrupt(vcpu);
> > > > > > > > >  	struct kvm_lapic *apic = vcpu->arch.apic;
> > > > > > > > >  
> > > > > > > > > -	if (vector == -1)
> > > > > > > > > +	/* Detect interrupt nesting and disable EOI optimization */
> > > > > > > > > +	if (pv_eoi_enabled(vcpu) && vector == -2)
> > > > > > > > > +		pv_eoi_clr_pending(vcpu);
> > > > > > > > > +
> > > > > > > > > +	if (vector < 0)
> > > > > > > > 
> > > > > > > > With interrupt window exiting, the guest will exit:
> > > > > > > > 
> > > > > > > > - as soon as it sets RFLAGS.IF=1 and there is any 
> > > > > > > > interrupt pending in IRR.
> > > > > > > > - any new interrupt is set in IRR will kick vcpu
> > > > > > > > out of guest mode and recalculate interrupt-window-exiting.
> > > > > > > > 
> > > > > > > > Doesnt this make this bit unnecessary ?
> > > > > > > 
> > > > > > > Looks like we could cut it out.  But I'm not sure how architectural it is
> > > > > > > that we exit on interrupt window.
> > > > > > > I guess there are reasons to exit on interrupt window but
> > > > > > > isn't it better to make the feature independent of it?
> > > > > > 
> > > > > > Hum... not sure. Is it helpful for the Hyper-V interface?
> > > > > > 
> > > > > > > This almost never happens in my testing anyway, so
> > > > > > > however we handle it is unlikely to affect performance.
> > > > > > 
> > > > > > It decreases the amount of state that must be maintained.
> > > > > > 
> > > > > > BTW there is a bug covered by interrupt window exiting:
> > > > > > 
> > > > > > vcpu0                               host
> > > > > > - irr 5 set
> > > > > > - isr 5 set, irr 5 cleared
> > > > > > - eoi_skip bit not set, 
> > > > > > no other bit set in irr.
> > > > > > - enter guest
> > > > > > 
> > > > > >                                     irr 4 set
> > > > > >                                     kick vcpu0 out of guest mode
> > > > > > 
> > > > > > - eoi pending bit not set
> > > > > >   (previous interrupt injection 
> > > > > >    still pending)
> > > > > > - skip eoi
> > > > > > 
> > > > > > If it were not for interrupt window exiting, this would 
> > > > > > inject vector 4 on an unrelated exit who knows how long 
> > > > > > in the future.
> > > > > > 
> > > > > > Also note optimization depends on the fact that the host 
> > > > > > kicks vcpu out unconditionally (so it is dependent on 
> > > > > > certain kvm implementation details).
> > > > > > 
> > > > > 
> > > > > Look we can summarize as follows: irq windows exit is
> > > > > required both before and after this patch.
> > > > > But it does not make the check above redundant.
> > > > 
> > > > Right, it is not redundant.
> > > > 
> > > > The above is still a bug: a case where eoi pending bit is not updated
> > > > properly.
> > > When IRR is set while eoi_skip is enabled, eoi_skip should be cleared.
> > > Michael does your patch do that?
> > 
> > I think this does it:
> >         /* Detect interrupt nesting and disable EOI optimization */
> >         if (pv_eoi_enabled(vcpu) && vector == -2)
> >                 pv_eoi_clr_pending(vcpu);
> > 
> > -2 is returned when irr is set.
> > 
> This code is reached from kvm_cpu_get_interrupt(), but this function will
> not be called in above scenario.

I think I see. So this shall fix it also makes code cleaner
(no -2 hack). Right? kvm_apic_has_interrupt is called correct?

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index b4f7013..5a38e34 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1273,8 +1273,12 @@ int kvm_apic_has_interrupt(struct kvm_vcpu *vcpu)
 	highest_irr = apic_find_highest_irr(apic);
 	if (highest_irr == -1)
 		return -1;
-	if (((highest_irr & 0xF0) <= apic_get_reg(apic, APIC_PROCPRI)))
-		return -2;
+	/* Detect interrupt nesting and disable EOI optimization */
+	if ((highest_irr & 0xF0) <= apic_get_reg(apic, APIC_PROCPRI)) {
+		if (pv_eoi_enabled(vcpu))
+			pv_eoi_clr_pending(vcpu);
+		return -1;
+	}
 	return highest_irr;
 }
 
@@ -1306,10 +1310,6 @@ int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu)
 	int vector = kvm_apic_has_interrupt(vcpu);
 	struct kvm_lapic *apic = vcpu->arch.apic;
 
-	/* Detect interrupt nesting and disable EOI optimization */
-	if (pv_eoi_enabled(vcpu) && vector == -2)
-		pv_eoi_clr_pending(vcpu);
-
 	if (vector < 0)
 		return -1;
 
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[KVM ARM]     [KVM ia64]     [KVM ppc]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Linux Kernel]     [Linux SCSI]     [XFree86]

Add to Google Powered by Linux