From patchwork Sun Jun 13 12:27:10 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: 105788 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 o5DCRJhk027308 for ; Sun, 13 Jun 2010 12:27:19 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752895Ab0FMM1R (ORCPT ); Sun, 13 Jun 2010 08:27:17 -0400 Received: from mtagate3.uk.ibm.com ([194.196.100.163]:58737 "EHLO mtagate3.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751050Ab0FMM1Q (ORCPT ); Sun, 13 Jun 2010 08:27:16 -0400 Received: from d06nrmr1407.portsmouth.uk.ibm.com (d06nrmr1407.portsmouth.uk.ibm.com [9.149.38.185]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id o5DCRDSY023743 for ; Sun, 13 Jun 2010 12:27:13 GMT Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by d06nrmr1407.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o5DCRDcR589906 for ; Sun, 13 Jun 2010 13:27:13 +0100 Received: from d06av04.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o5DCRCoo005100 for ; Sun, 13 Jun 2010 13:27:13 +0100 Received: from rice.haifa.ibm.com (rice.haifa.ibm.com [9.148.8.205]) by d06av04.portsmouth.uk.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id o5DCRBEg005095 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 13 Jun 2010 13:27:12 +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 o5DCRBxW012970; Sun, 13 Jun 2010 15:27:11 +0300 Received: (from nyh@localhost) by rice.haifa.ibm.com (8.14.4/8.14.4/Submit) id o5DCRAB0012968; Sun, 13 Jun 2010 15:27:10 +0300 Date: Sun, 13 Jun 2010 15:27:10 +0300 Message-Id: <201006131227.o5DCRAB0012968@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 9/24] Implement VMCLEAR 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:27:19 +0000 (UTC) --- .before/arch/x86/kvm/vmx.c 2010-06-13 15:01:29.000000000 +0300 +++ .after/arch/x86/kvm/vmx.c 2010-06-13 15:01:29.000000000 +0300 @@ -138,6 +138,8 @@ struct __attribute__ ((__packed__)) vmcs */ u32 revision_id; u32 abort; + + bool launch_state; /* set to 0 by VMCLEAR, to 1 by VMLAUNCH */ }; struct vmcs_list { @@ -3827,6 +3829,46 @@ static int read_guest_vmcs_gpa(struct kv return 0; } +static void clear_rflags_cf_zf(struct kvm_vcpu *vcpu) +{ + unsigned long rflags; + rflags = vmx_get_rflags(vcpu); + rflags &= ~(X86_EFLAGS_CF | X86_EFLAGS_ZF); + vmx_set_rflags(vcpu, rflags); +} + +/* Emulate the VMCLEAR instruction */ +static int handle_vmclear(struct kvm_vcpu *vcpu) +{ + struct vcpu_vmx *vmx = to_vmx(vcpu); + gpa_t guest_vmcs_addr, save_current_vmptr; + + if (!nested_vmx_check_permission(vcpu)) + return 1; + + if (read_guest_vmcs_gpa(vcpu, &guest_vmcs_addr)) + return 1; + + save_current_vmptr = vmx->nested.current_vmptr; + + vmx->nested.current_vmptr = guest_vmcs_addr; + if (!nested_map_current(vcpu)) + return 1; + vmx->nested.current_l2_page->launch_state = 0; + nested_unmap_current(vcpu); + + nested_free_current_vmcs(vcpu); + + if (save_current_vmptr == guest_vmcs_addr) + vmx->nested.current_vmptr = -1ull; + else + vmx->nested.current_vmptr = save_current_vmptr; + + skip_emulated_instruction(vcpu); + clear_rflags_cf_zf(vcpu); + return 1; +} + static int handle_invlpg(struct kvm_vcpu *vcpu) { unsigned long exit_qualification = vmcs_readl(EXIT_QUALIFICATION); @@ -4109,7 +4151,7 @@ static int (*kvm_vmx_exit_handlers[])(st [EXIT_REASON_HLT] = handle_halt, [EXIT_REASON_INVLPG] = handle_invlpg, [EXIT_REASON_VMCALL] = handle_vmcall, - [EXIT_REASON_VMCLEAR] = handle_vmx_insn, + [EXIT_REASON_VMCLEAR] = handle_vmclear, [EXIT_REASON_VMLAUNCH] = handle_vmx_insn, [EXIT_REASON_VMPTRLD] = handle_vmx_insn, [EXIT_REASON_VMPTRST] = handle_vmx_insn,