From patchwork Thu Jul 31 15:00:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 34663 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6298320540 for ; Thu, 31 Jul 2014 15:02:38 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id ho1sf2438429wib.5 for ; Thu, 31 Jul 2014 08:02:34 -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=VZvfg9wgWBQAyGJgVtFo6S3coJSoUnX//eJ89CHm8+M=; b=aCPYPGYgStjgWN5BgFQbuxqlVZGqEEm+dziQ1NJOW8BQ0Mz5i6+F9E8Dne6EotLZMM mMQXbFR6vw9bXnSLYQSPmHrrnVRxNoLxCPXkaXxAQtsnv/XfXEo44YOwPURGF7/P6p/n eFmHqcW19K5W8BqEmrgFBc9npp4z/8KSKvKFb1oKvnNpCjVCIGFJTHoQHiZwzj4x6N6J XKUWQ9oPWztFmtpQ0gT77pS5CCuVbsWR4PpCCnyTwgNajARhQu20HDkkaVnYeVHbxzeW 7IruARTXHk6PCpt0c1I4eRnjIkSfg6mBYF1xj6ZUJB8H4BbceCEK7FWo3JY+ikcS26Dd tNSA== X-Gm-Message-State: ALoCoQm8mLPAEQRh15SFMzbVvZXqhf3cbMDINwet6ofejP0utbYCKGy5uFYAj6o8TlD9r+g8QFxm X-Received: by 10.180.104.163 with SMTP id gf3mr1197173wib.1.1406818953967; Thu, 31 Jul 2014 08:02:33 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.17.53 with SMTP id 50ls976143qgc.21.gmail; Thu, 31 Jul 2014 08:02:33 -0700 (PDT) X-Received: by 10.52.149.209 with SMTP id uc17mr15346734vdb.65.1406818953783; Thu, 31 Jul 2014 08:02:33 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id sv16si4609743vdb.55.2014.07.31.08.02.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 31 Jul 2014 08:02:14 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id le20so4327110vcb.14 for ; Thu, 31 Jul 2014 08:02:14 -0700 (PDT) X-Received: by 10.220.97.5 with SMTP id j5mr13420171vcn.16.1406818934706; Thu, 31 Jul 2014 08:02:14 -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.221.37.5 with SMTP id tc5csp25052vcb; Thu, 31 Jul 2014 08:02:14 -0700 (PDT) X-Received: by 10.70.54.42 with SMTP id g10mr13021416pdp.49.1406818933064; Thu, 31 Jul 2014 08:02:13 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id p14si14838365ick.96.2014.07.31.08.02.12 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 31 Jul 2014 08:02:13 -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 1XCrqz-0000Z3-MJ; Thu, 31 Jul 2014 15:01:13 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XCrqx-0000Xb-Ur for xen-devel@lists.xenproject.org; Thu, 31 Jul 2014 15:01:12 +0000 Received: from [85.158.139.211:31455] by server-3.bemta-5.messagelabs.com id 03/E2-13873-73A5AD35; Thu, 31 Jul 2014 15:01:11 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-6.tower-206.messagelabs.com!1406818870!11140476!1 X-Originating-IP: [209.85.212.170] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 4922 invoked from network); 31 Jul 2014 15:01:10 -0000 Received: from mail-wi0-f170.google.com (HELO mail-wi0-f170.google.com) (209.85.212.170) by server-6.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 31 Jul 2014 15:01:10 -0000 Received: by mail-wi0-f170.google.com with SMTP id f8so1411348wiw.5 for ; Thu, 31 Jul 2014 08:01:10 -0700 (PDT) X-Received: by 10.180.9.38 with SMTP id w6mr17561377wia.61.1406818870140; Thu, 31 Jul 2014 08:01:10 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id r20sm67128337wik.0.2014.07.31.08.01.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Jul 2014 08:01:09 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 31 Jul 2014 16:00:38 +0100 Message-Id: <1406818852-31856-8-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1406818852-31856-1-git-send-email-julien.grall@linaro.org> References: <1406818852-31856-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 07/21] 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.220.169 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_assign_irq to check if we can assign a given IRQ to the guest. Secondly, make sure the vIRQ (which is currently the same as the pIRQ) is not the greater that the number of IRQs handle to the vGIC. Finally, desc->arch.type which contains the IRQ type (i.e level/edge) must be correctly configured before. The IRQ type won't be configure when: - the device has been blacklist for the current platform - the IRQ has not been describe in the device tree I think we can safely assume that a user won't never ask to route as such IRQ to the guest. 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 --- 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 | 39 ++++++++++++++++++++++++++++++++++++--- xen/include/asm-arm/irq.h | 2 ++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/irq.c b/xen/arch/arm/irq.c index 830832c..7eeb8dd 100644 --- a/xen/arch/arm/irq.c +++ b/xen/arch/arm/irq.c @@ -379,6 +379,15 @@ 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 assignabled to the guest. + */ int route_irq_to_guest(struct domain *d, unsigned int virq, unsigned int irq, const char * devname) { @@ -388,6 +397,22 @@ int route_irq_to_guest(struct domain *d, unsigned int virq, unsigned long flags; int retval = 0; + if ( !is_assignable_irq(irq) ) + { + dprintk(XENLOG_G_ERR, "the IRQ%u is not routable\n", irq); + return -EINVAL; + } + + desc = irq_to_desc(irq); + + if ( virq >= vgic_num_irqs(d) ) + { + dprintk(XENLOG_G_ERR, + "the IRQ number %u is too high for domain %u (max = %u)\n", + irq, d->domain_id, vgic_num_irqs(d)); + return -EINVAL; + } + action = xmalloc(struct irqaction); if ( !action ) return -ENOMEM; @@ -408,6 +433,14 @@ int route_irq_to_guest(struct domain *d, unsigned int virq, spin_lock_irqsave(&desc->lock, flags); + if ( desc->arch.type == DT_IRQ_TYPE_INVALID ) + { + dprintk(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 * - Otherwise -> For now, don't allow the IRQ to be shared between @@ -421,10 +454,10 @@ int route_irq_to_guest(struct domain *d, unsigned int virq, goto out; if ( test_bit(_IRQ_GUEST, &desc->status) ) - printk(XENLOG_ERR "ERROR: IRQ %u is already used by domain %u\n", - irq, ad->domain_id); + dprintk(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); + dprintk(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 9bc3492..a7174f3 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);