public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: Add KVM-only CPUID.0xC0000001:EDX feature bits
@ 2026-03-05 11:05 Ewan Hai
  2026-03-05 19:43 ` Sean Christopherson
  0 siblings, 1 reply; 4+ messages in thread
From: Ewan Hai @ 2026-03-05 11:05 UTC (permalink / raw)
  To: seanjc, pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa, kvm,
	linux-kernel
  Cc: cobechen, tonywwang

Per Paolo's suggestion, add the missing CPUID.0xC0000001:EDX feature
bits as KVM-only X86_FEATURE_* definitions, so KVM can expose them to
userspace before they are added to the generic cpufeatures definitions.

Wire the new bits into kvm_set_cpu_caps() for CPUID_C000_0001_EDX.

As a result, KVM_GET_SUPPORTED_CPUID reports these bits according to
host capability, allowing VMMs to advertise only host-supported
features to guests.

Link: https://lore.kernel.org/all/b3632083-f8ff-4127-a488-05a2c7acf1ad@redhat.com/
Signed-off-by: Ewan Hai <ewanhai-oc@zhaoxin.com>
---
 arch/x86/kvm/cpuid.c         | 14 ++++++++++++++
 arch/x86/kvm/reverse_cpuid.h | 19 +++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 88a5426674a1..529705079904 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1242,8 +1242,12 @@ void kvm_set_cpu_caps(void)
 		kvm_cpu_cap_set(X86_FEATURE_NULL_SEL_CLR_BASE);
 
 	kvm_cpu_cap_init(CPUID_C000_0001_EDX,
+		F(SM2),
+		F(SM2_EN),
 		F(XSTORE),
 		F(XSTORE_EN),
+		F(CCS),
+		F(CCS_EN),
 		F(XCRYPT),
 		F(XCRYPT_EN),
 		F(ACE2),
@@ -1252,6 +1256,16 @@ void kvm_set_cpu_caps(void)
 		F(PHE_EN),
 		F(PMM),
 		F(PMM_EN),
+		F(PARALLAX),
+		F(PARALLAX_EN),
+		F(TM3),
+		F(TM3_EN),
+		F(RNG2),
+		F(RNG2_EN),
+		F(PHE2),
+		F(PHE2_EN),
+		F(RSA),
+		F(RSA_EN),
 	);
 
 	/*
diff --git a/arch/x86/kvm/reverse_cpuid.h b/arch/x86/kvm/reverse_cpuid.h
index 81b4a7acf72e..33e6a2755c84 100644
--- a/arch/x86/kvm/reverse_cpuid.h
+++ b/arch/x86/kvm/reverse_cpuid.h
@@ -59,6 +59,25 @@
 #define KVM_X86_FEATURE_TSA_SQ_NO	KVM_X86_FEATURE(CPUID_8000_0021_ECX, 1)
 #define KVM_X86_FEATURE_TSA_L1_NO	KVM_X86_FEATURE(CPUID_8000_0021_ECX, 2)
 
+/*
+ * Zhaoxin/Centaur-defined CPUID level 0xC0000001 (EDX) features that are
+ * currently KVM-only and not defined in cpufeatures.h.
+ */
+#define X86_FEATURE_SM2             KVM_X86_FEATURE(CPUID_C000_0001_EDX, 0)
+#define X86_FEATURE_SM2_EN          KVM_X86_FEATURE(CPUID_C000_0001_EDX, 1)
+#define X86_FEATURE_CCS             KVM_X86_FEATURE(CPUID_C000_0001_EDX, 4)
+#define X86_FEATURE_CCS_EN          KVM_X86_FEATURE(CPUID_C000_0001_EDX, 5)
+#define X86_FEATURE_PARALLAX        KVM_X86_FEATURE(CPUID_C000_0001_EDX, 16)
+#define X86_FEATURE_PARALLAX_EN     KVM_X86_FEATURE(CPUID_C000_0001_EDX, 17)
+#define X86_FEATURE_TM3             KVM_X86_FEATURE(CPUID_C000_0001_EDX, 20)
+#define X86_FEATURE_TM3_EN          KVM_X86_FEATURE(CPUID_C000_0001_EDX, 21)
+#define X86_FEATURE_RNG2            KVM_X86_FEATURE(CPUID_C000_0001_EDX, 22)
+#define X86_FEATURE_RNG2_EN         KVM_X86_FEATURE(CPUID_C000_0001_EDX, 23)
+#define X86_FEATURE_PHE2            KVM_X86_FEATURE(CPUID_C000_0001_EDX, 25)
+#define X86_FEATURE_PHE2_EN         KVM_X86_FEATURE(CPUID_C000_0001_EDX, 26)
+#define X86_FEATURE_RSA             KVM_X86_FEATURE(CPUID_C000_0001_EDX, 27)
+#define X86_FEATURE_RSA_EN          KVM_X86_FEATURE(CPUID_C000_0001_EDX, 28)
+
 struct cpuid_reg {
 	u32 function;
 	u32 index;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread
* Re: [PATCH] KVM: x86: Add KVM-only CPUID.0xC0000001:EDX feature bits
@ 2026-03-05 21:45 Christian Ludloff
  0 siblings, 0 replies; 4+ messages in thread
From: Christian Ludloff @ 2026-03-05 21:45 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Ewan Hai, pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa, kvm,
	linux-kernel, cobechen, tonywwang

> There needs to be a _lot_ more documentation [...]

The docs for GMI, Padlock, and PAUSEOPT are available
from the Zhaoxin website. A bit cumbersome to download,
but copies can be found at kib's site here:

    https://kib.kiev.ua/x86docs/Zhaoxin/

The details for TM3 and PARALLAX are harder to find – it
would be good if Zhaoxin can point to pdf files.

--
C.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-06  9:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-05 11:05 [PATCH] KVM: x86: Add KVM-only CPUID.0xC0000001:EDX feature bits Ewan Hai
2026-03-05 19:43 ` Sean Christopherson
2026-03-06  9:12   ` Ewan Hai
  -- strict thread matches above, loose matches on Subject: below --
2026-03-05 21:45 Christian Ludloff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox