From patchwork Fri Jan 24 16:43:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 23686 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f71.google.com (mail-pb0-f71.google.com [209.85.160.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B2EE9203C5 for ; Fri, 24 Jan 2014 16:43:59 +0000 (UTC) Received: by mail-pb0-f71.google.com with SMTP id jt11sf7803879pbb.10 for ; Fri, 24 Jan 2014 08:43:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=P7EqNQk683TJWAD5+UoQAz1j571CwBAfNMAFne+g2jc=; b=JVPiu1PleQYnr+B0nLIxvlb+cfU8fYMu+8OjN0yieNaqPCuOmfUWoz0bJ+TAhAI7+8 q3X98E4qIsZmn5VHpXKa5cDdse561Z/YsJ6ur0/8ec8US2WB7tFVkK+L2AZo08g9Cbb2 /XDpgz2XmuJv/sDiO/Y1c7vHUDIlII8dPpS7rdMxuVnOW0L3Bu6kUFwIbxhr+hjImaRw 6ta4sX/bF6XrnZ3EzA97FPFN/WabGpxDEXwj7MqDJ4OHbuKp6hkVwS1W1CCbBbrZpivO ozdcSbnMSqxR7KT75SMHwRxYurn2ibd9/xa9Cufp+UibBKPTsBEy4HVVQbqA5OMcM2lG Mbjw== X-Gm-Message-State: ALoCoQmDeCwLmoP47SAplRlUyUxn22pbh07KcKvZK9AwTpptQdlOjNoHO+m8+eZM/JCFnNTVYZea X-Received: by 10.66.144.41 with SMTP id sj9mr6095586pab.23.1390581838962; Fri, 24 Jan 2014 08:43:58 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.88.84 with SMTP id s78ls763331qgd.56.gmail; Fri, 24 Jan 2014 08:43:58 -0800 (PST) X-Received: by 10.58.90.131 with SMTP id bw3mr74488veb.63.1390581838818; Fri, 24 Jan 2014 08:43:58 -0800 (PST) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id lz6si805115vcb.106.2014.01.24.08.43.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Jan 2014 08:43:58 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id c14so2114575vea.34 for ; Fri, 24 Jan 2014 08:43:58 -0800 (PST) X-Received: by 10.220.98.204 with SMTP id r12mr94418vcn.48.1390581838726; Fri, 24 Jan 2014 08:43:58 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp115787vcz; Fri, 24 Jan 2014 08:43:58 -0800 (PST) X-Received: by 10.14.246.194 with SMTP id q42mr398885eer.35.1390581837700; Fri, 24 Jan 2014 08:43:57 -0800 (PST) Received: from mail-ea0-f174.google.com (mail-ea0-f174.google.com [209.85.215.174]) by mx.google.com with ESMTPS id d8si3165945eeh.158.2014.01.24.08.43.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Jan 2014 08:43:57 -0800 (PST) Received-SPF: neutral (google.com: 209.85.215.174 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=209.85.215.174; Received: by mail-ea0-f174.google.com with SMTP id b10so1106256eae.33 for ; Fri, 24 Jan 2014 08:43:57 -0800 (PST) X-Received: by 10.15.110.133 with SMTP id ch5mr42084eeb.112.1390581837123; Fri, 24 Jan 2014 08:43:57 -0800 (PST) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id k41sm5521285eey.0.2014.01.24.08.43.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Jan 2014 08:43:55 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Cc: patches@linaro.org, ian.campbell@citrix.com, tim@xen.org, stefano.stabellini@citrix.com, Julien Grall Subject: [PATCH for-4.5 6/8] xen/arm: IRQ: Add lock contrainst for gic_irq_{startup, shutdown} Date: Fri, 24 Jan 2014 16:43:40 +0000 Message-Id: <1390581822-32624-7-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1390581822-32624-1-git-send-email-julien.grall@linaro.org> References: <1390581822-32624-1-git-send-email-julien.grall@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , When multiple action will be supported, gic_irq_{startup,shutdown} will have to be called in the same critical zone has setup/release. Otherwise it could have a race condition if at the same time CPU A is calling release_dt_irq and CPU B is calling setup_dt_irq. This could end up to the IRQ is not enabled. Signed-off-by: Julien Grall --- xen/arch/arm/gic.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index 2643b46..ebd2b5f 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -129,43 +129,53 @@ void gic_restore_state(struct vcpu *v) gic_restore_pending_irqs(v); } -static void gic_irq_enable(struct irq_desc *desc) +static unsigned int gic_irq_startup(struct irq_desc *desc) { int irq = desc->irq; - unsigned long flags; - spin_lock_irqsave(&desc->lock, flags); + ASSERT(spin_is_locked(&desc->lock)); + ASSERT(!local_irq_is_enabled()); + spin_lock(&gic.lock); desc->status &= ~IRQ_DISABLED; dsb(); /* Enable routing */ GICD[GICD_ISENABLER + irq / 32] = (1u << (irq % 32)); spin_unlock(&gic.lock); - spin_unlock_irqrestore(&desc->lock, flags); + + return 0; } -static void gic_irq_disable(struct irq_desc *desc) +static void gic_irq_shutdown(struct irq_desc *desc) { int irq = desc->irq; - spin_lock(&desc->lock); + ASSERT(spin_is_locked(&desc->lock)); + ASSERT(!local_irq_is_enabled()); + spin_lock(&gic.lock); /* Disable routing */ GICD[GICD_ICENABLER + irq / 32] = (1u << (irq % 32)); desc->status |= IRQ_DISABLED; spin_unlock(&gic.lock); - spin_unlock(&desc->lock); } -static unsigned int gic_irq_startup(struct irq_desc *desc) +static void gic_irq_enable(struct irq_desc *desc) { - gic_irq_enable(desc); - return 0; + unsigned long flags; + + spin_lock_irqsave(&desc->lock, flags); + gic_irq_startup(desc); + spin_unlock_irqrestore(&desc->lock, flags); } -static void gic_irq_shutdown(struct irq_desc *desc) +static void gic_irq_disable(struct irq_desc *desc) { - gic_irq_disable(desc); + unsigned long flags; + + spin_lock_irqsave(&desc->lock, flags); + gic_irq_shutdown(desc); + spin_unlock_irqrestore(&desc->lock, flags); } static void gic_irq_ack(struct irq_desc *desc) @@ -528,9 +538,8 @@ void release_dt_irq(const struct dt_irq *irq, const void *dev_id) desc = irq_to_desc(irq->irq); - desc->handler->shutdown(desc); - spin_lock_irqsave(&desc->lock,flags); + desc->handler->shutdown(desc); action = desc->action; desc->action = NULL; desc->status &= ~IRQ_GUEST; @@ -600,11 +609,12 @@ int __init setup_dt_irq(const struct dt_irq *irq, struct irqaction *new) } rc = __setup_irq(desc, irq->irq, new); - spin_unlock_irqrestore(&desc->lock, flags); if ( !rc ) desc->handler->startup(desc); + spin_unlock_irqrestore(&desc->lock, flags); + return rc; }