public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
To: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: [PATCH] Correct management of REP prefix
Date: Tue, 02 Oct 2007 08:14:27 +0200	[thread overview]
Message-ID: <4701E1C3.7040904@qumranet.com> (raw)
In-Reply-To: <4700B611.1000803-6ktuUTfB/bM@public.gmane.org>

Laurent Vivier wrote:
> Avi Kivity wrote:
>   
>> Laurent Vivier wrote:
>>     
>>> This patch corrects some errors appearing when we have an emulation
>>> failure
>>> on an operation using REP prefix.
>>>
>>> When x86_emulate_insn() fails, saving EIP and ECX is not enough as
>>> emulation
>>> should have modified other registers like RSI or RDI. Moreover, the
>>> emulation
>>> can fail on the writeback, and in this case we are not able to restore
>>> registers.
>>>
>>> This patch takes another approach: at the beginning of
>>> x86_emulate_insn() we restore state we have at end of
>>> x86_decode_insn(). To do that, we store EIP in
>>> a new field in decode_cache, decode_eip. This field store the EIP as
>>> it is at
>>> the end of x86_decode_insn(); and at beginning of x86_emulate_insn(),
>>> we restore
>>> all registers as they are in vcpu. We can do that, because the
>>> x86_decode_insn()
>>> doesn't modify registers (except EIP).
>>>   
>>>       
>> How about doing it slightly differently: keep c->eip at its current
>> meaning, and add c->eip_orig to revert to? That will make the patch
>> smaller and reduce the changes of something being missed.
>>     
>
> I didn't do like that because I was afraid to miss some points to restore orig_eip.
>   


This could be done using something like

emulate(ctxt)
{
    decode_cache save = ctxt->decode_cache;

    r = __emulate(ctxt);
    if (r != success)
        ctxt->decode_cache = save;
    return r;
}

or in some similar way.

-- 
Any sufficiently difficult bug is indistinguishable from a feature.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

  parent reply	other threads:[~2007-10-02  6:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-27 21:34 [PATCH] Correct management of REP prefix Laurent Vivier
     [not found] ` <1190928863669-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
2007-09-30  9:06   ` Avi Kivity
     [not found]     ` <46FF6702.2060203-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-01  8:55       ` Laurent Vivier
     [not found]         ` <4700B611.1000803-6ktuUTfB/bM@public.gmane.org>
2007-10-02  6:14           ` Avi Kivity [this message]
2007-10-01  9:01   ` Laurent Vivier
     [not found]     ` <11912292661049-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
2007-10-02  6:11       ` Avi Kivity
2007-10-02 22:23       ` Kamble, Nitin A
     [not found]         ` <5461330FA59EDB46BE9AB8AAF2C431AD055A4295-1a9uaKK1+wJcIJlls4ac1rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-10-03  7:23           ` Laurent Vivier
     [not found]             ` <4703438A.6010307-6ktuUTfB/bM@public.gmane.org>
2007-10-03 17:10               ` Kamble, Nitin A

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=4701E1C3.7040904@qumranet.com \
    --to=avi-atkuwr5tajbwk0htik3j/w@public.gmane.org \
    --cc=Laurent.Vivier-6ktuUTfB/bM@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /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