From patchwork Thu Mar 19 19:29:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 46101 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4CBE821515 for ; Thu, 19 Mar 2015 19:32:33 +0000 (UTC) Received: by widex7 with SMTP id ex7sf14618175wid.2 for ; Thu, 19 Mar 2015 12:32:32 -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:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=0hL+5hMES0LiKyGyyCZigT8GYCRTlWdLeYM6k1Ri9Xs=; b=PIAmToLqdoC8cE9RNVjYW/IEL+t8K/RqJEnEEqSycJya4yEtf9IS5MdsEpXnKEbYTy orGy+0ai6iaVL08ywiZMWaBZikFj3thXfnjk3PjKS5aWKokknvt1lVlpv7PeA4MRxy7H waI2H9cvbv/UwbOsNRf5cXjtBubZApnsw5922ihqh2DJDlEh8SPmL6i+YTb9C6SvKsgb dJdpJtsKw/HorIBJOI4cyl5/f5ooPz4jDXvHxmSQMI4DuB92k0NoNul53Xjg47JAh0z/ GASM0zzqUeeY87CA2QCi5dCqHswWJr453HHhwfUw6fLcNnLBRVeZmdVAmNzTnhjiHsNV bDjQ== X-Gm-Message-State: ALoCoQkBuBp1T7KEiB+nm3O6ZUXcCk+tl5AxmQ4YBscYmRDaMDiK4898vcuK5CJrvqvPbaxlw8xt X-Received: by 10.180.13.195 with SMTP id j3mr2071138wic.2.1426793552652; Thu, 19 Mar 2015 12:32:32 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.14 with SMTP id t14ls341603laz.61.gmail; Thu, 19 Mar 2015 12:32:32 -0700 (PDT) X-Received: by 10.112.210.230 with SMTP id mx6mr39272325lbc.64.1426793552295; Thu, 19 Mar 2015 12:32:32 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id gd8si1666792lbc.67.2015.03.19.12.32.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 12:32:32 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbnq5 with SMTP id q5so32335247lbn.0 for ; Thu, 19 Mar 2015 12:32:32 -0700 (PDT) X-Received: by 10.112.204.197 with SMTP id la5mr69296037lbc.29.1426793552058; Thu, 19 Mar 2015 12:32:32 -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.35.133 with SMTP id h5csp597630lbj; Thu, 19 Mar 2015 12:32:31 -0700 (PDT) X-Received: by 10.55.40.9 with SMTP id o9mr126654661qkh.55.1426793550617; Thu, 19 Mar 2015 12:32:30 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id 191si2140070qhw.120.2015.03.19.12.32.29 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 19 Mar 2015 12:32:30 -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 1YYg9i-0004Qj-AJ; Thu, 19 Mar 2015 19:30:58 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YYg9f-0004Ls-Tf for xen-devel@lists.xenproject.org; Thu, 19 Mar 2015 19:30:56 +0000 Received: from [85.158.139.211] by server-2.bemta-5.messagelabs.com id 86/5E-07584-FE32B055; Thu, 19 Mar 2015 19:30:55 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-14.tower-206.messagelabs.com!1426793454!6563320!1 X-Originating-IP: [209.85.212.172] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.13.4; banners=-,-,- X-VirusChecked: Checked Received: (qmail 28383 invoked from network); 19 Mar 2015 19:30:54 -0000 Received: from mail-wi0-f172.google.com (HELO mail-wi0-f172.google.com) (209.85.212.172) by server-14.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 19 Mar 2015 19:30:54 -0000 Received: by wibdy8 with SMTP id dy8so126863711wib.0 for ; Thu, 19 Mar 2015 12:30:54 -0700 (PDT) X-Received: by 10.180.214.99 with SMTP id nz3mr19354126wic.82.1426793454189; Thu, 19 Mar 2015 12:30:54 -0700 (PDT) Received: from chilopoda.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id hl8sm3203005wjb.38.2015.03.19.12.30.52 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2015 12:30:53 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 19 Mar 2015 19:29:37 +0000 Message-Id: <1426793399-6283-12-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1426793399-6283-1-git-send-email-julien.grall@linaro.org> References: <1426793399-6283-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 v4 11/33] 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: , 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=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 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: 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 that 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 --- 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);