From patchwork Fri Mar 15 13:31:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Yang Z" X-Patchwork-Id: 2277731 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 8EE49E00E6 for ; Fri, 15 Mar 2013 13:35:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755349Ab3CONfZ (ORCPT ); Fri, 15 Mar 2013 09:35:25 -0400 Received: from mga02.intel.com ([134.134.136.20]:40929 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755268Ab3CONfY (ORCPT ); Fri, 15 Mar 2013 09:35:24 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 15 Mar 2013 06:35:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.84,850,1355126400"; d="scan'208";a="280001289" Received: from yang-desktop.sh.intel.com ([10.239.13.6]) by orsmga001.jf.intel.com with ESMTP; 15 Mar 2013 06:35:22 -0700 From: Yang Zhang To: kvm@vger.kernel.org Cc: gleb@redhat.com, mtosatti@redhat.com, xiantao.zhang@intel.com, Yang Zhang Subject: [PATCH v6 5/5] KVM : VMX: Use posted interrupt to deliver virtual interrupt Date: Fri, 15 Mar 2013 21:31:11 +0800 Message-Id: <1363354271-25302-6-git-send-email-yang.z.zhang@intel.com> X-Mailer: git-send-email 1.7.1.1 In-Reply-To: <1363354271-25302-1-git-send-email-yang.z.zhang@intel.com> References: <1363354271-25302-1-git-send-email-yang.z.zhang@intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Yang Zhang If posted interrupt is avaliable, then uses it to inject virtual interrupt to guest. Signed-off-by: Yang Zhang --- arch/x86/kvm/irq.c | 3 ++- arch/x86/kvm/lapic.c | 16 +++++++++++++--- arch/x86/kvm/lapic.h | 1 + arch/x86/kvm/vmx.c | 11 +++++++++++ arch/x86/kvm/x86.c | 4 ++++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/irq.c b/arch/x86/kvm/irq.c index 484bc87..5179988 100644 --- a/arch/x86/kvm/irq.c +++ b/arch/x86/kvm/irq.c @@ -81,7 +81,8 @@ int kvm_cpu_has_interrupt(struct kvm_vcpu *v) if (kvm_cpu_has_extint(v)) return 1; - return kvm_apic_has_interrupt(v) != -1; /* LAPIC */ + return (kvm_apic_has_interrupt(v) != -1) || + kvm_hwapic_has_interrupt(v); } EXPORT_SYMBOL_GPL(kvm_cpu_has_interrupt); diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index b3ea50e..46c7310 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -713,7 +713,10 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, } else apic_clear_vector(vector, apic->regs + APIC_TMR); - result = !apic_test_and_set_irr(vector, apic); + result = 1; + if (!kvm_x86_ops->deliver_posted_interrupt(vcpu, vector)) + result = !apic_test_and_set_irr(vector, apic); + trace_kvm_apic_accept_irq(vcpu->vcpu_id, delivery_mode, trig_mode, vector, !result); if (!result) { @@ -723,8 +726,10 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, break; } - kvm_make_request(KVM_REQ_EVENT, vcpu); - kvm_vcpu_kick(vcpu); + if (!kvm_x86_ops->vm_has_apicv(vcpu->kvm)) { + kvm_make_request(KVM_REQ_EVENT, vcpu); + kvm_vcpu_kick(vcpu); + } break; case APIC_DM_REMRD: @@ -1604,6 +1609,11 @@ int kvm_apic_has_interrupt(struct kvm_vcpu *vcpu) return highest_irr; } +bool kvm_hwapic_has_interrupt(struct kvm_vcpu *vcpu) +{ + return kvm_x86_ops->hwapic_has_interrupt(vcpu); +} + int kvm_apic_accept_pic_intr(struct kvm_vcpu *vcpu) { u32 lvt0 = kvm_apic_get_reg(vcpu->arch.apic, APIC_LVT0); diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index e5327be..c6abc63 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -37,6 +37,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu); void kvm_free_lapic(struct kvm_vcpu *vcpu); int kvm_apic_has_interrupt(struct kvm_vcpu *vcpu); +bool kvm_hwapic_has_interrupt(struct kvm_vcpu *vcpu); int kvm_apic_accept_pic_intr(struct kvm_vcpu *vcpu); int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu); void kvm_lapic_reset(struct kvm_vcpu *vcpu); diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 0b5a8ae..48a2239 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -3932,6 +3932,17 @@ static void vmx_posted_intr_clear_on(struct kvm_vcpu *vcpu) clear_bit(POSTED_INTR_ON, (unsigned long *)&vmx->pi_desc.u.control); } +/* + * Send interrupt to vcpu via posted interrupt way. + * Return false if posted interrupt is not supported and the caller will + * roll back to old way(via set vIRR). + * Return true if posted interrupt is avalialbe, the interrupt is set + * in pir(posted interrupt requests): + * 1. If target vcpu is running(non-root mode), send posted interrupt + * notification to vcpu and hardware will sync pir to vIRR atomically. + * 2. If target vcpu isn't running(root mode), kick it to pick up the + * interrupt from pir in next vmentry. + */ static bool vmx_deliver_posted_interrupt(struct kvm_vcpu *vcpu, int vector) { struct vcpu_vmx *vmx = to_vmx(vcpu); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 0baa90d..0981100 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2679,6 +2679,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) static int kvm_vcpu_ioctl_get_lapic(struct kvm_vcpu *vcpu, struct kvm_lapic_state *s) { + kvm_x86_ops->sync_pir_to_irr(vcpu); memcpy(s->regs, vcpu->arch.apic->regs, sizeof *s); return 0; @@ -5699,6 +5700,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) } if (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win) { + kvm_x86_ops->sync_pir_to_irr(vcpu); inject_pending_event(vcpu); /* enable NMI/IRQ window open exits if needed */ @@ -5741,6 +5743,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) local_irq_disable(); + kvm_x86_ops->posted_intr_clear_on(vcpu); + if (vcpu->mode == EXITING_GUEST_MODE || vcpu->requests || need_resched() || signal_pending(current)) { vcpu->mode = OUTSIDE_GUEST_MODE;