All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: kvm@vger.kernel.org
Subject: [PATCH 42/46] KVM: VMX: Consolidate userspace and kernel interrupt injection for VMX
Date: Wed, 20 May 2009 14:18:39 +0300	[thread overview]
Message-ID: <1242818323-10413-43-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1242818323-10413-1-git-send-email-avi@redhat.com>

From: Gleb Natapov <gleb@redhat.com>

Use the same callback to inject irq/nmi events no matter what irqchip is
in use. Only from VMX for now.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
---
 arch/x86/include/asm/kvm_host.h |    2 +-
 arch/x86/kvm/svm.c              |    2 +-
 arch/x86/kvm/vmx.c              |   71 +++++++++------------------------------
 arch/x86/kvm/x86.c              |    2 +-
 4 files changed, 19 insertions(+), 58 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index cb306cf..5edae35 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -517,7 +517,7 @@ struct kvm_x86_ops {
 	void (*queue_exception)(struct kvm_vcpu *vcpu, unsigned nr,
 				bool has_error_code, u32 error_code);
 	bool (*exception_injected)(struct kvm_vcpu *vcpu);
-	void (*inject_pending_irq)(struct kvm_vcpu *vcpu);
+	void (*inject_pending_irq)(struct kvm_vcpu *vcpu, struct kvm_run *run);
 	void (*inject_pending_vectors)(struct kvm_vcpu *vcpu,
 				       struct kvm_run *run);
 	int (*interrupt_allowed)(struct kvm_vcpu *vcpu);
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 6eef6d2..f2933ab 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -2298,7 +2298,7 @@ static int svm_interrupt_allowed(struct kvm_vcpu *vcpu)
 		(svm->vcpu.arch.hflags & HF_GIF_MASK);
 }
 
-static void svm_intr_assist(struct kvm_vcpu *vcpu)
+static void svm_intr_assist(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 {
 	struct vcpu_svm *svm = to_svm(vcpu);
 	struct vmcb *vmcb = svm->vmcb;
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index b3292c1..06252f7 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2510,48 +2510,6 @@ static int vmx_interrupt_allowed(struct kvm_vcpu *vcpu)
 	return vcpu->arch.interrupt_window_open;
 }
 
-static void do_interrupt_requests(struct kvm_vcpu *vcpu,
-				       struct kvm_run *kvm_run)
-{
-	vmx_update_window_states(vcpu);
-
-	if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
-		vmcs_clear_bits(GUEST_INTERRUPTIBILITY_INFO,
-				GUEST_INTR_STATE_STI |
-				GUEST_INTR_STATE_MOV_SS);
-
-	if (vcpu->arch.nmi_pending && !vcpu->arch.nmi_injected) {
-		if (vcpu->arch.interrupt.pending) {
-			enable_nmi_window(vcpu);
-		} else if (vcpu->arch.nmi_window_open) {
-			vcpu->arch.nmi_pending = false;
-			vcpu->arch.nmi_injected = true;
-		} else {
-			enable_nmi_window(vcpu);
-			return;
-		}
-	}
-	if (vcpu->arch.nmi_injected) {
-		vmx_inject_nmi(vcpu);
-		if (vcpu->arch.nmi_pending)
-			enable_nmi_window(vcpu);
-		else if (kvm_cpu_has_interrupt(vcpu) ||
-			 kvm_run->request_interrupt_window)
-			enable_irq_window(vcpu);
-		return;
-	}
-
-	if (vcpu->arch.interrupt_window_open) {
-		if (kvm_cpu_has_interrupt(vcpu) && !vcpu->arch.interrupt.pending)
-			kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu));
-
-		if (vcpu->arch.interrupt.pending)
-			vmx_inject_irq(vcpu, vcpu->arch.interrupt.nr);
-	} else if(kvm_cpu_has_interrupt(vcpu) ||
-		  kvm_run->request_interrupt_window)
-		enable_irq_window(vcpu);
-}
-
 static int vmx_set_tss_addr(struct kvm *kvm, unsigned int addr)
 {
 	int ret;
@@ -3351,8 +3309,11 @@ static void vmx_complete_interrupts(struct vcpu_vmx *vmx)
 	}
 }
 
-static void vmx_intr_assist(struct kvm_vcpu *vcpu)
+static void vmx_intr_assist(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 {
+	bool req_int_win = !irqchip_in_kernel(vcpu->kvm) &&
+		kvm_run->request_interrupt_window;
+
 	update_tpr_threshold(vcpu);
 
 	vmx_update_window_states(vcpu);
@@ -3373,25 +3334,25 @@ static void vmx_intr_assist(struct kvm_vcpu *vcpu)
 			return;
 		}
 	}
+
 	if (vcpu->arch.nmi_injected) {
 		vmx_inject_nmi(vcpu);
-		if (vcpu->arch.nmi_pending)
-			enable_nmi_window(vcpu);
-		else if (kvm_cpu_has_interrupt(vcpu))
-			enable_irq_window(vcpu);
-		return;
+		goto out;
 	}
+
 	if (!vcpu->arch.interrupt.pending && kvm_cpu_has_interrupt(vcpu)) {
 		if (vcpu->arch.interrupt_window_open)
 			kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu));
-		else
-			enable_irq_window(vcpu);
 	}
-	if (vcpu->arch.interrupt.pending) {
+
+	if (vcpu->arch.interrupt.pending)
 		vmx_inject_irq(vcpu, vcpu->arch.interrupt.nr);
-		if (kvm_cpu_has_interrupt(vcpu))
-			enable_irq_window(vcpu);
-	}
+
+out:
+	if (vcpu->arch.nmi_pending)
+		enable_nmi_window(vcpu);
+	else if (kvm_cpu_has_interrupt(vcpu) || req_int_win)
+		enable_irq_window(vcpu);
 }
 
 /*
@@ -3733,7 +3694,7 @@ static struct kvm_x86_ops vmx_x86_ops = {
 	.queue_exception = vmx_queue_exception,
 	.exception_injected = vmx_exception_injected,
 	.inject_pending_irq = vmx_intr_assist,
-	.inject_pending_vectors = do_interrupt_requests,
+	.inject_pending_vectors = vmx_intr_assist,
 	.interrupt_allowed = vmx_interrupt_allowed,
 	.set_tss_addr = vmx_set_tss_addr,
 	.get_tdp_level = get_ept_level,
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0c9c13c..7a572ec 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3169,7 +3169,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 	if (vcpu->arch.exception.pending)
 		__queue_exception(vcpu);
 	else if (irqchip_in_kernel(vcpu->kvm))
-		kvm_x86_ops->inject_pending_irq(vcpu);
+		kvm_x86_ops->inject_pending_irq(vcpu, kvm_run);
 	else
 		kvm_x86_ops->inject_pending_vectors(vcpu, kvm_run);
 
-- 
1.6.0.6


  parent reply	other threads:[~2009-05-20 11:23 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-20 11:17 [PATCH 00/46] KVM updates for the 2.6.31 merge window (batch 2/3) Avi Kivity
2009-05-20 11:17 ` [PATCH 01/46] KVM: VMX: Make flexpriority module parameter reflect hardware capability Avi Kivity
2009-05-20 11:17 ` [PATCH 02/46] KVM: VMX: Correct wrong vmcs field sizes Avi Kivity
2009-05-20 11:18 ` [PATCH 03/46] KVM: MMU: Fix comment in page_fault() Avi Kivity
2009-05-20 11:18 ` [PATCH 04/46] KVM: ia64: enable external interrupt in vmm Avi Kivity
2009-05-20 11:18 ` [PATCH 05/46] KVM: MMU: Emulate #PF error code of reserved bits violation Avi Kivity
2009-05-20 11:18 ` [PATCH 06/46] KVM: MMU: Use different shadows when EFER.NXE changes Avi Kivity
2009-05-20 11:18 ` [PATCH 07/46] KVM: remove pointless conditional before kfree() in lapic initialization Avi Kivity
2009-05-20 11:18 ` [PATCH 08/46] KVM: VMX: Clean up Flex Priority related Avi Kivity
2009-05-20 11:18 ` [PATCH 09/46] KVM: VMX: Fix feature testing Avi Kivity
2009-05-20 11:18 ` [PATCH 10/46] KVM: Use rsvd_bits_mask in load_pdptrs() Avi Kivity
2009-05-20 11:18 ` [PATCH 11/46] KVM: VMX: Fix handling of a fault during NMI unblocked due to IRET Avi Kivity
2009-05-20 11:18 ` [PATCH 12/46] KVM: VMX: Rewrite vmx_complete_interrupt()'s twisted maze of if() statements Avi Kivity
2009-05-20 11:18 ` [PATCH 13/46] KVM: VMX: Do not zero idt_vectoring_info in vmx_complete_interrupts() Avi Kivity
2009-05-20 11:18 ` [PATCH 14/46] KVM: Fix task switch back link handling Avi Kivity
2009-05-20 11:18 ` [PATCH 15/46] KVM: Fix unneeded instruction skipping during task switching Avi Kivity
2009-05-20 11:18 ` [PATCH 16/46] KVM: MMU: Discard reserved bits checking on PDE bit 7-8 Avi Kivity
2009-05-20 11:18 ` [PATCH 17/46] KVM: x86 emulator: fix call near emulation Avi Kivity
2009-05-20 11:18 ` [PATCH 18/46] KVM: ia64: make kvm depend on CONFIG_MODULES Avi Kivity
2009-05-20 11:18 ` [PATCH 19/46] KVM: PIT: fix count read and mode 0 handling Avi Kivity
2009-05-20 11:18 ` [PATCH 20/46] KVM: Make kvm header C++ friendly Avi Kivity
2009-05-20 11:18 ` [PATCH 21/46] KVM: MMU: remove global page optimization logic Avi Kivity
2009-05-20 11:18 ` [PATCH 22/46] KVM: x86 emulator: Add decoding of 16bit second immediate argument Avi Kivity
2009-05-20 11:18 ` [PATCH 23/46] KVM: x86 emulator: Add lcall decoding Avi Kivity
2009-05-20 11:18 ` [PATCH 24/46] KVM: x86 emulator: Complete ljmp decoding at decode stage Avi Kivity
2009-05-20 11:18 ` [PATCH 25/46] KVM: x86 emulator: Complete short/near jcc decoding in " Avi Kivity
2009-05-20 11:18 ` [PATCH 26/46] KVM: x86 emulator: Complete decoding of call near " Avi Kivity
2009-05-20 11:18 ` [PATCH 27/46] KVM: x86 emulator: Add unsigned byte immediate decode Avi Kivity
2009-05-20 11:18 ` [PATCH 28/46] KVM: x86 emulator: Completely decode in/out at decoding stage Avi Kivity
2009-05-20 11:18 ` [PATCH 29/46] KVM: x86 emulator: Decode soft interrupt instructions Avi Kivity
2009-05-20 11:18 ` [PATCH 30/46] KVM: x86 emulator: Add new mode of instruction emulation: skip Avi Kivity
2009-05-20 11:18 ` [PATCH 31/46] KVM: SVM: Skip instruction on a task switch only when appropriate Avi Kivity
2009-05-20 11:18 ` [PATCH 32/46] KVM: Replace kvmclock open-coded get_cpu_var() with the real thing Avi Kivity
2009-05-20 11:18 ` [PATCH 33/46] KVM: ia64: Don't hold slots_lock in guest mode Avi Kivity
2009-05-20 11:18 ` [PATCH 34/46] KVM: x86: check for cr3 validity in ioctl_set_sregs Avi Kivity
2009-05-20 11:18 ` [PATCH 35/46] KVM: ia64: Flush all TLBs once guest's memory mapping changes Avi Kivity
2009-05-20 11:18 ` [PATCH 36/46] KVM: ia64: remove empty function vti_vcpu_load() Avi Kivity
2009-05-20 11:18 ` [PATCH 37/46] KVM: ia64: restore irq state before calling kvm_vcpu_init Avi Kivity
2009-05-20 11:18 ` [PATCH 38/46] KVM: ia64: preserve int status through call to kvm_insert_vmm_mapping Avi Kivity
2009-05-20 11:18 ` [PATCH 39/46] KVM: ia64: ia64 vcpu_reset() do not call kmalloc() with irqs disabled Avi Kivity
2009-05-20 11:18 ` [PATCH 40/46] KVM: MMU: Fix auditing code Avi Kivity
2009-05-20 11:18 ` [PATCH 41/46] KVM: Make kvm_cpu_(has|get)_interrupt() work for userspace irqchip too Avi Kivity
2009-05-20 11:18 ` Avi Kivity [this message]
2009-05-20 11:18 ` [PATCH 43/46] KVM: VMX: Cleanup vmx_intr_assist() Avi Kivity
2009-05-20 11:18 ` [PATCH 44/46] KVM: Use kvm_arch_interrupt_allowed() instead of checking interrupt_window_open directly Avi Kivity
2009-05-20 11:18 ` [PATCH 45/46] KVM: SVM: Coalesce userspace/kernel irqchip interrupt injection logic Avi Kivity
2009-05-20 11:18 ` [PATCH 46/46] KVM: Remove exception_injected() callback Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1242818323-10413-43-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.