From patchwork Wed Apr 1 16:21:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 46647 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F2DA6216D1 for ; Wed, 1 Apr 2015 16:50:22 +0000 (UTC) Received: by wgfh4 with SMTP id h4sf11652545wgf.1 for ; Wed, 01 Apr 2015 09:50:22 -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:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=KT2oKlaxvayzT8XNRwGET+bwjsSkBqJQ4f1AjpbFJcw=; b=LmD9AGySe52Fp1T4sCVqGwzDHIMQP4ZfyGc+9hrH0DP+vPpmdb4Vo/0b2LvYVcXetA 8WHrUbzXhCyvUzzIds/R+JxVv3X0SfV2hnvL5q0n+r76K2ViIZ7gWGnbck6+b+TIDPDz amHyEdOUzHKoprlwLKojbJX7cqBQxZw0NJ2etIkJEX/ytIgCKEmYDV8JKaPQwGdYUaur 9DGOm/8KGSLrin4KRMLZhwOz/QcPyo/U7zpdiW3QkVEEiFsR7eVIYUZElK6E2KQSdzlo l/WQ89dSY1gMlAbTRdC4+t8etjCguKdQlTH4R17JnGFBXix2Mc0Dke/FtFivLWJGhWzo qgwg== X-Gm-Message-State: ALoCoQm6HcgAunNGZ/r1a8CkVEJFl1fRWzyWa17yZiawyhXR3XZPBpyCoAUbd3/Gis2UafyjnUo4 X-Received: by 10.180.86.66 with SMTP id n2mr1660439wiz.0.1427907022275; Wed, 01 Apr 2015 09:50:22 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.198.232 with SMTP id jf8ls105291lac.83.gmail; Wed, 01 Apr 2015 09:50:22 -0700 (PDT) X-Received: by 10.152.163.35 with SMTP id yf3mr10150823lab.86.1427907022008; Wed, 01 Apr 2015 09:50:22 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id p1si2034020laj.165.2015.04.01.09.50.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Apr 2015 09:50:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbbug6 with SMTP id ug6so40851848lbb.3 for ; Wed, 01 Apr 2015 09:50:21 -0700 (PDT) X-Received: by 10.112.185.66 with SMTP id fa2mr36063259lbc.117.1427907021877; Wed, 01 Apr 2015 09:50:21 -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.112.57.201 with SMTP id k9csp785678lbq; Wed, 1 Apr 2015 09:50:20 -0700 (PDT) X-Received: by 10.52.108.161 with SMTP id hl1mr40687728vdb.75.1427907019903; Wed, 01 Apr 2015 09:50:19 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id vm13si1731586vdb.9.2015.04.01.09.50.19 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 01 Apr 2015 09:50:19 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) 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 1YdLoI-0001gP-8V; Wed, 01 Apr 2015 16:48:10 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YdLoG-0001g0-Uf for xen-devel@lists.xenproject.org; Wed, 01 Apr 2015 16:48:09 +0000 Received: from [85.158.139.211] by server-3.bemta-5.messagelabs.com id 59/0B-30545-8412C155; Wed, 01 Apr 2015 16:48:08 +0000 X-Env-Sender: julien.grall@citrix.com X-Msg-Ref: server-4.tower-206.messagelabs.com!1427906882!13297215!3 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 6.13.6; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10826 invoked from network); 1 Apr 2015 16:48:07 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-4.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 1 Apr 2015 16:48:07 -0000 X-IronPort-AV: E=Sophos;i="5.11,504,1422921600"; d="scan'208";a="250401387" From: Julien Grall To: Date: Wed, 1 Apr 2015 17:21:43 +0100 Message-ID: <1427905307-23749-11-git-send-email-julien.grall@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1427905307-23749-1-git-send-email-julien.grall@citrix.com> References: <1427905307-23749-1-git-send-email-julien.grall@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com, Stefano Stabellini Subject: [Xen-devel] [PATCH v5 p1 10/14] xen/arm: route_irq_to_guest: Check validity of the IRQ 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: , 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: patch@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) 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: From: Julien Grall Currently Xen only supports SPIs routing for guest, add a function is_assignable_irq to check if we can assign a given IRQ to the guest. Secondly, make sure the vIRQ is not the greater than the number of IRQs configured in the vGIC and it's an SPI. Thirdly, when the IRQ is already assigned to the domain, check the user is not asking to use a different vIRQ than the one already bound. Finally, desc->arch.type which contains the IRQ type (i.e level/edge) must be correctly configured before. The misconfiguration can happen when: - the device has been blacklisted for the current platform - the IRQ has not been described in the device tree Also, use XENLOG_G_ERR in the error message within the function as it will be later called from a guest. Signed-off-by: Julien Grall Acked-by: Stefano Stabellini Acked-by: Ian Campbell --- Changes in v5: - Typoe in the commit message - Add Ian and Stefano's ack Changes in v4: - Use NR_LOCAL_IRQS rather than 32 - Move the check to the IRQ and irq_to_desc after the vIRQ check - Typoes and rewording the commit message and in the patch - Use printk rather than dprintk. Changes in v3: - Fix typo in commit message and comment - Add a check that the vIRQ is an SPI - Check if the user is not asking for a different vIRQ when the IRQ is already assigned to the guest Changes in v2: - Rename is_routable_irq into is_assignable_irq - Check if the IRQ is not greater than the number handled by the number of IRQs handled by the gic - Move is_assignable_irq in irq.c rather than defining in the header irq.h - Retrieve the irq descriptor after checking the validity of the IRQ - vgic_num_irqs has been moved in a separate patch - Fix the irq check against vgic_num_irqs - Use virq instead of irq for vGIC sanity check --- xen/arch/arm/irq.c | 59 +++++++++++++++++++++++++++++++++++++++++++---- xen/include/asm-arm/irq.h | 2 ++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/irq.c b/xen/arch/arm/irq.c index beb746a..4c3e381 100644 --- a/xen/arch/arm/irq.c +++ b/xen/arch/arm/irq.c @@ -387,6 +387,16 @@ err: return rc; } +bool_t is_assignable_irq(unsigned int irq) +{ + /* For now, we can only route SPIs to the guest */ + return ((irq >= NR_LOCAL_IRQS) && (irq < gic_number_lines())); +} + +/* + * Route an IRQ to a specific guest. + * For now only SPIs are assignable to the guest. + */ int route_irq_to_guest(struct domain *d, unsigned int virq, unsigned int irq, const char * devname) { @@ -396,6 +406,28 @@ int route_irq_to_guest(struct domain *d, unsigned int virq, unsigned long flags; int retval = 0; + if ( virq >= vgic_num_irqs(d) ) + { + printk(XENLOG_G_ERR + "the vIRQ number %u is too high for domain %u (max = %u)\n", + irq, d->domain_id, vgic_num_irqs(d)); + return -EINVAL; + } + + /* Only routing to virtual SPIs is supported */ + if ( virq < NR_LOCAL_IRQS ) + { + printk(XENLOG_G_ERR "IRQ can only be routed to an SPI"); + return -EINVAL; + } + + if ( !is_assignable_irq(irq) ) + { + printk(XENLOG_G_ERR "the IRQ%u is not routable\n", irq); + return -EINVAL; + } + desc = irq_to_desc(irq); + action = xmalloc(struct irqaction); if ( !action ) return -ENOMEM; @@ -416,8 +448,18 @@ int route_irq_to_guest(struct domain *d, unsigned int virq, 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 + if ( desc->arch.type == DT_IRQ_TYPE_INVALID ) + { + printk(XENLOG_G_ERR "IRQ %u has not been configured\n", irq); + retval = -EIO; + goto out; + } + + /* + * If the IRQ is already used by someone + * - If it's the same domain -> Xen doesn't need to update the IRQ desc. + * For safety check if we are not trying to assign the IRQ to a + * different vIRQ. * - Otherwise -> For now, don't allow the IRQ to be shared between * Xen and domains. */ @@ -426,13 +468,22 @@ int route_irq_to_guest(struct domain *d, unsigned int virq, struct domain *ad = irq_get_domain(desc); if ( test_bit(_IRQ_GUEST, &desc->status) && d == ad ) + { + if ( irq_get_guest_info(desc)->virq != virq ) + { + printk(XENLOG_G_ERR + "d%u: IRQ %u is already assigned to vIRQ %u\n", + d->domain_id, irq, irq_get_guest_info(desc)->virq); + retval = -EBUSY; + } goto out; + } if ( test_bit(_IRQ_GUEST, &desc->status) ) - printk(XENLOG_ERR "ERROR: IRQ %u is already used by domain %u\n", + printk(XENLOG_G_ERR "IRQ %u is already used by domain %u\n", irq, ad->domain_id); else - printk(XENLOG_ERR "ERROR: IRQ %u is already used by Xen\n", irq); + printk(XENLOG_G_ERR "IRQ %u is already used by Xen\n", irq); retval = -EBUSY; goto out; } diff --git a/xen/include/asm-arm/irq.h b/xen/include/asm-arm/irq.h index f00eb11..71b39e7 100644 --- a/xen/include/asm-arm/irq.h +++ b/xen/include/asm-arm/irq.h @@ -37,6 +37,8 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq); #define domain_pirq_to_irq(d, pirq) (pirq) +bool_t is_assignable_irq(unsigned int irq); + void init_IRQ(void); void init_secondary_IRQ(void);