Skip to content

Commit c017d0d

Browse files
committed
Merge branch 'kvm-updates/3.0' of git://git.kernel.org/pub/scm/virt/kvm/kvm
* 'kvm-updates/3.0' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: x86 emulator: fix %rip-relative addressing with immediate source operand
2 parents c773547 + cb16c34 commit c017d0d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

arch/x86/kvm/emulate.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3372,7 +3372,7 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
33723372
int def_op_bytes, def_ad_bytes, goffset, simd_prefix;
33733373
bool op_prefix = false;
33743374
struct opcode opcode;
3375-
struct operand memop = { .type = OP_NONE };
3375+
struct operand memop = { .type = OP_NONE }, *memopp = NULL;
33763376

33773377
c->eip = ctxt->eip;
33783378
c->fetch.start = c->eip;
@@ -3547,9 +3547,6 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
35473547
if (memop.type == OP_MEM && c->ad_bytes != 8)
35483548
memop.addr.mem.ea = (u32)memop.addr.mem.ea;
35493549

3550-
if (memop.type == OP_MEM && c->rip_relative)
3551-
memop.addr.mem.ea += c->eip;
3552-
35533550
/*
35543551
* Decode and fetch the source operand: register, memory
35553552
* or immediate.
@@ -3571,6 +3568,7 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
35713568
c->op_bytes;
35723569
srcmem_common:
35733570
c->src = memop;
3571+
memopp = &c->src;
35743572
break;
35753573
case SrcImmU16:
35763574
rc = decode_imm(ctxt, &c->src, 2, false);
@@ -3667,6 +3665,7 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
36673665
case DstMem:
36683666
case DstMem64:
36693667
c->dst = memop;
3668+
memopp = &c->dst;
36703669
if ((c->d & DstMask) == DstMem64)
36713670
c->dst.bytes = 8;
36723671
else
@@ -3700,10 +3699,13 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
37003699
/* Special instructions do their own operand decoding. */
37013700
default:
37023701
c->dst.type = OP_NONE; /* Disable writeback. */
3703-
return 0;
3702+
break;
37043703
}
37053704

37063705
done:
3706+
if (memopp && memopp->type == OP_MEM && c->rip_relative)
3707+
memopp->addr.mem.ea += c->eip;
3708+
37073709
return (rc == X86EMUL_UNHANDLEABLE) ? EMULATION_FAILED : EMULATION_OK;
37083710
}
37093711

0 commit comments

Comments
 (0)