From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christoffer Dall Subject: Re: [RFC PATCH 11/45] KVM: arm/arm64: vgic-new: Implement kvm_vgic_vcpu_pending_irq Date: Thu, 31 Mar 2016 10:54:32 +0200 Message-ID: <20160331085432.GQ4126@cbox> References: <1458871508-17279-1-git-send-email-andre.przywara@arm.com> <1458871508-17279-12-git-send-email-andre.przywara@arm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: Marc Zyngier , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org To: Andre Przywara Return-path: Content-Disposition: inline In-Reply-To: <1458871508-17279-12-git-send-email-andre.przywara@arm.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu List-Id: kvm.vger.kernel.org On Fri, Mar 25, 2016 at 02:04:34AM +0000, Andre Przywara wrote: > From: Eric Auger > > Tell KVM whether a particular VCPU has an IRQ that needs handling > in the guest. This is used to decide whether a VCPU is runnable. > > Signed-off-by: Eric Auger > Signed-off-by: Andre Przywara > --- > include/kvm/vgic/vgic.h | 2 ++ > virt/kvm/arm/vgic/vgic.c | 22 ++++++++++++++++++++++ > 2 files changed, 24 insertions(+) > > diff --git a/include/kvm/vgic/vgic.h b/include/kvm/vgic/vgic.h > index 986f23f..2ce9b4a 100644 > --- a/include/kvm/vgic/vgic.h > +++ b/include/kvm/vgic/vgic.h > @@ -181,6 +181,8 @@ struct vgic_cpu { > int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, > bool level); > > +int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu); > + > #define irqchip_in_kernel(k) (!!((k)->arch.vgic.in_kernel)) > #define vgic_initialized(k) (false) > #define vgic_ready(k) ((k)->arch.vgic.ready) > diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c > index 9eb031e8..d6c8c92 100644 > --- a/virt/kvm/arm/vgic/vgic.c > +++ b/virt/kvm/arm/vgic/vgic.c > @@ -477,3 +477,25 @@ void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu) > vgic_populate_lrs(vcpu); > spin_unlock(&vcpu->arch.vgic_cpu.ap_list_lock); > } > + > +int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu) > +{ > + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; > + struct vgic_irq *irq; > + bool pending = false; > + > + spin_lock(&vgic_cpu->ap_list_lock); > + > + list_for_each_entry(irq, &vgic_cpu->ap_list_head, ap_list) { > + spin_lock(&irq->irq_lock); > + pending = irq->pending && irq->enabled; > + spin_unlock(&irq->irq_lock); > + > + if (pending) > + break; > + } > + > + spin_unlock(&vgic_cpu->ap_list_lock); > + > + return pending; > +} as long as we only call this in the wfi/wfe path, then it's fine. If we start calling this in the critical path, I think we should check the common case of list_empty(&vgic_cpu->ap_list) first. Thanks, -Christoffer From mboxrd@z Thu Jan 1 00:00:00 1970 From: christoffer.dall@linaro.org (Christoffer Dall) Date: Thu, 31 Mar 2016 10:54:32 +0200 Subject: [RFC PATCH 11/45] KVM: arm/arm64: vgic-new: Implement kvm_vgic_vcpu_pending_irq In-Reply-To: <1458871508-17279-12-git-send-email-andre.przywara@arm.com> References: <1458871508-17279-1-git-send-email-andre.przywara@arm.com> <1458871508-17279-12-git-send-email-andre.przywara@arm.com> Message-ID: <20160331085432.GQ4126@cbox> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On Fri, Mar 25, 2016 at 02:04:34AM +0000, Andre Przywara wrote: > From: Eric Auger > > Tell KVM whether a particular VCPU has an IRQ that needs handling > in the guest. This is used to decide whether a VCPU is runnable. > > Signed-off-by: Eric Auger > Signed-off-by: Andre Przywara > --- > include/kvm/vgic/vgic.h | 2 ++ > virt/kvm/arm/vgic/vgic.c | 22 ++++++++++++++++++++++ > 2 files changed, 24 insertions(+) > > diff --git a/include/kvm/vgic/vgic.h b/include/kvm/vgic/vgic.h > index 986f23f..2ce9b4a 100644 > --- a/include/kvm/vgic/vgic.h > +++ b/include/kvm/vgic/vgic.h > @@ -181,6 +181,8 @@ struct vgic_cpu { > int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, > bool level); > > +int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu); > + > #define irqchip_in_kernel(k) (!!((k)->arch.vgic.in_kernel)) > #define vgic_initialized(k) (false) > #define vgic_ready(k) ((k)->arch.vgic.ready) > diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c > index 9eb031e8..d6c8c92 100644 > --- a/virt/kvm/arm/vgic/vgic.c > +++ b/virt/kvm/arm/vgic/vgic.c > @@ -477,3 +477,25 @@ void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu) > vgic_populate_lrs(vcpu); > spin_unlock(&vcpu->arch.vgic_cpu.ap_list_lock); > } > + > +int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu) > +{ > + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; > + struct vgic_irq *irq; > + bool pending = false; > + > + spin_lock(&vgic_cpu->ap_list_lock); > + > + list_for_each_entry(irq, &vgic_cpu->ap_list_head, ap_list) { > + spin_lock(&irq->irq_lock); > + pending = irq->pending && irq->enabled; > + spin_unlock(&irq->irq_lock); > + > + if (pending) > + break; > + } > + > + spin_unlock(&vgic_cpu->ap_list_lock); > + > + return pending; > +} as long as we only call this in the wfi/wfe path, then it's fine. If we start calling this in the critical path, I think we should check the common case of list_empty(&vgic_cpu->ap_list) first. Thanks, -Christoffer