mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Chang S. Bae" <chang.seok.bae@intel.com>
To: Jim Mattson <jmattson@google.com>
Cc: <seanjc@google.com>, <pbonzini@redhat.com>, <kvm@vger.kernel.org>,
	<x86@kernel.org>, <linux-kernel@vger.kernel.org>,
	<zhao1.liu@intel.com>
Subject: Re: [PATCH v9 12/20] KVM: x86: Handle EGPR index and REX2-incompatible opcodes
Date: Wed, 18 Nov 2026 17:55:23 -0800	[thread overview]
Message-ID: <28474044-d65c-49ec-99a4-b5ac5248c598@intel.com> (raw)
In-Reply-To: <CALMp9eQBQnitBu0ybMz7uidz1KLvMUi6GChyrp=45Qw1j=1i=g@mail.gmail.com>

On 11/18/2026 3:02 PM, Jim Mattson wrote:
> 
>>   static void __decode_register_operand(struct x86_emulate_ctxt *ctxt,
>>                                        struct operand *op, int reg)
>>   {
>>          if ((ctxt->d & Avx) && ctxt->op_bytes == 32) {
>> +               reg &= 0xf;
> 
> Thanks. That takes care of the BUG() in _kvm_read_sse_reg(). However,
> you didn't respond to the other half of that comment on v8:
> 
>    Similarly, em_mov_rm_sreg() and em_mov_sreg_rm() use ctxt->modrm_reg
>    directly without masking off REX.R / REX2.R3 and REX2.R4, so setting
>    R3=1 or R4=1 on opcode 0x8C or 0x8E will erroneously inject #UD.
> 
> Per Section 3.1.2.1 ("REX2 Prefix") of the Intel APX Architecture
> Specification (rev. 9.0):
> 
>    Furthermore, if ModRM.Reg addresses a segment register, both REX2.R4
>    and REX2.R3 are ignored.

Bah...thanks for the catch (again)! I suppose masking should've been
there since REX as well.

With the changelog,
     "... Also, ignore the high-order register index bits when accessing
     vector registers (XMM and YMM) or segment registers."

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index c6e11f551438..2b649d15d5f5 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -3359,6 +3359,9 @@ static int em_store_sreg(struct x86_emulate_ctxt 
*ctxt, int segment)

  static int em_mov_rm_sreg(struct x86_emulate_ctxt *ctxt)
  {
+       /* Ignore higher register index bits from REX/REX2: */
+       ctxt->modrm_reg &= 7;
+
         if (ctxt->modrm_reg > VCPU_SREG_GS)
                 return emulate_ud(ctxt);

@@ -3369,6 +3372,9 @@ static int em_mov_sreg_rm(struct x86_emulate_ctxt 
*ctxt)
  {
         u16 sel = ctxt->src.val;

+       /* Ignore higher register index bits from REX/REX2: */
+       ctxt->modrm_reg &= 7;
+
         if (ctxt->modrm_reg == VCPU_SREG_CS || ctxt->modrm_reg > 
VCPU_SREG_GS)
                 return emulate_ud(ctxt);

  reply	other threads:[~2026-11-19  1:55 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 18:02 [PATCH v9 00/20] KVM: x86: Enable APX for guest Chang S. Bae
2026-11-17 18:02 ` [PATCH v9 01/20] KVM: x86: Extend VCPU registers for EGPRs Chang S. Bae
2026-11-18  4:12   ` Jim Mattson
2026-11-17 18:02 ` [PATCH v9 02/20] KVM: VMX: Save guest EGPRs in VCPU cache Chang S. Bae
2026-11-17 18:02 ` [PATCH v9 03/20] KVM: x86: Support EGPRs on VCPU RESET/INIT events Chang S. Bae
2026-11-18  4:44   ` Jim Mattson
2026-11-17 18:02 ` [PATCH v9 04/20] KVM: x86: Support APX state for XSAVE ABI Chang S. Bae
2026-11-18 22:39   ` Jim Mattson
2026-11-19  1:55     ` Chang S. Bae
2026-11-17 18:02 ` [PATCH v9 05/20] KVM: VMX: Refactor VMX instruction information access Chang S. Bae
2026-11-17 18:02 ` [PATCH v9 06/20] KVM: VMX: Refactor instruction information decoding Chang S. Bae
2026-11-17 18:02 ` [PATCH v9 07/20] KVM: VMX: Remove unused control-register access defines Chang S. Bae
2026-11-17 18:02 ` [PATCH v9 08/20] KVM: VMX: Refactor register index retrieval from exit qualification Chang S. Bae
2026-11-17 18:02 ` [PATCH v9 09/20] KVM: VMX: Support instruction information extension Chang S. Bae
2026-11-18  4:13   ` Jim Mattson
2026-11-17 18:03 ` [PATCH v9 10/20] KVM: nVMX: Propagate extended instruction information Chang S. Bae
2026-11-18  4:14   ` Jim Mattson
2026-11-17 18:03 ` [PATCH v9 11/20] KVM: x86: Support EGPR accessing and tracking for emulator Chang S. Bae
2026-11-17 18:03 ` [PATCH v9 12/20] KVM: x86: Handle EGPR index and REX2-incompatible opcodes Chang S. Bae
2026-11-18 23:02   ` Jim Mattson
2026-11-19  1:55     ` Chang S. Bae [this message]
2026-11-17 18:03 ` [PATCH v9 13/20] KVM: x86: Support REX2-prefixed opcode decode Chang S. Bae
2026-11-18 23:03   ` Jim Mattson
2026-11-17 18:03 ` [PATCH v9 14/20] KVM: x86: Document EVEX-prefix not implemented Chang S. Bae
2026-11-18 23:05   ` Jim Mattson
2026-11-17 18:03 ` [PATCH v9 15/20] KVM: x86: Move KVM_SUPPORTED_{XCR0,XSS} into kvm_x86_vendor_init() Chang S. Bae
2026-11-17 18:03 ` [PATCH v9 16/20] KVM: x86: Guard valid XCR0.APX settings Chang S. Bae
2026-11-17 18:03 ` [PATCH v9 17/20] KVM: x86: Add APX to supported XCR0 Chang S. Bae
2026-11-17 18:03 ` [PATCH v9 18/20] KVM: x86: Expose APX feature to userspace Chang S. Bae
2026-11-18 23:07   ` Jim Mattson
2026-11-17 18:03 ` [PATCH v9 19/20] KVM: selftests: Add APX state and ABI test Chang S. Bae
2026-11-17 18:03 ` [PATCH v9 20/20] KVM: selftests: Add APX state handling and XCR0 sanity checks Chang S. Bae

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=28474044-d65c-49ec-99a4-b5ac5248c598@intel.com \
    --to=chang.seok.bae@intel.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=x86@kernel.org \
    --cc=zhao1.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®