]> 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:10:47 +0000 (12:10 -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 c709c0795b07f4163c07f6392fe8404ddc472709..2aa87ae6b8f31be276cf12493d62c603e84dfd3a 100644 (file)
@@ -789,6 +789,10 @@ static void nested_vmcb02_prepare_save(struct vcpu_svm *svm)
 
        kvm_set_rflags(vcpu, 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);