From patchwork Sun Jun 13 12:33:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Har'El X-Patchwork-Id: 105800 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o5DCXPk7029128 for ; Sun, 13 Jun 2010 12:33:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753471Ab0FMMdX (ORCPT ); Sun, 13 Jun 2010 08:33:23 -0400 Received: from mtagate6.de.ibm.com ([195.212.17.166]:59685 "EHLO mtagate6.de.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753443Ab0FMMdX (ORCPT ); Sun, 13 Jun 2010 08:33:23 -0400 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate6.de.ibm.com (8.13.1/8.13.1) with ESMTP id o5DCXMCp011976 for ; Sun, 13 Jun 2010 12:33:22 GMT Received: from d12av01.megacenter.de.ibm.com (d12av01.megacenter.de.ibm.com [9.149.165.212]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o5DCXLdH839762 for ; Sun, 13 Jun 2010 14:33:21 +0200 Received: from d12av01.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av01.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o5DCXLMU005287 for ; Sun, 13 Jun 2010 14:33:21 +0200 Received: from rice.haifa.ibm.com (rice.haifa.ibm.com [9.148.8.205]) by d12av01.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id o5DCXKKi005277 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 13 Jun 2010 14:33:21 +0200 Received: from rice.haifa.ibm.com (lnx-nyh.haifa.ibm.com [127.0.0.1]) by rice.haifa.ibm.com (8.14.4/8.14.4) with ESMTP id o5DCXKck013145; Sun, 13 Jun 2010 15:33:20 +0300 Received: (from nyh@localhost) by rice.haifa.ibm.com (8.14.4/8.14.4/Submit) id o5DCXJqT013143; Sun, 13 Jun 2010 15:33:19 +0300 Date: Sun, 13 Jun 2010 15:33:19 +0300 Message-Id: <201006131233.o5DCXJqT013143@rice.haifa.ibm.com> X-Authentication-Warning: rice.haifa.ibm.com: nyh set sender to "Nadav Har'El" using -f Cc: kvm@vger.kernel.org To: avi@redhat.com From: "Nadav Har'El" References: <1276431753-nyh@il.ibm.com> Subject: [PATCH 21/24] Correct handling of exception injection Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sun, 13 Jun 2010 12:33:25 +0000 (UTC) --- .before/arch/x86/kvm/vmx.c 2010-06-13 15:01:30.000000000 +0300 +++ .after/arch/x86/kvm/vmx.c 2010-06-13 15:01:30.000000000 +0300 @@ -1564,6 +1564,9 @@ static void skip_emulated_instruction(st vmx_set_interrupt_shadow(vcpu, 0); } +static int nested_vmx_check_exception(struct kvm_vcpu *vcpu, unsigned nr, + bool has_error_code, u32 error_code); + static void vmx_queue_exception(struct kvm_vcpu *vcpu, unsigned nr, bool has_error_code, u32 error_code, bool reinject) @@ -1571,6 +1574,9 @@ static void vmx_queue_exception(struct k struct vcpu_vmx *vmx = to_vmx(vcpu); u32 intr_info = nr | INTR_INFO_VALID_MASK; + if (nested_vmx_check_exception(vcpu, nr, has_error_code, error_code)) + return; + if (has_error_code) { vmcs_write32(VM_ENTRY_EXCEPTION_ERROR_CODE, error_code); intr_info |= INTR_INFO_DELIVER_CODE_MASK; @@ -3670,6 +3676,9 @@ static void vmx_inject_nmi(struct kvm_vc { struct vcpu_vmx *vmx = to_vmx(vcpu); + if (vmx->nested.nested_mode) + return; + if (!cpu_has_virtual_nmis()) { /* * Tracking the NMI-blocked state in software is built upon @@ -6513,6 +6522,26 @@ static int nested_vmx_vmexit(struct kvm_ return 0; } +static int nested_vmx_check_exception(struct kvm_vcpu *vcpu, unsigned nr, + bool has_error_code, u32 error_code) +{ + if (!to_vmx(vcpu)->nested.nested_mode) + return 0; + if (!nested_vmx_exit_handled(vcpu, false)) + return 0; + nested_vmx_vmexit(vcpu, false); + if (!nested_map_current(vcpu)) + return 1; + get_shadow_vmcs(vcpu)->vm_exit_reason = EXIT_REASON_EXCEPTION_NMI; + get_shadow_vmcs(vcpu)->vm_exit_intr_info = (nr + | INTR_TYPE_HARD_EXCEPTION | INTR_INFO_VALID_MASK + | (has_error_code ? INTR_INFO_DELIVER_CODE_MASK : 0)); + if (has_error_code) + get_shadow_vmcs(vcpu)->vm_exit_intr_error_code = error_code; + nested_unmap_current(vcpu); + return 1; +} + static struct kvm_x86_ops vmx_x86_ops = { .cpu_has_kvm_support = cpu_has_kvm_support, .disabled_by_bios = vmx_disabled_by_bios,