Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758234AbcKDJiw (ORCPT ); Fri, 4 Nov 2016 05:38:52 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33646 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752329AbcKDJiu (ORCPT ); Fri, 4 Nov 2016 05:38:50 -0400 Subject: Re: [PATCH 2/5] KVM: x86: do not scan IRR twice on APICv vmentry To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= References: <1476469291-5039-1-git-send-email-pbonzini@redhat.com> <1476469291-5039-3-git-send-email-pbonzini@redhat.com> <20161026195900.GC4212@potion> <00273a1a-ef5d-f814-3e02-24b4e855d229@redhat.com> <20161103150356.GE7771@potion> <20161103180753.GF7771@potion> <18e681d1-640f-8c56-dc05-acc7ca34cd45@redhat.com> <20161103182930.GG7771@potion> <20161103201638.GH7771@potion> Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, yang.zhang.wz@gmail.com, feng.wu@intel.com, mst@redhat.com From: Paolo Bonzini Message-ID: <753178ee-b9bb-4f17-a92c-a15d5b110ba8@redhat.com> Date: Fri, 4 Nov 2016 10:38:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20161103201638.GH7771@potion> 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 Content-Length: 1085 Lines: 38 On 03/11/2016 21:16, Radim Krčmář wrote: > > + if (!pi_test_on(&vmx->pi_desc)) > > We don't call vmx_hwapic_irr_update() when returning early. This might be a good start, but it's on purpose: IRR is not changing and the invariant _should_ be that RVI=highest-bit(IRR): - IRR cleared by processor: see SDM 29.2.2 Virtual-interrupt delivery - IRR set by processor: see SDM 29.6 Posted-interrupt processing - IRR set by KVM: ON=1 so it doesn't exit here - IRR cleared by KVM: might indeed be buggy here, but the next patch does add a + kvm_x86_ops->hwapic_irr_update(vcpu, + apic_find_highest_irr(apic)); to apic_clear_irr, which doesn't fix the bug (and doesn't fix it also if backported here). So we're missing a place where IRR has changed but RVI is not being updated. It should be related to vmx_check_nested_events and kvm_cpu_has_interrupt as you said, but I cannot really see it. Paolo >> > + return; >> > + >> > + pi_clear_on(&vmx->pi_desc); >> > + max_irr = kvm_apic_update_irr(vcpu, vmx->pi_desc.pir); >> > + vmx_hwapic_irr_update(vcpu, max_irr); >> > +}