From patchwork Fri Jan 24 16:43:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 23683 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f199.google.com (mail-yk0-f199.google.com [209.85.160.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 11B9C203C5 for ; Fri, 24 Jan 2014 16:43:53 +0000 (UTC) Received: by mail-yk0-f199.google.com with SMTP id 142sf14314224ykq.2 for ; Fri, 24 Jan 2014 08:43:53 -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:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=YEjqHMBPNUIclsDbTl8UOSt90DKGGrhe3I+hbf14uyw=; b=Y3BKhiyK3N0ikRqmRv1zJaE5e4rEQYrUgnGcl5JDWtchzzz1Danw8KYuqh6SI/nyji 7H+N22jpeVIjLaeZNnD0SfYuPS9tEcNDVXu+xhQAMcCnxio9+rVwVfsd+2L4y0dNTowO Kfmj73ordbthA7gLhhMaTRiHhZPRBdOOiCPGzZ5YaswZFdFc/zVFtMnWeVJRU476q31Q NohQ0lC9I0ATGYnJyuWBdMLZH9dBsCfzxP/xk/ijByX6qMGdmvBxu6pUFbL3uB4Axpqe a0hHfnZWjE5Rk88JpeLlID5Sy4Sr0otbLCUgY7k2stro4yKVIK1inYYbWZ8t7M9c2gfD plgw== X-Gm-Message-State: ALoCoQmVOzpdFE9DUQUFM32vY11tfNr5HhEOUKZlkjZGbyb+33XlKCbwx380NAD71K3divUGBjL5 X-Received: by 10.236.207.98 with SMTP id m62mr5343125yho.2.1390581833050; Fri, 24 Jan 2014 08:43:53 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.26.195 with SMTP id 61ls695934qgv.19.gmail; Fri, 24 Jan 2014 08:43:53 -0800 (PST) X-Received: by 10.58.235.129 with SMTP id um1mr8228738vec.17.1390581832958; Fri, 24 Jan 2014 08:43:52 -0800 (PST) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id c5si813311vco.69.2014.01.24.08.43.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Jan 2014 08:43:52 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.169 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.169; Received: by mail-vc0-f169.google.com with SMTP id hq11so2013608vcb.14 for ; Fri, 24 Jan 2014 08:43:52 -0800 (PST) X-Received: by 10.221.26.10 with SMTP id rk10mr8215982vcb.0.1390581832883; Fri, 24 Jan 2014 08:43:52 -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.220.174.196 with SMTP id u4csp115781vcz; Fri, 24 Jan 2014 08:43:52 -0800 (PST) X-Received: by 10.15.25.67 with SMTP id k43mr13369168eeu.48.1390581831729; Fri, 24 Jan 2014 08:43:51 -0800 (PST) Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com [74.125.83.53]) by mx.google.com with ESMTPS id d41si3259138eep.8.2014.01.24.08.43.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Jan 2014 08:43:51 -0800 (PST) Received-SPF: neutral (google.com: 74.125.83.53 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=74.125.83.53; Received: by mail-ee0-f53.google.com with SMTP id t10so1058415eei.26 for ; Fri, 24 Jan 2014 08:43:51 -0800 (PST) X-Received: by 10.14.4.67 with SMTP id 43mr9559231eei.70.1390581831316; Fri, 24 Jan 2014 08:43:51 -0800 (PST) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id k41sm5521285eey.0.2014.01.24.08.43.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Jan 2014 08:43:50 -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 for-4.5 3/8] xen/arm: IRQ: Protect IRQ to be shared between domains and XEN Date: Fri, 24 Jan 2014 16:43:37 +0000 Message-Id: <1390581822-32624-4-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1390581822-32624-1-git-send-email-julien.grall@linaro.org> References: <1390581822-32624-1-git-send-email-julien.grall@linaro.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.169 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 55e7622..d68bde3 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -605,6 +605,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); @@ -759,7 +774,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; @@ -773,6 +788,29 @@ int gic_route_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 ) + { + 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;