From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Stabellini Subject: [PATCH v2 5/6] xen/arm: Only enable physical IRQs when the guest asks Date: Tue, 10 Dec 2013 13:06:07 +0000 Message-ID: <1386680768-15543-5-git-send-email-stefano.stabellini@eu.citrix.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xensource.com Cc: julien.grall@citrix.com, Julien Grall , Ian.Campbell@citrix.com, Stefano Stabellini List-Id: xen-devel@lists.xenproject.org From: Julien Grall Set/Unset IRQ_DISABLED from gic_irq_enable and gic_irq_disable. Enable IRQs when the guest requests it, not unconditionally at boot time. Signed-off-by: Stefano Stabellini Signed-off-by: Julien Grall Changes in v2: - protect startup and shutdown with gic and desc locks. --- xen/arch/arm/gic.c | 46 ++++++++++++++++++++++++++-------------------- xen/arch/arm/vgic.c | 6 ++---- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index 5e60c5a..62330dd 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -133,16 +133,26 @@ static void gic_irq_enable(struct irq_desc *desc) { int irq = desc->irq; + spin_lock(&desc->lock); + spin_lock(&gic.lock); /* Enable routing */ GICD[GICD_ISENABLER + irq / 32] = (1u << (irq % 32)); + desc->status &= ~IRQ_DISABLED; + spin_unlock(&gic.lock); + spin_unlock(&desc->lock); } static void gic_irq_disable(struct irq_desc *desc) { int irq = desc->irq; + spin_lock(&desc->lock); + spin_lock(&gic.lock); /* Disable routing */ GICD[GICD_ICENABLER + irq / 32] = (1u << (irq % 32)); + desc->status |= IRQ_DISABLED; + spin_unlock(&gic.lock); + spin_unlock(&desc->lock); } static unsigned int gic_irq_startup(struct irq_desc *desc) @@ -247,24 +257,20 @@ static int gic_route_irq(unsigned int irq, bool_t level, ASSERT(priority <= 0xff); /* Only 8 bits of priority */ ASSERT(irq < gic.lines); /* Can't route interrupts that don't exist */ - spin_lock_irqsave(&desc->lock, flags); - spin_lock(&gic.lock); - if ( desc->action != NULL ) - { - spin_unlock(&gic.lock); - spin_unlock(&desc->lock); return -EBUSY; - } - - desc->handler = &gic_host_irq_type; /* Disable interrupt */ desc->handler->shutdown(desc); - gic_set_irq_properties(irq, level, cpu_mask, priority); + spin_lock_irqsave(&desc->lock, flags); + desc->handler = &gic_host_irq_type; + + spin_lock(&gic.lock); + gic_set_irq_properties(irq, level, cpu_mask, priority); spin_unlock(&gic.lock); + spin_unlock_irqrestore(&desc->lock, flags); return 0; } @@ -557,16 +563,13 @@ void __init release_irq(unsigned int irq) desc = irq_to_desc(irq); + desc->handler->shutdown(desc); + spin_lock_irqsave(&desc->lock,flags); action = desc->action; desc->action = NULL; - desc->status |= IRQ_DISABLED; desc->status &= ~IRQ_GUEST; - spin_lock(&gic.lock); - desc->handler->shutdown(desc); - spin_unlock(&gic.lock); - spin_unlock_irqrestore(&desc->lock,flags); /* Wait to make sure it's not being used on another CPU */ @@ -583,11 +586,8 @@ static int __setup_irq(struct irq_desc *desc, unsigned int irq, return -EBUSY; desc->action = new; - desc->status &= ~IRQ_DISABLED; dsb(); - desc->handler->startup(desc); - return 0; } @@ -600,11 +600,12 @@ int __init setup_dt_irq(const struct dt_irq *irq, struct irqaction *new) desc = irq_to_desc(irq->irq); spin_lock_irqsave(&desc->lock, flags); - rc = __setup_irq(desc, irq->irq, new); - spin_unlock_irqrestore(&desc->lock, flags); + desc->handler->startup(desc); + + return rc; } @@ -740,6 +741,7 @@ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq, unsigned long flags; int retval; bool_t level; + struct pending_irq *p; action = xmalloc(struct irqaction); if (!action) @@ -766,6 +768,10 @@ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq, goto out; } + /* TODO: do not assume delivery to vcpu0 */ + p = irq_to_pending(d->vcpu[0], irq->irq); + p->desc = desc; + out: spin_unlock(&gic.lock); spin_unlock_irqrestore(&desc->lock, flags); diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c index 75df571..5886696 100644 --- a/xen/arch/arm/vgic.c +++ b/xen/arch/arm/vgic.c @@ -372,6 +372,8 @@ static void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n) set_bit(_GIC_IRQ_GUEST_ENABLED, &p->status); if ( !list_empty(&p->inflight) && !test_bit(_GIC_IRQ_GUEST_VISIBLE, &p->status) ) gic_set_guest_irq(v, irq, GICH_LR_PENDING, p->priority); + if ( p->desc != NULL ) + p->desc->handler->enable(p->desc); i++; } } @@ -692,10 +694,6 @@ void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq, int virtual) n->irq = irq; set_bit(_GIC_IRQ_GUEST_PENDING, &n->status); n->priority = priority; - if (!virtual) - n->desc = irq_to_desc(irq); - else - n->desc = NULL; /* the irq is enabled */ if ( test_bit(_GIC_IRQ_GUEST_ENABLED, &n->status) ) -- 1.7.10.4