Skip to contentSkip to conversation

KVM: x86: XSS and XCR0 fixes

PATCH In review Sean Christopherson 2 participants 8 messages Jan 26, 2022 – Jan 27, 2022

Subsystems (3)
lore
Share & tools
lore

Sean Christopherson

author maintainer
#0 lore raw

cover KVM: x86: XSS and XCR0 fixes

For convenience, Like's patch split up and applied on top of Xiaoyao. Tagged all for @stable, probably want to (retroactively?) get Xiaoyao's patch tagged too?

Like Xu (2):
KVM: x86: Update vCPU's runtime CPUID on write to MSR_IA32_XSS
KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time

Xiaoyao Li (1):
KVM: x86: Keep MSR_IA32_XSS unchanged for INIT

 arch/x86/kvm/x86.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

base-commit: e2e83a73d7ce66f62c7830a85619542ef59c90e4

Signature · 1 line
2.35.0.rc0.227.g00780c9af4-goog
author maintainer
#1 lore raw

PATCH 1/3 KVM: x86: Keep MSR_IA32_XSS unchanged for INIT

From: Xiaoyao Li <[email protected]>

It has been corrected from SDM version 075 that MSR_IA32_XSS is reset to zero on Power up and Reset but keeps unchanged on INIT.

Fixes a554d207dc46 ("KVM: X86: Processor States following Reset or INIT")
---
 arch/x86/kvm/x86.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kvm/x86.c +1 -2
index 55518b7d3b96..c0727939684e 100644
@@ -11257,6 +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;
+		vcpu->arch.ia32_xss = 0;
 	}
 
 	/* All GPRs except RDX (handled below) are zeroed on RESET/INIT. */
@@ -11273,8 +11274,6 @@ 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;
-
 	static_call(kvm_x86_vcpu_reset)(vcpu, init_event);
 
 	kvm_set_rflags(vcpu, X86_EFLAGS_FIXED);
Signature · 1 line
2.35.0.rc0.227.g00780c9af4-goog
author maintainer
#2 lore raw

PATCH 2/3 KVM: x86: Update vCPU's runtime CPUID on write to MSR_IA32_XSS

In reply to Sean Christopherson

From: Like Xu <[email protected]>

Do a runtime CPUID update for a vCPU if MSR_IA32_XSS is written, as the size in bytes of the XSAVE area is affected by the states enabled in XSS.

Fixes 203000993de5 ("kvm: vmx: add MSR logic for XSAVES")
[sean: split out as a separate patch, adjust Fixes tag]
---
 arch/x86/kvm/x86.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/kvm/x86.c +1 -0
index c0727939684e..13793582f26d 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)
Signature · 1 line
2.35.0.rc0.227.g00780c9af4-goog
author maintainer
#3 lore raw

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

In reply to Sean Christopherson

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")
---
 arch/x86/kvm/x86.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +2 -2
index 13793582f26d..2e8a8fb42269 100644
@@ -11257,8 +11257,8 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 
 		vcpu->arch.msr_misc_features_enables = 0;
 
-		vcpu->arch.xcr0 = XFEATURE_MASK_FP;
-		vcpu->arch.ia32_xss = 0;
+		__kvm_set_xcr(vcpu, 0, XFEATURE_MASK_FP);
+		__kvm_set_msr(vcpu, MSR_IA32_XSS, 0, true);
 	}
 
 	/* All GPRs except RDX (handled below) are zeroed on RESET/INIT. */
Signature · 1 line
2.35.0.rc0.227.g00780c9af4-goog
maintainer
#4 lore raw
In reply to Sean Christopherson
Quoted 8 lines · Sean Christopherson

For convenience, Like's patch split up and applied on top of Xiaoyao. Tagged all for @stable, probably want to (retroactively?) get Xiaoyao's patch tagged too?

Like Xu (2):
KVM: x86: Update vCPU's runtime CPUID on write to MSR_IA32_XSS
KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time

Quoted 8 lines

Xiaoyao Li (1):
KVM: x86: Keep MSR_IA32_XSS unchanged for INIT

  arch/x86/kvm/x86.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

base-commit: e2e83a73d7ce66f62c7830a85619542ef59c90e4

Queued, though I'll note that I kinda disagree with the stable@ marking of patch 1 (and therefore with the patch order) as it has no effect in practice.

Paolo

author maintainer
#5 lore raw
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Sean Christopherson

For convenience, Like's patch split up and applied on top of Xiaoyao. Tagged all for @stable, probably want to (retroactively?) get Xiaoyao's patch tagged too?
Like Xu (2):
KVM: x86: Update vCPU's runtime CPUID on write to MSR_IA32_XSS
KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time

Xiaoyao Li (1):
KVM: x86: Keep MSR_IA32_XSS unchanged for INIT

  arch/x86/kvm/x86.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 5 lines
Quoted 1 line

base-commit: e2e83a73d7ce66f62c7830a85619542ef59c90e4

Queued, though I'll note that I kinda disagree with the stable@ marking of patch 1 (and therefore with the patch order) as it has no effect in practice.

Hmm, that's not a given, is it? E.g. the guest can configure XSS early on and then expect the configured value to live across INIT-SIPI-SIPI. I agree it's highly unlikely for any guest to actually do that, but I don't like assuming all guests will behave a certain way.

maintainer
#6 lore raw
Quoted 18 lines · Sean Christopherson
Quoted 17 lines · Paolo Bonzini
Quoted 15 lines · Sean Christopherson

For convenience, Like's patch split up and applied on top of Xiaoyao. Tagged all for @stable, probably want to (retroactively?) get Xiaoyao's patch tagged too?
Like Xu (2):
KVM: x86: Update vCPU's runtime CPUID on write to MSR_IA32_XSS
KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time

Xiaoyao Li (1):
KVM: x86: Keep MSR_IA32_XSS unchanged for INIT

   arch/x86/kvm/x86.c | 6 +++---
   1 file changed, 3 insertions(+), 3 deletions(-)

base-commit: e2e83a73d7ce66f62c7830a85619542ef59c90e4

Quoted 8 lines
Quoted 3 lines

Queued, though I'll note that I kinda disagree with the stable@ marking of patch 1 (and therefore with the patch order) as it has no effect in practice.

Hmm, that's not a given, is it? E.g. the guest can configure XSS early on and then expect the configured value to live across INIT-SIPI-SIPI. I agree it's highly unlikely for any guest to actually do that, but I don't like assuming all guests will behave a certain way.

No, I meant in the sense that supported_xss is always zero right now, and therefore so is MSR_IA32_XSS.

Paolo

author maintainer
#7 lore raw
Quoted 23 lines · Paolo Bonzini
Quoted 22 lines · Sean Christopherson
Quoted 20 lines · Paolo Bonzini
Quoted 7 lines · Sean Christopherson

For convenience, Like's patch split up and applied on top of Xiaoyao. Tagged all for @stable, probably want to (retroactively?) get Xiaoyao's patch tagged too?
Like Xu (2):
KVM: x86: Update vCPU's runtime CPUID on write to MSR_IA32_XSS
KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time

Quoted 8 lines

Xiaoyao Li (1):
KVM: x86: Keep MSR_IA32_XSS unchanged for INIT

   arch/x86/kvm/x86.c | 6 +++---
   1 file changed, 3 insertions(+), 3 deletions(-)

base-commit: e2e83a73d7ce66f62c7830a85619542ef59c90e4

Queued, though I'll note that I kinda disagree with the stable@ marking of patch 1 (and therefore with the patch order) as it has no effect in practice.

Quoted 7 lines
Quoted 4 lines

Hmm, that's not a given, is it? E.g. the guest can configure XSS early on and then expect the configured value to live across INIT-SIPI-SIPI. I agree it's highly unlikely for any guest to actually do that, but I don't like assuming all guests will behave a certain way.

No, I meant in the sense that supported_xss is always zero right now, and therefore so is MSR_IA32_XSS.

Oh, duh.