From patchwork Fri Jan 10 20:50:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 23115 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f70.google.com (mail-vb0-f70.google.com [209.85.212.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9416720A64 for ; Fri, 10 Jan 2014 20:50:17 +0000 (UTC) Received: by mail-vb0-f70.google.com with SMTP id w17sf1358968vbj.1 for ; Fri, 10 Jan 2014 12:50:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=EHvg3QKa6QqIeV3RbdypNfoCs7PBSTyw8n9SP5qiIIc=; b=kuKRdFaNCrWXxUW2AFMZXG5ewVokB+rhBX5nBErq1bvV8gcONgqriaVUm6xu0SEe9S O+uahSEOAQNVET6ii61nwWfdnXjeei9JOieKJBQ7Ckjw4K/VfBrTf0U/EhLmLGs8EGwC IBYpq8mzM9nyZZ4hsi72xlboeDI4H9O7TuBOLYADF7EWagTVUa6h9gtNWT6DyFs7TdmN gl20vdQO6EdKP/nlkkjg7JGk9KFn0m+N+lgJNHUWosIot30LWniwXnngrfgjEflvqfLl 4fXs6U3CE7E+Y2E9ciQBLgRG+AVEfNn+eCgmO9BuDWkYQf5q/t2UJNvXmh9F3v3+2L+/ lpGw== X-Gm-Message-State: ALoCoQn3Au+8A2D4ZNUWDvUYx5O4wWVR5rACwAwJ2RPZRedAL7Na/5+/qjJpnbmKoLorNKpbbTbR X-Received: by 10.236.122.234 with SMTP id t70mr3442656yhh.23.1389387016639; Fri, 10 Jan 2014 12:50:16 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.133.36 with SMTP id oz4ls1083512qeb.7.gmail; Fri, 10 Jan 2014 12:50:16 -0800 (PST) X-Received: by 10.52.163.65 with SMTP id yg1mr7999511vdb.14.1389387016559; Fri, 10 Jan 2014 12:50:16 -0800 (PST) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id uo18si5578391veb.143.2014.01.10.12.50.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 Jan 2014 12:50:16 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id jx11so3887625veb.34 for ; Fri, 10 Jan 2014 12:50:16 -0800 (PST) X-Received: by 10.52.171.227 with SMTP id ax3mr7892096vdc.34.1389387016434; Fri, 10 Jan 2014 12:50:16 -0800 (PST) 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.59.13.131 with SMTP id ey3csp116506ved; Fri, 10 Jan 2014 12:50:15 -0800 (PST) X-Received: by 10.14.99.66 with SMTP id w42mr11798114eef.63.1389387015492; Fri, 10 Jan 2014 12:50:15 -0800 (PST) Received: from mail-ee0-f51.google.com (mail-ee0-f51.google.com [74.125.83.51]) by mx.google.com with ESMTPS id e2si12117553eeg.240.2014.01.10.12.50.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 Jan 2014 12:50:15 -0800 (PST) Received-SPF: neutral (google.com: 74.125.83.51 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=74.125.83.51; Received: by mail-ee0-f51.google.com with SMTP id b15so2130395eek.24 for ; Fri, 10 Jan 2014 12:50:15 -0800 (PST) X-Received: by 10.15.56.9 with SMTP id x9mr5421eew.112.1389387015078; Fri, 10 Jan 2014 12:50:15 -0800 (PST) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id o1sm17484496eea.10.2014.01.10.12.50.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Jan 2014 12:50:14 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Cc: patches@linaro.org, ian.campbell@citrix.com, tim@xen.org, stefano.stabellini@citrix.com, Julien Grall Subject: [PATCH] xen/arm: IRQ: Protect IRQ to be shared between domains and XEN Date: Fri, 10 Jan 2014 20:50:12 +0000 Message-Id: <1389387012-26247-1-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.175 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: , The current dt_route_irq_to_guest implementation set IRQ_GUEST no matter if the IRQ is correctly setup. As IRQ can be shared between devices, if the devices are not assigned to the same domain or Xen, this could result to IRQ route to the domain instead of Xen ... Also avoid to rely on wrong behaviour when Xen is routing an IRQ to DOM0. Signed-off-by: Julien Grall --- Hopefully, none of the supported platforms have UARTs (the only device currently used by Xen). It would be nice to have this patch for Xen 4.4 to avoid waste of time for developer. The downside of this patch is if someone wants to support a such platform (eg IRQ shared between device assigned to different domain/XEN), it will end up to a error message and a panic. --- xen/arch/arm/domain_build.c | 8 ++++++-- xen/arch/arm/gic.c | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 47b781b..1fc359a 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -712,8 +712,12 @@ 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); - /* Don't check return because the IRQ can be use by multiple device */ - gic_route_irq_to_guest(d, &irq, dt_node_name(dev)); + res = gic_route_irq_to_guest(d, &irq, dt_node_name(dev)); + if ( res ) + { + printk(XENLOG_ERR "Unable to route the IRQ %u to dom0\n", irq.irq); + return res; + } } /* Map the address ranges */ diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index 62510e3..829d767 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -602,6 +602,21 @@ 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); + + if ( desc->status & IRQ_GUEST ) + { + struct domain *d; + + ASSERT(desc->action != NULL); + + d = desc->action->dev_id; + + spin_unlock_irqrestore(&desc->lock, flags); + printk(XENLOG_ERR "ERROR: IRQ %u is already used by the domain %u\n", + irq->irq, d->domain_id); + return -EADDRINUSE; + } + rc = __setup_irq(desc, irq->irq, new); spin_unlock_irqrestore(&desc->lock, flags); @@ -756,7 +771,7 @@ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq, struct irqaction *action; struct irq_desc *desc = irq_to_desc(irq->irq); unsigned long flags; - int retval; + int retval = 0; bool_t level; struct pending_irq *p; @@ -771,6 +786,29 @@ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq, spin_lock_irqsave(&desc->lock, flags); spin_lock(&gic.lock); + /* If the IRQ is already used by someone + * - If it's the same domain -> Xen doesn't need to update the IRQ desc + * - Otherwise -> For now, don't allow the IRQ to be shared between + * Xen and domains. + */ + if ( desc->action != NULL ) + { + if ( (desc->status & IRQ_GUEST) && d == desc->action->dev_id ) + goto out; + + if ( desc->status & IRQ_GUEST ) + { + d = desc->action->dev_id; + printk(XENLOG_ERR "ERROR: IRQ %u is already used by the domain %u\n", + irq->irq, d->domain_id); + } + else + printk(XENLOG_ERR "ERROR: IRQ %u is already used by Xen\n", + irq->irq); + retval = -EADDRINUSE; + goto out; + } + desc->handler = &gic_guest_irq_type; desc->status |= IRQ_GUEST;