KVM: x86: Expose Zhaoxin CPUID 0xC0000001 EDX cryptographic features
cover KVM: x86: Expose Zhaoxin CPUID 0xC0000001 EDX cryptographic features
This series exposes five groups of Zhaoxin-specific CPUID 0xC0000001 EDX feature bits to KVM guests. Each group corresponds to a category of user-mode cryptographic or RNG instructions that have been present in Zhaoxin processors but not yet advertised by KVM.
All instructions covered here are user-mode and available in all CPU modes (real / V86 / compat / protected / long), with no associated MSR control. Each feature is reported as a (X, X_EN) pair where the two bits are redundant by hardware design (set or cleared together), and both are CPUID-level reporting bits requiring no KVM emulation.
The five feature groups:
1. SM2 (bits 0, 1): SM2 elliptic-curve public-key cryptography algorithm per GM/T 0003-2012. Used for key generation, encryption/decryption, digital signatures, and key exchange in Chinese cryptographic standards.
2. CCS (bits 4, 5): SM3 hash algorithm per GM/T 0004-2012 and SM4 block cipher per GM/T 0002-2012 (supports ECB / CBC / CFB / OFB / CTR plus CBC-MAC / CFB-MAC). Foundational primitives for Chinese cryptographic protocols.
3. RNG2 (bits 22, 23): Second-generation hardware RNG exposed via the REP XRNG2 instruction. Two on-die RNG sources selectable per call, with raw and post-processed output modes. Provides high-quality entropy for cryptographic operations.
4. PHE2 (bits 25, 26): SHA-384 and SHA-512 hardware acceleration per FIPS 180-3, exposed via REP XSHA384 and REP XSHA512. Used by TLS, SSH, file integrity, and signature schemes.
5. RSA (bits 27, 28): Big-number modular exponentiation (REP XMODEXP, A^B mod M) and modular multiplication (REP MONTMUL2, A*B mod M), supporting operand sizes from 256 to 32768 bits. Used for RSA and related public-key operations.
References:
The instruction encodings, control-word formats, and per-feature semantics referenced in the individual patches are documented in:
- GMI Instruction Set Reference (SM2 / SM3 / SM4)
- PadLock Instruction Reference (XRNG2 / XSHA384 / XSHA512 / XMODEXP / MONTMUL2)
Both available from https://kib.kiev.ua/x86docs/Zhaoxin/
Ewan Hai (5):
KVM: x86: Expose Zhaoxin SM2 CPUID feature
KVM: x86: Expose Zhaoxin CCS (SM3 + SM4) CPUID feature
KVM: x86: Expose Zhaoxin RNG2 CPUID feature
KVM: x86: Expose Zhaoxin PHE2 CPUID feature
KVM: x86: Expose Zhaoxin RSA CPUID feature
arch/x86/kvm/cpuid.c | 10 ++++++++++ arch/x86/kvm/reverse_cpuid.h | 12 ++++++++++++ 2 files changed, 22 insertions(+)
base-commit: 50897c955902c93ae71c38698abb910525ebdc89 --
2.34.1
PATCH 1/5 KVM: x86: Expose Zhaoxin SM2 CPUID feature
Advertise the Zhaoxin SM2 instruction support to guests via CPUID 0xC0000001 EDX bits 0 (SM2) and 1 (SM2_EN).
The SM2 instruction (encoding F2 0F A6 C0) implements the SM2 elliptic-curve public-key cryptography algorithm specified in GM/T 0003-2012; the hardware-level behavior is documented in the Zhaoxin GMI Instruction Set Reference, chapter 1 ("SM2"). The instruction multiplexes its sub-functions on the RDX[5:0] control
word: encryption (subsection 1.1), decryption (1.2), signing (1.3), signature verification (1.4), the three key-exchange sub-operations of section 1.5 (1.5.1 SM2 key-pair generation, which the spec also uses for the initiator's ephemeral key; 1.5.2 responder shared-key derivation; 1.5.3 initiator shared-key derivation), and two preprocess steps for identity and message hashing (1.6.1 and 1.6.2).
The instruction is user-mode and available in all CPU modes, with no associated MSR control. The SM2 and SM2_EN bits are redundant by hardware design (set or cleared together) and both serve purely as CPUID-level feature-presence reporting flags requiring no KVM emulation. Both bits are advertised because different software may probe either one when checking for SM2 availability.
--- arch/x86/kvm/cpuid.c | 2 ++ arch/x86/kvm/reverse_cpuid.h | 4 ++++ 2 files changed, 6 insertions(+)
arch/x86/kvm/cpuid.c +2 -0
@@ -1272,6 +1272,8 @@ void kvm_initialize_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(XCRYPT),
arch/x86/kvm/reverse_cpuid.h +4 -0
@@ -76,6 +76,10 @@#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 sub-features, CPUID level 0xC0000001 (EDX) */ +#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) +struct cpuid_reg {u32 function;u32 index;
Signature · 1 line
2.34.1
Re: [PATCH 1/5] KVM: x86: Expose Zhaoxin SM2 CPUID feature
Quoted 46 lines · Ewan Hai
Advertise the Zhaoxin SM2 instruction support to guests via CPUID
0xC0000001EDX bits 0 (SM2) and 1 (SM2_EN).The SM2 instruction (encoding F2 0F A6 C0) implements the SM2 elliptic-curve public-key cryptography algorithm specified in GM/T 0003-2012; the hardware-level behavior is documented in the Zhaoxin GMI Instruction Set Reference, chapter 1 ("SM2"). The instruction multiplexes its sub-functions on the RDX[5:0] control
word: encryption (subsection 1.1), decryption (1.2), signing (1.3), signature verification (1.4), the three key-exchange sub-operations of section 1.5 (1.5.1 SM2 key-pair generation, which the spec also uses for the initiator's ephemeral key; 1.5.2 responder shared-key derivation; 1.5.3 initiator shared-key derivation), and two preprocess steps for identity and message hashing (1.6.1 and 1.6.2).The instruction is user-mode and available in all CPU modes, with no associated MSR control. The SM2 and
SM2_ENbits are redundant by hardware design (set or cleared together) and both serve purely as CPUID-level feature-presence reporting flags requiring no KVM emulation. Both bits are advertised because different software may probe either one when checking for SM2 availability.Signed-off-by Ewan Hai <[email protected]>--- arch/x86/kvm/cpuid.c | 2 ++ arch/x86/kvm/reverse_cpuid.h | 4 ++++ 2 files changed, 6 insertions(+)arch/x86/kvm/cpuid.c +2
-0@@ -1272,6 +1272,8 @@ void kvm_initialize_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(XCRYPT),arch/x86/kvm/reverse_cpuid.h +0
-0
arch/x86/kvm/reverse_cpuid.h line 81
Quoted 6 lines
arch/x86/kvm/reverse_cpuid.h +3
-0@@ -76,6 +76,10 @@#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 sub-features, CPUID level 0xC0000001 (EDX) */ +#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)
Are these new bits really KVM-only feature bits?
KVM_X86_FEATURE() is used for the features either scattered by cpufeatures.h or features that are 100% KVM-only.
Kernel already has a feature word CPUID_C000_0001_EDX defined for CPUID 0xC0000001 (EDX). I think these new feature bits should be put together with the existing ones (i.e. X86_FEATURE_XSTORE, ..., X86_FEATURE_PMM_EN) in cpufeatures.h.
Same for the other patches.
Quoted 4 lines
arch/x86/kvm/reverse_cpuid.h +1
-0+struct cpuid_reg {u32 function;u32 index;
Re: [PATCH 1/5] KVM: x86: Expose Zhaoxin SM2 CPUID feature
Quoted 62 lines · Binbin Wu <[email protected]> 于2026年5月13日周三 18:36写道:
Quoted 46 lines · Ewan Hai
Advertise the Zhaoxin SM2 instruction support to guests via CPUID
0xC0000001EDX bits 0 (SM2) and 1 (SM2_EN).The SM2 instruction (encoding F2 0F A6 C0) implements the SM2 elliptic-curve public-key cryptography algorithm specified in GM/T 0003-2012; the hardware-level behavior is documented in the Zhaoxin GMI Instruction Set Reference, chapter 1 ("SM2"). The instruction multiplexes its sub-functions on the RDX[5:0] control
word: encryption (subsection 1.1), decryption (1.2), signing (1.3), signature verification (1.4), the three key-exchange sub-operations of section 1.5 (1.5.1 SM2 key-pair generation, which the spec also uses for the initiator's ephemeral key; 1.5.2 responder shared-key derivation; 1.5.3 initiator shared-key derivation), and two preprocess steps for identity and message hashing (1.6.1 and 1.6.2).The instruction is user-mode and available in all CPU modes, with no associated MSR control. The SM2 and
SM2_ENbits are redundant by hardware design (set or cleared together) and both serve purely as CPUID-level feature-presence reporting flags requiring no KVM emulation. Both bits are advertised because different software may probe either one when checking for SM2 availability.Signed-off-by Ewan Hai <[email protected]>--- arch/x86/kvm/cpuid.c | 2 ++ arch/x86/kvm/reverse_cpuid.h | 4 ++++ 2 files changed, 6 insertions(+)arch/x86/kvm/cpuid.c +2
-0@@ -1272,6 +1272,8 @@ void kvm_initialize_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(XCRYPT),arch/x86/kvm/reverse_cpuid.h +0
-0arch/x86/kvm/reverse_cpuid.h line 81
Quoted 6 lines
arch/x86/kvm/reverse_cpuid.h +3
-0@@ -76,6 +76,10 @@#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 sub-features, CPUID level 0xC0000001 (EDX) */ +#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)Are these new bits really KVM-only feature bits?
KVM_X86_FEATURE()is used for the features either scattered bycpufeatures.hor features that are 100% KVM-only.
Quoted 7 lines
Kernel already has a feature word
CPUID_C000_0001_EDXdefined for CPUID0xC0000001(EDX). I think these new feature bits should be put together with the existing ones (i.e.X86_FEATURE_XSTORE, ...,X86_FEATURE_PMM_EN) incpufeatures.h.Same for the other patches.
Thanks for the review.
Some history that might help. We tried the cpufeatures.h approach back in April 2023:
https://lore.kernel.org/all/[email protected]/
That didn't go in. The pushback then was that cpufeatures.h additions should come with an in-kernel user of the feature, not just to expose a bit. Nothing under drivers/crypto/ or lib/crypto/ calls these instructions, and we don't have a kernel user lined up. They're unprivileged, and the practical pattern is host/guest user space probing CPUID directly and calling them inline. OpenSSL's PadLock engine does exactly this today for XCRYPT/XSHA, and the new bits would be used the same way.
That's why we ended up in reverse_cpuid.h, reading "no in-kernel consumer" as the line between the two headers.
If the rule has shifted and you'd rather see these in cpufeatures.h next to the existing word-5 entries, we can respin as v2.
Quoted 6 lines
Quoted 5 lines
arch/x86/kvm/reverse_cpuid.h +1
-0+struct cpuid_reg {u32 function;u32 index;
Re: [PATCH 1/5] KVM: x86: Expose Zhaoxin SM2 CPUID feature
Quoted 87 lines · Ewan Hai
Quoted 62 lines · Binbin Wu <[email protected]> 于2026年5月13日周三 18:36写道:
Quoted 46 lines · Ewan Hai
Advertise the Zhaoxin SM2 instruction support to guests via CPUID
0xC0000001EDX bits 0 (SM2) and 1 (SM2_EN).The SM2 instruction (encoding F2 0F A6 C0) implements the SM2 elliptic-curve public-key cryptography algorithm specified in GM/T 0003-2012; the hardware-level behavior is documented in the Zhaoxin GMI Instruction Set Reference, chapter 1 ("SM2"). The instruction multiplexes its sub-functions on the RDX[5:0] control
word: encryption (subsection 1.1), decryption (1.2), signing (1.3), signature verification (1.4), the three key-exchange sub-operations of section 1.5 (1.5.1 SM2 key-pair generation, which the spec also uses for the initiator's ephemeral key; 1.5.2 responder shared-key derivation; 1.5.3 initiator shared-key derivation), and two preprocess steps for identity and message hashing (1.6.1 and 1.6.2).The instruction is user-mode and available in all CPU modes, with no associated MSR control. The SM2 and
SM2_ENbits are redundant by hardware design (set or cleared together) and both serve purely as CPUID-level feature-presence reporting flags requiring no KVM emulation. Both bits are advertised because different software may probe either one when checking for SM2 availability.Signed-off-by Ewan Hai <[email protected]>--- arch/x86/kvm/cpuid.c | 2 ++ arch/x86/kvm/reverse_cpuid.h | 4 ++++ 2 files changed, 6 insertions(+)arch/x86/kvm/cpuid.c +2
-0@@ -1272,6 +1272,8 @@ void kvm_initialize_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(XCRYPT),arch/x86/kvm/reverse_cpuid.h +0
-0arch/x86/kvm/reverse_cpuid.h line 81
Quoted 6 lines
arch/x86/kvm/reverse_cpuid.h +3
-0@@ -76,6 +76,10 @@#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 sub-features, CPUID level 0xC0000001 (EDX) */ +#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)Are these new bits really KVM-only feature bits?
KVM_X86_FEATURE()is used for the features either scattered bycpufeatures.hor features that are 100% KVM-only.Quoted 7 lines
Kernel already has a feature word
CPUID_C000_0001_EDXdefined for CPUID0xC0000001(EDX). I think these new feature bits should be put together with the existing ones (i.e.X86_FEATURE_XSTORE, ...,X86_FEATURE_PMM_EN) incpufeatures.h.Same for the other patches.
Thanks for the review.
Some history that might help. We tried the
cpufeatures.happroach back in April 2023:https://lore.kernel.org/all/[email protected]/
That didn't go in. The pushback then was that
cpufeatures.hadditions should come with an in-kernel user of the feature, not just to expose a bit. Nothing underdrivers/crypto/orlib/crypto/calls these instructions, and we don't have a kernel user lined up. They're unprivileged, and the practical pattern is host/guest user space probing CPUID directly and calling them inline. OpenSSL's PadLock engine does exactly this today for XCRYPT/XSHA, and the new bits would be used the same way.
Quoted 5 lines
That's why we ended up in
reverse_cpuid.h, reading "no in-kernel consumer" as the line between the two headers.If the rule has shifted and you'd rather see these in
cpufeatures.hnext to the existing word-5 entries, we can respin as v2.
Sorry, I missed the info that these are only used in user mode. Please ignore my previous comments.
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
arch/x86/kvm/reverse_cpuid.h +1
-0+struct cpuid_reg {u32 function;u32 index;
Re: [PATCH 1/5] KVM: x86: Expose Zhaoxin SM2 CPUID feature
Quoted 91 lines · Binbin Wu
Quoted 87 lines · Ewan Hai
Quoted 62 lines · Binbin Wu <[email protected]> 于2026年5月13日周三 18:36写道:
Quoted 46 lines · Ewan Hai
Advertise the Zhaoxin SM2 instruction support to guests via CPUID
0xC0000001EDX bits 0 (SM2) and 1 (SM2_EN).The SM2 instruction (encoding F2 0F A6 C0) implements the SM2 elliptic-curve public-key cryptography algorithm specified in GM/T 0003-2012; the hardware-level behavior is documented in the Zhaoxin GMI Instruction Set Reference, chapter 1 ("SM2"). The instruction multiplexes its sub-functions on the RDX[5:0] control
word: encryption (subsection 1.1), decryption (1.2), signing (1.3), signature verification (1.4), the three key-exchange sub-operations of section 1.5 (1.5.1 SM2 key-pair generation, which the spec also uses for the initiator's ephemeral key; 1.5.2 responder shared-key derivation; 1.5.3 initiator shared-key derivation), and two preprocess steps for identity and message hashing (1.6.1 and 1.6.2).The instruction is user-mode and available in all CPU modes, with no associated MSR control. The SM2 and
SM2_ENbits are redundant by hardware design (set or cleared together) and both serve purely as CPUID-level feature-presence reporting flags requiring no KVM emulation. Both bits are advertised because different software may probe either one when checking for SM2 availability.Signed-off-by Ewan Hai <[email protected]>--- arch/x86/kvm/cpuid.c | 2 ++ arch/x86/kvm/reverse_cpuid.h | 4 ++++ 2 files changed, 6 insertions(+)arch/x86/kvm/cpuid.c +2
-0@@ -1272,6 +1272,8 @@ void kvm_initialize_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(XCRYPT),arch/x86/kvm/reverse_cpuid.h +0
-0arch/x86/kvm/reverse_cpuid.h line 81
Quoted 6 lines
arch/x86/kvm/reverse_cpuid.h +3
-0@@ -76,6 +76,10 @@#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 sub-features, CPUID level 0xC0000001 (EDX) */ +#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)Are these new bits really KVM-only feature bits?
KVM_X86_FEATURE()is used for the features either scattered bycpufeatures.hor features that are 100% KVM-only.Quoted 7 lines
Kernel already has a feature word
CPUID_C000_0001_EDXdefined for CPUID0xC0000001(EDX). I think these new feature bits should be put together with the existing ones (i.e.X86_FEATURE_XSTORE, ...,X86_FEATURE_PMM_EN) incpufeatures.h.Same for the other patches.
Thanks for the review.
Some history that might help. We tried the
cpufeatures.happroach back in April 2023:https://lore.kernel.org/all/[email protected]/
That didn't go in. The pushback then was that
cpufeatures.hadditions should come with an in-kernel user of the feature, not just to expose a bit. Nothing underdrivers/crypto/orlib/crypto/calls these instructions, and we don't have a kernel user lined up. They're unprivileged, and the practical pattern is host/guest user space probing CPUID directly and calling them inline. OpenSSL's PadLock engine does exactly this today for XCRYPT/XSHA, and the new bits would be used the same way.
Quoted 9 lines
Quoted 5 lines
That's why we ended up in
reverse_cpuid.h, reading "no in-kernel consumer" as the line between the two headers.If the rule has shifted and you'd rather see these in
cpufeatures.hnext to the existing word-5 entries, we can respin as v2.Sorry, I missed the info that these are only used in user mode. Please ignore my previous comments.
No worries.
One quick clarification in case it trips up other reviewers: these aren't user-mode only. They're unprivileged, so ring 0 can execute them too. There's just no in-tree kernel code that does, and in practice user space is where they actually get used.
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
arch/x86/kvm/reverse_cpuid.h +1
-0+struct cpuid_reg {u32 function;u32 index;
PATCH 2/5 KVM: x86: Expose Zhaoxin CCS (SM3 + SM4) CPUID feature
In reply to Ewan HaiAdvertise the Zhaoxin CCS (Chinese Cryptography Standard) feature to guests via CPUID 0xC0000001 EDX bits 4 (CCS) and 5 (CCS_EN). CCS groups two user-mode instructions for Chinese national cryptographic primitives, documented in the Zhaoxin GMI Instruction Set Reference, chapter 2 ("CCS instruction group"):
- SM3 (encoding F3 0F A6 E8, subsection 2.1) implements the SM3 hash algorithm specified in GM/T 0004-2012. It supports two modes selected by RAX: auto-padding stream mode (RAX=0) and pre-padded block mode (RAX=-1).
- SM4 (encoding F3 0F A7 F0, subsection 2.2) implements the SM4 block cipher specified in GM/T 0002-2012, supporting ECB / CBC / CFB / OFB / CTR modes via a control word in RAX, and CBC-MAC / CFB-MAC when RAX bit[11] is set.
Both instructions are user-mode and available in all CPU modes, with no associated MSR control. The CCS and CCS_EN bits are redundant by hardware design (set or cleared together) and both serve purely as CPUID-level feature-presence reporting flags requiring no KVM emulation. Both bits are advertised because different software may probe either one when checking for CCS availability.
--- arch/x86/kvm/cpuid.c | 2 ++ arch/x86/kvm/reverse_cpuid.h | 2 ++ 2 files changed, 4 insertions(+)
arch/x86/kvm/cpuid.c +2 -0
@@ -1276,6 +1276,8 @@ void kvm_initialize_cpu_caps(void)F (SM2_EN ),F (XSTORE ),F (XSTORE_EN ), +F (CCS ), +F (CCS_EN ),F (XCRYPT ),F (XCRYPT_EN ), F(ACE2),
arch/x86/kvm/reverse_cpuid.h +2 -0
@@ -79,6 +79,8 @@/* Zhaoxin/Centaur sub-features, CPUID level 0xC0000001 (EDX) */ #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)struct cpuid_reg {u32 function;
Signature · 1 line
2.34.1
PATCH 3/5 KVM: x86: Expose Zhaoxin RNG2 CPUID feature
In reply to Ewan HaiAdvertise the Zhaoxin second-generation hardware RNG to guests via CPUID 0xC0000001 EDX bits 22 (RNG2) and 23 (RNG2_EN).
RNG2 is exposed by the REP XRNG2 instruction (encoding F3 0F A7 F8), documented in the Zhaoxin PadLock Instruction Reference, subsection 1.3 ("REP XRNG2"). It produces random bytes from two on-die RNG sources selectable via RAX bits[10:9] and an output mode (raw vs post-processed) controlled by RDX bits[1:0], providing high-quality entropy intended for cryptographic operations.
REP XRNG2 is user-mode and available in all CPU modes, with no associated MSR control. The RNG2 and RNG2_EN bits are redundant by hardware design (set or cleared together) and both serve purely as CPUID-level feature-presence reporting flags requiring no KVM emulation. Both bits are advertised because different software may probe either one when checking for RNG2 availability.
--- arch/x86/kvm/cpuid.c | 2 ++ arch/x86/kvm/reverse_cpuid.h | 2 ++ 2 files changed, 4 insertions(+)
arch/x86/kvm/cpuid.c +2 -0
@@ -1286,6 +1286,8 @@ void kvm_initialize_cpu_caps(void)F (PHE_EN ),F (PMM ),F (PMM_EN ), +F (RNG2 ), + F(RNG2_EN), );/*
arch/x86/kvm/reverse_cpuid.h +2 -0
@@ -81,6 +81,8 @@#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_RNG2 KVM_X86_FEATURE(CPUID_C000_0001_EDX, 22) +#define X86_FEATURE_RNG2_EN KVM_X86_FEATURE(CPUID_C000_0001_EDX, 23)struct cpuid_reg {u32 function;
Signature · 1 line
2.34.1
PATCH 4/5 KVM: x86: Expose Zhaoxin PHE2 CPUID feature
In reply to Ewan HaiAdvertise the Zhaoxin PadLock Hash Engine v2 to guests via CPUID 0xC0000001 EDX bits 25 (PHE2) and 26 (PHE2_EN). PHE2 extends the PadLock hash family with SHA-384 and SHA-512 support per FIPS 180-3, complementing the existing PHE feature (SHA-1 and SHA-256).
Two user-mode instructions are exposed, documented in the Zhaoxin PadLock Instruction Reference, chapter 3 ("Hash Engine"):
- REP XSHA384 (encoding F3 0F A6 D8, subsection 3.3)
- REP XSHA512 (encoding F3 0F A6 E0, subsection 3.4)
Both consume software-padded 128-byte blocks (RCX = block count, RSI = input, RDI = state) and produce hash output in the state buffer.
Both instructions are user-mode and available in all CPU modes, with no associated MSR control. The PHE2 and PHE2_EN bits are redundant by hardware design (set or cleared together) and both serve purely as CPUID-level feature-presence reporting flags requiring no KVM emulation. Both bits are advertised because different software may probe either one when checking for PHE2 availability.
--- arch/x86/kvm/cpuid.c | 2 ++ arch/x86/kvm/reverse_cpuid.h | 2 ++ 2 files changed, 4 insertions(+)
arch/x86/kvm/cpuid.c +2 -0
@@ -1288,6 +1288,8 @@ void kvm_initialize_cpu_caps(void)F (PMM_EN ),F (RNG2 ),F (RNG2_EN ), +F (PHE2 ), + F(PHE2_EN), );/*
arch/x86/kvm/reverse_cpuid.h +2 -0
@@ -83,6 +83,8 @@#define X86_FEATURE_CCS_EN KVM_X86_FEATURE(CPUID_C000_0001_EDX, 5)#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)struct cpuid_reg {u32 function;
Signature · 1 line
2.34.1
PATCH 5/5 KVM: x86: Expose Zhaoxin RSA CPUID feature
In reply to Ewan HaiAdvertise the Zhaoxin big-number arithmetic engine to guests via CPUID 0xC0000001 EDX bits 27 (RSA) and 28 (RSA_EN). The RSA feature provides two user-mode instructions for modular arithmetic on big integers, documented in the Zhaoxin PadLock Instruction Reference, chapter 4 ("Modular Multiplication and Exponentiation Engine"). Both support operand sizes from 256 to 32768 bits (in 128-bit increments):
- REP XMODEXP (encoding F3 0F A6 F8, subsection 4.1) computes A^B mod M
- REP MONTMUL2 (encoding F3 0F A6 F0, subsection 4.2) computes A*B mod M
REP MONTMUL2 is the long-mode replacement of legacy REP MONTMUL, which is restricted to compatibility and 32-bit protected modes. These primitives accelerate RSA and related public-key operations.
Both instructions are user-mode and available in all CPU modes, with no associated MSR control. The RSA and RSA_EN bits are redundant by hardware design (set or cleared together) and both serve purely as CPUID-level feature-presence reporting flags requiring no KVM emulation. Both bits are advertised because different software may probe either one when checking for RSA availability.
--- arch/x86/kvm/cpuid.c | 2 ++ arch/x86/kvm/reverse_cpuid.h | 2 ++ 2 files changed, 4 insertions(+)
arch/x86/kvm/cpuid.c +2 -0
@@ -1290,6 +1290,8 @@ void kvm_initialize_cpu_caps(void)F (RNG2_EN ),F (PHE2 ),F (PHE2_EN ), +F (RSA ), + F(RSA_EN), );/*
arch/x86/kvm/reverse_cpuid.h +2 -0
@@ -85,6 +85,8 @@#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;
Signature · 1 line
2.34.1