[PATCH 2/2] KVM: SVM: Simplify MSR interception logic for IA32_XSS MSR

Chao Gao posted 2 patches 4 months ago
[PATCH 2/2] KVM: SVM: Simplify MSR interception logic for IA32_XSS MSR
Posted by Chao Gao 4 months ago
Use svm_set_intercept_for_msr() directly to configure IA32_XSS MSR
interception, ensuring consistency with other cases where MSRs are
intercepted depending on guest caps and CPUIDs.

No functional change intended.

Signed-off-by: Chao Gao <chao.gao@intel.com>
---
With this patch applied, svm_enable_intercept_for_msr() has no user.
Should it be removed?
---
 arch/x86/kvm/svm/sev.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 6282c2930cda..504e8a87644a 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -4371,11 +4371,9 @@ void sev_es_recalc_msr_intercepts(struct kvm_vcpu *vcpu)
 	 * XSAVES being exposed to the guest so that KVM can at least honor
 	 * guest CPUID for RDMSR and WRMSR.
 	 */
-	if (guest_cpu_cap_has(vcpu, X86_FEATURE_XSAVES) &&
-	    guest_cpuid_has(vcpu, X86_FEATURE_XSAVES))
-		svm_disable_intercept_for_msr(vcpu, MSR_IA32_XSS, MSR_TYPE_RW);
-	else
-		svm_enable_intercept_for_msr(vcpu, MSR_IA32_XSS, MSR_TYPE_RW);
+	svm_set_intercept_for_msr(vcpu, MSR_IA32_XSS, MSR_TYPE_RW,
+				  !guest_cpu_cap_has(vcpu, X86_FEATURE_XSAVES) ||
+				  !guest_cpuid_has(vcpu, X86_FEATURE_XSAVES));
 }
 
 void sev_vcpu_after_set_cpuid(struct vcpu_svm *svm)
-- 
2.47.1
Re: [PATCH 2/2] KVM: SVM: Simplify MSR interception logic for IA32_XSS MSR
Posted by Binbin Wu 3 months, 2 weeks ago

On 6/12/2025 4:19 PM, Chao Gao wrote:
> Use svm_set_intercept_for_msr() directly to configure IA32_XSS MSR
> interception, ensuring consistency with other cases where MSRs are
> intercepted depending on guest caps and CPUIDs.
>
> No functional change intended.
>
> Signed-off-by: Chao Gao <chao.gao@intel.com>

Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com>

> ---
> With this patch applied, svm_enable_intercept_for_msr() has no user.
> Should it be removed?
> ---
>   arch/x86/kvm/svm/sev.c | 8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 6282c2930cda..504e8a87644a 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -4371,11 +4371,9 @@ void sev_es_recalc_msr_intercepts(struct kvm_vcpu *vcpu)
>   	 * XSAVES being exposed to the guest so that KVM can at least honor
>   	 * guest CPUID for RDMSR and WRMSR.
>   	 */
> -	if (guest_cpu_cap_has(vcpu, X86_FEATURE_XSAVES) &&
> -	    guest_cpuid_has(vcpu, X86_FEATURE_XSAVES))
> -		svm_disable_intercept_for_msr(vcpu, MSR_IA32_XSS, MSR_TYPE_RW);
> -	else
> -		svm_enable_intercept_for_msr(vcpu, MSR_IA32_XSS, MSR_TYPE_RW);
> +	svm_set_intercept_for_msr(vcpu, MSR_IA32_XSS, MSR_TYPE_RW,
> +				  !guest_cpu_cap_has(vcpu, X86_FEATURE_XSAVES) ||
> +				  !guest_cpuid_has(vcpu, X86_FEATURE_XSAVES));
>   }
>   
>   void sev_vcpu_after_set_cpuid(struct vcpu_svm *svm)
Re: [PATCH 2/2] KVM: SVM: Simplify MSR interception logic for IA32_XSS MSR
Posted by Sean Christopherson 3 months, 2 weeks ago
On Thu, Jun 12, 2025, Chao Gao wrote:
> Use svm_set_intercept_for_msr() directly to configure IA32_XSS MSR
> interception, ensuring consistency with other cases where MSRs are
> intercepted depending on guest caps and CPUIDs.
> 
> No functional change intended.
> 
> Signed-off-by: Chao Gao <chao.gao@intel.com>
> ---
> With this patch applied, svm_enable_intercept_for_msr() has no user.
> Should it be removed?

I'd say leave it.  If it's a static inline, then there's no dead overhead in the
binary, and I like having parity between VMX and SVM.
Re: [PATCH 2/2] KVM: SVM: Simplify MSR interception logic for IA32_XSS MSR
Posted by Mi, Dapeng 3 months, 4 weeks ago
On 6/12/2025 4:19 PM, Chao Gao wrote:
> Use svm_set_intercept_for_msr() directly to configure IA32_XSS MSR
> interception, ensuring consistency with other cases where MSRs are
> intercepted depending on guest caps and CPUIDs.
>
> No functional change intended.
>
> Signed-off-by: Chao Gao <chao.gao@intel.com>
> ---
> With this patch applied, svm_enable_intercept_for_msr() has no user.
> Should it be removed?
> ---
>  arch/x86/kvm/svm/sev.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 6282c2930cda..504e8a87644a 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -4371,11 +4371,9 @@ void sev_es_recalc_msr_intercepts(struct kvm_vcpu *vcpu)
>  	 * XSAVES being exposed to the guest so that KVM can at least honor
>  	 * guest CPUID for RDMSR and WRMSR.
>  	 */
> -	if (guest_cpu_cap_has(vcpu, X86_FEATURE_XSAVES) &&
> -	    guest_cpuid_has(vcpu, X86_FEATURE_XSAVES))
> -		svm_disable_intercept_for_msr(vcpu, MSR_IA32_XSS, MSR_TYPE_RW);
> -	else
> -		svm_enable_intercept_for_msr(vcpu, MSR_IA32_XSS, MSR_TYPE_RW);
> +	svm_set_intercept_for_msr(vcpu, MSR_IA32_XSS, MSR_TYPE_RW,
> +				  !guest_cpu_cap_has(vcpu, X86_FEATURE_XSAVES) ||
> +				  !guest_cpuid_has(vcpu, X86_FEATURE_XSAVES));
>  }
>  
>  void sev_vcpu_after_set_cpuid(struct vcpu_svm *svm)

Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>