From patchwork Mon Jun 16 16:17:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 31982 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f199.google.com (mail-qc0-f199.google.com [209.85.216.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 86DAD2107C for ; Mon, 16 Jun 2014 16:20:07 +0000 (UTC) Received: by mail-qc0-f199.google.com with SMTP id l6sf13489362qcy.2 for ; Mon, 16 Jun 2014 09:20:07 -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=Gm/VvkmbYFX2GsmGV70Gtzj3cqeulinaTYGThuHSfkY=; b=Aq7abGK8Afn5JMjidfSGP8iE6+g0zswJ+eht7h0HVivx3Y6uMkVXljCxbTRIk9k08y gEp25RdWPV2cHINzV4ukbnu89NLnDjcKBDYxBIOHPjtKZbukLRtbNBOPWI/p6dkMqkYI H/hQG+730jRbbd3lRe8gP6ebdyKLq5EhGSBcsZuaaVNQOngYe7uyFgP/D7yCRVkySbjL QV7nXYFXc9VidGtTOyhfuooabQUTSsciVatl1CfH2Har7/zXmToGQIFezHkbszoLwvEc 27fV/zbDNSkoZ4AL16KIj9nXZ9Vxy5V+0HgXvDiWn3zkdkLo+5Mgq6FyhxeFl8Ft6C1A FRpQ== X-Gm-Message-State: ALoCoQmdt16JELarGxtLi7Y72NEQyvBLG1YkoVEA3eXU2NBQDYy+VZ4HHoYFv5c5ILBImHSzv+tL X-Received: by 10.236.128.112 with SMTP id e76mr588508yhi.38.1402935607035; Mon, 16 Jun 2014 09:20:07 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.108.2 with SMTP id i2ls497855qgf.78.gmail; Mon, 16 Jun 2014 09:20:07 -0700 (PDT) X-Received: by 10.52.121.39 with SMTP id lh7mr745931vdb.66.1402935606966; Mon, 16 Jun 2014 09:20:06 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id py4si4287154vcb.49.2014.06.16.09.20.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Jun 2014 09:20:06 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.177 as permitted sender) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id ij19so5064672vcb.22 for ; Mon, 16 Jun 2014 09:20:06 -0700 (PDT) X-Received: by 10.58.112.65 with SMTP id io1mr900549veb.61.1402935606879; Mon, 16 Jun 2014 09:20:06 -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.54.6 with SMTP id vs6csp146174vcb; Mon, 16 Jun 2014 09:20:06 -0700 (PDT) X-Received: by 10.58.178.2 with SMTP id cu2mr390665vec.70.1402935606372; Mon, 16 Jun 2014 09:20:06 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id gx9si4281297vdc.17.2014.06.16.09.20.05 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 16 Jun 2014 09:20:06 -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 1WwZbz-0006iR-Ov; Mon, 16 Jun 2014 16:18:23 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WwZbx-0006hl-Uq for xen-devel@lists.xenproject.org; Mon, 16 Jun 2014 16:18:22 +0000 Received: from [85.158.137.68:61538] by server-14.bemta-3.messagelabs.com id 37/9E-30903-DC81F935; Mon, 16 Jun 2014 16:18:21 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-11.tower-31.messagelabs.com!1402935500!10411376!1 X-Originating-IP: [74.125.82.177] 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 16917 invoked from network); 16 Jun 2014 16:18:20 -0000 Received: from mail-we0-f177.google.com (HELO mail-we0-f177.google.com) (74.125.82.177) by server-11.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 16 Jun 2014 16:18:20 -0000 Received: by mail-we0-f177.google.com with SMTP id u56so5858579wes.22 for ; Mon, 16 Jun 2014 09:18:20 -0700 (PDT) X-Received: by 10.194.60.35 with SMTP id e3mr30471671wjr.12.1402935500251; Mon, 16 Jun 2014 09:18:20 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id l45sm34836161eep.25.2014.06.16.09.18.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Jun 2014 09:18:19 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jun 2014 17:17:51 +0100 Message-Id: <1402935486-29136-5-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1402935486-29136-1-git-send-email-julien.grall@linaro.org> References: <1402935486-29136-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] [RFC 04/19] 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.177 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_routable_irq to check if we can route 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 --- xen/arch/arm/irq.c | 32 +++++++++++++++++++++++++++++--- xen/include/asm-arm/gic.h | 2 ++ xen/include/asm-arm/irq.h | 6 ++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/irq.c b/xen/arch/arm/irq.c index 9c141bc..4e51fee 100644 --- a/xen/arch/arm/irq.c +++ b/xen/arch/arm/irq.c @@ -361,6 +361,10 @@ err: return rc; } +/* Route an IRQ to a specific guest. + * For now the vIRQ is equal to the pIRQ and only SPIs are routabled to + * the guest. + */ int route_irq_to_guest(struct domain *d, unsigned int irq, const char * devname) { @@ -369,6 +373,20 @@ int route_irq_to_guest(struct domain *d, unsigned int irq, unsigned long flags; int retval = 0; + if ( !is_routable_irq(irq) ) + { + dprintk(XENLOG_G_ERR, "the IRQ%u is not routable\n", irq); + return -EINVAL; + } + + if ( irq > 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; @@ -379,6 +397,14 @@ int route_irq_to_guest(struct domain *d, unsigned int irq, 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 @@ -392,10 +418,10 @@ int route_irq_to_guest(struct domain *d, unsigned int irq, goto out; if ( desc->status & IRQ_GUEST ) - 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/gic.h b/xen/include/asm-arm/gic.h index 8e37ccf..6e7375c 100644 --- a/xen/include/asm-arm/gic.h +++ b/xen/include/asm-arm/gic.h @@ -163,6 +163,8 @@ #define DT_MATCH_GIC DT_MATCH_COMPATIBLE("arm,cortex-a15-gic"), \ DT_MATCH_COMPATIBLE("arm,cortex-a7-gic") +#define vgic_num_irqs(d) ((d)->arch.vgic.nr_lines + 32) + extern int domain_vgic_init(struct domain *d); extern void domain_vgic_free(struct domain *d); diff --git a/xen/include/asm-arm/irq.h b/xen/include/asm-arm/irq.h index e567f71..63926a5 100644 --- a/xen/include/asm-arm/irq.h +++ b/xen/include/asm-arm/irq.h @@ -37,6 +37,12 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq); #define domain_pirq_to_irq(d, pirq) (pirq) +static inline bool_t is_routable_irq(unsigned int irq) +{ + /* For now, we can only route SPIs to the guest */ + return (irq >= NR_LOCAL_IRQS); +} + void init_IRQ(void); void init_secondary_IRQ(void);