Re: [PATCH v9 13/20] KVM: x86: Support REX2-prefixed opcode decode
From: Jim Mattson
Date: Wed Nov 18 2026 - 18:04:37 EST
On Tue, Nov 17, 2026 at 10:32 AM Chang S. Bae <chang.seok.bae@xxxxxxxxx> wrote:
>
> Extend the instruction decoder to recognize and handle the REX2 prefix,
> including validation of prefix sequences and correct opcode table
> selection. Prepare the UD opcode flag explicitly with Undefined, instead
> of zeroing.
>
> REX2 is a terminal prefix: once 0xD5 is encountered, the following byte
> is the opcode. When REX2.M=0, most prefix bytes are invalid after REX2,
> including REX, VEX, EVEX, and another REX2. Also, REX2-prefixed
> instructions are only valid in 64-bit mode.
>
> All of the invalid prefix combinations after REX2 coincide with opcodes
> that are architecturally invalid in 64-bit mode. Thus, marking such
> opcodes with No64 in opcode_table[] naturally disallows those illegal
> prefix sequences.
>
> The 0x40 - 0x4F opcode row was missing the No64 flag. While NoRex2
> already invalidates REX2 for these opcodes, adding No64 makes opcode
> attributes explicit and complete.
>
> Note opcodes marked NotImpl alone end up in handle_emulation_failure(),
> but that will inject #UD eventually.
>
> Suggested-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
> Tested-by: Zhao Liu <zhao1.liu@xxxxxxxxx>
> Signed-off-by: Chang S. Bae <chang.seok.bae@xxxxxxxxx>
> Link: https://lore.kernel.org/CABgObfYYGTvkYpeyqLSr9JgKMDA_STSff2hXBNchLZuKFU+MMA@xxxxxxxxxxxxxx
Reviewed-by: Jim Mattson <jmattson@xxxxxxxxxx>