From patchwork Thu Apr 3 20:42:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 27706 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f197.google.com (mail-vc0-f197.google.com [209.85.220.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9973720490 for ; Thu, 3 Apr 2014 20:44:17 +0000 (UTC) Received: by mail-vc0-f197.google.com with SMTP id if11sf5689246vcb.8 for ; Thu, 03 Apr 2014 13:44:16 -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=yfDj3HrD33t85RcuraZHOiaf+seYVUtKgQVtMkHjX/w=; b=l9+st42vaoHXK//fFrKAy/eQQZ5JCV5YuhKswAw+yDJXWftUP6E3Ps+plGeaeLCzKR tDjI+VyqeVCOAwcYkaplgg+dYTXtFE7gT7U1YngqjOTLwIoiYMNrZR5m78QWorz+wvLN Abg6ApWzO7G0YW/W9wLbJqXr4aIGvMoMOvdR5dDnAq6UiBLY6YmbfVwJanlnO6sjIANC 9dw6RsxGOwZ/hIum8XA1vgp4QZcOqS7ZU6jOo0EAxfuQPcgOC8siiBDc3aca6eVmXX6j 7pY4c5UVu65KaQgACLKHrP4bGOdq0c3wIrM07KoVxZwOS2ratwac6wTXZWGUtS4VYRHz AJCg== X-Gm-Message-State: ALoCoQlhoTPUGElJi1o5I0UEj0ZaHRmNuzGqZHQCIVm2kxGTUp5xUExS6IAhZ2GZ9wY6fkFYTIjv X-Received: by 10.236.69.74 with SMTP id m50mr4913767yhd.0.1396557856605; Thu, 03 Apr 2014 13:44:16 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.19.136 with SMTP id 8ls776105qgh.43.gmail; Thu, 03 Apr 2014 13:44:16 -0700 (PDT) X-Received: by 10.221.26.10 with SMTP id rk10mr4590478vcb.0.1396557856532; Thu, 03 Apr 2014 13:44:16 -0700 (PDT) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id u5si1414248vdo.76.2014.04.03.13.44.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 03 Apr 2014 13:44:16 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.179 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.179; Received: by mail-ve0-f179.google.com with SMTP id db12so725043veb.38 for ; Thu, 03 Apr 2014 13:44:16 -0700 (PDT) X-Received: by 10.52.104.33 with SMTP id gb1mr342344vdb.45.1396557856436; Thu, 03 Apr 2014 13:44:16 -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 v8csp59800vcv; Thu, 3 Apr 2014 13:44:14 -0700 (PDT) X-Received: by 10.229.53.136 with SMTP id m8mr10122335qcg.4.1396557843192; Thu, 03 Apr 2014 13:44:03 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id c3si2618858qan.247.2014.04.03.13.44.02 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 03 Apr 2014 13:44:03 -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 1WVoT9-0008F3-90; Thu, 03 Apr 2014 20:42:39 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WVoT7-0008E7-Ot for xen-devel@lists.xenproject.org; Thu, 03 Apr 2014 20:42:37 +0000 Received: from [193.109.254.147:35867] by server-4.bemta-14.messagelabs.com id AE/E4-02781-DB7CD335; Thu, 03 Apr 2014 20:42:37 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-12.tower-27.messagelabs.com!1396557756!6148383!1 X-Originating-IP: [74.125.82.172] 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 28392 invoked from network); 3 Apr 2014 20:42:36 -0000 Received: from mail-we0-f172.google.com (HELO mail-we0-f172.google.com) (74.125.82.172) by server-12.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 3 Apr 2014 20:42:36 -0000 Received: by mail-we0-f172.google.com with SMTP id t61so2498796wes.3 for ; Thu, 03 Apr 2014 13:42:36 -0700 (PDT) X-Received: by 10.180.101.134 with SMTP id fg6mr14639857wib.6.1396557755930; Thu, 03 Apr 2014 13:42:35 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id t50sm14510572eev.28.2014.04.03.13.42.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Apr 2014 13:42:35 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 3 Apr 2014 21:42:02 +0100 Message-Id: <1396557727-19102-12-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1396557727-19102-1-git-send-email-julien.grall@linaro.org> References: <1396557727-19102-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 v2 11/16] xen/arm: IRQ: Protect 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.128.179 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 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 route the IRQ 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 --- 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 1262a9c..2bf6618 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 ) {