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")
Reported-by: Roger Pau Monné <roger.pau@amd.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -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;
On 24/11/2026 1:32 pm, Jan Beulich wrote:
> 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")
> Reported-by: Roger Pau Monné <roger.pau@amd.com>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
© 2016 - 2026 Red Hat, Inc.