From patchwork Sun Oct 17 10:15:22 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: 259941 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9HAFSFv019748 for ; Sun, 17 Oct 2010 10:15:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932387Ab0JQKP0 (ORCPT ); Sun, 17 Oct 2010 06:15:26 -0400 Received: from mtagate1.de.ibm.com ([195.212.17.161]:36992 "EHLO mtagate1.de.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932234Ab0JQKPZ (ORCPT ); Sun, 17 Oct 2010 06:15:25 -0400 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate1.de.ibm.com (8.13.1/8.13.1) with ESMTP id o9HAFOxQ002654 for ; Sun, 17 Oct 2010 10:15:24 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o9HAFOEE4124872 for ; Sun, 17 Oct 2010 12:15:24 +0200 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o9HAFNEG001469 for ; Sun, 17 Oct 2010 12:15:24 +0200 Received: from rice.haifa.ibm.com (rice.haifa.ibm.com [9.148.8.112]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id o9HAFMtA001329 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 17 Oct 2010 12:15:23 +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 o9HAFM8e029579; Sun, 17 Oct 2010 12:15:22 +0200 Received: (from nyh@localhost) by rice.haifa.ibm.com (8.14.4/8.14.4/Submit) id o9HAFMMt029577; Sun, 17 Oct 2010 12:15:22 +0200 Date: Sun, 17 Oct 2010 12:15:22 +0200 Message-Id: <201010171015.o9HAFMMt029577@rice.haifa.ibm.com> X-Authentication-Warning: rice.haifa.ibm.com: nyh set sender to "Nadav Har'El" using -f Cc: gleb@redhat.com, avi@redhat.com To: kvm@vger.kernel.org From: "Nadav Har'El" References: <1287309814-nyh@il.ibm.com> Subject: [PATCH 23/27] nVMX: 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 (demeter1.kernel.org [140.211.167.41]); Sun, 17 Oct 2010 10:15:29 +0000 (UTC) --- .before/arch/x86/kvm/vmx.c 2010-10-17 11:52:03.000000000 +0200 +++ .after/arch/x86/kvm/vmx.c 2010-10-17 11:52:03.000000000 +0200 @@ -337,6 +337,10 @@ struct nested_vmx { struct vmcs_fields *vmcs01_fields; /* 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; }; struct vcpu_vmx { @@ -5365,6 +5369,22 @@ static void vmx_cancel_injection(struct vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 0); } +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)) @@ -5386,6 +5406,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(); @@ -5506,6 +5529,15 @@ static void vmx_vcpu_run(struct kvm_vcpu 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); + } + asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS)); vmx->launched = 1;