mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Chang S. Bae" <chang.seok.bae@intel.com>
To: seanjc@google.com, jmattson@google.com
Cc: pbonzini@redhat.com, kvm@vger.kernel.org, x86@kernel.org,
	linux-kernel@vger.kernel.org, zhao1.liu@intel.com,
	chang.seok.bae@intel.com
Subject: [PATCH v9 18/20] KVM: x86: Expose APX feature to userspace
Date: Tue, 17 Nov 2026 18:03:08 +0000	[thread overview]
Message-ID: <20261117180310.921701-19-chang.seok.bae@intel.com> (raw)
In-Reply-To: <20261117180310.921701-1-chang.seok.bae@intel.com>

Expose the APX feature and its sub-features to userspace. Add support for
CPUID leaf 0x29, sub-leaf 0, to enumerate the APX sub-features.

On SVM or when using eVMCS, do not advertise APX, as EGPR support is not
implemented yet.

Tested-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
---
V8 -> V9:
 * Add CPUID filtering and merge both exposure (Jim Mattson)
 * Hide when using eVMCS (Jim Mattson)
---
 arch/x86/include/asm/cpuid/api.h |  1 +
 arch/x86/include/asm/kvm_host.h  |  1 +
 arch/x86/kvm/cpuid.c             | 21 ++++++++++++++++++++-
 arch/x86/kvm/reverse_cpuid.h     |  4 ++++
 arch/x86/kvm/svm/svm.c           |  1 +
 arch/x86/kvm/vmx/vmx.c           |  4 ++++
 6 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/cpuid/api.h b/arch/x86/include/asm/cpuid/api.h
index 759b12d94bbf..80402959804f 100644
--- a/arch/x86/include/asm/cpuid/api.h
+++ b/arch/x86/include/asm/cpuid/api.h
@@ -183,6 +183,7 @@ static __always_inline bool cpuid_function_is_indexed(u32 function)
 	case 0x1f:
 	case 0x23:
 	case 0x24:
+	case 0x29:
 	case 0x8000001d:
 		return true;
 	}
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 7db87bc99f4a..f3380fbc4694 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -723,6 +723,7 @@ enum kvm_only_cpuid_leafs {
 	CPUID_7_1_ECX,
 	CPUID_1E_1_EAX,
 	CPUID_24_1_ECX,
+	CPUID_29_0_EBX,
 	NR_KVM_CPU_CAPS,
 
 	NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS,
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index f476a78a570a..2fa48efb1caa 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1049,8 +1049,12 @@ void kvm_initialize_cpu_caps(void)
 		F(AVX_VNNI_INT16),
 		F(PREFETCHITI),
 		F(AVX10),
+		SCATTERED_F(APX),
 	);
 
+	if (!IS_ENABLED(CONFIG_KVM_APX))
+		kvm_cpu_cap_clear(X86_FEATURE_APX);
+
 	kvm_cpu_cap_init(CPUID_7_2_EDX,
 		F(INTEL_PSFD),
 		F(IPRED_CTRL),
@@ -1095,6 +1099,10 @@ void kvm_initialize_cpu_caps(void)
 		F(AVX10_V1_AUX),
 	);
 
+	kvm_cpu_cap_init(CPUID_29_0_EBX,
+		F(APX_NCI_NDD_NF),
+	);
+
 	kvm_cpu_cap_init(CPUID_8000_0001_ECX,
 		F(LAHF_LM),
 		F(CMP_LEGACY),
@@ -1463,7 +1471,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
 	switch (function) {
 	case 0:
 		/* Limited to the highest leaf implemented in KVM. */
-		entry->eax = min(entry->eax, 0x24U);
+		entry->eax = min(entry->eax, 0x29U);
 		break;
 	case 1:
 		cpuid_entry_override(entry, CPUID_1_EDX);
@@ -1734,6 +1742,17 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
 		}
 		break;
 	}
+	/* APX sub-features */
+	case 0x29:
+		if (!kvm_cpu_cap_has(X86_FEATURE_APX)) {
+			entry->eax = entry->ebx = entry->ecx = entry->edx = 0;
+			break;
+		}
+		cpuid_entry_override(entry, CPUID_29_0_EBX);
+		entry->eax = 0;
+		entry->ecx = 0;
+		entry->edx = 0;
+		break;
 	case KVM_CPUID_SIGNATURE: {
 		const u32 *sigptr = (const u32 *)KVM_SIGNATURE;
 		entry->eax = KVM_CPUID_FEATURES;
diff --git a/arch/x86/kvm/reverse_cpuid.h b/arch/x86/kvm/reverse_cpuid.h
index 1ff87fe63c3c..9a4445138a8f 100644
--- a/arch/x86/kvm/reverse_cpuid.h
+++ b/arch/x86/kvm/reverse_cpuid.h
@@ -69,6 +69,9 @@
 /* Intel-defined sub-features, CPUID level 0x00000024:1 (ECX) */
 #define X86_FEATURE_AVX10_V1_AUX	KVM_X86_FEATURE(CPUID_24_1_ECX, 2)
 
+/* Intel-defined sub-features, CPUID level 0x00000029:0 (EBX) */
+#define X86_FEATURE_APX_NCI_NDD_NF	KVM_X86_FEATURE(CPUID_29_0_EBX, 0)
+
 /* CPUID level 0x80000007 (EDX). */
 #define KVM_X86_FEATURE_CONSTANT_TSC	KVM_X86_FEATURE(CPUID_8000_0007_EDX, 8)
 
@@ -112,6 +115,7 @@ static const struct cpuid_reg reverse_cpuid[] = {
 	[CPUID_7_1_ECX]       = {         7, 1, CPUID_ECX},
 	[CPUID_1E_1_EAX]      = {      0x1e, 1, CPUID_EAX},
 	[CPUID_24_1_ECX]      = {      0x24, 1, CPUID_ECX},
+	[CPUID_29_0_EBX]      = {      0x29, 0, CPUID_EBX},
 };
 
 /*
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 5ef785811e3f..074c8dab7420 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -5730,6 +5730,7 @@ static __init void svm_set_cpu_caps(void)
 	 * but that require explicit SVM support (that isn't yet implemented).
 	 */
 	kvm_cpu_cap_clear(X86_FEATURE_MSR_IMM);
+	kvm_cpu_cap_clear(X86_FEATURE_APX);
 
 	/*
 	 * LBR Virtualization must be enabled to support BusLockTrap inside the
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index ce6024a19cb3..390afa8015c5 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -8023,6 +8023,10 @@ static __init void vmx_set_cpu_caps(void)
 	 */
 	kvm_cpu_cap_set(X86_FEATURE_EFER_LMSLE_MBZ);
 
+	/* eVMCS isn't prepared yet for APX */
+	if (kvm_is_using_evmcs())
+		kvm_cpu_cap_clear(X86_FEATURE_APX);
+
 	kvm_setup_xss_caps();
 	kvm_finalize_cpu_caps();
 }
-- 
2.53.0


  parent reply	other threads:[~2026-11-17 18:32 UTC|newest]

Thread overview: 21+ 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-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-17 18:02 ` [PATCH v9 04/20] KVM: x86: Support APX state for XSAVE ABI 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-17 18:03 ` [PATCH v9 10/20] KVM: nVMX: Propagate extended instruction information Chang S. Bae
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-17 18:03 ` [PATCH v9 13/20] KVM: x86: Support REX2-prefixed opcode decode Chang S. Bae
2026-11-17 18:03 ` [PATCH v9 14/20] KVM: x86: Document EVEX-prefix not implemented Chang S. Bae
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 ` Chang S. Bae [this message]
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=20261117180310.921701-19-chang.seok.bae@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®