From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH] Correct management of REP prefix Date: Tue, 02 Oct 2007 08:14:27 +0200 Message-ID: <4701E1C3.7040904@qumranet.com> References: <1190928863669-git-send-email-Laurent.Vivier@bull.net> <46FF6702.2060203@qumranet.com> <4700B611.1000803@bull.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org To: Laurent Vivier Return-path: In-Reply-To: <4700B611.1000803-6ktuUTfB/bM@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.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/