From patchwork Tue Jan 13 14:25:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 43015 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f199.google.com (mail-we0-f199.google.com [74.125.82.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DAC7D20DE8 for ; Tue, 13 Jan 2015 14:28:48 +0000 (UTC) Received: by mail-we0-f199.google.com with SMTP id k11sf1857032wes.2 for ; Tue, 13 Jan 2015 06:28:48 -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=Wd1H1C0i3eHpFUu0CeD0q1uLrdL6xJxCcC1VeM04uZ0=; b=HpQfijz0B9t/Xhfyd3ZxNU0vk8hhnZL1JHfTxdK4vq5Ozrzd3eL9FO4C9hdNiTiFYg Nc0CjzLGXwM1Y0jUrqK2m0WtzxYAyHD6pRSu6rr5Ypx5+aGCtOPoJMYj9tWUz/n+Kyrq BS1Lr/boy3PxaD3mI32m5jjFRUqkQom0vFpTmaOGurJzBg36RCYXgG4IK+96AF7h21R/ x8rkQfKT+ETu7qXxYK9KaVi776y0rPJeio2tkgkcKFU25HqWEbUEHbNVEYCGeBFBtrop DQ92wYWMKrvQmdyxEEl48SmU8LA/qL5B4jc/Vm9GvDYEEv/n2jjVuc6mRa0S0oNeSrO5 eQpw== X-Gm-Message-State: ALoCoQnLuExONTXJyfRd8R5lYYbR1PfEkHL8HBcAPhaKAq45oPW4J1tbPkhDmdsSrlMajkm8Ek8A X-Received: by 10.112.133.98 with SMTP id pb2mr1916925lbb.2.1421159328108; Tue, 13 Jan 2015 06:28:48 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.1 with SMTP id s1ls2352lal.23.gmail; Tue, 13 Jan 2015 06:28:47 -0800 (PST) X-Received: by 10.112.166.73 with SMTP id ze9mr41831218lbb.38.1421159327767; Tue, 13 Jan 2015 06:28:47 -0800 (PST) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id rx8si24436545lbb.33.2015.01.13.06.28.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 Jan 2015 06:28:47 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by mail-la0-f48.google.com with SMTP id gf13so2878032lab.7 for ; Tue, 13 Jan 2015 06:28:47 -0800 (PST) X-Received: by 10.112.14.6 with SMTP id l6mr43020491lbc.91.1421159327673; Tue, 13 Jan 2015 06:28:47 -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 c8csp1398987lbb; Tue, 13 Jan 2015 06:28:46 -0800 (PST) X-Received: by 10.140.30.244 with SMTP id d107mr55703559qgd.70.1421159308020; Tue, 13 Jan 2015 06:28:28 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id r9si26923320qas.100.2015.01.13.06.28.27 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 13 Jan 2015 06:28:28 -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 1YB2Qc-0001Gd-Kd; Tue, 13 Jan 2015 14:26:42 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YB2Qa-0001CS-Oo for xen-devel@lists.xenproject.org; Tue, 13 Jan 2015 14:26:41 +0000 Received: from [193.109.254.147] by server-7.bemta-14.messagelabs.com id E5/0A-27785-F1B25B45; Tue, 13 Jan 2015 14:26:39 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-8.tower-27.messagelabs.com!1421159198!20326434!1 X-Originating-IP: [74.125.82.46] 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 21487 invoked from network); 13 Jan 2015 14:26:38 -0000 Received: from mail-wg0-f46.google.com (HELO mail-wg0-f46.google.com) (74.125.82.46) by server-8.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 13 Jan 2015 14:26:38 -0000 Received: by mail-wg0-f46.google.com with SMTP id x13so3248258wgg.5 for ; Tue, 13 Jan 2015 06:26:38 -0800 (PST) X-Received: by 10.194.89.39 with SMTP id bl7mr68691449wjb.76.1421159198014; Tue, 13 Jan 2015 06:26:38 -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.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Jan 2015 06:26:37 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 13 Jan 2015 14:25:19 +0000 Message-Id: <1421159133-31526-11-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 10/24] xen/arm: gic: Add sanity checks gic_route_irq_to_guest 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.48 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: With the addition of interrupt assignment to guest, we need to make sure the guest don't blow up the interrupt management in Xen. Before associating the IRQ to a vIRQ we need to make sure: - the vIRQ is not already associated to another IRQ - the guest didn't enable the vIRQ Signed-off-by: Julien Grall --- Changes in v3: - Patch added --- xen/arch/arm/gic.c | 34 ++++++++++++++++++++++++++-------- xen/arch/arm/irq.c | 12 ++++++++++-- xen/include/asm-arm/gic.h | 7 +++---- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index 15de283..240870f 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -126,22 +126,40 @@ void gic_route_irq_to_xen(struct irq_desc *desc, const cpumask_t *cpu_mask, /* Program the GIC to route an interrupt to a guest * - desc.lock must be held */ -void gic_route_irq_to_guest(struct domain *d, unsigned int virq, - struct irq_desc *desc, - const cpumask_t *cpu_mask, unsigned int priority) +int gic_route_irq_to_guest(struct domain *d, unsigned int virq, + struct irq_desc *desc, unsigned int priority) { - struct pending_irq *p; + unsigned long flags; + /* Use vcpu0 to retrieve the pending_irq struct. Given that we only + * route SPIs to guests, it doesn't make any difference. */ + struct vcpu *v_target = vgic_get_target_vcpu(d->vcpu[0], virq); + struct vgic_irq_rank *rank = vgic_rank_irq(v_target, virq); + struct pending_irq *p = irq_to_pending(v_target, virq); + int res = -EBUSY; + ASSERT(spin_is_locked(&desc->lock)); + /* We only support SPIs */ + ASSERT(virq >= 32 && virq < vgic_num_irqs(d)); + + vgic_lock_rank(v_target, rank, flags); + + if ( p->desc || + /* The VIRQ should not be already enabled by the guest */ + test_bit(GIC_IRQ_GUEST_ENABLED, &p->status) ) + goto out; desc->handler = gic_hw_ops->gic_guest_irq_type; set_bit(_IRQ_GUEST, &desc->status); - gic_set_irq_properties(desc, cpumask_of(smp_processor_id()), GIC_PRI_IRQ); + gic_set_irq_properties(desc, cpumask_of(v_target->processor), priority); - /* Use vcpu0 to retrieve the pending_irq struct. Given that we only - * route SPIs to guests, it doesn't make any difference. */ - p = irq_to_pending(d->vcpu[0], virq); p->desc = desc; + res = 0; + +out: + vgic_unlock_rank(v_target, rank, flags); + + return res; } int gic_irq_xlate(const u32 *intspec, unsigned int intsize, diff --git a/xen/arch/arm/irq.c b/xen/arch/arm/irq.c index af408ac..0072347 100644 --- a/xen/arch/arm/irq.c +++ b/xen/arch/arm/irq.c @@ -483,14 +483,22 @@ int route_irq_to_guest(struct domain *d, unsigned int virq, if ( retval ) goto out; - gic_route_irq_to_guest(d, virq, desc, cpumask_of(smp_processor_id()), - GIC_PRI_IRQ); + retval = gic_route_irq_to_guest(d, virq, desc, GIC_PRI_IRQ); + spin_unlock_irqrestore(&desc->lock, flags); + + if ( retval ) + { + release_irq(desc->irq, info); + goto free_info; + } + return 0; out: spin_unlock_irqrestore(&desc->lock, flags); xfree(action); +free_info: xfree(info); return retval; diff --git a/xen/include/asm-arm/gic.h b/xen/include/asm-arm/gic.h index cf9f257..a8ac294 100644 --- a/xen/include/asm-arm/gic.h +++ b/xen/include/asm-arm/gic.h @@ -213,10 +213,9 @@ extern enum gic_version gic_hw_version(void); /* Program the GIC to route an interrupt */ extern void gic_route_irq_to_xen(struct irq_desc *desc, const cpumask_t *cpu_mask, unsigned int priority); -extern void gic_route_irq_to_guest(struct domain *, unsigned int virq, - struct irq_desc *desc, - const cpumask_t *cpu_mask, - unsigned int priority); +extern int gic_route_irq_to_guest(struct domain *, unsigned int virq, + struct irq_desc *desc, + unsigned int priority); extern void gic_inject(void); extern void gic_clear_pending_irqs(struct vcpu *v);