From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752029AbdHXI55 (ORCPT ); Thu, 24 Aug 2017 04:57:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33686 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751249AbdHXI54 (ORCPT ); Thu, 24 Aug 2017 04:57:56 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EEB3D81DE3 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=pbonzini@redhat.com Subject: Re: [PATCH v3 2/4] KVM: X86: Fix loss of exception which has not yet injected To: Wanpeng Li , "linux-kernel@vger.kernel.org" , kvm Cc: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Wanpeng Li References: <1503548506-4457-1-git-send-email-wanpeng.li@hotmail.com> <1503548506-4457-2-git-send-email-wanpeng.li@hotmail.com> From: Paolo Bonzini Message-ID: Date: Thu, 24 Aug 2017 10:57:52 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 24 Aug 2017 08:57:56 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24/08/2017 08:52, Wanpeng Li wrote: >> @@ -6862,6 +6876,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) >> kvm_x86_ops->enable_nmi_window(vcpu); >> if (kvm_cpu_has_injectable_intr(vcpu) || req_int_win) >> kvm_x86_ops->enable_irq_window(vcpu); >> + WARN_ON(vcpu->arch.exception.pending); > > This WARN_ON() is suggested during the review of last version, > however, there are many cases in inject_pending_event() can result in > return directly w/ vcpu->arch.exception.pending is true. Actually I > have already catched the warning several times during the testing. I > think we should remove it when committing. No, it's a good thing that it's failing, because it's finding a bug. There's no such thing as an "exception window", so at the very least it should set req_immediate_exit to true. Does this help? diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index b698b2f135a2..76d5a192be6c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6365,14 +6365,20 @@ static int inject_pending_event(struct kvm_vcpu *vcpu, bool req_int_win) return 0; } - if (vcpu->arch.nmi_injected) { - kvm_x86_ops->set_nmi(vcpu); - return 0; - } + /* + * Exceptions must be injected immediately, or the exception + * frame will have the address of the NMI or interrupt handler. + */ + if (!vcpu->arch.exception.pending) { + if (vcpu->arch.nmi_injected) { + kvm_x86_ops->set_nmi(vcpu); + return 0; + } - if (vcpu->arch.interrupt.pending) { - kvm_x86_ops->set_irq(vcpu); - return 0; + if (vcpu->arch.interrupt.pending) { + kvm_x86_ops->set_irq(vcpu); + return 0; + } } if (is_guest_mode(vcpu) && kvm_x86_ops->check_nested_events) { Paolo