[PATCH v9 17/20] KVM: x86: Add APX to supported XCR0
From: Chang S. Bae
Date: Tue Nov 17 2026 - 13:33:54 EST
Set kvm_caps.supported_xcr0[APX] when the host has enabled the APX state
along with CONFIG_KVM_APX=y, and eVMCS is not in use as eVMCS does not
support APX yet.
Tested-by: Zhao Liu <zhao1.liu@xxxxxxxxx>
Signed-off-by: Chang S. Bae <chang.seok.bae@xxxxxxxxx>
Reviewed-by: Jim Mattson <jmattson@xxxxxxxxxx>
---
V8 -> V9: Tighten up with eVMCS gating [*]
[*] vmx_instr_info_extended() already has this gating from patch10 and
next patch (patch18) clears APX from KVM capabilities with eVMCS.
---
arch/x86/kvm/vmx/vmx.c | 4 ++++
arch/x86/kvm/x86.c | 2 ++
2 files changed, 6 insertions(+)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 032c8988d50c..ce6024a19cb3 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -8571,6 +8571,10 @@ __init int vmx_hardware_setup(void)
kvm_caps.supported_xcr0 &= ~(XFEATURE_MASK_BNDREGS |
XFEATURE_MASK_BNDCSR);
+ /* eVMCS isn't prepared yet for APX */
+ if (kvm_is_using_evmcs())
+ kvm_caps.supported_xcr0 &= ~XFEATURE_MASK_APX;
+
if (!cpu_has_vmx_vpid() || !cpu_has_vmx_invvpid() ||
!(cpu_has_vmx_invvpid_single() || cpu_has_vmx_invvpid_global()))
enable_vpid = 0;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 71378e02ee0f..a58b67810a4e 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -7193,6 +7193,8 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
if (boot_cpu_has(X86_FEATURE_XSAVE)) {
kvm_host.xcr0 = xgetbv(XCR_XFEATURE_ENABLED_MASK);
kvm_caps.supported_xcr0 = kvm_host.xcr0 & KVM_SUPPORTED_XCR0;
+ if (IS_ENABLED(CONFIG_KVM_APX))
+ kvm_caps.supported_xcr0 |= kvm_host.xcr0 & XFEATURE_MASK_APX;
}
if (boot_cpu_has(X86_FEATURE_XSAVES)) {
--
2.53.0