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 04/20] KVM: x86: Support APX state for XSAVE ABI
Date: Wed, 18 Nov 2026 17:55:13 -0800 [thread overview]
Message-ID: <b47462b9-ebd9-4a1e-8791-ee9c861d0bd3@intel.com> (raw)
In-Reply-To: <CALMp9eQABxnk2EV64xXXeH+V03LWrnK8qWOcWcDeX3tiY_N3zQ@mail.gmail.com>
On 11/18/2026 2:39 PM, Jim Mattson wrote:
>
>> +#ifdef CONFIG_KVM_APX
>> +static void kvm_copy_vcpu_regs_to_uabi(struct kvm_vcpu *vcpu, void *buf, u64 supported_xcr0)
>> +{
>> + union fpregs_state *xstate = (union fpregs_state *)buf;
>> +
>> + BUILD_BUG_ON(NR_VCPU_GENERAL_PURPOSE_REGS <= VCPU_REGS_R31);
>> +
>> + if (!(supported_xcr0 & XFEATURE_MASK_APX))
>> + return;
>
> Now that this is called only after fpu_copy_uabi_to_guest_fpstate()
> succeeds, this condition cannot be true. fpu_copy_uabi_to_guest_fpstate()
> has already rejected any XSTATE_BV bits that aren't in
> kvm_caps.supported_xcr0. (That was the second half of my comment on v8.)
I assume you meant kvm_copy_uabi_to_vcpu_regs() since that's the
function after kvm_copy_uabi_to_vcpu_regs().
Then, the check can be skipped when XSTATE_BV[APX] is set, as
fpu_copy_uabi_to_guest_fpstate() has already validated the XCR0 support.
But when XSTATE_BV[APX] is clear, still need to check supported_xcr0
before zeroing the VCPU cache of EGPRs.
While the sanity check is redundant, the rational for the removal has to
be documented, So,
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 84d9a71e14e3..c559ae29b916 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3169,6 +3169,10 @@ static void kvm_copy_vcpu_regs_to_uabi(struct
kvm_vcpu *vcpu, void *buf, u64 sup
xstate->xsave.header.xfeatures |= XFEATURE_MASK_APX;
}
+/*
+ * Must call this after successful fpu_copy_uabi_to_guest_fpstate(),
+ * which means APX is XCR0-supported if XSTATE_BV[APX] is set.
+ */
static int kvm_copy_uabi_to_vcpu_regs(struct kvm_vcpu *vcpu, void
*buf, u64 supported_xcr0)
{
union fpregs_state *xstate = (union fpregs_state *)buf;
@@ -3182,9 +3186,6 @@ static int kvm_copy_uabi_to_vcpu_regs(struct
kvm_vcpu *vcpu, void *buf, u64 supp
return 0;
}
- if (!(supported_xcr0 & XFEATURE_MASK_APX))
- return -EINVAL;
-
memcpy(&vcpu->arch.regs[VCPU_REGS_R16],
buf + xstate_offset(XFEATURE_APX),
xstate_size(XFEATURE_APX));
I think I ended up leaving the checker here rather than adding the code
comment, but I'm fine with removing the redundant check.
> With vcpu->arch.regs[] being the single source of truth, how hard would it
> be to keep the APX state out of guest_fpu altogether? It seems like that
> would be cleaner.
So, the the guest fpstate has to stay in sync with the VCPU cache.
On VM entry/exit, the guest XSTATE remains in the physical registers.
When returning to userspace, or preempted, it is saved to the guest
fpstate storage. This part is already handled, so straightforward.
But the complication is with emulator and VMX exit handling, where those
registers need to be updated through accessors, similar to how {X|Y}MM
registers are handled in fpu.h. It thus requires bringing back the ugly
switch statement [*] that previously was dropped out, or adding
something similar that is unlikely to be any simpler.
[*]
https://lore.kernel.org/kvm/20260112235408.168200-3-chang.seok.bae@intel.com/
Thanks,
Chang
next prev parent 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 [this message]
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
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=b47462b9-ebd9-4a1e-8791-ee9c861d0bd3@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®