From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: [PATCH] KVM : Set success rflags when emulate VMXON/VMXOFF in nested virt Date: Thu, 04 Jul 2013 07:22:07 +0200 Message-ID: <51D5067F.80405@web.de> References: <1372867517-32111-1-git-send-email-yzt356@gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="----enig2VNCOELQBHORIEXNGNRCP" Cc: kvm@vger.kernel.org, gleb@redhat.com, pbonzini@redhat.com To: Arthur Chunqi Li Return-path: Received: from mout.web.de ([212.227.15.4]:49689 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752385Ab3GDFWO (ORCPT ); Thu, 4 Jul 2013 01:22:14 -0400 In-Reply-To: <1372867517-32111-1-git-send-email-yzt356@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2VNCOELQBHORIEXNGNRCP Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable On 2013-07-03 18:05, Arthur Chunqi Li wrote: > Set success rflags after emulating VMXON/VMXOFF in nested environment. >=20 > Re-arrange the code sequence of 3 functions, > nested_vmx_succeed()/failValid()/failInvalid(), to avoid double > declaration in the same file. Just don't forget to provide corresponding test cases. But you can collect trivial checks like these and do a single VMX startup/shutdown test case that consists of several smaller test steps. Jan >=20 > Signed-off-by: Arthur Chunqi Li > --- > arch/x86/kvm/vmx.c | 85 ++++++++++++++++++++++++++------------------= -------- > 1 file changed, 42 insertions(+), 43 deletions(-) >=20 > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 260a919..423bc411 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -5551,8 +5551,47 @@ static void nested_free_all_saved_vmcss(struct v= cpu_vmx *vmx) > free_loaded_vmcs(&vmx->vmcs01); > } > =20 > +/* > + * The following 3 functions, nested_vmx_succeed()/failValid()/failInv= alid(), > + * set the success or error code of an emulated VMX instruction, as sp= ecified > + * by Vol 2B, VMX Instruction Reference, "Conventions". > + */ > +static void nested_vmx_succeed(struct kvm_vcpu *vcpu) > +{ > + vmx_set_rflags(vcpu, vmx_get_rflags(vcpu) > + & ~(X86_EFLAGS_CF | X86_EFLAGS_PF | X86_EFLAGS_AF | > + X86_EFLAGS_ZF | X86_EFLAGS_SF | X86_EFLAGS_OF)); > +} > + > +static void nested_vmx_failInvalid(struct kvm_vcpu *vcpu) > +{ > + vmx_set_rflags(vcpu, (vmx_get_rflags(vcpu) > + & ~(X86_EFLAGS_PF | X86_EFLAGS_AF | X86_EFLAGS_ZF | > + X86_EFLAGS_SF | X86_EFLAGS_OF)) > + | X86_EFLAGS_CF); > +} > + > static void nested_vmx_failValid(struct kvm_vcpu *vcpu, > - u32 vm_instruction_error); > + u32 vm_instruction_error) > +{ > + if (to_vmx(vcpu)->nested.current_vmptr =3D=3D -1ull) { > + /* > + * failValid writes the error number to the current VMCS, which > + * can't be done there isn't a current VMCS. > + */ > + nested_vmx_failInvalid(vcpu); > + return; > + } > + vmx_set_rflags(vcpu, (vmx_get_rflags(vcpu) > + & ~(X86_EFLAGS_CF | X86_EFLAGS_PF | X86_EFLAGS_AF | > + X86_EFLAGS_SF | X86_EFLAGS_OF)) > + | X86_EFLAGS_ZF); > + get_vmcs12(vcpu)->vm_instruction_error =3D vm_instruction_error; > + /* > + * We don't need to force a shadow sync because > + * VM_INSTRUCTION_ERROR is not shadowed > + */ > +} > =20 > /* > * Emulate the VMXON instruction. > @@ -5612,6 +5651,7 @@ static int handle_vmon(struct kvm_vcpu *vcpu) > vmx->nested.vmxon =3D true; > =20 > skip_emulated_instruction(vcpu); > + nested_vmx_succeed(vcpu); > return 1; > } > =20 > @@ -5696,6 +5736,7 @@ static int handle_vmoff(struct kvm_vcpu *vcpu) > return 1; > free_nested(to_vmx(vcpu)); > skip_emulated_instruction(vcpu); > + nested_vmx_succeed(vcpu); > return 1; > } > =20 > @@ -5752,48 +5793,6 @@ static int get_vmx_mem_address(struct kvm_vcpu *= vcpu, > return 0; > } > =20 > -/* > - * The following 3 functions, nested_vmx_succeed()/failValid()/failInv= alid(), > - * set the success or error code of an emulated VMX instruction, as sp= ecified > - * by Vol 2B, VMX Instruction Reference, "Conventions". > - */ > -static void nested_vmx_succeed(struct kvm_vcpu *vcpu) > -{ > - vmx_set_rflags(vcpu, vmx_get_rflags(vcpu) > - & ~(X86_EFLAGS_CF | X86_EFLAGS_PF | X86_EFLAGS_AF | > - X86_EFLAGS_ZF | X86_EFLAGS_SF | X86_EFLAGS_OF)); > -} > - > -static void nested_vmx_failInvalid(struct kvm_vcpu *vcpu) > -{ > - vmx_set_rflags(vcpu, (vmx_get_rflags(vcpu) > - & ~(X86_EFLAGS_PF | X86_EFLAGS_AF | X86_EFLAGS_ZF | > - X86_EFLAGS_SF | X86_EFLAGS_OF)) > - | X86_EFLAGS_CF); > -} > - > -static void nested_vmx_failValid(struct kvm_vcpu *vcpu, > - u32 vm_instruction_error) > -{ > - if (to_vmx(vcpu)->nested.current_vmptr =3D=3D -1ull) { > - /* > - * failValid writes the error number to the current VMCS, which > - * can't be done there isn't a current VMCS. > - */ > - nested_vmx_failInvalid(vcpu); > - return; > - } > - vmx_set_rflags(vcpu, (vmx_get_rflags(vcpu) > - & ~(X86_EFLAGS_CF | X86_EFLAGS_PF | X86_EFLAGS_AF | > - X86_EFLAGS_SF | X86_EFLAGS_OF)) > - | X86_EFLAGS_ZF); > - get_vmcs12(vcpu)->vm_instruction_error =3D vm_instruction_error; > - /* > - * We don't need to force a shadow sync because > - * VM_INSTRUCTION_ERROR is not shadowed > - */ > -} > - > /* Emulate the VMCLEAR instruction */ > static int handle_vmclear(struct kvm_vcpu *vcpu) > { >=20 ------enig2VNCOELQBHORIEXNGNRCP Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlHVBn8ACgkQitSsb3rl5xSXKACfYiToe/7I2dqj0VtiKjCQR3iQ 3pkAoNXH8VDnCWLl3puidEETNYuuSbIP =fvan -----END PGP SIGNATURE----- ------enig2VNCOELQBHORIEXNGNRCP--