From: Zachary Amsden <zamsden@redhat.com>
To: Gleb Natapov <gleb@redhat.com>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu, avi@redhat.com,
mtosatti@redhat.com
Subject: Re: use of setjmp/longjmp in x86 emulator.
Date: Mon, 01 Mar 2010 08:39:49 -1000 [thread overview]
Message-ID: <4B8C09F5.9070506@redhat.com> (raw)
In-Reply-To: <20100301174724.GA12867@redhat.com>
On 03/01/2010 07:47 AM, Gleb Natapov wrote:
> On Mon, Mar 01, 2010 at 06:13:53AM -1000, Zachary Amsden wrote:
>
>
>> ... you are broken. This case can be made very much more complex
>> and hard to reason about by using local variables which are reset by
>> the longjmp.
>>
>> Further, it requires use of the volatile keyword to interact
>> properly with logic involving more than one variable, and thus, by
>> definition is impossible to use in the kernel, which does not
>> implement the volatile keyword. :)
>>
> volatile is a language keyword how it can be not implemented by the
> kernel? And why volatile is needed to implement longjmp?
>
Local variables which are not volatile are "undefined" after a longjmp.
Thus setjmp() return value is the only valid rvalue otherwise.
As I said, the kernel does not implement the volatile keyword :)
(i.e. its use is heavily discouraged to the point one can consider it
not implemented)
>> Instead, for this case, use the fact that there is an
>> architecturally designed finite number of exceptions that can be
>> processed simultaneously. This means if you queue exceptions to a
>> pending list of control-flow interrupting events to be processed, as
>> long as the queue is appropriately sized, you will never overflow
>> this queue and never require dynamic allocation. Further, you can
>> then naturally follow the exception priority rules at the top-level
>> of the emulator and never need to pass back complex exception
>> structures, merely a simple return value which indicates whether to
>> return to top-level control logic or continue with instruction
>> emulation. I believe using this style of programming will make your
>> need for setjmp/longjmp go away.
>>
>>
> Of course it is possible to use return values instead. This is what code
> does currently and this is completely unrelated to exception queue
> depth. Code will be much simpler if we will be able to bail out from the
> depth of emulator immediately if exception condition is met or exit to
> userspace is required instead of passing the condition up the call
> chain.
>
Anything that can generate exceptions is going to need logic to handle
error cases anyway... the depth can not be that bad. Especially if you
structure it so as to optimize for tail calling.
Zach
next prev parent reply other threads:[~2010-03-01 18:39 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-01 9:18 use of setjmp/longjmp in x86 emulator Gleb Natapov
2010-03-01 12:45 ` Takuya Yoshikawa
2010-03-01 12:52 ` Gleb Natapov
2010-03-01 13:17 ` Takuya Yoshikawa
2010-03-01 13:26 ` Gleb Natapov
2010-03-01 19:13 ` john cooper
2010-03-02 7:28 ` Gleb Natapov
2010-03-07 9:00 ` Avi Kivity
2010-03-08 23:11 ` Eric W. Biederman
2010-03-09 6:28 ` Gleb Natapov
2010-03-01 16:13 ` Zachary Amsden
2010-03-01 17:47 ` Gleb Natapov
2010-03-01 18:39 ` Zachary Amsden [this message]
2010-03-01 18:47 ` Luca Barbieri
2010-03-01 19:03 ` Gleb Natapov
2010-03-01 19:18 ` Zachary Amsden
2010-03-01 22:31 ` H. Peter Anvin
2010-03-01 22:56 ` H. Peter Anvin
2010-03-01 23:34 ` Zachary Amsden
2010-03-01 23:43 ` H. Peter Anvin
2010-03-02 8:05 ` Gleb Natapov
2010-03-02 8:49 ` Gleb Natapov
2010-03-07 9:04 ` Avi Kivity
2010-03-08 0:08 ` H. Peter Anvin
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=4B8C09F5.9070506@redhat.com \
--to=zamsden@redhat.com \
--cc=avi@redhat.com \
--cc=gleb@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mtosatti@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).