Skip to content

Commit 9622e11

Browse files
yang-weijiangsean-jc
authored andcommitted
KVM: x86: Refresh CPUID on write to guest MSR_IA32_XSS
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 <[email protected]> Co-developed-by: Zhang Yi Z <[email protected]> Signed-off-by: Zhang Yi Z <[email protected]> Signed-off-by: Yang Weijiang <[email protected]> Reviewed-by: Maxim Levitsky <[email protected]> Reviewed-by: Chao Gao <[email protected]> Reviewed-by: Xiaoyao Li <[email protected]> Tested-by: Mathias Krause <[email protected]> Tested-by: John Allen <[email protected]> Tested-by: Rick Edgecombe <[email protected]> Signed-off-by: Chao Gao <[email protected]> Reviewed-by: Binbin Wu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 338543c commit 9622e11

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

arch/x86/kvm/cpuid.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ static void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
316316
best = kvm_find_cpuid_entry_index(vcpu, 0xD, 1);
317317
if (best && (cpuid_entry_has(best, X86_FEATURE_XSAVES) ||
318318
cpuid_entry_has(best, X86_FEATURE_XSAVEC)))
319-
best->ebx = xstate_required_size(vcpu->arch.xcr0, true);
319+
best->ebx = xstate_required_size(vcpu->arch.xcr0 |
320+
vcpu->arch.ia32_xss, true);
320321
}
321322

322323
static bool kvm_cpuid_has_hyperv(struct kvm_vcpu *vcpu)

arch/x86/kvm/x86.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3993,6 +3993,8 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
39933993
*/
39943994
if (data & ~vcpu->arch.guest_supported_xss)
39953995
return 1;
3996+
if (vcpu->arch.ia32_xss == data)
3997+
break;
39963998
vcpu->arch.ia32_xss = data;
39973999
vcpu->arch.cpuid_dynamic_bits_dirty = true;
39984000
break;

0 commit comments

Comments
 (0)