From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case Date: Wed, 24 Jul 2013 10:53:17 +0200 Message-ID: <51EF95FD.6060503@web.de> References: <1374087242-6125-1-git-send-email-yzt356@gmail.com> <51E78295.2010700@redhat.com> <20130718072652.GB11772@redhat.com> <51E7C7D2.5040303@redhat.com> <20130718110639.GA26173@redhat.com> <51E7DAD3.8000906@redhat.com> <20130718195712.GN13732@redhat.com> <51E8DFCC.8060108@redhat.com> <20130719094027.GY13732@redhat.com> <51E92BE2.1080600@redhat.com> <51EF76E2.2030201@redhat.com> <51EF78B9.9090908@redhat.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="----enig2UVRHARVBLXERSFXXHKJN" Cc: Paolo Bonzini , Gleb Natapov , kvm To: Arthur Chunqi Li Return-path: Received: from mout.web.de ([212.227.15.4]:50617 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751889Ab3GXIxU (ORCPT ); Wed, 24 Jul 2013 04:53:20 -0400 Received: from mchn199C.mchp.siemens.de ([95.157.58.223]) by smtp.web.de (mrweb004) with ESMTPSA (Nemesis) id 0LlJzS-1UQvZg2d42-00b7Xr for ; Wed, 24 Jul 2013 10:53:18 +0200 In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2UVRHARVBLXERSFXXHKJN Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 2013-07-24 10:48, Arthur Chunqi Li wrote: > So as what Gleb said, what about the following codes: >=20 > static int vmx_run2() > { > u32 eax; > bool ret; >=20 > asm volatile( > "mov %%rsp, %%rsi\n\t" > "mov %2, %%edi\n\t" > "call vmcs_write\n\t" > "vmlaunch\n\t" Just like in KVM, provide a flag to the asm block that selects vmlaunch or vmresume, then grab all the required information on return and leave the asm block quickly again. Jan > "setbe %0\n\t" > "jne 4f\n\t" >=20 > "vmx_return:\n\t" > SAVE_GPR_C > "call exit_handler\n\t" > "cmp %3, %%eax\n\t" > "je 2f\n\t" > "cmp %4, %%eax\n\t" > "je 1f\n\t" > "jmp 3f\n\t" >=20 > /* VMX_TEST_RESUME */ > "1:\n\t" > LOAD_GPR_C > "vmresume\n\t" > "setbe %0\n\t" > "jne 4f\n\t" > /* VMX_TEST_VMEXIT */ > "2:\n\t" > "mov $0, %1\n\t" > "jmp 5f\n\t" > /* undefined ret from exit_handler */ > "3:\n\t" > "mov $2, %1\n\t" > "jmp 5f\n\t" > /* vmlaunch/vmresume failed, exit */ > "4:\n\t" > "mov $1, %1\n\t" > "5:\n\t" > : "=3Dr"(ret), "=3Dr"(eax) > : "i"(HOST_RSP), "i"(VMX_TEST_VMEXIT), > "i"(VMX_TEST_RESUME) > : "rax", "rbx", "rdi", "rsi", > "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", > "memory", "cc" > ); > switch (eax) { > case 0: > return 0; > case 1: > printf("%s : vmenter failed.\n", __func__); > break; > default: > printf("%s : unhandled ret from exit_handler.\n", __func__); > break; > } > return 1; > } >=20 > On Wed, Jul 24, 2013 at 2:48 PM, Paolo Bonzini wr= ote: >> Il 24/07/2013 08:46, Arthur Chunqi Li ha scritto: >>> On Wed, Jul 24, 2013 at 2:40 PM, Paolo Bonzini = wrote: >>>> Il 24/07/2013 08:11, Arthur Chunqi Li ha scritto: >>>>> >>>>> static int vmx_run() >>>>> { >>>>> u32 eax; >>>>> bool ret; >>>>> >>>>> vmcs_write(HOST_RSP, get_rsp()); >>>>> ret =3D vmlaunch(); >>>> >>>> The compiler can still change rsp between here... >>>> >>>>> while (!ret) { >>>>> asm volatile( >>>>> "vmx_return:\n\t" >>>> >>>> ... and here. >>>> >>>> If you want to write it in C, the only thing that can be after >>>> vmlaunch/vmresume is "exit()". Else it has to be asm. >>> Actually, you mean we need to write all the codes in asm to avoid >>> changing to rsp, right? >> >> Not necessarily all the code. It is also ok to use setjmp/longjmp wit= h >> a small asm trampoline, because this method won't care about the exact= >> rsp values that are used. But if you want to do as Gleb said, and put= >> vmx_return just after vmlaunch, it has to be all asm as in KVM's >> arch/x86/kvm/vmx.c. >> >> Paolo >=20 >=20 >=20 ------enig2UVRHARVBLXERSFXXHKJN 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/ iEYEARECAAYFAlHvlf0ACgkQitSsb3rl5xTohQCgzGipmFHHfjwTy0G5C0rcNGDS nUYAoMs1zLrtSpO7AWM0jo2yw6JbAshq =sJRr -----END PGP SIGNATURE----- ------enig2UVRHARVBLXERSFXXHKJN--