Skip to content

Commit e2b43fb

Browse files
committed
KVM: x86: Apply runtime updates to current CPUID during KVM_SET_CPUID{,2}
When handling KVM_SET_CPUID{,2}, do runtime CPUID updates on the vCPU's current CPUID (and caps) prior to swapping in the incoming CPUID state so that KVM doesn't lose pending updates if the incoming CPUID is rejected, and to prevent a false failure on the equality check. Note, runtime updates are unconditionally performed on the incoming/new CPUID (and associated caps), i.e. clearing the dirty flag won't negatively affect the new CPUID. Fixes: 93da6af ("KVM: x86: Defer runtime updates of dynamic CPUID bits until CPUID emulation") Reported-by: Igor Mammedov <imammedo@redhat.com> Closes: https://lore.kernel.org/all/20251128123202.68424a95@imammedo Cc: stable@vger.kernel.org Acked-by: Igor Mammedov <imammedo@redhat.com> Tested-by: Igor Mammedov <imammedo@redhat.com> Link: https://patch.msgid.link/20251202015049.1167490-2-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 1b9439c commit e2b43fb

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,18 @@ static int kvm_set_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *e2,
509509
u32 vcpu_caps[NR_KVM_CPU_CAPS];
510510
int r;
511511

512+
/*
513+
* Apply pending runtime CPUID updates to the current CPUID entries to
514+
* avoid false positives due to mismatches on KVM-owned feature flags.
515+
*/
516+
if (vcpu->arch.cpuid_dynamic_bits_dirty)
517+
kvm_update_cpuid_runtime(vcpu);
518+
512519
/*
513520
* Swap the existing (old) entries with the incoming (new) entries in
514521
* order to massage the new entries, e.g. to account for dynamic bits
515-
* that KVM controls, without clobbering the current guest CPUID, which
516-
* KVM needs to preserve in order to unwind on failure.
522+
* that KVM controls, without losing the current guest CPUID, which KVM
523+
* needs to preserve in order to unwind on failure.
517524
*
518525
* Similarly, save the vCPU's current cpu_caps so that the capabilities
519526
* can be updated alongside the CPUID entries when performing runtime

0 commit comments

Comments
 (0)