]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: x86: Refresh CPUID on write to guest MSR_IA32_XSS
authorYang Weijiang <weijiang.yang@intel.com>
Fri, 19 Sep 2025 22:32:14 +0000 (15:32 -0700)
committerSean Christopherson <seanjc@google.com>
Tue, 23 Sep 2025 16:00:46 +0000 (09:00 -0700)
Update CPUID.(EAX=0DH,ECX=1).EBX to reflect current required xstate size
due to XSS MSR modification.
CPUID(EAX=0DH,ECX=1).EBX reports the required storage size of all enabled
xstate features in (XCR0 | IA32_XSS). The CPUID value can be used by guest
before allocate sufficient xsave buffer.

Note, KVM does not yet support any XSS based features, i.e. supported_xss
is guaranteed to be zero at this time.

Opportunistically skip CPUID updates if XSS value doesn't change.

Suggested-by: Sean Christopherson <seanjc@google.com>
Co-developed-by: Zhang Yi Z <yi.z.zhang@linux.intel.com>
Signed-off-by: Zhang Yi Z <yi.z.zhang@linux.intel.com>
Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Chao Gao <chao.gao@intel.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Tested-by: Mathias Krause <minipli@grsecurity.net>
Tested-by: John Allen <john.allen@amd.com>
Tested-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Chao Gao <chao.gao@intel.com>
Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com>
Link: https://lore.kernel.org/r/20250919223258.1604852-8-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/cpuid.c
arch/x86/kvm/x86.c

index 6b8b5d8b13ccbec4a537b0e507a9757b137a7139..32fde9e80c2863c38cc588cfdf4f7bbe631020bb 100644 (file)
@@ -316,7 +316,8 @@ static void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
        best = kvm_find_cpuid_entry_index(vcpu, 0xD, 1);
        if (best && (cpuid_entry_has(best, X86_FEATURE_XSAVES) ||
                     cpuid_entry_has(best, X86_FEATURE_XSAVEC)))
-               best->ebx = xstate_required_size(vcpu->arch.xcr0, true);
+               best->ebx = xstate_required_size(vcpu->arch.xcr0 |
+                                                vcpu->arch.ia32_xss, true);
 }
 
 static bool kvm_cpuid_has_hyperv(struct kvm_vcpu *vcpu)
index 6ae12e8c9d052a99f24ce6d716540b9e689088f6..d142cbc71aaa11d702b7645d627505b06b08c885 100644 (file)
@@ -3993,6 +3993,8 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
                 */
                if (data & ~vcpu->arch.guest_supported_xss)
                        return 1;
+               if (vcpu->arch.ia32_xss == data)
+                       break;
                vcpu->arch.ia32_xss = data;
                vcpu->arch.cpuid_dynamic_bits_dirty = true;
                break;