diff mbox series

[v2,2/3] KVM: SVM: Fix TSC_AUX virtualization intercept update logic

Message ID aa46606f21303d5b45544ed2043966c2b3d7f69a.1694811272.git.thomas.lendacky@amd.com (mailing list archive)
State New, archived
Headers show
Series SEV-ES TSC_AUX virtualization fix and optimization | expand

Commit Message

Tom Lendacky Sept. 15, 2023, 8:54 p.m. UTC
With the TSC_AUX virtualization support now in the vcpu_set_after_cpuid()
path, the intercepts must be either cleared or set based on the guest
CPUID input. Currently the support only clears the intercepts.

Also, vcpu_set_after_cpuid() calls svm_recalc_instruction_intercepts() as
part of the processing, so the setting or clearing of the RDTSCP intercept
can be dropped from the TSC_AUX virtualization support.

Update the support to always set or clear the TSC_AUX MSR intercept based
on the virtualization requirements.

Fixes: 296d5a17e793 ("KVM: SEV-ES: Use V_TSC_AUX if available instead of RDTSC/MSR_TSC_AUX intercepts")
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
 arch/x86/kvm/svm/sev.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Comments

Tom Lendacky Sept. 15, 2023, 8:57 p.m. UTC | #1
On 9/15/23 15:54, Tom Lendacky wrote:
> With the TSC_AUX virtualization support now in the vcpu_set_after_cpuid()
> path, the intercepts must be either cleared or set based on the guest
> CPUID input. Currently the support only clears the intercepts.
> 
> Also, vcpu_set_after_cpuid() calls svm_recalc_instruction_intercepts() as
> part of the processing, so the setting or clearing of the RDTSCP intercept
> can be dropped from the TSC_AUX virtualization support.
> 
> Update the support to always set or clear the TSC_AUX MSR intercept based
> on the virtualization requirements.
> 
> Fixes: 296d5a17e793 ("KVM: SEV-ES: Use V_TSC_AUX if available instead of RDTSC/MSR_TSC_AUX intercepts")
> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>

In the end, I was really on the fence about this being a separate patch 
given the common Fixes: tag. Your call, feel free to squash with patch #1 
and massage the commit message if you'd like (or I can send a v3 with them 
squashed if you prefer).

Thanks,
Tom

> ---
>   arch/x86/kvm/svm/sev.c | 11 +++++------
>   1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 4ac01f338903..4900c078045a 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -2966,12 +2966,11 @@ static void sev_es_vcpu_after_set_cpuid(struct vcpu_svm *svm)
>   {
>   	struct kvm_vcpu *vcpu = &svm->vcpu;
>   
> -	if (boot_cpu_has(X86_FEATURE_V_TSC_AUX) &&
> -	    (guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP) ||
> -	     guest_cpuid_has(vcpu, X86_FEATURE_RDPID))) {
> -		set_msr_interception(vcpu, svm->msrpm, MSR_TSC_AUX, 1, 1);
> -		if (guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP))
> -			svm_clr_intercept(svm, INTERCEPT_RDTSCP);
> +	if (boot_cpu_has(X86_FEATURE_V_TSC_AUX)) {
> +		bool v_tsc_aux = guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP) ||
> +				 guest_cpuid_has(vcpu, X86_FEATURE_RDPID);
> +
> +		set_msr_interception(vcpu, svm->msrpm, MSR_TSC_AUX, v_tsc_aux, v_tsc_aux);
>   	}
>   }
>
diff mbox series

Patch

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 4ac01f338903..4900c078045a 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -2966,12 +2966,11 @@  static void sev_es_vcpu_after_set_cpuid(struct vcpu_svm *svm)
 {
 	struct kvm_vcpu *vcpu = &svm->vcpu;
 
-	if (boot_cpu_has(X86_FEATURE_V_TSC_AUX) &&
-	    (guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP) ||
-	     guest_cpuid_has(vcpu, X86_FEATURE_RDPID))) {
-		set_msr_interception(vcpu, svm->msrpm, MSR_TSC_AUX, 1, 1);
-		if (guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP))
-			svm_clr_intercept(svm, INTERCEPT_RDTSCP);
+	if (boot_cpu_has(X86_FEATURE_V_TSC_AUX)) {
+		bool v_tsc_aux = guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP) ||
+				 guest_cpuid_has(vcpu, X86_FEATURE_RDPID);
+
+		set_msr_interception(vcpu, svm->msrpm, MSR_TSC_AUX, v_tsc_aux, v_tsc_aux);
 	}
 }