Re: [PATCH RFC v1 16/20] KVM: x86: Decode REX2 prefix in the emulator
From: Paolo Bonzini
Date: Thu Nov 13 2025 - 18:34:36 EST
On 11/14/25 00:30, Chang S. Bae wrote:
On 11/11/2025 9:55 AM, Paolo Bonzini wrote:
On 11/10/25 19:01, Chang S. Bae wrote:
Here you should also check
case 0x40 ... 0x4f: /* REX */
if (mode != X86EMUL_MODE_PROT64)
goto done_prefixes;
+ if (ctxt->rex_prefix == REX2_PREFIX)
+ break;
ctxt->rex_prefix = REX_PREFIX;
ctxt->rex.raw = 0x0f & ctxt->b;
continue;
+ case 0xd5: /* REX2 */
+ if (mode != X86EMUL_MODE_PROT64)
+ goto done_prefixes;
if (ctxt->rex_prefix == REX_PREFIX) {
ctxt->rex_prefix = REX2_INVALID;
goto done_prefixes;
}
You're right. Section 3.1.2.1 states:
| A REX prefix (0x4*) immediately preceding the REX2 prefix is not
| allowed and triggers #UD.
Now I think REX2_INVALID would just add another condition to handle
later. Instead, for such invalid case, it might be simpler to mark the
opcode as undefined and jump all the way after the lookup. See the diff
-- please let me know if you dislike it.
Yes, I also thought it was unnecessary but waited until we merged the respective patches.
Paolo