Re: [PATCH] KVM: X86: Remove stale values from ctxt->memop beforeemulation
From: Joerg Roedel
Date: Mon May 07 2012 - 06:12:33 EST
On Sun, May 06, 2012 at 11:21:52AM +0300, Avi Kivity wrote:
> > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> > index d4bf50c..1b516ec 100644
> > --- a/arch/x86/kvm/emulate.c
> > +++ b/arch/x86/kvm/emulate.c
> > @@ -3937,6 +3937,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
> > struct opcode opcode;
> >
> > ctxt->memop.type = OP_NONE;
> > + ctxt->memop.val = 0;
> > ctxt->memopp = NULL;
> > ctxt->_eip = ctxt->eip;
> > ctxt->fetch.start = ctxt->_eip;
>
> This only works for long sized values - it doesn't initialize val64 on
> i386, for example. So I think it's better to change bsr (and family) to
> use emualte_2op_SrcV_nobyte() instead (which has the added benefit of
> using the same values as the processor for the "undefined" bits).
Right, thats a better solution. How about the attached patch? The zf
check shouldn't be necessary anymore because the generated assembly uses
dst.val as input and output so writeback shouldn't do anything wrong.
The bsr and bsf unittests all pass again with this patch.
Joerg