Skip to contentSkip to conversation

KVM: SVM: Add module parameter to control SEV-SNP Secure TSC feature

PATCH In review Nikunj A Dadhania 3 participants 5 messages Oct 29, 2025

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

PATCH 1/1 KVM: SVM: Add module parameter to control SEV-SNP Secure TSC feature

Add a module parameter secure_tsc to allow control of the SEV-SNP Secure TSC feature at module load time, providing administrators with the ability to disable Secure TSC support even when the hardware and kernel support it.

Default the parameter to enabled (true) to maintain existing behavior when the feature is supported. Set the parameter to false if the feature cannot be enabled to reflect the actual state.

---
 arch/x86/kvm/svm/sev.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
arch/x86/kvm/svm/sev.c +9 -1
index 0835c664fbfd..1f359e31104f 100644
@@ -56,6 +56,11 @@ module_param_named(sev_snp, sev_snp_enabled, bool, 0444);
 /* enable/disable SEV-ES DebugSwap support */
 static bool sev_es_debug_swap_enabled = true;
 module_param_named(debug_swap, sev_es_debug_swap_enabled, bool, 0444);
+
+/* enable/disable Secure TSC support */
+static bool sev_snp_secure_tsc_enabled = true;
+module_param_named(secure_tsc, sev_snp_secure_tsc_enabled, bool, 0444);
+
 static u64 sev_supported_vmsa_features;
 
 static unsigned int nr_ciphertext_hiding_asids;
@@ -3147,8 +3152,11 @@ void __init sev_hardware_setup(void)
 	if (sev_es_debug_swap_enabled)
 		sev_supported_vmsa_features |= SVM_SEV_FEAT_DEBUG_SWAP;
 
-	if (sev_snp_enabled && tsc_khz && cpu_feature_enabled(X86_FEATURE_SNP_SECURE_TSC))
+	if (sev_snp_enabled && sev_snp_secure_tsc_enabled &&
+	    tsc_khz && cpu_feature_enabled(X86_FEATURE_SNP_SECURE_TSC))
 		sev_supported_vmsa_features |= SVM_SEV_FEAT_SECURE_TSC;
+	else
+		sev_snp_secure_tsc_enabled = false;
 }
 
 void sev_hardware_unsetup(void)

base-commit: 6b36119b94d0b2bb8cea9d512017efafd461d6ac

Signature · 1 line
2.48.1
#1 lore raw
Quoted 31 lines · Nikunj A Dadhania

Add a module parameter secure_tsc to allow control of the SEV-SNP Secure TSC feature at module load time, providing administrators with the ability to disable Secure TSC support even when the hardware and kernel support it.

Default the parameter to enabled (true) to maintain existing behavior when the feature is supported. Set the parameter to false if the feature cannot be enabled to reflect the actual state.

---
 arch/x86/kvm/svm/sev.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
arch/x86/kvm/svm/sev.c +5 -0
index 0835c664fbfd..1f359e31104f 100644
@@ -56,6 +56,11 @@ module_param_named(sev_snp, sev_snp_enabled, bool, 0444);
 /* enable/disable SEV-ES DebugSwap support */
 static bool sev_es_debug_swap_enabled = true;
 module_param_named(debug_swap, sev_es_debug_swap_enabled, bool, 0444);
+
+/* enable/disable Secure TSC support */
+static bool sev_snp_secure_tsc_enabled = true;
+module_param_named(secure_tsc, sev_snp_secure_tsc_enabled, bool, 0444);
+
 static u64 sev_supported_vmsa_features;
 
 static unsigned int nr_ciphertext_hiding_asids;

arch/x86/kvm/svm/sev.c void __init sev_hardware_setup(void) · line 3159

Quoted 9 lines
arch/x86/kvm/svm/sev.c +4 -1
@@ -3147,8 +3152,11 @@ void __init sev_hardware_setup(void)
 	if (sev_es_debug_swap_enabled)
 		sev_supported_vmsa_features |= SVM_SEV_FEAT_DEBUG_SWAP;
 
-	if (sev_snp_enabled && tsc_khz && cpu_feature_enabled(X86_FEATURE_SNP_SECURE_TSC))
+	if (sev_snp_enabled && sev_snp_secure_tsc_enabled &&
+	    tsc_khz && cpu_feature_enabled(X86_FEATURE_SNP_SECURE_TSC))
 		sev_supported_vmsa_features |= SVM_SEV_FEAT_SECURE_TSC;
+	else
+		sev_snp_secure_tsc_enabled = false;

Looks reasonable to me. My only nit is to rework this to look like the debug_swap support, e.g.:

arch/x86/kvm/svm/sev.c +4 -1
index 0835c664fbfd..4cf26ba637d2 100644
@@ -3143,11 +3143,14 @@ void __init sev_hardware_setup(void)
 	    !cpu_feature_enabled(X86_FEATURE_NO_NESTED_DATA_BP))
 		sev_es_debug_swap_enabled = false;
 
+	if (!sev_snp_enabled || !tsc_khz || !cpu_feature_enabled(X86_FEATURE_SNP_SECURE_TSC))
+		sev_snp_secure_tsc_enabled = false;
+
 	sev_supported_vmsa_features = 0;
 	if (sev_es_debug_swap_enabled)
 		sev_supported_vmsa_features |= SVM_SEV_FEAT_DEBUG_SWAP;
 
-	if (sev_snp_enabled && tsc_khz && cpu_feature_enabled(X86_FEATURE_SNP_SECURE_TSC))
+	if (sev_snp_secure_tsc_enabled)
 		sev_supported_vmsa_features |= SVM_SEV_FEAT_SECURE_TSC;
 }
 

But I'll leave that decision up to the maintainers.

Thanks,
Tom

Quoted 5 lines
arch/x86/kvm/svm/sev.c +0 -0
 }
 
 void sev_hardware_unsetup(void)

base-commit: 6b36119b94d0b2bb8cea9d512017efafd461d6ac

#2 lore raw
In reply to Nikunj A Dadhania
Quoted 3 lines · Nikunj A Dadhania

Add a module parameter secure_tsc to allow control of the SEV-SNP Secure TSC feature at module load time, providing administrators with the ability to disable Secure TSC support even when the hardware and kernel support it.

Why?

#3 lore raw
Quoted 6 lines · Sean Christopherson
Quoted 3 lines · Nikunj A Dadhania

Add a module parameter secure_tsc to allow control of the SEV-SNP Secure TSC feature at module load time, providing administrators with the ability to disable Secure TSC support even when the hardware and kernel support it.

Why?

That's on me. Based on the debug_swap parameter I thought we wanted to be able to control all SEV features that are advertised and thought this was just missed for Secure TSC. I'm good with not adding it we don't need to do that.

Thanks,
Tom

#4 lore raw
Quoted 6 lines · Tom Lendacky
Quoted 5 lines · Sean Christopherson
Quoted 3 lines · Nikunj A Dadhania

Add a module parameter secure_tsc to allow control of the SEV-SNP Secure TSC feature at module load time, providing administrators with the ability to disable Secure TSC support even when the hardware and kernel support it.

Quoted 6 lines
Quoted 1 line

Why?

That's on me. Based on the debug_swap parameter I thought we wanted to be able to control all SEV features that are advertised and thought this was just missed for Secure TSC. I'm good with not adding it we don't need to do that.

DebugSwap was one big mistake. At this point, I think we can and should rip out its module param.

Commit d1f85fbe836e ("KVM: SEV: Enable data breakpoints in SEV-ES") goofed by not adding a way for the userspace VMM to control the feature. Functionally, that was fine, but it broke attestation signatures because SEV_FEATURES are included in the signature.

Commit 5abf6dceb066 ("SEV: disable SEV-ES DebugSwap by default") fixed that issue, but the underlying flaw of userspace not having a way to control SEV_FEATURES was still there.

That flaw was addressed by commit 4f5defae7089 ("KVM: SEV: introduce KVM_SEV_INIT2 operation"), and so then 4dd5ecacb9a4 ("KVM: SEV: allow SEV-ES DebugSwap again") re-enabled DebugSwap by default.

Now that the dust is settled, the module param doesn't serve any meaningful purpose.