From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753446AbcI1Lun (ORCPT ); Wed, 28 Sep 2016 07:50:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56080 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752469AbcI1Lud (ORCPT ); Wed, 28 Sep 2016 07:50:33 -0400 Subject: Re: [PATCH 2/3] kvm: x86: do not use KVM_REQ_EVENT for APICv interrupt injection To: "Wu, Feng" , "Michael S. Tsirkin" References: <1475011213-34225-1-git-send-email-pbonzini@redhat.com> <1475011213-34225-3-git-send-email-pbonzini@redhat.com> <20160928020319-mutt-send-email-mst@kernel.org> <286c39fb-6ba3-3267-dff6-b04ee4cbb1c7@redhat.com> Cc: "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "yang.zhang.wz@gmail.com" , "rkrcmar@redhat.com" From: Paolo Bonzini Message-ID: <7b5daf1a-dd92-d199-a9b2-c6564b46f1fc@redhat.com> Date: Wed, 28 Sep 2016 13:50:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 28 Sep 2016 11:50:33 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 28/09/2016 13:40, Wu, Feng wrote: > IIUIC, the issue you describe above is that IPI for posted-interrupts may be > issued between > > vcpu->mode = IN_GUEST_MODE; > > and > > local_irq_disable(); > > But if that really happens, we will call kvm_vcpu_kick() in > vmx_deliver_posted_interrupt(), hence the vcpu->mode will be changed > to EXITING_GUEST_MODE, then we will goto cancel_injection in > vcpu_enter_guest, so the posted-interrupt will be delivered to guest > in the next vmentry. Seems I cannot see the problem. Do I miss something? No, if that happens kvm_trigger_posted_interrupt returns true, hence kvm_vcpu_kick is not called. With the fix, the IPI is processed as soon as the guest enters non-root mode, and the interrupt is injected. The other issue occurs when the IPI is sent between kvm_x86_ops->hwapic_irr_update(vcpu, kvm_lapic_find_highest_irr(vcpu)); and vcpu->mode = IN_GUEST_MODE; In this case, kvm_vcpu_kick is called but it (correctly) doesn't do anything because it sees vcpu->mode == OUTSIDE_GUEST_MODE. Then the guest is entered with PIR.ON, but the PI interrupt is not pending and hence the interrupt is never delivered to the guest. The fix for this is to move the RVI update after IN_GUEST_MODE. Then the source CPU uses the posted interrupt IPI instead of kvm_cpu_kick, and everything works. Paolo