From patchwork Tue Jan 13 14:25:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 43010 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7950720DE8 for ; Tue, 13 Jan 2015 14:28:32 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id x12sf1864454wgg.0 for ; Tue, 13 Jan 2015 06:28:31 -0800 (PST) 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=2wGRw46rL3jt2ar4vUw6QzyE1Z6nyIeo6tY9F3QLy34=; b=lHst20yeoLQlQ1ETLhe6u4X+laW3EOt1BVIu3+kGzGDMLnHHlZL0mmPC+LWUWox9gc OIZ42Pq3jYx4jBZriJPXADCjKqqtnGaj/rCiCx6i5AyKboEREEUM1WrIzkuy0GgEEPPX QkNb6WLEa66DWwkjj7FN5xdQjGX4c2pFdvOcUxgNtdq8rH8gT/MsSUmYLhWjqKbIBvU4 Ag+iJ/ZPPVEOLNfAl2+4XS1mmuOnpnFYKJF0RjB49IIlv7MgKqis/fKeIc3qBEZiudtF v4EV9+rc+YqQOYCVn1026cA6J5g0AoCsRksXAn12Z8q7r7p4Z9eIxFqUwihg0/FPUrsu b8YA== X-Gm-Message-State: ALoCoQkKTGw5aQ18ZA5z1Qz/vtNABOGAsYRl6mRUggVpFymjzBzhMAFjTzatdn7wmx8S4SuvV34s X-Received: by 10.180.228.38 with SMTP id sf6mr2899817wic.5.1421159311772; Tue, 13 Jan 2015 06:28:31 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.161.198 with SMTP id xu6ls149019lab.86.gmail; Tue, 13 Jan 2015 06:28:31 -0800 (PST) X-Received: by 10.112.205.231 with SMTP id lj7mr42207581lbc.86.1421159311549; Tue, 13 Jan 2015 06:28:31 -0800 (PST) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id k1si3011146lah.94.2015.01.13.06.28.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 Jan 2015 06:28:31 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by mail-la0-f44.google.com with SMTP id gd6so2905779lab.3 for ; Tue, 13 Jan 2015 06:28:31 -0800 (PST) X-Received: by 10.152.197.5 with SMTP id iq5mr42318205lac.6.1421159311434; Tue, 13 Jan 2015 06:28:31 -0800 (PST) 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.9.200 with SMTP id c8csp1398918lbb; Tue, 13 Jan 2015 06:28:30 -0800 (PST) X-Received: by 10.220.89.132 with SMTP id e4mr21423498vcm.2.1421159291534; Tue, 13 Jan 2015 06:28:11 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id vf3si8044093vcb.105.2015.01.13.06.28.10 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 13 Jan 2015 06:28:11 -0800 (PST) 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 1YB2Qb-0001Ez-7j; Tue, 13 Jan 2015 14:26:41 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YB2QZ-0001Bm-E4 for xen-devel@lists.xenproject.org; Tue, 13 Jan 2015 14:26:39 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id 40/DD-31453-E1B25B45; Tue, 13 Jan 2015 14:26:38 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-7.tower-206.messagelabs.com!1421159197!17833911!1 X-Originating-IP: [209.85.212.180] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.12.5; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17613 invoked from network); 13 Jan 2015 14:26:37 -0000 Received: from mail-wi0-f180.google.com (HELO mail-wi0-f180.google.com) (209.85.212.180) by server-7.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 13 Jan 2015 14:26:37 -0000 Received: by mail-wi0-f180.google.com with SMTP id n3so4275006wiv.1 for ; Tue, 13 Jan 2015 06:26:37 -0800 (PST) X-Received: by 10.180.212.113 with SMTP id nj17mr36876641wic.77.1421159196286; Tue, 13 Jan 2015 06:26:36 -0800 (PST) Received: from chilopoda.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id ni15sm14513482wic.18.2015.01.13.06.26.34 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Jan 2015 06:26:35 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 13 Jan 2015 14:25:18 +0000 Message-Id: <1421159133-31526-10-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1421159133-31526-1-git-send-email-julien.grall@linaro.org> References: <1421159133-31526-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 v3 09/24] 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.215.44 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 handle to the vGIC and it's an SPIs. 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 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 --- 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 | 58 +++++++++++++++++++++++++++++++++++++++++++---- xen/include/asm-arm/irq.h | 2 ++ 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/irq.c b/xen/arch/arm/irq.c index 830832c..af408ac 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,29 @@ 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 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 < 32 ) + { + dprintk(XENLOG_G_ERR, "IRQ can only be routed to a virtual SPIs"); + return -EINVAL; + } + action = xmalloc(struct irqaction); if ( !action ) return -ENOMEM; @@ -408,8 +440,18 @@ 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 + * - 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. */ @@ -418,13 +460,21 @@ 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 ) + { + dprintk(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 = -EPERM; + } 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 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);