Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-24 Thread Arthur Chunqi Li
Hi Gleb and Paolo, What about organizing vmx_run() as follows: static int vmx_run() { u32 eax; bool ret; vmcs_write(HOST_RSP, get_rsp()); ret = vmlaunch(); while (!ret) { asm volatile( vmx_return:\n\t SAVE_GPR ); eax =

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-24 Thread Paolo Bonzini
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 = vmlaunch(); The compiler can still change rsp between here... while (!ret) { asm volatile( vmx_return:\n\t ...

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-24 Thread Arthur Chunqi Li
On Wed, Jul 24, 2013 at 2:40 PM, Paolo Bonzini pbonz...@redhat.com 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 = vmlaunch(); The compiler can still change rsp between here...

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-24 Thread Paolo Bonzini
Il 24/07/2013 08:46, Arthur Chunqi Li ha scritto: On Wed, Jul 24, 2013 at 2:40 PM, Paolo Bonzini pbonz...@redhat.com 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 = vmlaunch(); The

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-24 Thread Arthur Chunqi Li
So as what Gleb said, what about the following codes: static int vmx_run2() { u32 eax; bool ret; asm volatile( mov %%rsp, %%rsi\n\t mov %2, %%edi\n\t call vmcs_write\n\t vmlaunch\n\t setbe %0\n\t jne 4f\n\t vmx_return:\n\t

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-24 Thread Jan Kiszka
On 2013-07-24 10:48, Arthur Chunqi Li wrote: So as what Gleb said, what about the following codes: static int vmx_run2() { u32 eax; bool ret; asm volatile( mov %%rsp, %%rsi\n\t mov %2, %%edi\n\t call vmcs_write\n\t vmlaunch\n\t Just like

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-24 Thread Paolo Bonzini
Il 24/07/2013 10:48, Arthur Chunqi Li ha scritto: So as what Gleb said, what about the following codes: static int vmx_run2() { u32 eax; bool ret; asm volatile( mov %%rsp, %%rsi\n\t mov %2, %%edi\n\t call vmcs_write\n\t vmlaunch\n\t

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-24 Thread Arthur Chunqi Li
So what about this one. I merged all the exit reason to ret and remove the flag detection after vmlaunch/vmresume (because I think this detection is useless). Currently we support only one guest, so variant launched is located in vmx_run(). If we want to support multiple guest, we could move it to

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-24 Thread Jan Kiszka
On 2013-07-24 11:56, Arthur Chunqi Li wrote: So what about this one. I merged all the exit reason to ret and remove the flag detection after vmlaunch/vmresume (because I think this detection is useless). Currently we support only one guest, so variant launched is located in vmx_run(). If we

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-24 Thread Arthur Chunqi Li
On Wed, Jul 24, 2013 at 6:03 PM, Jan Kiszka jan.kis...@web.de wrote: On 2013-07-24 11:56, Arthur Chunqi Li wrote: So what about this one. I merged all the exit reason to ret and remove the flag detection after vmlaunch/vmresume (because I think this detection is useless). Currently we support

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-24 Thread Jan Kiszka
On 2013-07-24 12:16, Arthur Chunqi Li wrote: On Wed, Jul 24, 2013 at 6:03 PM, Jan Kiszka jan.kis...@web.de wrote: On 2013-07-24 11:56, Arthur Chunqi Li wrote: So what about this one. I merged all the exit reason to ret and remove the flag detection after vmlaunch/vmresume (because I think

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-24 Thread Arthur Chunqi Li
And what about this version: static int vmx_run() { u32 ret = 0; asm volatile( mov %%rsp, %%rsi\n\t mov %2, %%edi\n\t call vmcs_write\n\t 0: LOAD_GPR_C cmpl $0, %1\n\t jne 1f\n\t vmlaunch;seta %1\n\t /* vmlaunch

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-24 Thread Jan Kiszka
On 2013-07-24 13:20, Arthur Chunqi Li wrote: And what about this version: static int vmx_run() { u32 ret = 0; asm volatile( mov %%rsp, %%rsi\n\t mov %2, %%edi\n\t call vmcs_write\n\t 0: LOAD_GPR_C cmpl $0, %1\n\t

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-19 Thread Paolo Bonzini
Il 18/07/2013 21:57, Gleb Natapov ha scritto: On Thu, Jul 18, 2013 at 02:08:51PM +0200, Paolo Bonzini wrote: Il 18/07/2013 13:06, Gleb Natapov ha scritto: On Thu, Jul 18, 2013 at 12:47:46PM +0200, Paolo Bonzini wrote: and for a testsuite I'd prefer the latter---which means I'd still favor

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-19 Thread Gleb Natapov
On Fri, Jul 19, 2013 at 08:42:20AM +0200, Paolo Bonzini wrote: Il 18/07/2013 21:57, Gleb Natapov ha scritto: On Thu, Jul 18, 2013 at 02:08:51PM +0200, Paolo Bonzini wrote: Il 18/07/2013 13:06, Gleb Natapov ha scritto: On Thu, Jul 18, 2013 at 12:47:46PM +0200, Paolo Bonzini wrote: and for

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-19 Thread Paolo Bonzini
Il 19/07/2013 11:40, Gleb Natapov ha scritto: Because this is written in C, and I know trying to fool the compiler is a losing game. So my reaction is okay, HOST_RIP must be set so that code will not jump around. If I see asm(vmlaunch) exit(-1) the reaction is the opposite: hmm,

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-18 Thread Gleb Natapov
On Thu, Jul 18, 2013 at 07:52:21AM +0200, Paolo Bonzini wrote: Il 17/07/2013 20:54, Arthur Chunqi Li ha scritto: + .globl entry_sysenter\n\t + entry_sysenter:\n\t + SAVE_GPR + and $0xf, %rax\n\t + push%rax\n\t push should be wrong here, the first

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-18 Thread Paolo Bonzini
Il 18/07/2013 09:26, Gleb Natapov ha scritto: I had written a long explanation here about why I don't trust the compiler to do the right thing, and ideas about how to fix that. But in the end the only workable solution is a single assembly blob like vmx.c in KVM to do vmlaunch/vmresume,

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-18 Thread Gleb Natapov
On Thu, Jul 18, 2013 at 12:47:46PM +0200, Paolo Bonzini wrote: and for a testsuite I'd prefer the latter---which means I'd still favor setjmp/longjmp. Now, here is the long explanation. I must admit that the code looks nice. There are some nits I'd like to see done

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-18 Thread Paolo Bonzini
Il 18/07/2013 13:06, Gleb Natapov ha scritto: On Thu, Jul 18, 2013 at 12:47:46PM +0200, Paolo Bonzini wrote: and for a testsuite I'd prefer the latter---which means I'd still favor setjmp/longjmp. Now, here is the long explanation. I must admit that the code looks nice. There are some nits

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-18 Thread Arthur Chunqi Li
On Thu, Jul 18, 2013 at 8:08 PM, Paolo Bonzini pbonz...@redhat.com wrote: Il 18/07/2013 13:06, Gleb Natapov ha scritto: On Thu, Jul 18, 2013 at 12:47:46PM +0200, Paolo Bonzini wrote: and for a testsuite I'd prefer the latter---which means I'd still favor setjmp/longjmp. Now, here is the long

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-18 Thread Gleb Natapov
On Thu, Jul 18, 2013 at 02:08:51PM +0200, Paolo Bonzini wrote: Il 18/07/2013 13:06, Gleb Natapov ha scritto: On Thu, Jul 18, 2013 at 12:47:46PM +0200, Paolo Bonzini wrote: and for a testsuite I'd prefer the latter---which means I'd still favor setjmp/longjmp. Now, here is the long

[RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-17 Thread Arthur Chunqi Li
This is the first version of VMX nested environment. It contains the basic VMX instructions test cases, including VMXON/VMXOFF/VMXPTRLD/ VMXPTRST/VMCLEAR/VMLAUNCH/VMRESUME/VMCALL. This patchalso tests the basic execution routine in VMX nested environment andlet the VM print Hello World to inform

Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case

2013-07-17 Thread Paolo Bonzini
Il 17/07/2013 20:54, Arthur Chunqi Li ha scritto: +/* entry_sysenter */ +asm( + .align 4, 0x90\n\t + .globl entry_sysenter\n\t + entry_sysenter:\n\t + SAVE_GPR +and $0xf, %rax\n\t +push%rax\n\t push should be wrong here, the first argument