KVM: x86/mmu: Return -EIO if page fault returns RET_PF_INVALID
authorSean Christopherson <sean.j.christopherson@intel.com>
Wed, 23 Sep 2020 22:04:22 +0000 (15:04 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 28 Sep 2020 11:57:35 +0000 (07:57 -0400)
Exit to userspace with an error if the MMU is buggy and returns
RET_PF_INVALID when servicing a page fault.  This will allow a future
patch to invert the emulation path, i.e. emulate only on RET_PF_EMULATE
instead of emulating on anything but RET_PF_RETRY.  This technically
means that KVM will exit to userspace instead of emulating on
RET_PF_INVALID, but practically speaking it's a nop as the MMU never
returns RET_PF_INVALID.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Message-Id: <20200923220425.18402-2-sean.j.christopherson@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/mmu/mmu.c

index 0db1ca0ba5dfae7042eb559b97a63952dbbdb1bf..68c0a1a374cf840f1cc1581d6eb8e48059cf4ba8 100644 (file)
@@ -5462,7 +5462,8 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u64 error_code,
        if (r == RET_PF_INVALID) {
                r = kvm_mmu_do_page_fault(vcpu, cr2_or_gpa,
                                          lower_32_bits(error_code), false);
-               WARN_ON(r == RET_PF_INVALID);
+               if (WARN_ON_ONCE(r == RET_PF_INVALID))
+                       return -EIO;
        }
 
        if (r == RET_PF_RETRY)