KVM: x86: Swap incoming guest CPUID into vCPU before massaging in KVM_SET_CPUID2
authorSean Christopherson <seanjc@google.com>
Thu, 28 Nov 2024 01:33:58 +0000 (17:33 -0800)
committerSean Christopherson <seanjc@google.com>
Wed, 18 Dec 2024 22:19:54 +0000 (14:19 -0800)
commit8c01290bda1ab957c0b6d4640bdb351985a26123
tree4a63dd8982ff0ccc61a471f49a11571c055c6598
parent6174004ebd2508556204255757fd77fbc10009f9
KVM: x86: Swap incoming guest CPUID into vCPU before massaging in KVM_SET_CPUID2

When handling KVM_SET_CPUID{,2}, swap the old and new CPUID arrays and
lengths before processing the new CPUID, and simply undo the swap if
setting the new CPUID fails for whatever reason.

To keep the diff reasonable, continue passing the entry array and length
to most helpers, and defer the more complete cleanup to future commits.

For any sane VMM, setting "bad" CPUID state is not a hot path (or even
something that is surviable), and setting guest CPUID before it's known
good will allow removing all of KVM's infrastructure for processing CPUID
entries directly (as opposed to operating on vcpu->arch.cpuid_entries).

Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Link: https://lore.kernel.org/r/20241128013424.4096668-32-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/cpuid.c