From patchwork Wed Aug 13 16:29:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 35373 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0068F20DCC for ; Wed, 13 Aug 2014 16:32:45 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id i7sf54304055oag.0 for ; Wed, 13 Aug 2014 09:32:45 -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:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=//0XvDdOprclXiEI0Rj0ojrfMcxHvkuouL+fyMkS3LY=; b=kZCQTdUykLhT5IT/EzuvPhduf4mR26Kjkcrl3ZfgUgfMysgfT6rYe2mqgEZr8+pdwB 6iGhsswPAVGwXRBn2JdpT76IgFlzd+SgNbx8mXWjuuaf73wQoPEkwI6D55PMfxyS7tAS wfK061Ladmtew9NObMJzstGdquZt41soMNCU1UbWLiYAdCbh8yDFiNl4ymhB75q+DLex LgfY9w6ntsG6P4jnMmj3WTE1FpccltJjRNx1Y6+mj4xCM4PFjR1JaOy1oIOkvbcTd8q/ r41roU42V98a+1tNOkTS6gecaI6G0dilokbJLpcmp1OI3pTvz21U0mkqfleAmMUfDo0b ueWg== X-Gm-Message-State: ALoCoQlocQ0LIhjY0JVMYKeQvBX8ceq5MLwg5BiUTTJFW6Rh0wSLvI8bJWzfRR2iTr0DpJ73HVgP X-Received: by 10.182.28.102 with SMTP id a6mr2993720obh.44.1407947565569; Wed, 13 Aug 2014 09:32:45 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.50.141 with SMTP id s13ls593902qga.6.gmail; Wed, 13 Aug 2014 09:32:45 -0700 (PDT) X-Received: by 10.52.5.201 with SMTP id u9mr1553639vdu.85.1407947565418; Wed, 13 Aug 2014 09:32:45 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id xe4si1417812vcb.10.2014.08.13.09.32.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 13 Aug 2014 09:32:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id la4so15358340vcb.37 for ; Wed, 13 Aug 2014 09:32:45 -0700 (PDT) X-Received: by 10.220.118.136 with SMTP id v8mr1885027vcq.50.1407947565315; Wed, 13 Aug 2014 09:32:45 -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.37.5 with SMTP id tc5csp344293vcb; Wed, 13 Aug 2014 09:32:44 -0700 (PDT) X-Received: by 10.50.8.65 with SMTP id p1mr9214602iga.46.1407947563529; Wed, 13 Aug 2014 09:32:43 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id bb7si4870610icb.87.2014.08.13.09.32.43 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 13 Aug 2014 09:32:43 -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 1XHbSG-0003Rr-US; Wed, 13 Aug 2014 16:31:16 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XHbSF-0003QW-KP for xen-devel@lists.xensource.com; Wed, 13 Aug 2014 16:31:15 +0000 Received: from [193.109.254.147:41222] by server-6.bemta-14.messagelabs.com id A1/90-31278-2D29BE35; Wed, 13 Aug 2014 16:31:14 +0000 X-Env-Sender: Stefano.Stabellini@citrix.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1407947472!12326331!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n X-StarScan-Received: X-StarScan-Version: 6.12.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 20345 invoked from network); 13 Aug 2014 16:31:14 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-2.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 13 Aug 2014 16:31:14 -0000 X-IronPort-AV: E=Sophos;i="5.01,857,1400025600"; d="scan'208";a="161414775" Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.79) with Microsoft SMTP Server id 14.3.181.6; Wed, 13 Aug 2014 12:31:09 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1XHbS4-00059X-6F; Wed, 13 Aug 2014 17:31:04 +0100 From: Stefano Stabellini To: Date: Wed, 13 Aug 2014 17:29:44 +0100 Message-ID: <1407947384-24279-10-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-DLP: MIA1 Cc: julien.grall@citrix.com, Ian.Campbell@citrix.com, Stefano Stabellini Subject: [Xen-devel] [PATCH v12 10/10] xen/arm: make accesses to desc->status flags atomic 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: , 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: stefano.stabellini@eu.citrix.com 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.178 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: This way we don't need to take the desc->lock in order to access desc->status in many of the gic and vgic functions. Using *_bit manipulation functions on desc->status is safe on arm64: status is an unsigned int but is the first field of a struct that contains pointers, therefore the alignement of the struct is at least 8 bytes. Signed-off-by: Stefano Stabellini Acked-by: Ian Campbell Acked-by: Julien Grall --- Changes in v10: - add in-code comment; - fix _IRQF_SHARED renaming. Changes in v2: - rebase on ab78724fc5628318b172b4344f7280621a151e1b. --- xen/arch/arm/gic-v2.c | 4 ++-- xen/arch/arm/gic.c | 6 +++--- xen/arch/arm/irq.c | 33 +++++++++++++++++---------------- xen/include/xen/irq.h | 5 +++++ 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/xen/arch/arm/gic-v2.c b/xen/arch/arm/gic-v2.c index da60a41..78ad4de 100644 --- a/xen/arch/arm/gic-v2.c +++ b/xen/arch/arm/gic-v2.c @@ -516,7 +516,7 @@ static void gicv2_irq_enable(struct irq_desc *desc) ASSERT(spin_is_locked(&desc->lock)); spin_lock_irqsave(&gicv2.lock, flags); - desc->status &= ~IRQ_DISABLED; + clear_bit(_IRQ_DISABLED, &desc->status); dsb(sy); /* Enable routing */ writel_gicd((1u << (irq % 32)), GICD_ISENABLER + (irq / 32) * 4); @@ -533,7 +533,7 @@ static void gicv2_irq_disable(struct irq_desc *desc) spin_lock_irqsave(&gicv2.lock, flags); /* Disable routing */ writel_gicd(1u << (irq % 32), GICD_ICENABLER + (irq / 32) * 4); - desc->status |= IRQ_DISABLED; + set_bit(_IRQ_DISABLED, &desc->status); spin_unlock_irqrestore(&gicv2.lock, flags); } diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index 2aa9500..6611ba0 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -115,7 +115,7 @@ void gic_route_irq_to_xen(struct irq_desc *desc, const cpumask_t *cpu_mask, { ASSERT(priority <= 0xff); /* Only 8 bits of priority */ ASSERT(desc->irq < gic_number_lines());/* Can't route interrupts that don't exist */ - ASSERT(desc->status & IRQ_DISABLED); + ASSERT(test_bit(_IRQ_DISABLED, &desc->status)); ASSERT(spin_is_locked(&desc->lock)); desc->handler = gic_hw_ops->gic_host_irq_type; @@ -133,7 +133,7 @@ void gic_route_irq_to_guest(struct domain *d, struct irq_desc *desc, ASSERT(spin_is_locked(&desc->lock)); desc->handler = gic_hw_ops->gic_guest_irq_type; - desc->status |= IRQ_GUEST; + set_bit(_IRQ_GUEST, &desc->status); gic_set_irq_properties(desc, cpumask_of(smp_processor_id()), GIC_PRI_IRQ); @@ -369,7 +369,7 @@ static void gic_update_one_lr(struct vcpu *v, int i) if ( p->desc != NULL ) { - p->desc->status &= ~IRQ_INPROGRESS; + clear_bit(_IRQ_INPROGRESS, &p->desc->status); if ( platform_has_quirk(PLATFORM_QUIRK_GUEST_PIRQ_NEED_EOI) ) gic_hw_ops->deactivate_irq(p->desc); } diff --git a/xen/arch/arm/irq.c b/xen/arch/arm/irq.c index 7150c7a..25ecf1d 100644 --- a/xen/arch/arm/irq.c +++ b/xen/arch/arm/irq.c @@ -126,7 +126,7 @@ static inline struct domain *irq_get_domain(struct irq_desc *desc) { ASSERT(spin_is_locked(&desc->lock)); - if ( !(desc->status & IRQ_GUEST) ) + if ( !test_bit(_IRQ_GUEST, &desc->status) ) return dom_xen; ASSERT(desc->action != NULL); @@ -195,13 +195,13 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq) goto out; } - if ( desc->status & IRQ_GUEST ) + if ( test_bit(_IRQ_GUEST, &desc->status) ) { struct domain *d = irq_get_domain(desc); desc->handler->end(desc); - desc->status |= IRQ_INPROGRESS; + set_bit(_IRQ_INPROGRESS, &desc->status); desc->arch.eoi_cpu = smp_processor_id(); /* the irq cannot be a PPI, we only support delivery of SPIs to @@ -210,22 +210,23 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq) goto out_no_end; } - desc->status |= IRQ_PENDING; + set_bit(_IRQ_PENDING, &desc->status); /* * Since we set PENDING, if another processor is handling a different * instance of this same irq, the other processor will take care of it. */ - if ( desc->status & (IRQ_DISABLED | IRQ_INPROGRESS) ) + if ( test_bit(_IRQ_DISABLED, &desc->status) || + test_bit(_IRQ_INPROGRESS, &desc->status) ) goto out; - desc->status |= IRQ_INPROGRESS; + set_bit(_IRQ_INPROGRESS, &desc->status); - while ( desc->status & IRQ_PENDING ) + while ( test_bit(_IRQ_PENDING, &desc->status) ) { struct irqaction *action; - desc->status &= ~IRQ_PENDING; + clear_bit(_IRQ_PENDING, &desc->status); action = desc->action; spin_unlock_irq(&desc->lock); @@ -239,7 +240,7 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq) spin_lock_irq(&desc->lock); } - desc->status &= ~IRQ_INPROGRESS; + clear_bit(_IRQ_INPROGRESS, &desc->status); out: desc->handler->end(desc); @@ -282,13 +283,13 @@ void release_irq(unsigned int irq, const void *dev_id) if ( !desc->action ) { desc->handler->shutdown(desc); - desc->status &= ~IRQ_GUEST; + clear_bit(_IRQ_GUEST, &desc->status); } spin_unlock_irqrestore(&desc->lock,flags); /* Wait to make sure it's not being used on another CPU */ - do { smp_mb(); } while ( desc->status & IRQ_INPROGRESS ); + do { smp_mb(); } while ( test_bit(_IRQ_INPROGRESS, &desc->status) ); if ( action->free_on_release ) xfree(action); @@ -305,13 +306,13 @@ static int __setup_irq(struct irq_desc *desc, unsigned int irqflags, * - if the IRQ is marked as shared * - dev_id is not NULL when IRQF_SHARED is set */ - if ( desc->action != NULL && (!(desc->status & IRQF_SHARED) || !shared) ) + if ( desc->action != NULL && (!test_bit(_IRQF_SHARED, &desc->status) || !shared) ) return -EINVAL; if ( shared && new->dev_id == NULL ) return -EINVAL; if ( shared ) - desc->status |= IRQF_SHARED; + set_bit(_IRQF_SHARED, &desc->status); new->next = desc->action; dsb(ish); @@ -332,7 +333,7 @@ int setup_irq(unsigned int irq, unsigned int irqflags, struct irqaction *new) spin_lock_irqsave(&desc->lock, flags); - if ( desc->status & IRQ_GUEST ) + if ( test_bit(_IRQ_GUEST, &desc->status) ) { struct domain *d = irq_get_domain(desc); @@ -396,10 +397,10 @@ int route_irq_to_guest(struct domain *d, unsigned int irq, { struct domain *ad = irq_get_domain(desc); - if ( (desc->status & IRQ_GUEST) && d == ad ) + if ( test_bit(_IRQ_GUEST, &desc->status) && d == ad ) goto out; - if ( desc->status & IRQ_GUEST ) + if ( test_bit(_IRQ_GUEST, &desc->status) ) printk(XENLOG_ERR "ERROR: IRQ %u is already used by domain %u\n", irq, ad->domain_id); else diff --git a/xen/include/xen/irq.h b/xen/include/xen/irq.h index 96d818f..ffb5932 100644 --- a/xen/include/xen/irq.h +++ b/xen/include/xen/irq.h @@ -76,6 +76,11 @@ struct msi_desc; * This is the "IRQ descriptor", which contains various information * about the irq, including what kind of hardware handling it has, * whether it is disabled etc etc. + * + * Note: on ARMv8 we can use normal bit manipulation functions to access + * the status field because struct irq_desc contains pointers, therefore + * the alignment of the struct is at least 8 bytes and status is the + * first field. */ typedef struct irq_desc { unsigned int status; /* IRQ status */