public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Ewan Hai <ewanhai-oc@zhaoxin.com>
Cc: pbonzini@redhat.com, tglx@kernel.org, mingo@redhat.com,
	bp@alien8.de,  dave.hansen@linux.intel.com, x86@kernel.org,
	hpa@zytor.com,  kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org, cobechen@zhaoxin.com,
	 tonywwang@zhaoxin.com
Subject: Re: [PATCH] KVM: x86: Add KVM-only CPUID.0xC0000001:EDX feature bits
Date: Thu, 5 Mar 2026 11:43:51 -0800	[thread overview]
Message-ID: <aanc9xtztj5cYFvk@google.com> (raw)
In-Reply-To: <20260305110519.308860-1-ewanhai-oc@zhaoxin.com>

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
> 

  reply	other threads:[~2026-03-05 19:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-03-06  9:12   ` Ewan Hai
  -- strict thread matches above, loose matches on Subject: below --
2026-03-05 21:45 Christian Ludloff

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=aanc9xtztj5cYFvk@google.com \
    --to=seanjc@google.com \
    --cc=bp@alien8.de \
    --cc=cobechen@zhaoxin.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=ewanhai-oc@zhaoxin.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=tglx@kernel.org \
    --cc=tonywwang@zhaoxin.com \
    --cc=x86@kernel.org \
    /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