From patchwork Sun Jun 13 12:33:50 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: 105801 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 o5DCXuiD029223 for ; Sun, 13 Jun 2010 12:33:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753480Ab0FMMdy (ORCPT ); Sun, 13 Jun 2010 08:33:54 -0400 Received: from mtagate5.uk.ibm.com ([194.196.100.165]:42196 "EHLO mtagate5.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753443Ab0FMMdx (ORCPT ); Sun, 13 Jun 2010 08:33:53 -0400 Received: from d06nrmr1707.portsmouth.uk.ibm.com (d06nrmr1707.portsmouth.uk.ibm.com [9.149.39.225]) by mtagate5.uk.ibm.com (8.13.1/8.13.1) with ESMTP id o5DCXqSG024298 for ; Sun, 13 Jun 2010 12:33:52 GMT Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o5DCXqfD1364034 for ; Sun, 13 Jun 2010 13:33:52 +0100 Received: from d06av01.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o5DCXqfi000893 for ; Sun, 13 Jun 2010 13:33:52 +0100 Received: from rice.haifa.ibm.com (rice.haifa.ibm.com [9.148.8.205]) by d06av01.portsmouth.uk.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id o5DCXpqU000886 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 13 Jun 2010 13:33:51 +0100 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 o5DCXolH013159; Sun, 13 Jun 2010 15:33:50 +0300 Received: (from nyh@localhost) by rice.haifa.ibm.com (8.14.4/8.14.4/Submit) id o5DCXoel013156; Sun, 13 Jun 2010 15:33:50 +0300 Date: Sun, 13 Jun 2010 15:33:50 +0300 Message-Id: <201006131233.o5DCXoel013156@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 22/24] Correct handling of idt vectoring info 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:56 +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 @@ -320,6 +320,10 @@ struct nested_vmx { struct vmcs *l1_vmcs; /* L2 must run next, and mustn't decide to exit to L1. */ bool nested_run_pending; + /* true if last exit was of L2, and had a valid idt_vectoring_info */ + bool valid_idt_vectoring_info; + /* These are saved if valid_idt_vectoring_info */ + u32 vm_exit_instruction_len, idt_vectoring_error_code; }; enum vmcs_field_type { @@ -5460,6 +5464,22 @@ static void fixup_rmode_irq(struct vcpu_ | vmx->rmode.irq.vector; } +static void nested_handle_valid_idt_vectoring_info(struct vcpu_vmx *vmx) +{ + int irq = vmx->idt_vectoring_info & VECTORING_INFO_VECTOR_MASK; + int type = vmx->idt_vectoring_info & VECTORING_INFO_TYPE_MASK; + int errCodeValid = vmx->idt_vectoring_info & + VECTORING_INFO_DELIVER_CODE_MASK; + vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, + irq | type | INTR_INFO_VALID_MASK | errCodeValid); + + vmcs_write32(VM_ENTRY_INSTRUCTION_LEN, + vmx->nested.vm_exit_instruction_len); + if (errCodeValid) + vmcs_write32(VM_ENTRY_EXCEPTION_ERROR_CODE, + vmx->nested.idt_vectoring_error_code); +} + static inline void sync_cached_regs_to_vmcs(struct kvm_vcpu *vcpu) { if (test_bit(VCPU_REGS_RSP, (unsigned long *)&vcpu->arch.regs_dirty)) @@ -5481,6 +5501,9 @@ static void vmx_vcpu_run(struct kvm_vcpu { struct vcpu_vmx *vmx = to_vmx(vcpu); + if (vmx->nested.nested_mode && vmx->nested.valid_idt_vectoring_info) + nested_handle_valid_idt_vectoring_info(vmx); + /* Record the guest's net vcpu time for enforced NMI injections. */ if (unlikely(!cpu_has_virtual_nmis() && vmx->soft_vnmi_blocked)) vmx->entry_time = ktime_get(); @@ -5600,6 +5623,16 @@ static void vmx_vcpu_run(struct kvm_vcpu | (1 << VCPU_EXREG_PDPTR)); vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD); + + vmx->nested.valid_idt_vectoring_info = vmx->nested.nested_mode && + (vmx->idt_vectoring_info & VECTORING_INFO_VALID_MASK); + if (vmx->nested.valid_idt_vectoring_info) { + vmx->nested.vm_exit_instruction_len = + vmcs_read32(VM_EXIT_INSTRUCTION_LEN); + vmx->nested.idt_vectoring_error_code = + vmcs_read32(IDT_VECTORING_ERROR_CODE); + } + if (vmx->rmode.irq.pending) fixup_rmode_irq(vmx);