[PATCH RFC v1 12/20] KVM: x86: Support REX2-extended register index in the decoder
From: Chang S. Bae
Date: Mon Nov 10 2025 - 13:30:32 EST
Update register index decoding to account for the additional bit fields
introduced by the REX2 prefix.
Both ModR/M and opcode register decoding paths now consider the extended
index bits (R4, X4, B4) in addition to the legacy REX bits (R3, X3, B3).
Signed-off-by: Chang S. Bae <chang.seok.bae@xxxxxxxxx>
---
arch/x86/kvm/emulate.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 9c98843094a1..ed3a8c0bca20 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -1084,7 +1084,8 @@ static void decode_register_operand(struct x86_emulate_ctxt *ctxt,
reg = ctxt->modrm_reg;
} else {
reg = (ctxt->b & 7) |
- (ctxt->rex.bits.b3 * BIT(3));
+ (ctxt->rex.bits.b3 * BIT(3)) |
+ (ctxt->rex.bits.b4 * BIT(4));
}
if (ctxt->d & Sse) {
@@ -1124,9 +1125,12 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt,
int rc = X86EMUL_CONTINUE;
ulong modrm_ea = 0;
- ctxt->modrm_reg = ctxt->rex.bits.r3 * BIT(3);
- index_reg = ctxt->rex.bits.x3 * BIT(3);
- base_reg = ctxt->rex.bits.b3 * BIT(3);
+ ctxt->modrm_reg = (ctxt->rex.bits.r3 * BIT(3)) |
+ (ctxt->rex.bits.r4 * BIT(4));
+ index_reg = (ctxt->rex.bits.x3 * BIT(3)) |
+ (ctxt->rex.bits.x4 * BIT(4));
+ base_reg = (ctxt->rex.bits.b3 * BIT(3)) |
+ (ctxt->rex.bits.b4 * BIT(4));
ctxt->modrm_mod = (ctxt->modrm & 0xc0) >> 6;
ctxt->modrm_reg |= (ctxt->modrm & 0x38) >> 3;
--
2.51.0