From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755175AbdGWBGE (ORCPT ); Sat, 22 Jul 2017 21:06:04 -0400 Received: from mail-qk0-f195.google.com ([209.85.220.195]:37814 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752099AbdGWBGC (ORCPT ); Sat, 22 Jul 2017 21:06:02 -0400 From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Wanpeng Li Subject: [PATCH] KVM: nVMX: consult PFER_MASK and PFER_MATCH before nested vmexit if inject #PF Date: Sat, 22 Jul 2017 18:05:54 -0700 Message-Id: <1500771954-3979-1-git-send-email-wanpeng.li@hotmail.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wanpeng Li When generating #PF VM-exit, check equality: (PFEC & PFEC_MASK) == PFEC_MATCH If there is equality, the 14 bit of exception bitmap is used to take decision about generating #PF VM-exit. If there is inequality, inverted 14 bit is used. Reported-by: Jim Mattson Cc: Paolo Bonzini Cc: Radim Krčmář Signed-off-by: Wanpeng Li --- arch/x86/kvm/vmx.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 29fd8af..8a213f2 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2429,6 +2429,8 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu) vmx_set_interrupt_shadow(vcpu, 0); } +static bool nested_vmx_is_page_fault_vmexit(struct vmcs12 *vmcs12, u16 error_code); + /* * KVM wants to inject page-faults which it got to the guest. This function * checks whether in a nested guest, we need to inject them to L1 or L2. @@ -2442,6 +2444,10 @@ static int nested_vmx_check_exception(struct kvm_vcpu *vcpu) (nr == PF_VECTOR && vcpu->arch.exception.nested_apf))) return 0; + if (nr == PF_VECTOR && !vcpu->arch.exception.nested_apf && + !nested_vmx_is_page_fault_vmexit(vmcs12, vcpu->arch.exception.error_code)) + return 0; + if (vcpu->arch.exception.nested_apf) { vmcs_write32(VM_EXIT_INTR_ERROR_CODE, vcpu->arch.exception.error_code); nested_vmx_vmexit(vcpu, EXIT_REASON_EXCEPTION_NMI, -- 2.7.4