Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752578AbdIFJG6 (ORCPT ); Wed, 6 Sep 2017 05:06:58 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5980 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752463AbdIFJG4 (ORCPT ); Wed, 6 Sep 2017 05:06:56 -0400 Message-ID: <59AFBA95.6070508@huawei.com> Date: Wed, 6 Sep 2017 17:06:29 +0800 From: Shannon Zhao User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Marc Zyngier , , , , CC: Jason Cooper , Thomas Gleixner Subject: Re: [PATCH v3 51/59] KVM: arm/arm64: GICv4: Add doorbell interrupt handling References: <20170731172637.29355-1-marc.zyngier@arm.com> <20170731172637.29355-52-marc.zyngier@arm.com> In-Reply-To: <20170731172637.29355-52-marc.zyngier@arm.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.16.142] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A010203.59AFBAA5.0076,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 9b98424e6e773d9c340af51039783baa Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2253 Lines: 85 On 2017/8/1 1:26, Marc Zyngier wrote: > When a vPE is not running, a VLPI being made pending results in a > doorbell interrupt being delivered. Let's handle this interrupt > and update the pending_last flag that indicates that VLPIs are > pending. The corresponding vcpu is also kicked into action. > > Signed-off-by: Marc Zyngier > --- > virt/kvm/arm/vgic/vgic-v4.c | 34 ++++++++++++++++++++++++++++++++++ > 1 file changed, 34 insertions(+) > > diff --git a/virt/kvm/arm/vgic/vgic-v4.c b/virt/kvm/arm/vgic/vgic-v4.c > index 534d3051a078..6af3cde6d7d4 100644 > --- a/virt/kvm/arm/vgic/vgic-v4.c > +++ b/virt/kvm/arm/vgic/vgic-v4.c > @@ -21,6 +21,19 @@ > > #include "vgic.h" > > +static irqreturn_t vgic_v4_doorbell_handler(int irq, void *info) > +{ > + struct kvm_vcpu *vcpu = info; > + > + if (!kvm_vgic_vcpu_pending_irq(vcpu)) { > + vcpu->arch.vgic_cpu.vgic_v3.its_vpe.pending_last = true; > + kvm_make_request(KVM_REQ_IRQ_PENDING, vcpu); > + kvm_vcpu_kick(vcpu); > + } > + > + return IRQ_HANDLED; > +} > + > int vgic_v4_init(struct kvm *kvm) > { > struct vgic_dist *dist = &kvm->arch.vgic; > @@ -57,16 +70,37 @@ int vgic_v4_init(struct kvm *kvm) > return ret; > } > > + kvm_for_each_vcpu(i, vcpu, kvm) { > + int irq = dist->its_vm.vpes[i]->irq; > + > + ret = request_irq(irq, vgic_v4_doorbell_handler, > + 0, "vcpu", vcpu); > + if (ret) { > + kvm_err("failed to allocate vcpu IRQ%d\n", irq); > + dist->its_vm.nr_vpes = i; This overwirtes the nr_vpes while it uses kvm->online_vcpus in its_alloc_vcpu_irqs to alloc irqs and if this fails it uses the overwirten nr_vpes other than kvm->online_vcpus in its_free_vcpu_irqs to free the irqs. So there will be memory leak on error path. > + break; > + } > + } > + > + if (ret) > + vgic_v4_teardown(kvm); > + > return ret; > } > > void vgic_v4_teardown(struct kvm *kvm) > { > struct its_vm *its_vm = &kvm->arch.vgic.its_vm; > + int i; > > if (!its_vm->vpes) > return; > > + for (i = 0; i < its_vm->nr_vpes; i++) { > + struct kvm_vcpu *vcpu = kvm_get_vcpu(kvm, i); > + free_irq(its_vm->vpes[i]->irq, vcpu); > + } > + > its_free_vcpu_irqs(its_vm); > kfree(its_vm->vpes); > its_vm->nr_vpes = 0; > Thanks, -- Shannon