All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Joerg Roedel <joerg.roedel@amd.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: X86: Remove stale values from ctxt->memop before emulation
Date: Sun, 06 May 2012 11:21:52 +0300	[thread overview]
Message-ID: <4FA634A0.8020504@redhat.com> (raw)
In-Reply-To: <1336148056-15662-1-git-send-email-joerg.roedel@amd.com>

On 05/04/2012 07:14 PM, Joerg Roedel wrote:
> When instruction decoding begins there could be stale values
> in the ctxt->memop structure. This causes problems when an
> instruction is emulated with more op-bytes then the guest
> wants (like the bsr instruction which is always emulated
> with 4 or 8 op-bytes).
>
> The stale value in this structure causes the unit-test for
> the bsrw instruction to fail. Initialize the memop.val with
> 0 to prevent such bugs (an alternative fix could be to
> always emulate instructions with the number of op-bytes
> requested by the guest).
>
>
> 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).

-- 
error compiling committee.c: too many arguments to function

  reply	other threads:[~2012-05-06  8:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-04 16:14 [PATCH] KVM: X86: Remove stale values from ctxt->memop before emulation Joerg Roedel
2012-05-06  8:21 ` Avi Kivity [this message]
2012-05-07 10:12   ` Joerg Roedel
2012-05-07 10:18     ` Avi Kivity
2012-05-07 10:43       ` Joerg Roedel
2012-05-14  8:32     ` Avi Kivity

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=4FA634A0.8020504@redhat.com \
    --to=avi@redhat.com \
    --cc=joerg.roedel@amd.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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 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.