From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Dong, Eddie" Subject: RE: [PATCH 9/24] Implement VMCLEAR Date: Tue, 6 Jul 2010 10:56:19 +0800 Message-ID: <1A42CE6F5F474C41B63392A5F80372B21F67B41F@shsmsx501.ccr.corp.intel.com> References: <1276431753-nyh@il.ibm.com> <201006131227.o5DCRAB0012968@rice.haifa.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT Cc: "kvm@vger.kernel.org" , "Dong, Eddie" , "Dong, Eddie" To: Nadav Har'El , "avi@redhat.com" Return-path: Received: from mga01.intel.com ([192.55.52.88]:51578 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752575Ab0GFDAM convert rfc822-to-8bit (ORCPT ); Mon, 5 Jul 2010 23:00:12 -0400 In-Reply-To: <201006131227.o5DCRAB0012968@rice.haifa.ibm.com> Content-Language: en-US Sender: kvm-owner@vger.kernel.org List-ID: Nadav Har'El wrote: > This patch implements the VMCLEAR instruction. > > Signed-off-by: Nadav Har'El > --- > --- .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; > + SDM implements alignment check, range check and reserve bit check and may generate VMfail(VMCLEAR with invalid physical address). As well as "addr != VMXON pointer" check Missed? > + 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); SDM has formal definition of VMSucceed. Cleating CF/ZF only is not sufficient as SDM 2B 5.2 mentioned. Any special concern here? BTW, should we define formal VMfail() & VMsucceed() API for easy understand and map to SDM? > + 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,