From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: [PATCH 9/11] VMX: Provide support for user space injected NMIs Date: Tue, 23 Sep 2008 17:42:55 +0200 Message-ID: <48D90E7F.2020001@siemens.com> References: <48D74CE6.5060008@siemens.com> <48D75046.8020800@siemens.com> <200809231428.58933.sheng.yang@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Cc: kvm-devel , Avi Kivity , Gleb Natapov To: "Yang, Sheng" Return-path: Received: from lizzard.sbs.de ([194.138.37.39]:22134 "EHLO lizzard.sbs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751388AbYIWPnO (ORCPT ); Tue, 23 Sep 2008 11:43:14 -0400 In-Reply-To: <200809231428.58933.sheng.yang@intel.com> Sender: kvm-owner@vger.kernel.org List-ID: Yang, Sheng wrote: > On Monday 22 September 2008 15:59:02 Jan Kiszka wrote: >> This patch adds the required bits to the VMX side for user space >> injected NMIs. As with the preexisting in-kernel irqchip support, the >> CPU must provide the "virtual NMI" feature for proper tracking of the >> NMI blocking state. >> >> Based on the original patch by Sheng Yang. >> >> Signed-off-by: Jan Kiszka >> --- >> arch/x86/kvm/vmx.c | 33 +++++++++++++++++++++++++++++++++ >> 1 file changed, 33 insertions(+) >> >> Index: b/arch/x86/kvm/vmx.c >> =================================================================== >> --- a/arch/x86/kvm/vmx.c >> +++ b/arch/x86/kvm/vmx.c >> @@ -2356,6 +2356,7 @@ static void vmx_inject_nmi(struct kvm_vc >> { >> struct vcpu_vmx *vmx = to_vmx(vcpu); >> >> + ++vcpu->stat.nmi_injections; >> if (vcpu->arch.rmode.active) { >> vmx->rmode.irq.pending = true; >> vmx->rmode.irq.vector = NMI_VECTOR; >> @@ -2424,6 +2425,30 @@ static void do_interrupt_requests(struct >> { >> vmx_update_window_states(vcpu); >> >> + if (cpu_has_virtual_nmis()) { >> + if (vcpu->arch.nmi_pending && !vcpu->arch.nmi_injected) { >> + 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 >> + || kvm_run->request_nmi_window) >> + enable_nmi_window(vcpu); >> + else if (vcpu->arch.irq_summary >> + || kvm_run->request_interrupt_window) >> + enable_irq_window(vcpu); >> + return; >> + } >> + if (!vcpu->arch.nmi_window_open || >> kvm_run->request_nmi_window) + >> enable_nmi_window(vcpu); >> + } >> + >> if (vcpu->arch.interrupt_window_open) { >> if (vcpu->arch.irq_summary && >> !vcpu->arch.interrupt.pending) kvm_do_inject_irq(vcpu); >> @@ -2936,6 +2961,14 @@ static int handle_nmi_window(struct kvm_ >> vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control); >> ++vcpu->stat.nmi_window_exits; >> >> + /* >> + * If the user space waits to inject a NNI, exit as soon as >> possible + */ > > o... found a typo :) Fatal! Fixed-up version below. --------- This patch adds the required bits to the VMX side for user space injected NMIs. As with the preexisting in-kernel irqchip support, the CPU must provide the "virtual NMI" feature for proper tracking of the NMI blocking state. Based on the original patch by Sheng Yang. Signed-off-by: Jan Kiszka --- arch/x86/kvm/vmx.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) Index: b/arch/x86/kvm/vmx.c =================================================================== --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2356,6 +2356,7 @@ static void vmx_inject_nmi(struct kvm_vc { struct vcpu_vmx *vmx = to_vmx(vcpu); + ++vcpu->stat.nmi_injections; if (vcpu->arch.rmode.active) { vmx->rmode.irq.pending = true; vmx->rmode.irq.vector = NMI_VECTOR; @@ -2424,6 +2425,30 @@ static void do_interrupt_requests(struct { vmx_update_window_states(vcpu); + if (cpu_has_virtual_nmis()) { + if (vcpu->arch.nmi_pending && !vcpu->arch.nmi_injected) { + 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 + || kvm_run->request_nmi_window) + enable_nmi_window(vcpu); + else if (vcpu->arch.irq_summary + || kvm_run->request_interrupt_window) + enable_irq_window(vcpu); + return; + } + if (!vcpu->arch.nmi_window_open || kvm_run->request_nmi_window) + enable_nmi_window(vcpu); + } + if (vcpu->arch.interrupt_window_open) { if (vcpu->arch.irq_summary && !vcpu->arch.interrupt.pending) kvm_do_inject_irq(vcpu); @@ -2936,6 +2961,14 @@ static int handle_nmi_window(struct kvm_ vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control); ++vcpu->stat.nmi_window_exits; + /* + * If the user space waits to inject a NMI, exit as soon as possible + */ + if (kvm_run->request_nmi_window && !vcpu->arch.nmi_pending) { + kvm_run->exit_reason = KVM_EXIT_NMI_WINDOW_OPEN; + return 0; + } + return 1; }