Skip to contentSkip to conversation

KVM: x86: Update the states size cpuid even if XCR0/IA32_XSS is reset

PATCH In review Like Xu 3 participants 9 messages Jan 17, 2022 – Jan 26, 2022

Subsystems (3)
lore
Share & tools
lore

Like Xu

author
#0 lore raw

PATCH 1/1 KVM: x86: Update the states size cpuid even if XCR0/IA32_XSS is reset

From: Like Xu <[email protected]>

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")
---
 arch/x86/kvm/x86.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/x86/kvm/x86.c +8 -0
index 76b4803dd3bd..5748a57e1cb7 100644
@@ -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);
 
Signature · 1 line
2.33.1
maintainer
#1 lore raw
Quoted 9 lines · Like Xu

From: Like Xu <[email protected]>

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")

Can you write a test case please?

Thanks,

Paolo

Quoted 44 lines
---
  arch/x86/kvm/x86.c | 8 ++++++++
  1 file changed, 8 insertions(+)
arch/x86/kvm/x86.c +8 -0
index 76b4803dd3bd..5748a57e1cb7 100644
@@ -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);
 
author
#2 lore raw

PATCH v2 1/1 KVM: x86: Sync the states size with the XCR0/IA32_XSS at any time

From: Like Xu <[email protected]>

XCR0 is reset to 1 by RESET but not INIT and IA32_XSS is zeroed by both RESET and INIT. The kvm_set_msr_common()'s handling of MSR_IA32_XSS also needs to update kvm_update_cpuid_runtime(). In the above cases, the size in bytes of the XSAVE area containing all states enabled by XCR0 or (XCRO | IA32_XSS) needs to be updated.

For simplicity and consistency, legacy helpers are used to write values and call kvm_update_cpuid_runtime(), and it's not exactly a fast path.

Fixes a554d207dc46 ("KVM: X86: Processor States following Reset or INIT")

---
v1 -> v2 Changelog:
- Strongly prefer that use the helpers to write the values; (Sean)
- Postpone IA32_XSS test cases once non-zero values are supported; (Paolo)
- User space may call SET_CPUID2 after kvm_vcpu_reset(init_event=false); (Paolo)

 arch/x86/kvm/x86.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +2 -2
index 55518b7d3b96..22d4b1d15e94 100644
@@ -11256,7 +11256,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 
 		vcpu->arch.msr_misc_features_enables = 0;
 
-		vcpu->arch.xcr0 = XFEATURE_MASK_FP;
+		__kvm_set_xcr(vcpu, 0, XFEATURE_MASK_FP);
 	}
 
 	/* All GPRs except RDX (handled below) are zeroed on RESET/INIT. */
@@ -11273,7 +11273,7 @@ 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);
 
-	vcpu->arch.ia32_xss = 0;
+	__kvm_set_msr(vcpu, MSR_IA32_XSS, 0, true);
 
 	static_call(kvm_x86_vcpu_reset)(vcpu, init_event);
 
Signature · 1 line
2.33.1
#3 lore raw

Re: [PATCH v2] KVM: x86: Sync the states size with the XCR0/IA32_XSS at any time

Quoted 9 lines · Like Xu

From: Like Xu <[email protected]>

XCR0 is reset to 1 by RESET but not INIT and IA32_XSS is zeroed by both RESET and INIT. The kvm_set_msr_common()'s handling of MSR_IA32_XSS also needs to update kvm_update_cpuid_runtime(). In the above cases, the size in bytes of the XSAVE area containing all states enabled by XCR0 or (XCRO | IA32_XSS) needs to be updated.

For simplicity and consistency, legacy helpers are used to write values

s/legacy/existing

"legacy" refers to something that is outdated/deprecated, which isn't what you intend here.

Quoted 27 lines

and call kvm_update_cpuid_runtime(), and it's not exactly a fast path.

Fixes a554d207dc46 ("KVM: X86: Processor States following Reset or INIT")

---
v1 -> v2 Changelog:
- Strongly prefer that use the helpers to write the values; (Sean)
- Postpone IA32_XSS test cases once non-zero values are supported; (Paolo)
- User space may call SET_CPUID2 after kvm_vcpu_reset(init_event=false); (Paolo)

 arch/x86/kvm/x86.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +1 -1
index 55518b7d3b96..22d4b1d15e94 100644
@@ -11256,7 +11256,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 
 		vcpu->arch.msr_misc_features_enables = 0;
 
-		vcpu->arch.xcr0 = XFEATURE_MASK_FP;
+		__kvm_set_xcr(vcpu, 0, XFEATURE_MASK_FP);
 	}
 
 	/* All GPRs except RDX (handled below) are zeroed on RESET/INIT. */

arch/x86/kvm/x86.c void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) · line 11276

Quoted 5 lines
arch/x86/kvm/x86.c +1 -1
@@ -11273,7 +11273,7 @@ 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);
 
-	vcpu->arch.ia32_xss = 0;
+	__kvm_set_msr(vcpu, MSR_IA32_XSS, 0, true);

This relies on a prep patch to invoke kvm_update_cpuid_runtime() in kvm_set_msr_common() for MSR_IA32_XSS, no?

Quoted 6 lines
arch/x86/kvm/x86.c +0 -0
 	static_call(kvm_x86_vcpu_reset)(vcpu, init_event);
 
Signature · 1 line
2.33.1
author
#4 lore raw

PATCH v3 1/1 KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time

From: Like Xu <[email protected]>

XCR0 is reset to 1 by RESET but not INIT and IA32_XSS is zeroed by both RESET and INIT. The kvm_set_msr_common()'s handling of MSR_IA32_XSS also needs to update kvm_update_cpuid_runtime(). In the above cases, the size in bytes of the XSAVE area containing all states enabled by XCR0 or (XCRO | IA32_XSS) needs to be updated.

For simplicity and consistency, existing helpers are used to write values and call kvm_update_cpuid_runtime(), and it's not exactly a fast path.

Fixes a554d207dc46 ("KVM: X86: Processor States following Reset or INIT")

---
v2 -> v3 Changelog:
- Apply s/legacy/existing in the commit message; (Sean)
- Invoke kvm_update_cpuid_runtime() for MSR_IA32_XSS; (Sean)

 arch/x86/kvm/x86.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +3 -2
index 55518b7d3b96..4b509b26d9ab 100644
@@ -3535,6 +3535,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 		if (data & ~supported_xss)
 			return 1;
 		vcpu->arch.ia32_xss = data;
+		kvm_update_cpuid_runtime(vcpu);
 		break;
 	case MSR_SMI_COUNT:
 		if (!msr_info->host_initiated)
@@ -11256,7 +11257,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 
 		vcpu->arch.msr_misc_features_enables = 0;
 
-		vcpu->arch.xcr0 = XFEATURE_MASK_FP;
+		__kvm_set_xcr(vcpu, 0, XFEATURE_MASK_FP);
 	}
 
 	/* All GPRs except RDX (handled below) are zeroed on RESET/INIT. */
@@ -11273,7 +11274,7 @@ 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);
 
-	vcpu->arch.ia32_xss = 0;
+	__kvm_set_msr(vcpu, MSR_IA32_XSS, 0, true);
 
 	static_call(kvm_x86_vcpu_reset)(vcpu, init_event);
 
Signature · 1 line
2.33.1
#5 lore raw

Re: [PATCH v3] KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time

Quoted 44 lines · Like Xu

From: Like Xu <[email protected]>

XCR0 is reset to 1 by RESET but not INIT and IA32_XSS is zeroed by both RESET and INIT. The kvm_set_msr_common()'s handling of MSR_IA32_XSS also needs to update kvm_update_cpuid_runtime(). In the above cases, the size in bytes of the XSAVE area containing all states enabled by XCR0 or (XCRO | IA32_XSS) needs to be updated.

For simplicity and consistency, existing helpers are used to write values and call kvm_update_cpuid_runtime(), and it's not exactly a fast path.

Fixes a554d207dc46 ("KVM: X86: Processor States following Reset or INIT")

---
v2 -> v3 Changelog:
- Apply s/legacy/existing in the commit message; (Sean)
- Invoke kvm_update_cpuid_runtime() for MSR_IA32_XSS; (Sean)

 arch/x86/kvm/x86.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +1 -0
index 55518b7d3b96..4b509b26d9ab 100644
@@ -3535,6 +3535,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct
 msr_data *msr_info)
 		if (data & ~supported_xss)
 			return 1;
 		vcpu->arch.ia32_xss = data;
+		kvm_update_cpuid_runtime(vcpu);
 		break;
 	case MSR_SMI_COUNT:
arch/x86/kvm/x86.c +1 -1
 		if (!msr_info->host_initiated)
@@ -11256,7 +11257,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 
 		vcpu->arch.msr_misc_features_enables = 0;
 
-		vcpu->arch.xcr0 = XFEATURE_MASK_FP;
+		__kvm_set_xcr(vcpu, 0, XFEATURE_MASK_FP);
 	}
 
 	/* All GPRs except RDX (handled below) are zeroed on RESET/INIT. */

arch/x86/kvm/x86.c void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) · line 11277

Quoted 5 lines
arch/x86/kvm/x86.c +1 -1
@@ -11273,7 +11274,7 @@ 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);
 
-	vcpu->arch.ia32_xss = 0;
+	__kvm_set_msr(vcpu, MSR_IA32_XSS, 0, true);

Heh, this now conflicts with a patch Xiaoyao just posted, turns out the SDM was wrong. I think there's also some whitespace change or something that prevents this from applying cleanly. For convenience, I'll post a miniseries with this and Xiaoyao's patch.

[*] https://lore.kernel.org/all/[email protected]

Quoted 7 lines
arch/x86/kvm/x86.c +0 -0
 	static_call(kvm_x86_vcpu_reset)(vcpu, init_event);
 
Signature · 1 line
2.33.1
maintainer
#6 lore raw

Re: [PATCH v3] KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time

Quoted 56 lines · Sean Christopherson
Quoted 44 lines · Like Xu

From: Like Xu <[email protected]>

XCR0 is reset to 1 by RESET but not INIT and IA32_XSS is zeroed by both RESET and INIT. The kvm_set_msr_common()'s handling of MSR_IA32_XSS also needs to update kvm_update_cpuid_runtime(). In the above cases, the size in bytes of the XSAVE area containing all states enabled by XCR0 or (XCRO | IA32_XSS) needs to be updated.

For simplicity and consistency, existing helpers are used to write values and call kvm_update_cpuid_runtime(), and it's not exactly a fast path.

Fixes a554d207dc46 ("KVM: X86: Processor States following Reset or INIT")

---
v2 -> v3 Changelog:
- Apply s/legacy/existing in the commit message; (Sean)
- Invoke kvm_update_cpuid_runtime() for MSR_IA32_XSS; (Sean)

  arch/x86/kvm/x86.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +1 -0
index 55518b7d3b96..4b509b26d9ab 100644
@@ -3535,6 +3535,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct
 msr_data *msr_info)
  		if (data & ~supported_xss)
  			return 1;
  		vcpu->arch.ia32_xss = data;
+		kvm_update_cpuid_runtime(vcpu);
  		break;
  	case MSR_SMI_COUNT:

if (!msr_info->host_initiated)

arch/x86/kvm/x86.c +1 -1
@@ -11256,7 +11257,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 
  		vcpu->arch.msr_misc_features_enables = 0;
 
-		vcpu->arch.xcr0 = XFEATURE_MASK_FP;
+		__kvm_set_xcr(vcpu, 0, XFEATURE_MASK_FP);
  	}
 
  	/* All GPRs except RDX (handled below) are zeroed on RESET/INIT. */

arch/x86/kvm/x86.c void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) · line 11277

Quoted 5 lines
arch/x86/kvm/x86.c +1 -1
@@ -11273,7 +11274,7 @@ 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);
 
-	vcpu->arch.ia32_xss = 0;
+	__kvm_set_msr(vcpu, MSR_IA32_XSS, 0, true);

Heh, this now conflicts with a patch Xiaoyao just posted, turns out the SDM was wrong. I think there's also some whitespace change or something that prevents this from applying cleanly. For convenience, I'll post a miniseries with this and Xiaoyao's patch.

Quoted 1 line

[*] https://lore.kernel.org/all/[email protected]

It's okay, fixing the conflict in Xiaoyao's patch is trivial and---anyway---KVM does not support XSS != 0 for now so his patch doesn't really have any practical effect.

Like's patch queued, thanks.

Paolo

#7 lore raw
In reply to Like Xu
Quoted 35 lines · Like Xu

From: Like Xu <[email protected]>

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")
---
 arch/x86/kvm/x86.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/x86/kvm/x86.c +3 -0
index 76b4803dd3bd..5748a57e1cb7 100644
@@ -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;
 	}
 

arch/x86/kvm/x86.c void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) · line 11223

Quoted 5 lines
arch/x86/kvm/x86.c +2 -0
@@ -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;

This means that kvm_set_msr_common()'s handling of MSR_IA32_XSS also needs to update kvm_update_cpuid_runtime(). And then for bnoth XCR0 and XSS, I would very strongly prefer that use the helpers to write the values and let the helpers call kvm_update_cpuid_runtime(). Yes, that will mean kvm_update_cpuid_runtime() may be called multiple times during INIT, but that's already true (CR4), and this isn't exactly a fast path.

arch/x86/kvm/x86.c +2 -2
index 55518b7d3b96..22d4b1d15e94 100644
@@ -11256,7 +11256,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 
                vcpu->arch.msr_misc_features_enables = 0;
 
-               vcpu->arch.xcr0 = XFEATURE_MASK_FP;
+               __kvm_set_xcr(vcpu, 0, XFEATURE_MASK_FP);
        }
 
        /* All GPRs except RDX (handled below) are zeroed on RESET/INIT. */
@@ -11273,7 +11273,7 @@ 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);
 
-       vcpu->arch.ia32_xss = 0;
+       __kvm_set_msr(vcpu, MSR_IA32_XSS, 0, true);
 
        static_call(kvm_x86_vcpu_reset)(vcpu, init_event);
 
author
#8 lore raw
Quoted 39 lines · Sean Christopherson
Quoted 38 lines · Like Xu

From: Like Xu <[email protected]>

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")
---
  arch/x86/kvm/x86.c | 8 ++++++++
  1 file changed, 8 insertions(+)
arch/x86/kvm/x86.c +3 -0
index 76b4803dd3bd..5748a57e1cb7 100644
@@ -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);
 
Quoted 6 lines

arch/x86/kvm/x86.c void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) · line 11223

Quoted 2 lines
arch/x86/kvm/x86.c +2 -0
+	if (vcpu->arch.ia32_xss)
+		need_update_cpuid = true;

This means that kvm_set_msr_common()'s handling of MSR_IA32_XSS also needs to update kvm_update_cpuid_runtime(). And then for bnoth XCR0 and XSS, I would very strongly prefer that use the helpers to write the values and let the helpers call

Looks good to me and let me apply it in the next version.

Quoted 3 lines

kvm_update_cpuid_runtime(). Yes, that will mean kvm_update_cpuid_runtime() may be called multiple times during INIT, but that's already true (CR4), and this isn't exactly a fast path.

An undisclosed lazy mechanism is under analyzed for performance gains.

Quoted 24 lines
arch/x86/kvm/x86.c +2 -2
index 55518b7d3b96..22d4b1d15e94 100644
@@ -11256,7 +11256,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 
                 vcpu->arch.msr_misc_features_enables = 0;
 
-               vcpu->arch.xcr0 = XFEATURE_MASK_FP;
+               __kvm_set_xcr(vcpu, 0, XFEATURE_MASK_FP);
         }
 
         /* All GPRs except RDX (handled below) are zeroed on RESET/INIT. */
@@ -11273,7 +11273,7 @@ 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);
 
-       vcpu->arch.ia32_xss = 0;
+       __kvm_set_msr(vcpu, MSR_IA32_XSS, 0, true);
 
         static_call(kvm_x86_vcpu_reset)(vcpu, init_event);