[PATCH] KVM: x86: Add KVM-only CPUID.0xC0000001:EDX feature bits

Ewan Hai posted 1 patch 1 month ago
arch/x86/kvm/cpuid.c         | 14 ++++++++++++++
arch/x86/kvm/reverse_cpuid.h | 19 +++++++++++++++++++
2 files changed, 33 insertions(+)
[PATCH] KVM: x86: Add KVM-only CPUID.0xC0000001:EDX feature bits
Posted by Ewan Hai 1 month ago
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
Re: [PATCH] KVM: x86: Add KVM-only CPUID.0xC0000001:EDX feature bits
Posted by Sean Christopherson 1 month ago
On Thu, Mar 05, 2026, Ewan Hai wrote:
> 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.

There needs to be a _lot_ more documentation explaining what these features are,
and most importantly why it's safe/sane for KVM to advertise support to userspace
without any corresponding code changes in KVM.

The _EN flags in particular suggest some amount of emulation is required.

The patch also needs to be split up into related feature bundles (or invididual
patches if each and every feature flag represents a completely independent feature).

> 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
>
Re: [PATCH] KVM: x86: Add KVM-only CPUID.0xC0000001:EDX feature bits
Posted by Ewan Hai 1 month ago
On 3/6/26 3:43 AM, Sean Christopherson wrote:
> 
> 
> On Thu, Mar 05, 2026, Ewan Hai wrote:
>> 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.
> 
> There needs to be a _lot_ more documentation explaining what these features are,
> and most importantly why it's safe/sane for KVM to advertise support to userspace
> without any corresponding code changes in KVM.
> 

Agreed. We don't have public documentation for most of these features at the
moment, but I will do my best to provide sufficient detail about each feature
and its safety implications in the next submission.

> The _EN flags in particular suggest some amount of emulation is required.

Right, I oversimplified this in the initial patch. I will investigate the _EN
bits more carefully and document what each one actually controls and whether KVM
needs to do anything beyond passthrough.

> 
> The patch also needs to be split up into related feature bundles (or invididual
> patches if each and every feature flag represents a completely independent feature).
> 

Makes sense. I will do thorough research on these features and group them into
logical bundles based on their functionality for the next version.

>> 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
>>