From patchwork Mon Jun 24 23:04:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 18081 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f71.google.com (mail-qe0-f71.google.com [209.85.128.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0C57225E10 for ; Mon, 24 Jun 2013 23:04:57 +0000 (UTC) Received: by mail-qe0-f71.google.com with SMTP id 1sf1031263qee.10 for ; Mon, 24 Jun 2013 16:04:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=e60o6k9hNRBeYcrDCHeXaPi4QH0aLFJ/cqVCrPvUZxA=; b=ZxAPK5q5e1gee+YkJ0/zKwWZt5KJvS9AgHLUGKqH2J8VQw9vWfnfCK7OXwZT5vCO6w M5rVO5OJ5+QqAlavt9CE10dT9Zo/a1tQ9uVDyYGVcA52OlLbESdNtwdRay6/MxF5m9bd feEQZGztxVgHeoU/dm7+HULcqTPHCg4Dme1RDRm2mqE9p/i7uZB3Phl+ae6qbVnHXCEl sbbZibNGI42+74uM7TZOmqw7gg3FDb5iFVkk5QPcBhOy7kzxkwl5wg2BHjmJLD73sIMO 6jlThsiavgIebV6bYuM5U0lFYBUMcqZOWjqGl4HAOyWFyzs+HKsqo+J/fH9gT+9yifh/ igog== X-Received: by 10.224.200.202 with SMTP id ex10mr27696816qab.8.1372115096727; Mon, 24 Jun 2013 16:04:56 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.95.138 with SMTP id dk10ls2295698qeb.4.gmail; Mon, 24 Jun 2013 16:04:56 -0700 (PDT) X-Received: by 10.52.72.15 with SMTP id z15mr3824065vdu.91.1372115096540; Mon, 24 Jun 2013 16:04:56 -0700 (PDT) Received: from mail-vc0-x22c.google.com (mail-vc0-x22c.google.com [2607:f8b0:400c:c03::22c]) by mx.google.com with ESMTPS id bs2si5506037veb.43.2013.06.24.16.04.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Jun 2013 16:04:56 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c03::22c is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c03::22c; Received: by mail-vc0-f172.google.com with SMTP id ib11so529193vcb.17 for ; Mon, 24 Jun 2013 16:04:56 -0700 (PDT) X-Received: by 10.220.203.197 with SMTP id fj5mr1504341vcb.60.1372115096441; Mon, 24 Jun 2013 16:04:56 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.165.8 with SMTP id yu8csp45692veb; Mon, 24 Jun 2013 16:04:54 -0700 (PDT) X-Received: by 10.194.93.74 with SMTP id cs10mr18766541wjb.9.1372115094384; Mon, 24 Jun 2013 16:04:54 -0700 (PDT) Received: from mail-we0-x22e.google.com (mail-we0-x22e.google.com [2a00:1450:400c:c03::22e]) by mx.google.com with ESMTPS id m3si148043wiy.28.2013.06.24.16.04.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Jun 2013 16:04:54 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c03::22e is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=2a00:1450:400c:c03::22e; Received: by mail-we0-f174.google.com with SMTP id q58so8659552wes.19 for ; Mon, 24 Jun 2013 16:04:54 -0700 (PDT) X-Received: by 10.180.36.205 with SMTP id s13mr7387493wij.31.1372115093602; Mon, 24 Jun 2013 16:04:53 -0700 (PDT) Received: from belegaer.uk.xensource.com. (firewall.ctxuk.citrix.com. [46.33.159.2]) by mx.google.com with ESMTPSA id m3sm508537wij.5.2013.06.24.16.04.52 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Jun 2013 16:04:52 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Cc: ian.campbell@citrix.com, Stefano.Stabellini@eu.citrix.com, patches@linaro.org, Julien Grall Subject: [PATCH 5/5] xen/arm: Only enable physical IRQs when the guest asks Date: Tue, 25 Jun 2013 00:04:26 +0100 Message-Id: <1372115067-17071-6-git-send-email-julien.grall@citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1372115067-17071-1-git-send-email-julien.grall@citrix.com> References: <1372115067-17071-1-git-send-email-julien.grall@citrix.com> X-Gm-Message-State: ALoCoQkzZqpcVbKqESdMyFFVqHHGwhDOinDYygYNNKIr9IS9DSGyyrJdtfVtjrpUZUBQHFFzBfhp X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c03::22c is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , If the guest VCPU receives an interrupts when it's disabled, it will throw away the IRQ with EOIed it. This is result to lost IRQ forever. Directly EOIed the interrupt doesn't help because the IRQ could be fired again and result to an infinited loop. It happens during dom0 boot on the versatile express TC2 with the ethernet card. Let the interrupt disabled when Xen setups the route and enable it when Linux asks to enable it. Signed-off-by: Julien Grall --- xen/arch/arm/domain_build.c | 14 ++++++++++++++ xen/arch/arm/gic.c | 25 +++++++++++++++++++++++-- xen/arch/arm/vgic.c | 7 +++---- xen/include/asm-arm/gic.h | 4 ++++ xen/include/asm-arm/irq.h | 6 ++++++ 5 files changed, 50 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index f5befbd..0470a2d 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -408,6 +408,20 @@ static int map_device(struct domain *d, const struct dt_device_node *dev) } DPRINT("irq %u = %u type = 0x%x\n", i, irq.irq, irq.type); + + /* + * Only map SGI interrupt in the guest as XEN won't handle + * it correctly. + * TODO: Fix it + */ + if ( !irq_is_sgi(irq.irq) ) + { + printk(XENLOG_WARNING "WARNING: Don't map irq %u for %s has " + "XEN doesn't handle properly non-SGI interrupt\n", + i, dt_node_full_name(dev)); + continue; + } + /* Don't check return because the IRQ can be use by multiple device */ gic_route_irq_to_guest(d, &irq, dt_node_name(dev)); } diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index b16ba8c..e7d082a 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -179,6 +179,17 @@ static hw_irq_controller gic_guest_irq_type = { .set_affinity = gic_irq_set_affinity, }; +void gic_irq_enable(struct irq_desc *desc) +{ + spin_lock_irq(&desc->lock); + spin_lock(&gic.lock); + + desc->handler->enable(desc); + + spin_unlock(&gic.lock); + spin_unlock_irq(&desc->lock); +} + /* needs to be called with gic.lock held */ static void gic_set_irq_properties(unsigned int irq, bool_t level, unsigned int cpu_mask, unsigned int priority) @@ -543,8 +554,6 @@ static int __setup_irq(struct irq_desc *desc, unsigned int irq, desc->status &= ~IRQ_DISABLED; dsb(); - desc->handler->startup(desc); - return 0; } @@ -560,6 +569,8 @@ int __init setup_dt_irq(const struct dt_irq *irq, struct irqaction *new) rc = __setup_irq(desc, irq->irq, new); + desc->handler->startup(desc); + spin_unlock_irqrestore(&desc->lock, flags); return rc; @@ -711,6 +722,7 @@ void gic_inject(void) gic_inject_irq_start(); } +/* TODO: Handle properly non SGI-interrupt */ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq, const char * devname) { @@ -719,11 +731,18 @@ 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; + /* XXX: handler other VCPU than 0 */ + struct vcpu *v = d->vcpu[0]; action = xmalloc(struct irqaction); if (!action) return -ENOMEM; + /* XXX: Here we assume a 1:1 interrupt mapping between the host and dom0 */ + BUG_ON(irq->irq >= (d->arch.vgic.nr_lines + NR_LOCAL_IRQS)); + p = irq_to_pending(v, irq->irq); + action->dev_id = d; action->name = devname; action->free_on_release = 1; @@ -744,6 +763,8 @@ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq, goto out; } + 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 cea9233..4f3d816 100644 --- a/xen/arch/arm/vgic.c +++ b/xen/arch/arm/vgic.c @@ -372,6 +372,9 @@ static void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n) if ( !list_empty(&p->inflight) && !gic_irq_injected(irq) ) gic_set_guest_irq(v, irq, GICH_LR_PENDING, p->priority); + if ( p->desc != NULL ) + gic_irq_enable(p->desc); + i++; } } @@ -685,10 +688,6 @@ void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq, int virtual) n->irq = irq; n->priority = priority; - if (!virtual) - n->desc = irq_to_desc(irq); - else - n->desc = NULL; /* the irq is enabled */ if ( rank->ienable & (1 << (irq % 32)) ) diff --git a/xen/include/asm-arm/gic.h b/xen/include/asm-arm/gic.h index f9e9ef1..f7f3c1e 100644 --- a/xen/include/asm-arm/gic.h +++ b/xen/include/asm-arm/gic.h @@ -134,6 +134,7 @@ #ifndef __ASSEMBLY__ #include +#include extern int domain_vgic_init(struct domain *d); extern void domain_vgic_free(struct domain *d); @@ -154,6 +155,9 @@ extern void gic_inject(void); extern void gic_clear_pending_irqs(struct vcpu *v); extern int gic_events_need_delivery(void); +/* Helper to enable an IRQ and take all the needed locks */ +extern void gic_irq_enable(struct irq_desc *desc); + extern void __cpuinit init_maintenance_interrupt(void); extern void gic_set_guest_irq(struct vcpu *v, unsigned int irq, unsigned int state, unsigned int priority); diff --git a/xen/include/asm-arm/irq.h b/xen/include/asm-arm/irq.h index 80ff68d..346dc1d 100644 --- a/xen/include/asm-arm/irq.h +++ b/xen/include/asm-arm/irq.h @@ -46,6 +46,12 @@ int __init request_dt_irq(const struct dt_irq *irq, void *dev_id); int __init setup_dt_irq(const struct dt_irq *irq, struct irqaction *new); +#define FIRST_SGI_IRQ 32 +static inline bool_t irq_is_sgi(unsigned int irq) +{ + return (irq >= FIRST_SGI_IRQ); +} + #endif /* _ASM_HW_IRQ_H */ /* * Local variables: