Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758657AbcKCQAw (ORCPT ); Thu, 3 Nov 2016 12:00:52 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:32886 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758494AbcKCQAs (ORCPT ); Thu, 3 Nov 2016 12:00:48 -0400 Subject: Re: [PATCH 2/5] KVM: x86: do not scan IRR twice on APICv vmentry To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= References: <1476469291-5039-1-git-send-email-pbonzini@redhat.com> <1476469291-5039-3-git-send-email-pbonzini@redhat.com> <20161026195900.GC4212@potion> <00273a1a-ef5d-f814-3e02-24b4e855d229@redhat.com> <20161103150356.GE7771@potion> Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, yang.zhang.wz@gmail.com, feng.wu@intel.com, mst@redhat.com From: Paolo Bonzini Message-ID: Date: Thu, 3 Nov 2016 17:00:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20161103150356.GE7771@potion> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3296 Lines: 92 On 03/11/2016 16:03, Radim Krčmář wrote: > 2016-11-03 14:30+0100, Paolo Bonzini: >> On 26/10/2016 21:59, Radim Krčmář wrote: >>> 2016-10-14 20:21+0200, Paolo Bonzini: >>>> Calling apic_find_highest_irr results in IRR being scanned twice, >>>> once in vmx_sync_pir_from_irr and once in apic_search_irr. Change >>>> sync_pir_from_irr to do the RVI write and kvm_apic_update_irr to >>>> compute the new RVI on the fly. >>>> >>>> Signed-off-by: Paolo Bonzini >>>> --- >>> >>> Reviewed-by: Radim Krčmář >> >> Nope, this breaks nested VMX exit on external interrupt. For now I'm >> testing only patch 1 and will push that one only to kvm/next. > > Hm, does it also happen with this change? Probably not but I wanted to understand why. :) Paolo > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index 4b20f7304b9c..6be110e53e9e 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -941,7 +941,7 @@ struct kvm_x86_ops { > void (*set_virtual_x2apic_mode)(struct kvm_vcpu *vcpu, bool set); > void (*set_apic_access_page_addr)(struct kvm_vcpu *vcpu, hpa_t hpa); > void (*deliver_posted_interrupt)(struct kvm_vcpu *vcpu, int vector); > - void (*sync_pir_to_irr)(struct kvm_vcpu *vcpu); > + int (*sync_pir_to_irr)(struct kvm_vcpu *vcpu); > int (*set_tss_addr)(struct kvm *kvm, unsigned int addr); > int (*get_tdp_level)(void); > u64 (*get_mt_mask)(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio); > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c > index f8157a36ab09..ffa541d38343 100644 > --- a/arch/x86/kvm/svm.c > +++ b/arch/x86/kvm/svm.c > @@ -4383,9 +4383,9 @@ static void svm_load_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap) > return; > } > > -static void svm_sync_pir_to_irr(struct kvm_vcpu *vcpu) > +static int svm_sync_pir_to_irr(struct kvm_vcpu *vcpu) > { > - return; > + return -1; // XXX > } > > static void svm_deliver_avic_intr(struct kvm_vcpu *vcpu, int vec) > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index f272ccfddc48..2211e1774733 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -8493,17 +8493,15 @@ static void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr) > } > } > > -static void vmx_sync_pir_to_irr(struct kvm_vcpu *vcpu) > +static int vmx_sync_pir_to_irr(struct kvm_vcpu *vcpu) > { > struct vcpu_vmx *vmx = to_vmx(vcpu); > - int max_irr; > > if (!pi_test_on(&vmx->pi_desc)) > return; > > pi_clear_on(&vmx->pi_desc); > - max_irr = kvm_apic_update_irr(vcpu, vmx->pi_desc.pir); > - vmx_hwapic_irr_update(vcpu, max_irr); > + return kvm_apic_update_irr(vcpu, vmx->pi_desc.pir); > } > > static void vmx_apicv_post_state_restore(struct kvm_vcpu *vcpu) > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 20d572c18293..e8789f3a9bfd 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -6675,7 +6675,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) > * notified with kvm_vcpu_kick. > */ > if (vcpu->arch.apicv_active) > - kvm_x86_ops->sync_pir_to_irr(vcpu); > + kvm_x86_ops->hwapic_irr_update(vcpu, kvm_x86_ops->sync_pir_to_irr(vcpu)); > } > > if (vcpu->mode == EXITING_GUEST_MODE || vcpu->requests >