Skip to contentSkip to conversation

x86/cpufeatures: Add macros for Intel's new fast rep string features

PATCH Applied Jim Mattson 4 participants 7 messages Sep 1, 2022 – Jan 19, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 x86/cpufeatures: Add macros for Intel's new fast rep string features

KVM_GET_SUPPORTED_CPUID should reflect these host CPUID bits. The bits are already cached in word 12. Give the bits X86_FEATURE names, so that they can be easily referenced. Hide these bits from /proc/cpuinfo, since the host kernel makes no use of them at present.

---
 arch/x86/include/asm/cpufeatures.h | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/include/asm/cpufeatures.h +3 -0
index ef4775c6db01..454f0faa8e90 100644
@@ -308,6 +308,9 @@
 /* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */
 #define X86_FEATURE_AVX_VNNI		(12*32+ 4) /* AVX VNNI instructions */
 #define X86_FEATURE_AVX512_BF16		(12*32+ 5) /* AVX512 BFLOAT16 instructions */
+#define X86_FEATURE_FZRM		(12*32+10) /* "" Fast zero-length REP MOVSB */
+#define X86_FEATURE_FSRS		(12*32+11) /* "" Fast short REP STOSB */
+#define X86_FEATURE_FSRC		(12*32+12) /* "" Fast short REP {CMPSB,SCASB} */
 
 /* AMD-defined CPU features, CPUID level 0x80000008 (EBX), word 13 */
 #define X86_FEATURE_CLZERO		(13*32+ 0) /* CLZERO instruction */
Signature · 1 line
2.37.2.789.g6183377224-goog
#1 lore raw

PATCH v3 2/2 KVM: x86: Expose CPUID.(EAX=7,ECX=1).EAX[12:10] to the guest

Fast zero-length REP MOVSB, fast short REP STOSB, and fast short REP {CMPSB,SCASB} are inherent features of the processor that cannot be hidden by the hypervisor. When these features are present on the host, enumerate them in KVM_GET_SUPPORTED_CPUID.

---
 arch/x86/kvm/cpuid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/cpuid.c +1 -1
index 75dcf7a72605..172cbfd60946 100644
@@ -636,7 +636,7 @@ void kvm_set_cpu_caps(void)
 		kvm_cpu_cap_set(X86_FEATURE_SPEC_CTRL_SSBD);
 
 	kvm_cpu_cap_mask(CPUID_7_1_EAX,
-		F(AVX_VNNI) | F(AVX512_BF16)
+		F(AVX_VNNI) | F(AVX512_BF16) | F(FZRM) | F(FSRS) | F(FSRC)
 	);
 
 	kvm_cpu_cap_mask(CPUID_D_1_EAX,
Signature · 1 line
2.37.2.789.g6183377224-goog
maintainer Reviewed-by on v3 2/2
#2 lore raw

Re: [PATCH v3 2/2] KVM: x86: Expose CPUID.(EAX=7,ECX=1).EAX[12:10] to the guest

The shortlog is trying to win some kind of award.

And technically, KVM_GET_SUPPORTED_CPUID advertises features to userspace, not to the guest. How about this?

KVM: x86: Advertise fast REP string features inherent to the CPU

Quoted 6 lines · Jim Mattson

Fast zero-length REP MOVSB, fast short REP STOSB, and fast short REP {CMPSB,SCASB} are inherent features of the processor that cannot be hidden by the hypervisor. When these features are present on the host, enumerate them in KVM_GET_SUPPORTED_CPUID.

With a less cryptic shortlog,

#3 lore raw
In reply to Jim Mattson
Quoted 15 lines · Jim Mattson

KVM_GET_SUPPORTED_CPUID should reflect these host CPUID bits. The bits are already cached in word 12. Give the bits X86_FEATURE names, so that they can be easily referenced. Hide these bits from /proc/cpuinfo, since the host kernel makes no use of them at present.

---
  arch/x86/include/asm/cpufeatures.h | 3 +++
  1 file changed, 3 insertions(+)
arch/x86/include/asm/cpufeatures.h +0 -0
index ef4775c6db01..454f0faa8e90 100644

arch/x86/include/asm/cpufeatures.h line 316

Quoted 9 lines
arch/x86/include/asm/cpufeatures.h +3 -0
@@ -308,6 +308,9 @@
  /* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */
  #define X86_FEATURE_AVX_VNNI		(12*32+ 4) /* AVX VNNI instructions */
  #define X86_FEATURE_AVX512_BF16		(12*32+ 5) /* AVX512 BFLOAT16 instructions */
+#define X86_FEATURE_FZRM		(12*32+10) /* "" Fast zero-length REP MOVSB */
+#define X86_FEATURE_FSRS		(12*32+11) /* "" Fast short REP STOSB */
+#define X86_FEATURE_FSRC		(12*32+12) /* "" Fast short REP {CMPSB,SCASB} */
 
  /* AMD-defined CPU features, CPUID level 0x80000008 (EBX), word 13 */
  #define X86_FEATURE_CLZERO		(13*32+ 0) /* CLZERO instruction */

Any reason why these bits are hidden from /proc/cpuinfo?

-hpa

maintainer
#4 lore raw
Quoted 1 line · H. Peter Anvin

Any reason why these bits are hidden from /proc/cpuinfo?

Yes, we aim to hide such purely CPUID bits from /proc/cpuinfo because it becomes a dumping ground for "enablement" of new features. But

1. those features are not really used - most userspace like binutils and gcc, etc do their own detection. (Yes, yes, I'd like to have ubiquitous CPUID faulting).

2. /proc/cpuinfo is an ABI so we have to carry *all* those gazillion flags for no good reason

So we have tools/arch/x86/kcpuid/ which we control and we can extend with all the CPUID querying needs we have.

These kvm enablement things are kinda needed because guest userspace gets an emulated CPUID so in order to detect features on its own, it needs them. And kvm has tied features to x86's X86_FEATURE stuff and there are sometimes weird interactions with it too but that's another topic...

Oh and we still do add visible flags to /proc/cpuinfo but only when they're features which need and have received non-trivial kernel enablement like TDX or SNP or so.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer Reviewed-by on v3 1/2
#5 lore raw
In reply to Jim Mattson
Quoted 7 lines · Jim Mattson

KVM_GET_SUPPORTED_CPUID should reflect these host CPUID bits. The bits are already cached in word 12. Give the bits X86_FEATURE names, so that they can be easily referenced. Hide these bits from /proc/cpuinfo, since the host kernel makes no use of them at present.

---

maintainer Applied
#6 lore raw
In reply to Jim Mattson
Quoted 6 lines · Jim Mattson

KVM_GET_SUPPORTED_CPUID should reflect these host CPUID bits. The bits are already cached in word 12. Give the bits X86_FEATURE names, so that they can be easily referenced. Hide these bits from /proc/cpuinfo, since the host kernel makes no use of them at present.

Applied to kvm-x86 misc, thanks!

[1/2] x86/cpufeatures: Add macros for Intel's new fast rep string features

      https://github.com/kvm-x86/linux/commit/751b1e1ee8e9
[2/2] KVM: x86: Expose CPUID.(EAX=7,ECX=1).EAX[12:10] to the guest
      https://github.com/kvm-x86/linux/commit/bbbe171ac12f

--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes