]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
KVM: x86: Disallow setting CPUID and/or feature MSRs if L2 is active
authorSean Christopherson <seanjc@google.com>
Tue, 30 Dec 2025 20:56:41 +0000 (12:56 -0800)
committerSean Christopherson <seanjc@google.com>
Wed, 7 Jan 2026 20:44:42 +0000 (12:44 -0800)
commitb47b93c15b12c7a9e560729aa6ad609466f83f0e
tree277cfd78b185f5a5562935447f4fe9a4c749682d
parent9ace4753a5202b02191d54e9fdf7f9e3d02b85eb
KVM: x86: Disallow setting CPUID and/or feature MSRs if L2 is active

Extend KVM's restriction on CPUID and feature MSR changes to disallow
updates while L2 is active in addition to rejecting updates after the vCPU
has run at least once.  Like post-run vCPU model updates, attempting to
react to model changes while L2 is active is practically infeasible, e.g.
KVM would need to do _something_ in response to impossible situations where
userspace has a removed a feature that was consumed as parted of nested
VM-Enter.

In practice, disallowing vCPU model changes while L2 is active is largely
uninteresting, as the only way for L2 to be active without the vCPU having
run at least once is if userspace stuffed state via KVM_SET_NESTED_STATE.
And because KVM_SET_NESTED_STATE can't put the vCPU into L2 without
userspace first defining the vCPU model, e.g. to enable SVM/VMX, modifying
the vCPU model while L2 is active would require deliberately setting the
vCPU model, then loading nested state, and then changing the model.  I.e.
no sane VMM should run afoul of the new restriction, and any VMM that does
encounter problems has likely been running a broken setup for a long time.

Cc: Yosry Ahmed <yosry.ahmed@linux.dev>
Cc: Kevin Cheng <chengkev@google.com>
Reviewed-by: Yosry Ahmed <yosry.ahmed@linux.dev>
Link: https://patch.msgid.link/20251230205641.4092235-1-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/cpuid.c
arch/x86/kvm/mmu/mmu.c
arch/x86/kvm/pmu.c
arch/x86/kvm/x86.c
arch/x86/kvm/x86.h