Re: [PATCH v10 13/27] KVM: x86: Refresh CPUID on write to guest MSR_IA32_XSS

From: Sean Christopherson
Date: Wed May 01 2024 - 16:43:59 EST


On Sun, Feb 18, 2024, Yang Weijiang wrote:
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 9eb5c8dbd4fb..b502d68a2576 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -3926,16 +3926,23 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
> }
> break;
> case MSR_IA32_XSS:
> - if (!msr_info->host_initiated &&
> - !guest_cpuid_has(vcpu, X86_FEATURE_XSAVES))
> + /*
> + * If KVM reported support of XSS MSR, even guest CPUID doesn't
> + * support XSAVES, still allow userspace to set default value(0)
> + * to this MSR.
> + */
> + if (!guest_cpuid_has(vcpu, X86_FEATURE_XSAVES) &&
> + !(msr_info->host_initiated && data == 0))

With my proposed MSR access cleanup[*], I think (hope?) this simply becomes:

if (!guest_cpuid_has(vcpu, X86_FEATURE_XSAVES))
return KVM_MSR_RET_UNSUPPORTED;

with no comment needed as the "host && !data" case is handled in common code.

[*] https://lore.kernel.org/all/20240425181422.3250947-1-seanjc@xxxxxxxxxx