Skip to content

Commit ed9aad2

Browse files
anadavbonzini
authored andcommitted
KVM: x86: MOVNTI emulation min opsize is not respected
Commit 3b32004 ("KVM: x86: movnti minimum op size of 32-bit is not kept") did not fully fix the minimum operand size of MONTI emulation. Still, MOVNTI may be mistakenly performed using 16-bit opsize. This patch add No16 flag to mark an instruction does not support 16-bits operand size. Signed-off-by: Nadav Amit <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 7f18792 commit ed9aad2

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

arch/x86/kvm/emulate.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
#define NoBigReal ((u64)1 << 50) /* No big real mode */
168168
#define PrivUD ((u64)1 << 51) /* #UD instead of #GP on CPL > 0 */
169169
#define NearBranch ((u64)1 << 52) /* Near branches */
170+
#define No16 ((u64)1 << 53) /* No 16 bit operand */
170171

171172
#define DstXacc (DstAccLo | SrcAccHi | SrcWrite)
172173

@@ -4134,7 +4135,7 @@ static const struct opcode twobyte_table[256] = {
41344135
D(DstReg | SrcMem8 | ModRM | Mov), D(DstReg | SrcMem16 | ModRM | Mov),
41354136
/* 0xC0 - 0xC7 */
41364137
F2bv(DstMem | SrcReg | ModRM | SrcWrite | Lock, em_xadd),
4137-
N, D(DstMem | SrcReg | ModRM | Mov),
4138+
N, I(DstMem | SrcReg | ModRM | No16 | Mov, em_mov),
41384139
N, N, N, GD(0, &group9),
41394140
/* 0xC8 - 0xCF */
41404141
X8(I(DstReg, em_bswap)),
@@ -4571,7 +4572,8 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
45714572
return EMULATION_FAILED;
45724573

45734574
if (unlikely(ctxt->d &
4574-
(NotImpl|Stack|Op3264|Sse|Mmx|Intercept|CheckPerm|NearBranch))) {
4575+
(NotImpl|Stack|Op3264|Sse|Mmx|Intercept|CheckPerm|NearBranch|
4576+
No16))) {
45754577
/*
45764578
* These are copied unconditionally here, and checked unconditionally
45774579
* in x86_emulate_insn.
@@ -4596,6 +4598,9 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
45964598
ctxt->op_bytes = 4;
45974599
}
45984600

4601+
if ((ctxt->d & No16) && ctxt->op_bytes == 2)
4602+
ctxt->op_bytes = 4;
4603+
45994604
if (ctxt->d & Sse)
46004605
ctxt->op_bytes = 16;
46014606
else if (ctxt->d & Mmx)
@@ -5061,11 +5066,6 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
50615066
ctxt->dst.val = (ctxt->src.bytes == 1) ? (s8) ctxt->src.val :
50625067
(s16) ctxt->src.val;
50635068
break;
5064-
case 0xc3: /* movnti */
5065-
ctxt->dst.bytes = ctxt->op_bytes;
5066-
ctxt->dst.val = (ctxt->op_bytes == 8) ? (u64) ctxt->src.val :
5067-
(u32) ctxt->src.val;
5068-
break;
50695069
default:
50705070
goto cannot_emulate;
50715071
}

0 commit comments

Comments
 (0)