From mboxrd@z Thu Jan 1 00:00:00 1970 From: Liran Alon Subject: [PATCH v2 3/8] KVM: x86: set/get_events ioctl should consider only injected exceptions Date: Tue, 21 Nov 2017 17:30:06 +0200 Message-ID: <1511278211-12257-4-git-send-email-liran.alon@oracle.com> References: <1511278211-12257-1-git-send-email-liran.alon@oracle.com> Cc: jmattson@google.com, wanpeng.li@hotmail.com, idan.brown@oracle.com, Liran Alon , Krish Sadhukhan To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Return-path: Received: from userp1040.oracle.com ([156.151.31.81]:35458 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750794AbdKUPbM (ORCPT ); Tue, 21 Nov 2017 10:31:12 -0500 In-Reply-To: <1511278211-12257-1-git-send-email-liran.alon@oracle.com> Sender: kvm-owner@vger.kernel.org List-ID: Do not consider pending exception when return injected exception to user-mode. A "pending" exception means it's side-effect have not been applied yet. In contrast, an "injected" exception means it's side-effect have been already applied. Therefore, we only need to report of injected exceptions to user-mode. This is aligned with how interrupts are reported in same ioctl. Being symmetrical, injecting an exception from user-mode should consider injected exception as in "injected" state and not in "pending" state. Fixes: 664f8e26b00c ("KVM: X86: Fix loss of exception which has not yet been injected") Signed-off-by: Liran Alon Reviewed-by: Nikita Leshenko Reviewed-by: Krish Sadhukhan Signed-off-by: Krish Sadhukhan --- arch/x86/kvm/x86.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 45baba8bc02e..1490da89de4b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3096,14 +3096,9 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu, struct kvm_vcpu_events *events) { process_nmi(vcpu); - /* - * FIXME: pass injected and pending separately. This is only - * needed for nested virtualization, whose state cannot be - * migrated yet. For now we can combine them. - */ + events->exception.injected = - (vcpu->arch.exception.pending || - vcpu->arch.exception.injected) && + vcpu->arch.exception.injected && !kvm_exception_is_soft(vcpu->arch.exception.nr); events->exception.nr = vcpu->arch.exception.nr; events->exception.has_error_code = vcpu->arch.exception.has_error_code; @@ -3158,8 +3153,8 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu, return -EINVAL; process_nmi(vcpu); - vcpu->arch.exception.injected = false; - vcpu->arch.exception.pending = events->exception.injected; + vcpu->arch.exception.injected = events->exception.injected; + vcpu->arch.exception.pending = false; vcpu->arch.exception.nr = events->exception.nr; vcpu->arch.exception.has_error_code = events->exception.has_error_code; vcpu->arch.exception.error_code = events->exception.error_code; -- 1.9.1