KVM: x86: Reinitialize context if host userspace toggles EFER.LME
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 9 Feb 2022 09:56:05 +0000 (04:56 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Apr 2022 12:24:03 +0000 (14:24 +0200)
commit d6174299365ddbbf491620c0b8c5ca1a6ef2eea5 upstream.

While the guest runs, EFER.LME cannot change unless CR0.PG is clear, and
therefore EFER.NX is the only bit that can affect the MMU role.  However,
set_efer accepts a host-initiated change to EFER.LME even with CR0.PG=1.
In that case, the MMU has to be reset.

Fixes: 11988499e62b ("KVM: x86: Skip EFER vs. guest CPUID checks for host-initiated writes")
Cc: stable@vger.kernel.org
Reviewed-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/mmu.h
arch/x86/kvm/x86.c

index e9688a9f7b579d521caeee89017d9b557397c652..7bb165c2323348647507631ece9a2c6029799619 100644 (file)
@@ -49,6 +49,7 @@
                               X86_CR4_LA57)
 
 #define KVM_MMU_CR0_ROLE_BITS (X86_CR0_PG | X86_CR0_WP)
+#define KVM_MMU_EFER_ROLE_BITS (EFER_LME | EFER_NX)
 
 static __always_inline u64 rsvd_bits(int s, int e)
 {
index 61bc54748f221a57156351c68db4ed42357223b1..3e606a6940dc80b7fb1d3c75d4450cbd7b233662 100644 (file)
@@ -1605,8 +1605,7 @@ static int set_efer(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
                return r;
        }
 
-       /* Update reserved bits */
-       if ((efer ^ old_efer) & EFER_NX)
+       if ((efer ^ old_efer) & KVM_MMU_EFER_ROLE_BITS)
                kvm_mmu_reset_context(vcpu);
 
        return 0;