Skip to contentSkip to conversation

x86: KVM: Add common feature flag for AMD's PSFD

PATCH Applied Sean Christopherson 2 participants 3 messages Jan 24, 2023 – Mar 24, 2023

Subsystems (3)
lore
Share & tools
lore

Sean Christopherson

author maintainer
#0 lore raw

PATCH 1/1 x86: KVM: Add common feature flag for AMD's PSFD

Use a common X86_FEATURE_* flag for AMD's PSFD, and suppress it from /proc/cpuinfo via the standard method of an empty string instead of hacking in a one-off "private" #define in KVM. The request that led to KVM defining its own flag was really just that the feature not show up in /proc/cpuinfo, and additional patches+discussions in the interim have clarified that defining flags in cpufeatures.h purely so that KVM can advertise features to userspace is ok so long as the kernel already uses a word to track the associated CPUID leaf.

No functional change intended.

---
 arch/x86/include/asm/cpufeatures.h | 1 +
 arch/x86/kvm/cpuid.c               | 8 +-------
 2 files changed, 2 insertions(+), 7 deletions(-)
arch/x86/include/asm/cpufeatures.h +1 -0
index 61012476d66e..2acaebc7bb76 100644
@@ -330,6 +330,7 @@
 #define X86_FEATURE_VIRT_SSBD		(13*32+25) /* Virtualized Speculative Store Bypass Disable */
 #define X86_FEATURE_AMD_SSB_NO		(13*32+26) /* "" Speculative Store Bypass is fixed in hardware. */
 #define X86_FEATURE_CPPC		(13*32+27) /* Collaborative Processor Performance Control */
+#define X86_FEATURE_AMD_PSFD            (13*32+28) /* "" Predictive Store Forwarding Disable */
 #define X86_FEATURE_BTC_NO		(13*32+29) /* "" Not vulnerable to Branch Type Confusion */
 #define X86_FEATURE_BRS			(13*32+31) /* Branch Sampling available */
 
arch/x86/kvm/cpuid.c +1 -7
index 2a9f1e200dbc..fb2b0e3ecce1 100644
@@ -59,12 +59,6 @@ u32 xstate_required_size(u64 xstate_bv, bool compacted)
 	return ret;
 }
 
-/*
- * This one is tied to SSB in the user API, and not
- * visible in /proc/cpuinfo.
- */
-#define KVM_X86_FEATURE_AMD_PSFD	(13*32+28) /* Predictive Store Forwarding Disable */
-
 #define F feature_bit
 
 /* Scattered Flag - For features that are scattered by cpufeatures.h. */
@@ -710,7 +704,7 @@ void kvm_set_cpu_caps(void)
 		F(CLZERO) | F(XSAVEERPTR) |
 		F(WBNOINVD) | F(AMD_IBPB) | F(AMD_IBRS) | F(AMD_SSBD) | F(VIRT_SSBD) |
 		F(AMD_SSB_NO) | F(AMD_STIBP) | F(AMD_STIBP_ALWAYS_ON) |
-		__feature_bit(KVM_X86_FEATURE_AMD_PSFD)
+		F(AMD_PSFD)
 	);
 
 	/*

base-commit: 7cb79f433e75b05d1635aefaa851cfcd1cb7dc4f

Signature · 1 line
2.39.1.456.gfc5497dd1b-goog
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Sean Christopherson

Use a common X86_FEATURE_* flag for AMD's PSFD, and suppress it from /proc/cpuinfo via the standard method of an empty string instead of hacking in a one-off "private" #define in KVM. The request that led to KVM defining its own flag was really just that the feature not show up in /proc/cpuinfo, and additional patches+discussions in the interim have clarified that defining flags in cpufeatures.h purely so that KVM can advertise features to userspace is ok so long as the kernel already uses a word to track the associated CPUID leaf.

No functional change intended.

Quoted 8 lines
---
  arch/x86/include/asm/cpufeatures.h | 1 +
  arch/x86/kvm/cpuid.c               | 8 +-------
  2 files changed, 2 insertions(+), 7 deletions(-)
Quoted 40 lines
arch/x86/include/asm/cpufeatures.h +1 -0
index 61012476d66e..2acaebc7bb76 100644
@@ -330,6 +330,7 @@
  #define X86_FEATURE_VIRT_SSBD		(13*32+25) /* Virtualized Speculative Store Bypass Disable */
  #define X86_FEATURE_AMD_SSB_NO		(13*32+26) /* "" Speculative Store Bypass is fixed in hardware. */
  #define X86_FEATURE_CPPC		(13*32+27) /* Collaborative Processor Performance Control */
+#define X86_FEATURE_AMD_PSFD            (13*32+28) /* "" Predictive Store Forwarding Disable */
  #define X86_FEATURE_BTC_NO		(13*32+29) /* "" Not vulnerable to Branch Type Confusion */
  #define X86_FEATURE_BRS			(13*32+31) /* Branch Sampling available */
 
arch/x86/kvm/cpuid.c +1 -7
index 2a9f1e200dbc..fb2b0e3ecce1 100644
@@ -59,12 +59,6 @@ u32 xstate_required_size(u64 xstate_bv, bool compacted)
  	return ret;
  }
 
-/*
- * This one is tied to SSB in the user API, and not
- * visible in /proc/cpuinfo.
- */
-#define KVM_X86_FEATURE_AMD_PSFD	(13*32+28) /* Predictive Store Forwarding Disable */
-
  #define F feature_bit
 
  /* Scattered Flag - For features that are scattered by cpufeatures.h. */
@@ -710,7 +704,7 @@ void kvm_set_cpu_caps(void)
  		F(CLZERO) | F(XSAVEERPTR) |
  		F(WBNOINVD) | F(AMD_IBPB) | F(AMD_IBRS) | F(AMD_SSBD) | F(VIRT_SSBD) |
  		F(AMD_SSB_NO) | F(AMD_STIBP) | F(AMD_STIBP_ALWAYS_ON) |
-		__feature_bit(KVM_X86_FEATURE_AMD_PSFD)
+		F(AMD_PSFD)
  	);
 
  	/*

base-commit: 7cb79f433e75b05d1635aefaa851cfcd1cb7dc4f

author maintainer Applied
#2 lore raw
In reply to Sean Christopherson
Quoted 10 lines · Sean Christopherson

Use a common X86_FEATURE_* flag for AMD's PSFD, and suppress it from /proc/cpuinfo via the standard method of an empty string instead of hacking in a one-off "private" #define in KVM. The request that led to KVM defining its own flag was really just that the feature not show up in /proc/cpuinfo, and additional patches+discussions in the interim have clarified that defining flags in cpufeatures.h purely so that KVM can advertise features to userspace is ok so long as the kernel already uses a word to track the associated CPUID leaf.

[...]

Applied to kvm-x86 misc, thanks!

[1/1] x86: KVM: Add common feature flag for AMD's PSFD

      https://github.com/kvm-x86/linux/commit/3d8f61bf8bcd

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