From: Paolo Bonzini <pbonzini@redhat.com>
To: Gleb Natapov <gleb@redhat.com>
Cc: Arthur Chunqi Li <yzt356@gmail.com>,
kvm@vger.kernel.org, jan.kiszka@web.de
Subject: Re: [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case
Date: Fri, 19 Jul 2013 08:42:20 +0200 [thread overview]
Message-ID: <51E8DFCC.8060108@redhat.com> (raw)
In-Reply-To: <20130718195712.GN13732@redhat.com>
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
>>>>>> 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 differently (such as putting vmx_return at the beginning of the
>>>>>> while (1), and the vmresume asm at the end), but it is indeed nice.
>>>>>
>>>>> Why do you prefer setjmp/longjmp then?
>>>>
>>>> Because it is still deceiving, and I dislike the deceit more than I like
>>>> the linear code flow.
>>>>
>>> What is deceiving about it? Of course for someone who has no idea how
>>> vmx works the code will not be obvious, but why should we care. For
>>> someone who knows what is deceiving about returning into the same
>>> function guest was launched from by using VMX mechanism
>>
>> The way the code is written is deceiving. If I see
>>
>> asm("vmlaunch; seta %0")
>> while (ret)
>>
>> I expect HOST_RIP to point at the seta or somewhere near, not at a
>> completely different label somewhere else.
>>
> Why would you expect that assuming you know what vmlaunch is?
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, anything that jumps around would
have a hard time with the compiler, there must be some assembly
trampoline somewhere; let's check what HOST_RIP is".
>>>> instead of longjmp()?
>>
>> Look again at the setjmp/longjmp version. longjmp is not used to handle
>> vmexit. It is used to jump back from the vmexit handler to main, which
>> is exactly what setjmp/longjmp is meant for.
>>
> That's because simple return will not work in that version, this is
> artifact of how vmexit was done.
I think it can be made to work without setjmp/longjmp, but the code
would be ugly.
>>>> the compiler, and you rely on the compiler not changing %rsp between the
>>>> vmlaunch and the vmx_return label. Minor nit, you cannot anymore print
>>> HOST_RSP should be loaded on each guest entry.
>>
>> Right, but my point is: without a big asm blob, you don't know the right
>> value to load. It depends on the generated code. And the big asm blob
>> limits a lot the "code looks nice" value of this approach.
>>
> I said it number of times already, this is not about "code looking nice",
> "code looks like KVM" or use less assembler as possible", this is about
> linear data flow. It is not fun chasing code execution path. Yes, you
> can argue that vmlaunch/vmresume inherently non linear, but there is a
> difference between skipping one instruction and remain in the same
> function and on the same stack, or jump completely to a different
> context.
I don't see anything bad in jumping completely to a different context.
The guest and host are sort of like two coroutines, they hardly have any
connection with the code that called vmlaunch.
> The actually differences in asm instruction between both
> version will not be bigger then a couple of lines (if we will not take
> setjmp/longjmp implementation into account :)),
I was waiting for this parenthetical remark to appear. ;)
> but I do not even see
> why we discuss this argument since minimizing asm instructions here is
> not an point. We should not use more then needed to achieve the goal of
> course, but design should not be around number of assembly lines.
I agree, I only mentioned it because you talked about
asm
C
asm
C
and this is not what the setjmp/longjmp code looks like---using inlines
for asm as if they were builtin functions is good, interspersing asm and
C in the same function is bad.
Paolo
next prev parent reply other threads:[~2013-07-19 6:42 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-17 18:54 [RFC PATCH] kvm-unit-tests : Basic architecture of VMX nested test case Arthur Chunqi Li
2013-07-18 5:52 ` Paolo Bonzini
2013-07-18 7:26 ` Gleb Natapov
2013-07-18 10:47 ` Paolo Bonzini
2013-07-18 11:06 ` Gleb Natapov
2013-07-18 12:08 ` Paolo Bonzini
2013-07-18 14:11 ` Arthur Chunqi Li
2013-07-18 19:57 ` Gleb Natapov
2013-07-19 6:42 ` Paolo Bonzini [this message]
2013-07-19 9:40 ` Gleb Natapov
2013-07-19 12:06 ` Paolo Bonzini
2013-07-24 6:11 ` Arthur Chunqi Li
2013-07-24 6:40 ` Paolo Bonzini
2013-07-24 6:46 ` Arthur Chunqi Li
2013-07-24 6:48 ` Paolo Bonzini
2013-07-24 8:48 ` Arthur Chunqi Li
2013-07-24 8:53 ` Jan Kiszka
2013-07-24 9:16 ` Paolo Bonzini
2013-07-24 9:56 ` Arthur Chunqi Li
2013-07-24 10:03 ` Jan Kiszka
2013-07-24 10:16 ` Arthur Chunqi Li
2013-07-24 10:24 ` Jan Kiszka
2013-07-24 11:20 ` Arthur Chunqi Li
2013-07-24 11:25 ` Jan Kiszka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51E8DFCC.8060108@redhat.com \
--to=pbonzini@redhat.com \
--cc=gleb@redhat.com \
--cc=jan.kiszka@web.de \
--cc=kvm@vger.kernel.org \
--cc=yzt356@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.