From: Adalbert Lazar Subject: [RFC PATCH 12/19] kvm: x86: Hook in kvmi_trap_event() Date: Fri, 16 Jun 2017 16:43:41 +0300 Message-ID: <20170616134348.17725-13-alazar@bitdefender.com> References: <20170616134348.17725-1-alazar@bitdefender.com> Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , alazar@bitdefender.com, mdontu@bitdefender.com To: kvm@vger.kernel.org Return-path: Received: from mx02.bbu.dsd.mx.bitdefender.com ([91.199.104.133]:49058 "EHLO mx02.buh.bitdefender.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753752AbdFPNnW (ORCPT ); Fri, 16 Jun 2017 09:43:22 -0400 In-Reply-To: <20170616134348.17725-1-alazar@bitdefender.com> Sender: kvm-owner@vger.kernel.org List-ID: From: Mihai Dontu Inform the guest introspection tool that a trap was successfully injected. It can happen for the tool to queue a pagefault but have it overwritten by an interrupt picked up during guest reentry. kvmi_trap_event() is used to inform the tool of all pending traps giving it a chance to determine if it should try again later. Signed-off-by: Mihai Dontu --- arch/x86/kvm/x86.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3a50710629b5..29d07f8aa7fa 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6928,6 +6928,30 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) vcpu->arch.switch_db_regs &= ~KVM_DEBUGREG_RELOAD; } + if (atomic_read(&vcpu->arch.next_interrupt_enabled)) { + if (vcpu->arch.exception.pending) { + unsigned int nr = vcpu->arch.exception.nr; + unsigned int type; + + if (kvm_exception_is_soft(nr)) + type = INTR_TYPE_SOFT_EXCEPTION; + else + type = INTR_TYPE_HARD_EXCEPTION; + kvmi_trap_event(vcpu, nr, type, + vcpu->arch.exception.error_code, + vcpu->arch.cr2); + } else if (vcpu->arch.interrupt.pending) { + unsigned int nr = vcpu->arch.interrupt.nr; + unsigned int type; + + if (vcpu->arch.interrupt.soft) + type = INTR_TYPE_SOFT_INTR; + else + type = INTR_TYPE_EXT_INTR; + kvmi_trap_event(vcpu, nr, type, 0, vcpu->arch.cr2); + } + } + kvm_x86_ops->run(vcpu); /* -- 2.12.2