Message ID | 20180315203050.19791-22-andre.przywara@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | New VGIC(-v2) implementation | expand |
Hi Andre, On 03/15/2018 08:30 PM, Andre Przywara wrote: > Tell Xen whether a particular VCPU has an IRQ that needs handling > in the guest. This is used to decide whether a VCPU is runnable or > if a hypercall should be preempted to let the guest handle the IRQ. > > This is based on Linux commit 90eee56c5f90, written by Eric Auger. > > Signed-off-by: Andre Przywara <andre.przywara@linaro.org> > --- > Changelog v1 ... v2: > - adjust to new vgic_vcpu_pending_irq() prototype, drop wrapper > > xen/arch/arm/vgic/vgic.c | 37 +++++++++++++++++++++++++++++++++++++ > 1 file changed, 37 insertions(+) > > diff --git a/xen/arch/arm/vgic/vgic.c b/xen/arch/arm/vgic/vgic.c > index 035c8c8f74..a1556e53e8 100644 > --- a/xen/arch/arm/vgic/vgic.c > +++ b/xen/arch/arm/vgic/vgic.c > @@ -637,6 +637,43 @@ void vgic_sync_to_lrs(void) > gic_hw_ops->update_hcr_status(GICH_HCR_EN, 1); > } > > +/** > + * vgic_vcpu_pending_irq() - determine if interrupts need to be injected > + * @vcpu: The vCPU on which to check for interrupts. > + * > + * Checks whether there is an interrupt on the given VCPU which needs > + * handling in the guest. This requires at least one IRQ to be pending > + * and enabled. > + * > + * Returns: 1 if the guest should run to handle interrupts, 0 otherwise. This does not match with the current implementation as you return bool. > + */ > +int vgic_vcpu_pending_irq(struct vcpu *vcpu) > +{ > + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic; > + struct vgic_irq *irq; > + bool pending = false; > + unsigned long flags; > + > + if ( !vcpu->domain->arch.vgic.enabled ) > + return false; Please don't mix bool and int. Ideally the interface should return a bool and not an int. > + > + spin_lock_irqsave(&vgic_cpu->ap_list_lock, flags); > + > + list_for_each_entry(irq, &vgic_cpu->ap_list_head, ap_list) > + { > + spin_lock(&irq->irq_lock); > + pending = irq_is_pending(irq) && irq->enabled; > + spin_unlock(&irq->irq_lock); > + > + if ( pending ) > + break; > + } > + > + spin_unlock_irqrestore(&vgic_cpu->ap_list_lock, flags); > + > + return pending; > +} > + > /* > * Local variables: > * mode: C > Cheers,
diff --git a/xen/arch/arm/vgic/vgic.c b/xen/arch/arm/vgic/vgic.c index 035c8c8f74..a1556e53e8 100644 --- a/xen/arch/arm/vgic/vgic.c +++ b/xen/arch/arm/vgic/vgic.c @@ -637,6 +637,43 @@ void vgic_sync_to_lrs(void) gic_hw_ops->update_hcr_status(GICH_HCR_EN, 1); } +/** + * vgic_vcpu_pending_irq() - determine if interrupts need to be injected + * @vcpu: The vCPU on which to check for interrupts. + * + * Checks whether there is an interrupt on the given VCPU which needs + * handling in the guest. This requires at least one IRQ to be pending + * and enabled. + * + * Returns: 1 if the guest should run to handle interrupts, 0 otherwise. + */ +int vgic_vcpu_pending_irq(struct vcpu *vcpu) +{ + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic; + struct vgic_irq *irq; + bool pending = false; + unsigned long flags; + + if ( !vcpu->domain->arch.vgic.enabled ) + return false; + + spin_lock_irqsave(&vgic_cpu->ap_list_lock, flags); + + list_for_each_entry(irq, &vgic_cpu->ap_list_head, ap_list) + { + spin_lock(&irq->irq_lock); + pending = irq_is_pending(irq) && irq->enabled; + spin_unlock(&irq->irq_lock); + + if ( pending ) + break; + } + + spin_unlock_irqrestore(&vgic_cpu->ap_list_lock, flags); + + return pending; +} + /* * Local variables: * mode: C
Tell Xen whether a particular VCPU has an IRQ that needs handling in the guest. This is used to decide whether a VCPU is runnable or if a hypercall should be preempted to let the guest handle the IRQ. This is based on Linux commit 90eee56c5f90, written by Eric Auger. Signed-off-by: Andre Przywara <andre.przywara@linaro.org> --- Changelog v1 ... v2: - adjust to new vgic_vcpu_pending_irq() prototype, drop wrapper xen/arch/arm/vgic/vgic.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)