kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: kvm-devel <kvm@vger.kernel.org>
Cc: "Yang, Sheng" <sheng.yang@intel.com>, Avi Kivity <avi@redhat.com>,
	Gleb Natapov <gleb@qumranet.com>
Subject: [PATCH 3/11] VMX: refactor IRQ and NMI window enabling
Date: Mon, 22 Sep 2008 09:58:26 +0200	[thread overview]
Message-ID: <48D75022.9020602@siemens.com> (raw)
In-Reply-To: <48D74CE6.5060008@siemens.com>

do_interrupt_requests and vmx_intr_assist go different way for
achieving the same: enabling the nmi/irq window start notification.
Unify their code over enable_{irq|nmi}_window, get rid of a redundant
call to enable_intr_window instead of direct enable_nmi_window
invocation and unroll enable_intr_window for both in-kernel and user
space irq injection accordingly.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 arch/x86/kvm/vmx.c |   78 +++++++++++++++++++++--------------------------------
 1 file changed, 32 insertions(+), 46 deletions(-)

Index: b/arch/x86/kvm/vmx.c
===================================================================
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2385,30 +2385,42 @@ static void kvm_do_inject_irq(struct kvm
 	kvm_queue_interrupt(vcpu, irq);
 }
 
-static void do_interrupt_requests(struct kvm_vcpu *vcpu,
-				       struct kvm_run *kvm_run)
+static void enable_irq_window(struct kvm_vcpu *vcpu)
 {
 	u32 cpu_based_vm_exec_control;
 
-	vmx_update_window_states(vcpu);
+	cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
+	cpu_based_vm_exec_control |= CPU_BASED_VIRTUAL_INTR_PENDING;
+	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
+}
 
-	if (vcpu->arch.interrupt_window_open &&
-	    vcpu->arch.irq_summary && !vcpu->arch.interrupt.pending)
-		kvm_do_inject_irq(vcpu);
+static void enable_nmi_window(struct kvm_vcpu *vcpu)
+{
+	u32 cpu_based_vm_exec_control;
 
-	if (vcpu->arch.interrupt_window_open && vcpu->arch.interrupt.pending)
-		vmx_inject_irq(vcpu, vcpu->arch.interrupt.nr);
+	if (!cpu_has_virtual_nmis())
+		return;
 
 	cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
+	cpu_based_vm_exec_control |= CPU_BASED_VIRTUAL_NMI_PENDING;
+	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
+}
+
+static void do_interrupt_requests(struct kvm_vcpu *vcpu,
+				       struct kvm_run *kvm_run)
+{
+	vmx_update_window_states(vcpu);
+
+	if (vcpu->arch.interrupt_window_open) {
+		if (vcpu->arch.irq_summary && !vcpu->arch.interrupt.pending)
+			kvm_do_inject_irq(vcpu);
+
+		if (vcpu->arch.interrupt.pending)
+			vmx_inject_irq(vcpu, vcpu->arch.interrupt.nr);
+	}
 	if (!vcpu->arch.interrupt_window_open &&
 	    (vcpu->arch.irq_summary || kvm_run->request_interrupt_window))
-		/*
-		 * Interrupts blocked.  Wait for unblock.
-		 */
-		cpu_based_vm_exec_control |= CPU_BASED_VIRTUAL_INTR_PENDING;
-	else
-		cpu_based_vm_exec_control &= ~CPU_BASED_VIRTUAL_INTR_PENDING;
-	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
+		enable_irq_window(vcpu);
 }
 
 static int vmx_set_tss_addr(struct kvm *kvm, unsigned int addr)
@@ -3040,35 +3052,6 @@ static void update_tpr_threshold(struct
 	vmcs_write32(TPR_THRESHOLD, (max_irr > tpr) ? tpr >> 4 : max_irr >> 4);
 }
 
-static void enable_irq_window(struct kvm_vcpu *vcpu)
-{
-	u32 cpu_based_vm_exec_control;
-
-	cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
-	cpu_based_vm_exec_control |= CPU_BASED_VIRTUAL_INTR_PENDING;
-	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
-}
-
-static void enable_nmi_window(struct kvm_vcpu *vcpu)
-{
-	u32 cpu_based_vm_exec_control;
-
-	if (!cpu_has_virtual_nmis())
-		return;
-
-	cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
-	cpu_based_vm_exec_control |= CPU_BASED_VIRTUAL_NMI_PENDING;
-	vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
-}
-
-static void enable_intr_window(struct kvm_vcpu *vcpu)
-{
-	if (vcpu->arch.nmi_pending)
-		enable_nmi_window(vcpu);
-	else if (kvm_cpu_has_interrupt(vcpu))
-		enable_irq_window(vcpu);
-}
-
 static void vmx_complete_interrupts(struct vcpu_vmx *vmx)
 {
 	u32 exit_intr_info;
@@ -3137,13 +3120,16 @@ static void vmx_intr_assist(struct kvm_v
 				vcpu->arch.nmi_pending = false;
 				vcpu->arch.nmi_injected = true;
 			} else {
-				enable_intr_window(vcpu);
+				enable_nmi_window(vcpu);
 				return;
 			}
 		}
 		if (vcpu->arch.nmi_injected) {
 			vmx_inject_nmi(vcpu);
-			enable_intr_window(vcpu);
+			if (vcpu->arch.nmi_pending)
+				enable_nmi_window(vcpu);
+			else if (kvm_cpu_has_interrupt(vcpu))
+				enable_irq_window(vcpu);
 			return;
 		}
 	}


  parent reply	other threads:[~2008-09-22  8:03 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-22  7:44 [PATCH 0/11] Fix&Enhance NMI support for KVM - v3 Jan Kiszka
2008-09-22  7:58 ` [PATCH 1/11] VMX: include all IRQ window exits in statistics Jan Kiszka
2008-09-22  7:58 ` [PATCH 2/11] VMX: refactor/fix IRQ and NMI injectability determination Jan Kiszka
2008-09-22  7:58 ` Jan Kiszka [this message]
2008-09-22  7:58 ` [PATCH 5/11] kvm-x86: Enable NMI Watchdog via in-kernel PIT source Jan Kiszka
2008-09-22  7:58 ` [PATCH 6/11] kvm-x86: VCPU with pending NMI is runnabled Jan Kiszka
2008-09-22  7:58 ` [PATCH 7/11] kvm: kick NMI receiving VCPU Jan Kiszka
2008-09-22  7:58 ` [PATCH 8/11] kvm-x86: Support for user space injected NMIs Jan Kiszka
2008-09-22  7:59 ` [PATCH 9/11] VMX: Provide support " Jan Kiszka
2008-09-23  6:28   ` Yang, Sheng
2008-09-23 15:42     ` Jan Kiszka
2008-09-22  7:59 ` [PATCH 10/11] VMX: work around lacking VNMI support Jan Kiszka
2008-09-22 14:15   ` Gleb Natapov
2008-09-23  8:46     ` Jan Kiszka
2008-09-23  8:50       ` Gleb Natapov
2008-09-23  8:57         ` Jan Kiszka
2008-09-23  9:00           ` Gleb Natapov
2008-09-23  9:08             ` Yang, Sheng
2008-09-23  9:15               ` Gleb Natapov
2008-09-23  9:24                 ` Yang, Sheng
2008-09-23  9:26                   ` Gleb Natapov
2008-09-23  9:37                     ` Yang, Sheng
2008-09-23  9:42                       ` Yang, Sheng
2008-09-23  9:45                         ` Gleb Natapov
2008-09-23  9:50                           ` Yang, Sheng
2008-09-24 12:40                             ` Jan Kiszka
2008-09-24 12:44                               ` Avi Kivity
2008-09-24 12:50                               ` Gleb Natapov
2008-09-24 12:56                                 ` Jan Kiszka
2008-09-24 13:02                                   ` Gleb Natapov
2008-09-24 13:08                                     ` Jan Kiszka
2008-09-24 13:24                                       ` Gleb Natapov
2008-09-24 13:33                                         ` Jan Kiszka
2008-09-24 13:35                                           ` Gleb Natapov
2008-09-24 13:35                                           ` Avi Kivity
2008-09-24 14:07                                         ` Jan Kiszka
2008-09-24 14:19                                           ` Avi Kivity
2008-09-24 13:11                                     ` Jan Kiszka
2008-09-24 13:17                                       ` Gleb Natapov
2008-09-24 13:20                                         ` Gleb Natapov
2008-09-24 13:39                                           ` Jan Kiszka
2008-09-24 14:48                                     ` Gleb Natapov
2008-09-23  9:27                 ` Yang, Sheng
2008-09-23 15:15               ` Jan Kiszka
2008-09-25  9:41   ` Jan Kiszka
2008-09-25 10:31     ` Avi Kivity
2008-09-25 14:22       ` Jan Kiszka
2008-09-27 10:57         ` Avi Kivity
2008-09-22  7:59 ` [PATCH 11/11] kvm: Enable NMI support for userspace irqchip Jan Kiszka
2008-09-22  8:00 ` [PATCH 4/11] VMX: fix real-mode NMI support Jan Kiszka

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=48D75022.9020602@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=avi@redhat.com \
    --cc=gleb@qumranet.com \
    --cc=kvm@vger.kernel.org \
    --cc=sheng.yang@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).