Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757777AbcKCPEC (ORCPT ); Thu, 3 Nov 2016 11:04:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45418 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755897AbcKCPEB (ORCPT ); Thu, 3 Nov 2016 11:04:01 -0400 Date: Thu, 3 Nov 2016 16:03:57 +0100 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, yang.zhang.wz@gmail.com, feng.wu@intel.com, mst@redhat.com Subject: Re: [PATCH 2/5] KVM: x86: do not scan IRR twice on APICv vmentry Message-ID: <20161103150356.GE7771@potion> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <00273a1a-ef5d-f814-3e02-24b4e855d229@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 03 Nov 2016 15:04:00 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3041 Lines: 84 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? 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