All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: Update the states size cpuid even if XCR0/IA32_XSS is reset
@ 2022-01-17  8:26 Like Xu
  2022-01-17 17:32 ` Paolo Bonzini
  2022-01-18 18:30 ` [PATCH] KVM: x86: Update the states size cpuid even if XCR0/IA32_XSS is reset Sean Christopherson
  0 siblings, 2 replies; 9+ messages in thread
From: Like Xu @ 2022-01-17  8:26 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Wanpeng Li, Sean Christopherson, Jim Mattson, Vitaly Kuznetsov,
	Joerg Roedel, kvm, linux-kernel

From: Like Xu <likexu@tencent.com>

XCR0 is reset to 1 by RESET but not INIT and IA32_XSS is zeroed by
both RESET and INIT. In both cases, the size in bytes of the XSAVE
area containing all states enabled by XCR0 or (XCRO | IA32_XSS)
needs to be updated.

Fixes: a554d207dc46 ("KVM: X86: Processor States following Reset or INIT")
Signed-off-by: Like Xu <likexu@tencent.com>
---
 arch/x86/kvm/x86.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 76b4803dd3bd..5748a57e1cb7 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -11134,6 +11134,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 	struct kvm_cpuid_entry2 *cpuid_0x1;
 	unsigned long old_cr0 = kvm_read_cr0(vcpu);
 	unsigned long new_cr0;
+	bool need_update_cpuid = false;
 
 	/*
 	 * Several of the "set" flows, e.g. ->set_cr0(), read other registers
@@ -11199,6 +11200,8 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 
 		vcpu->arch.msr_misc_features_enables = 0;
 
+		if (vcpu->arch.xcr0 != XFEATURE_MASK_FP)
+			need_update_cpuid = true;
 		vcpu->arch.xcr0 = XFEATURE_MASK_FP;
 	}
 
@@ -11216,6 +11219,8 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 	cpuid_0x1 = kvm_find_cpuid_entry(vcpu, 1, 0);
 	kvm_rdx_write(vcpu, cpuid_0x1 ? cpuid_0x1->eax : 0x600);
 
+	if (vcpu->arch.ia32_xss)
+		need_update_cpuid = true;
 	vcpu->arch.ia32_xss = 0;
 
 	static_call(kvm_x86_vcpu_reset)(vcpu, init_event);
@@ -11264,6 +11269,9 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 	 */
 	if (init_event)
 		kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu);
+
+	if (need_update_cpuid)
+		kvm_update_cpuid_runtime(vcpu);
 }
 EXPORT_SYMBOL_GPL(kvm_vcpu_reset);
 
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-01-26 17:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-17  8:26 [PATCH] KVM: x86: Update the states size cpuid even if XCR0/IA32_XSS is reset Like Xu
2022-01-17 17:32 ` Paolo Bonzini
2022-01-21  4:09   ` [PATCH v2] KVM: x86: Sync the states size with the XCR0/IA32_XSS at any time Like Xu
2022-01-21 15:41     ` Sean Christopherson
2022-01-23  4:37       ` [PATCH v3] KVM: x86: Sync the states size with the XCR0/IA32_XSS at, " Like Xu
2022-01-26 16:37         ` Sean Christopherson
2022-01-26 17:08           ` Paolo Bonzini
2022-01-18 18:30 ` [PATCH] KVM: x86: Update the states size cpuid even if XCR0/IA32_XSS is reset Sean Christopherson
2022-01-19  7:25   ` Like Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.