]> git.hungrycats.org Git - linux/commitdiff
KVM: nSVM: Ignore EFER.LMA if EFER.LME=0 when preparing L2 state
authorSean Christopherson <seanjc@google.com>
Wed, 2 Sep 2026 23:20:25 +0000 (16:20 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Nov 2026 17:06:09 +0000 (12:06 -0500)
commit 1c4c84a643b704e473cb171f7b61359ff29b12a4 upstream.

Force EFER.LMA=0 if EFER.LME=0 when preparing L2 state for VMRUN, i.e.
mimic real hardware's behavior of ignoring EFER.LMA if EFER.LME=0.  VMRUN
unfortunately allows the nonsensical combination, i.e. doesn't fail, but
KVM itself has an invariant EFER.LMA can be set et if and only if EFER.LME
is set.   Breaking that invariant can lead to a variety of issue,
particularly in MMU code that keys off EFER.LMA when determining whether to
emulate/virtualization 4/5-level paging versus PAE paging.

Cc: stable@vger.kernel.org
Cc: Yosry Ahmed <yosry@kernel.org>
Link: https://patch.msgid.link/20260902232028.2767071-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/svm/nested.c

index 0be0615595b692530f1cb0c33d102e0a18ab2862..064a2bb9cf8edeb467d322c96f723932cb738ae7 100644 (file)
@@ -671,6 +671,10 @@ static void nested_vmcb02_prepare_save(struct vcpu_svm *svm, struct vmcb *vmcb12
 
        kvm_set_rflags(vcpu, vmcb12->save.rflags | X86_EFLAGS_FIXED);
 
+       /* SVM ignores EFER.LMA if EFER.LME=0 (instead of failing VMRUN). */
+       if (!(svm->nested.save.efer & EFER_LME))
+               svm->nested.save.efer &= ~EFER_LMA;
+
        svm_set_efer(vcpu, svm->nested.save.efer);
 
        svm_set_cr0(vcpu, svm->nested.save.cr0);