Skip to contentSkip to conversation

KVM: x86: Restore update of required xstate size in guest's CPUID

PATCH In review Sean Christopherson 3 participants 3 messages May 8, 2020 – May 9, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: x86: Restore update of required xstate size in guest's CPUID

Restore a guest CPUID update that was unintentional collateral damage when the per-vCPU guest_xstate_size field was removed.

Cc Xiaoyao Li <[email protected]>
Fixes d87277414b851 ("kvm: x86: Cleanup vcpu->arch.guest_xstate_size")

---

There's nothing more thrilling than watching bisect home in on your own commits, only to land on someone else's on the very last step.

 arch/x86/kvm/cpuid.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/kvm/cpuid.c +4 -2
index 35845704cf57a..cd708b0b460a0 100644
@@ -84,11 +84,13 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu)
 				   kvm_read_cr4_bits(vcpu, X86_CR4_PKE));
 
 	best = kvm_find_cpuid_entry(vcpu, 0xD, 0);
-	if (!best)
+	if (!best) {
 		vcpu->arch.guest_supported_xcr0 = 0;
-	else
+	} else {
 		vcpu->arch.guest_supported_xcr0 =
 			(best->eax | ((u64)best->edx << 32)) & supported_xcr0;
+		best->ebx = xstate_required_size(vcpu->arch.xcr0, false);
+	}
 
 	best = kvm_find_cpuid_entry(vcpu, 0xD, 1);
 	if (best && (cpuid_entry_has(best, X86_FEATURE_XSAVES) ||
Signature · 1 line
2.26.0
#1 lore raw
Quoted 2 lines · Sean Christopherson

Restore a guest CPUID update that was unintentional collateral damage when the per-vCPU guest_xstate_size field was removed.

It's really unintentional. None of us noticed it. :(

It's good that you catch it!

Quoted 32 lines
Cc Xiaoyao Li <[email protected]>
Fixes d87277414b851 ("kvm: x86: Cleanup vcpu->arch.guest_xstate_size")

---

There's nothing more thrilling than watching bisect home in on your own commits, only to land on someone else's on the very last step.

  arch/x86/kvm/cpuid.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/kvm/cpuid.c +4 -2
index 35845704cf57a..cd708b0b460a0 100644
@@ -84,11 +84,13 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu)
  				   kvm_read_cr4_bits(vcpu, X86_CR4_PKE));
 
  	best = kvm_find_cpuid_entry(vcpu, 0xD, 0);
-	if (!best)
+	if (!best) {
  		vcpu->arch.guest_supported_xcr0 = 0;
-	else
+	} else {
  		vcpu->arch.guest_supported_xcr0 =
  			(best->eax | ((u64)best->edx << 32)) & supported_xcr0;
+		best->ebx = xstate_required_size(vcpu->arch.xcr0, false);
+	}
 
  	best = kvm_find_cpuid_entry(vcpu, 0xD, 1);
  	if (best && (cpuid_entry_has(best, X86_FEATURE_XSAVES) ||
maintainer
#2 lore raw
In reply to Sean Christopherson
Quoted 11 lines · Sean Christopherson
arch/x86/kvm/cpuid.c +1 -1
index 35845704cf57a..cd708b0b460a0 100644
@@ -84,11 +84,13 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu)
 				   kvm_read_cr4_bits(vcpu, X86_CR4_PKE));
 
 	best = kvm_find_cpuid_entry(vcpu, 0xD, 0);
-	if (!best)
+	if (!best) {
 		vcpu->arch.guest_supported_xcr0 = 0;

arch/x86/kvm/cpuid.c int kvm_update_cpuid(struct kvm_vcpu *vcpu)

Quoted 10 lines
arch/x86/kvm/cpuid.c +3 -2
-	else
+	} else {
 		vcpu->arch.guest_supported_xcr0 =
 			(best->eax | ((u64)best->edx << 32)) & supported_xcr0;
+		best->ebx = xstate_required_size(vcpu->arch.xcr0, false);
+	}
 
 	best = kvm_find_cpuid_entry(vcpu, 0xD, 1);
 	if (best && (cpuid_entry_has(best, X86_FEATURE_XSAVES) ||
-- 2.26.0

Ugh, I'll write a testcase as penance. Squashed, thanks.

Paolo