Re: [PATCH v8 12/20] KVM: x86: Support REX2-prefixed opcode decode

From: Chang S. Bae

Date: Tue Nov 17 2026 - 13:38:40 EST


On 11/6/2026 6:07 AM, Jim Mattson wrote:
On Thu, Nov 5, 2026 at 8:48 PM Jim Mattson <jmattson@xxxxxxxxxx> wrote:

"ud" is defined as I(SrcNone, emulate_ud), and SrcNone is 0. Jumping to
done_modrm with opcode.flags == 0 sets ctxt->d = 0, which then hits:

/* Unrecognised? */
if (ctxt->d == 0)
return EMULATION_FAILED;

before ctxt->execute is ever set. As a result, rex2_invalid() always
returns EMULATION_FAILED instead of injecting #UD.

Once again, on EMULATION_FAILED, x86_emulate_instruction() will raise #UD.

That leaves only this question on this patch...

So I add the Undefined tag explicitly here:

-static const struct opcode ud = I(SrcNone, emulate_ud);
+static const struct opcode ud = I(SrcNone | Undefined, emulate_ud);

Does hardware raise #UD on 0x48 0x66 0xD5, or does the intervening legacy
prefix nullify the REX prefix as in legacy encodings?

Yes, it is nullified and this behavior should be preserved, I think. I was also able to verify this on an APX-prototyped system.


The text clearly permits 0x48 0x66 0xD5, since the REX prefix doesn't
*immediately* precede the REX2 prefix. The table is unclear.

I'll pass this documentation feedback along to the relevant folks.

Thanks,
Chang