Skip to contentSkip to conversation

x86emul: ignore XOP.W for TBM insns in 32-bit mode

PATCH In review Jan Beulich 2 participants 2 messages Nov 24

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86emul: ignore XOP.W for TBM insns in 32-bit mode

Quoting 1179d51dcb7d ("x86emul: ignore VEX.W for BMI{1,2} insns in 32-bit mode"):
"While result values and other status flags are unaffected as long as we
can ignore the case of registers having their upper 32 bits non-zero outside of 64-bit mode, EFLAGS.SF may obtain a wrong value when we mistakenly re-execute the original insn with VEX.W set.

Note that guest the memory access, if any, is correctly carried out as 32-bit regardless of VEX.W. The emulator-local memory operand will be accessed as a 64-bit quantity, but it is pre-initialised to zero so no internal state can leak."

The same applies to XOP-encoded integer insns.

Fixes c4afd683f95c ("x86emul: support TBM insns")
xen/arch/x86/x86_emulate/x86_emulate.c +4 -0
@@ -8027,6 +8027,8 @@ x86_emulate(
         *pxop = vex;
         pxop->b = 1;
         pxop->r = 1;
+        if ( !mode_64bit() )
+            pxop->w = 0;
         pxop->reg = 0xf; /* rAX */
         buf[3] = b;
         buf[4] = (modrm & 0x38) | 0x01; /* r/m=(%rCX) */
@@ -8136,6 +8138,8 @@ x86_emulate(
         *pxop = vex;
         pxop->b = 1;
         pxop->r = 1;
+        if ( !mode_64bit() )
+            pxop->w = 0;
         buf[3] = b;
         buf[4] = 0x09; /* reg=rCX r/m=(%rCX) */
         *(uint32_t *)(buf + 5) = imm1;
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · Jan Beulich

Quoting 1179d51dcb7d ("x86emul: ignore VEX.W for BMI{1,2} insns in 32-bit mode"):
"While result values and other status flags are unaffected as long as we
can ignore the case of registers having their upper 32 bits non-zero outside of 64-bit mode, EFLAGS.SF may obtain a wrong value when we mistakenly re-execute the original insn with VEX.W set.

Note that guest the memory access, if any, is correctly carried out as 32-bit regardless of VEX.W. The emulator-local memory operand will be accessed as a 64-bit quantity, but it is pre-initialised to zero so no internal state can leak."

Quoted 5 lines

The same applies to XOP-encoded integer insns.

Fixes c4afd683f95c ("x86emul: support TBM insns")