Commit 16518d5a authored by Avi Kivity's avatar Avi Kivity Committed by Marcelo Tosatti

KVM: x86 emulator: fix regression with cmpxchg8b on i386 hosts

operand::val and operand::orig_val are 32-bit on i386, whereas cmpxchg8b
operands are 64-bit.

Fix by adding val64 and orig_val64 union members to struct operand, and
using them where needed.
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
parent d56557af
...@@ -152,9 +152,14 @@ struct x86_emulate_ops { ...@@ -152,9 +152,14 @@ struct x86_emulate_ops {
struct operand { struct operand {
enum { OP_REG, OP_MEM, OP_IMM, OP_NONE } type; enum { OP_REG, OP_MEM, OP_IMM, OP_NONE } type;
unsigned int bytes; unsigned int bytes;
unsigned long orig_val, *ptr; union {
unsigned long orig_val;
u64 orig_val64;
};
unsigned long *ptr;
union { union {
unsigned long val; unsigned long val;
u64 val64;
char valptr[sizeof(unsigned long) + 2]; char valptr[sizeof(unsigned long) + 2];
}; };
}; };
......
...@@ -1870,16 +1870,15 @@ static inline int emulate_grp9(struct x86_emulate_ctxt *ctxt, ...@@ -1870,16 +1870,15 @@ static inline int emulate_grp9(struct x86_emulate_ctxt *ctxt,
struct x86_emulate_ops *ops) struct x86_emulate_ops *ops)
{ {
struct decode_cache *c = &ctxt->decode; struct decode_cache *c = &ctxt->decode;
u64 old = c->dst.orig_val; u64 old = c->dst.orig_val64;
if (((u32) (old >> 0) != (u32) c->regs[VCPU_REGS_RAX]) || if (((u32) (old >> 0) != (u32) c->regs[VCPU_REGS_RAX]) ||
((u32) (old >> 32) != (u32) c->regs[VCPU_REGS_RDX])) { ((u32) (old >> 32) != (u32) c->regs[VCPU_REGS_RDX])) {
c->regs[VCPU_REGS_RAX] = (u32) (old >> 0); c->regs[VCPU_REGS_RAX] = (u32) (old >> 0);
c->regs[VCPU_REGS_RDX] = (u32) (old >> 32); c->regs[VCPU_REGS_RDX] = (u32) (old >> 32);
ctxt->eflags &= ~EFLG_ZF; ctxt->eflags &= ~EFLG_ZF;
} else { } else {
c->dst.val = ((u64)c->regs[VCPU_REGS_RCX] << 32) | c->dst.val64 = ((u64)c->regs[VCPU_REGS_RCX] << 32) |
(u32) c->regs[VCPU_REGS_RBX]; (u32) c->regs[VCPU_REGS_RBX];
ctxt->eflags |= EFLG_ZF; ctxt->eflags |= EFLG_ZF;
...@@ -2616,7 +2615,7 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) ...@@ -2616,7 +2615,7 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
c->src.valptr, c->src.bytes); c->src.valptr, c->src.bytes);
if (rc != X86EMUL_CONTINUE) if (rc != X86EMUL_CONTINUE)
goto done; goto done;
c->src.orig_val = c->src.val; c->src.orig_val64 = c->src.val64;
} }
if (c->src2.type == OP_MEM) { if (c->src2.type == OP_MEM) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment