From patchwork Thu Mar 19 19:29:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 46112 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DB30121515 for ; Thu, 19 Mar 2015 19:33:04 +0000 (UTC) Received: by wghb13 with SMTP id b13sf5503672wgh.3 for ; Thu, 19 Mar 2015 12:33:04 -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=JCqy8GRFVlJJA+/hal/ScbiWZKiFq3L/ap+oghgeH9A=; b=XbZtfYv7alqZ8nv2/lShsW0sNlJZ4jjMKDOHpT23ygUrsV5KIlCSRirwWlBXYcvyUe rcgIxkvBdLsvAgQLBBCO68PLgJqzDchV9hPNHb1NyRYvyZw0WgR2jU35+DIqT3RaHnKi 59NDb2cx/gnkjC+jVnTujUOTxiFBYktK6L9gcI3kYl48VIASesBgyiEO2agmtGDNHbYS C6CqbpO5TCyuM5ChkXtY0JP8oF4s+dBvgBwquFWhOhL+p9owNOO6hsug8TzLd2bIUujz RX/zOpl0mdzajKJWNdImqt6FBIlCSm8gHKkxrJS1pqUKwnW7CzvJ37EchaLJVEoXpkPh ntrg== X-Gm-Message-State: ALoCoQl6FsnWAjFFnz/0U0nBEtaNnvHdqUYioB6QdFHLcyuosRL43eDF4V6H+7Nnf4dOjKKw8ZEP X-Received: by 10.112.202.227 with SMTP id kl3mr5678527lbc.2.1426793584150; Thu, 19 Mar 2015 12:33:04 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.120.199 with SMTP id le7ls382153lab.89.gmail; Thu, 19 Mar 2015 12:33:03 -0700 (PDT) X-Received: by 10.152.5.36 with SMTP id p4mr70408349lap.7.1426793583804; Thu, 19 Mar 2015 12:33:03 -0700 (PDT) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id ll8si1649243lac.95.2015.03.19.12.33.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 12:33:03 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by ladw1 with SMTP id w1so70600627lad.0 for ; Thu, 19 Mar 2015 12:33:03 -0700 (PDT) X-Received: by 10.112.160.65 with SMTP id xi1mr7436329lbb.56.1426793583704; Thu, 19 Mar 2015 12:33:03 -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 h5csp597902lbj; Thu, 19 Mar 2015 12:33:02 -0700 (PDT) X-Received: by 10.52.104.105 with SMTP id gd9mr67280876vdb.76.1426793559300; Thu, 19 Mar 2015 12:32:39 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id m7si1959725vdh.73.2015.03.19.12.32.38 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 19 Mar 2015 12:32:39 -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 1YYg9j-0004Ro-0U; Thu, 19 Mar 2015 19:30:59 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YYg9h-0004NY-7c for xen-devel@lists.xenproject.org; Thu, 19 Mar 2015 19:30:57 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 03/50-01814-0F32B055; Thu, 19 Mar 2015 19:30:56 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-2.tower-31.messagelabs.com!1426793455!13799100!1 X-Originating-IP: [74.125.82.182] 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 26625 invoked from network); 19 Mar 2015 19:30:55 -0000 Received: from mail-we0-f182.google.com (HELO mail-we0-f182.google.com) (74.125.82.182) by server-2.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 19 Mar 2015 19:30:55 -0000 Received: by webcq43 with SMTP id cq43so65662548web.2 for ; Thu, 19 Mar 2015 12:30:55 -0700 (PDT) X-Received: by 10.180.7.194 with SMTP id l2mr19040574wia.39.1426793455640; Thu, 19 Mar 2015 12:30:55 -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.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2015 12:30:54 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 19 Mar 2015 19:29:38 +0000 Message-Id: <1426793399-6283-13-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, Stefano Stabellini Subject: [Xen-devel] [PATCH v4 12/33] 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.49 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 can'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 Acked-by: Stefano Stabellini --- Changes in v4: - Move functional change (GIC_IRQ_PRI -> priority) in a separate patch. - Split the 2 conditions of the ASSERT in 2 different ASSERTs - Typoes - Add Stefano's ack Changes in v3: - Patch added --- xen/arch/arm/gic.c | 35 +++++++++++++++++++++++++++-------- xen/arch/arm/irq.c | 12 ++++++++++-- xen/include/asm-arm/gic.h | 7 +++---- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index fe8f69b..2709415 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -126,22 +126,41 @@ 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)); + /* Caller has already checked that the IRQ is an SPI */ + ASSERT(virq >= 32); + ASSERT(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), GIC_PRI_IRQ); - /* 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 4c3e381..b2ddf6b 100644 --- a/xen/arch/arm/irq.c +++ b/xen/arch/arm/irq.c @@ -492,14 +492,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 bb2a922..ef4bf9a 100644 --- a/xen/include/asm-arm/gic.h +++ b/xen/include/asm-arm/gic.h @@ -216,10 +216,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);