Skip to contentSkip to conversation

target/i386: Mark MOVNTI as not valid with prefixes 0x66, 0xF2, 0xF3

PATCH In review Andrey Polivoda 1 participant 2 messages Aug 18 – Sep 4

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/i386: Mark MOVNTI as not valid with prefixes 0x66, 0xF2, 0xF3

According to both table A-3 in Volume 2 of Intel 64 and IA-32 Architectures Software Developer's Manual and table A-3 in Volume 3 of AMD64 Architecture Programmer's Manual, 0F C3 is decoded as MOVNTI only if the instruction is not preceded by prefixes 0x66, 0xF2, or 0xF3.

Currently, QEMU does not check the presence of these prefixes when decoding 0F C3, which leads to QEMU happily executing 0F C3 as MOVNTI instead of raising an expected #UD when any of these prefixes are present, which does not match the behavior of the real hardware.

This patch fixes this bug by correcting the decode table for MOVNTI so that it requires that none of the 0x66, 0xF2, and 0xF3 prefixes is present.

Cc Paolo Bonzini <[email protected]>
Cc Richard Henderson <[email protected]>
Fixes 3519b813e1f1 ("target/i386: port extensions of one-byte opcodes to new decoder")

---
Note: scripts/checkpatch.pl reports style errors. These are false positives, since the patch is not modifying the formatting of the affected part of the decoder table entry.
The error about the line being too long is also a false positive, because the length that exceeds 90 characters seems to be a normal thing in the decoder table.

 target/i386/tcg/decode-new.c.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/tcg/decode-new.c.inc +1 -1
index ac181308ca..cf8431e3f4 100644
@@ -1364,7 +1364,7 @@ static const X86OpEntry opcodes_0F[256] = {
     [0xc0] = X86_OP_ENTRY2(XADD,       E,b, G,b,            lock),
     [0xc1] = X86_OP_ENTRY2(XADD,       E,v, G,v,            lock),
     [0xc2] = X86_OP_ENTRY4(VCMP,       V,x, H,x, W,x,       vex2_rep3 p_00_66_f3_f2),
-    [0xc3] = X86_OP_ENTRY3(MOV,        EM,y,G,y, None,None, cpuid(SSE2)), /* MOVNTI */
+    [0xc3] = X86_OP_ENTRY3(MOV,        EM,y,G,y, None,None, cpuid(SSE2) p_00), /* MOVNTI */
     [0xc4] = X86_OP_ENTRY4(PINSRW,     V,dq,H,dq,E,w,       vex5 mmx p_00_66),
     [0xc5] = X86_OP_ENTRY3(PEXTRW,     G,d, U,dq,I,b,       vex5 mmx p_00_66),
     [0xc6] = X86_OP_ENTRY4(VSHUF,      V,x, H,x, W,x,       vex4 p_00_66),
Signature · 1 line
2.53.0