From patchwork Tue Apr 8 14:44:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 27988 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4E5982066E for ; Tue, 8 Apr 2014 14:45:53 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id eb12sf4553308oac.3 for ; Tue, 08 Apr 2014 07:45:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=/1QN5r+2SLBVxY5AzYK5S3dbSLLhk2AR/NmZs50Obfg=; b=YVG6ING9r/0XoF0wkJtRjm2V7JOheog5k3TJHqy6A0YJ8ng7Yv9W+PoSjfhKUySqTZ Zgbbn9JT2Wo1oUjlns8o1vB4cI5SmprYZC/v0Ozt+z4blOmqSjf4RrDt9Ti/sVHb+U0/ HTlOZOdW9VhO54F7YFVXpKT+WG2x43z157yobZUlBiGAx3/6c8XUJZ89Yhfye23u22Je 2XdAbumZ7lfdurhw9Fw73eoLOQ3hCCtEHzJngn/0UgqXHp1bsq5duTdBMgADXZ789bvo kXzqjYMjmpeqzupRm3NPjLWYumcQG8dZil+dI7gMIVjoqy5nZr2ti4fOwBUEA5wSI4L+ YQnQ== X-Gm-Message-State: ALoCoQkn/f2P75EZcVSooIplHSqQCa/RNWrgD8rOGbeh/O0tEf6CfH0FICQM8STznyEe1R24+Xn8 X-Received: by 10.42.123.139 with SMTP id s11mr1606463icr.15.1396968352858; Tue, 08 Apr 2014 07:45:52 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.26.119 with SMTP id 110ls229683qgu.20.gmail; Tue, 08 Apr 2014 07:45:52 -0700 (PDT) X-Received: by 10.52.90.37 with SMTP id bt5mr3005870vdb.7.1396968352684; Tue, 08 Apr 2014 07:45:52 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id e9si428432vcf.157.2014.04.08.07.45.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Apr 2014 07:45:52 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id la4so869001vcb.31 for ; Tue, 08 Apr 2014 07:45:52 -0700 (PDT) X-Received: by 10.52.3.129 with SMTP id c1mr459396vdc.37.1396968352597; Tue, 08 Apr 2014 07:45:52 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.12.8 with SMTP id v8csp251653vcv; Tue, 8 Apr 2014 07:45:52 -0700 (PDT) X-Received: by 10.140.84.40 with SMTP id k37mr4663238qgd.65.1396968351884; Tue, 08 Apr 2014 07:45:51 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id i1si938637qab.67.2014.04.08.07.45.51 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 08 Apr 2014 07:45:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xen.org designates 50.57.142.19 as permitted sender) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WXXGH-0000IP-DM; Tue, 08 Apr 2014 14:44:29 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WXXGF-0000G2-6M for xen-devel@lists.xenproject.org; Tue, 08 Apr 2014 14:44:27 +0000 Received: from [193.109.254.147:61040] by server-14.bemta-14.messagelabs.com id 78/9D-08195-A4B04435; Tue, 08 Apr 2014 14:44:26 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-13.tower-27.messagelabs.com!1396968265!7019637!1 X-Originating-IP: [74.125.83.44] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30143 invoked from network); 8 Apr 2014 14:44:25 -0000 Received: from mail-ee0-f44.google.com (HELO mail-ee0-f44.google.com) (74.125.83.44) by server-13.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 8 Apr 2014 14:44:25 -0000 Received: by mail-ee0-f44.google.com with SMTP id e49so771300eek.17 for ; Tue, 08 Apr 2014 07:44:25 -0700 (PDT) X-Received: by 10.14.47.133 with SMTP id t5mr301876eeb.67.1396968265439; Tue, 08 Apr 2014 07:44:25 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id m42sm5031709eex.21.2014.04.08.07.44.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Apr 2014 07:44:25 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 8 Apr 2014 15:44:01 +0100 Message-Id: <1396968247-8768-13-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1396968247-8768-1-git-send-email-julien.grall@linaro.org> References: <1396968247-8768-1-git-send-email-julien.grall@linaro.org> Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com Subject: [Xen-devel] [PATCH v3 12/18] xen/arm: IRQ: Do not allow IRQ to be shared between domains and XEN X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org 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.220.172 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 Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: The current dt_route_irq_to_guest implementation sets IRQ_GUEST even if the IRQ is correctly setup. An IRQ can be shared between devices, if the devices are not assigned to the same domain or Xen, then this could result in routing the IRQ to the domain instead of Xen ... Also avoid to relying on wrong the behaviour when Xen is routing an IRQ to DOM0. Therefore check the return code from route_dt_irq_to_guest in map_device. Signed-off-by: Julien Grall Acked-by: Ian Campbell --- Changes in v3: - Fix typoes and update commit message Changes in v2: - Use EBUSY instead of EADDRINUSE for error code - Don't hardcode the domain in error message - Fix typo in error message - Use irq_get_domain --- xen/arch/arm/domain_build.c | 9 +++++++-- xen/arch/arm/irq.c | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index e7b1674..f85e5a9 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -718,8 +718,13 @@ 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 */ - route_dt_irq_to_guest(d, &irq, dt_node_name(dev)); + res = route_dt_irq_to_guest(d, &irq, dt_node_name(dev)); + if ( res ) + { + printk(XENLOG_ERR "Unable to route IRQ %u to domain %u\n", + irq.irq, d->domain_id); + return res; + } } /* Map the address ranges */ diff --git a/xen/arch/arm/irq.c b/xen/arch/arm/irq.c index aac39b0..ae92919 100644 --- a/xen/arch/arm/irq.c +++ b/xen/arch/arm/irq.c @@ -253,6 +253,16 @@ int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new) spin_lock_irqsave(&desc->lock, flags); + if ( desc->status & IRQ_GUEST ) + { + struct domain *d = irq_get_domain(desc); + + spin_unlock_irqrestore(&desc->lock, flags); + printk(XENLOG_ERR "ERROR: IRQ %u is already in use by the domain %u\n", + irq->irq, d->domain_id); + return -EBUSY; + } + disabled = (desc->action == NULL); rc = __setup_irq(desc, new); @@ -289,7 +299,7 @@ int route_dt_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; action = xmalloc(struct irqaction); @@ -302,6 +312,28 @@ int route_dt_irq_to_guest(struct domain *d, const struct dt_irq *irq, spin_lock_irqsave(&desc->lock, flags); + /* 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 ) + { + struct domain *ad = irq_get_domain(desc); + + if ( (desc->status & IRQ_GUEST) && d == ad ) + goto out; + + if ( desc->status & IRQ_GUEST ) + printk(XENLOG_ERR "ERROR: IRQ %u is already used by domain %u\n", + irq->irq, ad->domain_id); + else + printk(XENLOG_ERR "ERROR: IRQ %u is already used by Xen\n", + irq->irq); + retval = -EBUSY; + goto out; + } + retval = __setup_irq(desc, action); if ( retval ) {