From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: [PATCH v5 4/5] KVM: VMX: Add the algorithm of deliver posted interrupt Date: Fri, 8 Mar 2013 17:21:09 -0300 Message-ID: <20130308202109.GA11546@amt.cnet> References: <1362705801-4467-1-git-send-email-yang.z.zhang@intel.com> <1362705801-4467-5-git-send-email-yang.z.zhang@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, gleb@redhat.com, xiantao.zhang@intel.com, mingo@kernel.org, hpa@linux.intel.com To: Yang Zhang Return-path: Received: from mx1.redhat.com ([209.132.183.28]:62922 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750851Ab3CHUZX (ORCPT ); Fri, 8 Mar 2013 15:25:23 -0500 Content-Disposition: inline In-Reply-To: <1362705801-4467-5-git-send-email-yang.z.zhang@intel.com> Sender: kvm-owner@vger.kernel.org List-ID: On Fri, Mar 08, 2013 at 09:23:20AM +0800, Yang Zhang wrote: > From: Yang Zhang > > Only deliver the posted interrupt when target vcpu is running > and there is no previous interrupt pending in pir. > > Signed-off-by: Yang Zhang > +static bool vmx_deliver_posted_interrupt(struct kvm_vcpu *vcpu, int vector) > +{ > + struct vcpu_vmx *vmx = to_vmx(vcpu); > + > + if (!vmx_vm_has_apicv(vcpu->kvm)) > + return false; > + > + if (pi_test_and_set_pir(vector, &vmx->pi_desc)) > + return true; > + > + kvm_make_request(KVM_REQ_EVENT, vcpu); > + if ((vcpu->mode == IN_GUEST_MODE)) { > + if (!pi_test_and_set_on(&vmx->pi_desc)) > + apic->send_IPI_mask(get_cpu_mask(vcpu->cpu), > + POSTED_INTR_VECTOR); > + } else > + kvm_vcpu_kick(vcpu); > + > + return true; > +} Meaning of return value is unclear. > + > +static bool vmx_sync_pir_to_irr(struct kvm_vcpu *vcpu, bool sync) > +{ > + struct vcpu_vmx *vmx = to_vmx(vcpu); > + > + if (!vmx_vm_has_apicv(vcpu->kvm)) > + return false; > + > + if (bitmap_empty((unsigned long *)vmx->pi_desc.pir, 256)) > + return false; > + > + if (sync) > + kvm_apic_update_irr(vcpu, vmx->pi_desc.pir); > + return true; > +} Please split in two kvm_x86_ops functions: one to query whether PIR is empty the other to perform the sync. Perhaps "->hwapic_has_interrupt" is a good name.