From patchwork Thu Jul 24 17:33:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 34237 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f198.google.com (mail-pd0-f198.google.com [209.85.192.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8958620C7F for ; Thu, 24 Jul 2014 17:36:05 +0000 (UTC) Received: by mail-pd0-f198.google.com with SMTP id fp1sf19154273pdb.5 for ; Thu, 24 Jul 2014 10:36: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: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=XFiFC62YxhPpHReCcQFuoVIrc4jWeMTp8YTXY54okDY=; b=QIbTLs3b3Qyk/L/LCnWhCeRb5cAKzOWIWqudyIjITPLOa6nIdx/rJwjzKhNemZDUWY Vv7uPliMX9FSKcOj3cgqQRAI0LbZj/qWF5f3nOK9/JXpb8v75HT3RfEPo5nkqYg+F0sE pYN1voE3m3JeCfaSz3d5irHCYog5Trlfe3U0Ems8I97jAhLB7VJH/yasqiU/VeFkKQEW NjvlqSffSeK+aJIH8tSESnZ72tmTPcxr/EquClYPjsApSJ6zEk3J8wIp9KOK1KNEindH Qi7XjwEMAgBcox3RNiVzKxUnwDj0cU6qNhWpjkaahXwrIB9rCq6fJvB+ABG/A7Hv8GsK 3TQQ== X-Gm-Message-State: ALoCoQluNhxQh5uMZ+I1FW+oX4+TaFtU9R06s7+LinGQGkm2YI9MhvWhFYTCc6a543xrZN1BqVhi X-Received: by 10.68.209.130 with SMTP id mm2mr5049289pbc.3.1406223364841; Thu, 24 Jul 2014 10:36:04 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.49.1 with SMTP id p1ls824463qga.97.gmail; Thu, 24 Jul 2014 10:36:04 -0700 (PDT) X-Received: by 10.52.154.106 with SMTP id vn10mr12028004vdb.36.1406223364629; Thu, 24 Jul 2014 10:36:04 -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 c7si5832239vez.8.2014.07.24.10.36.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 24 Jul 2014 10:36:04 -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 la4so5513483vcb.9 for ; Thu, 24 Jul 2014 10:36:04 -0700 (PDT) X-Received: by 10.221.47.9 with SMTP id uq9mr14693438vcb.48.1406223364536; Thu, 24 Jul 2014 10:36:04 -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 tc5csp383643vcb; Thu, 24 Jul 2014 10:36:04 -0700 (PDT) X-Received: by 10.50.79.202 with SMTP id l10mr17325258igx.16.1406223363533; Thu, 24 Jul 2014 10:36:03 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id z6si16360985icc.25.2014.07.24.10.36.03 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 24 Jul 2014 10:36:03 -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 1XAMur-0002Vz-7C; Thu, 24 Jul 2014 17:34:53 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XAMuo-0002TO-Dh for xen-devel@lists.xensource.com; Thu, 24 Jul 2014 17:34:50 +0000 Received: from [85.158.143.35:49618] by server-1.bemta-4.messagelabs.com id EC/87-05872-9B341D35; Thu, 24 Jul 2014 17:34:49 +0000 X-Env-Sender: Stefano.Stabellini@citrix.com X-Msg-Ref: server-5.tower-21.messagelabs.com!1406223286!19957100!2 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 25728 invoked from network); 24 Jul 2014 17:34:48 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-5.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 24 Jul 2014 17:34:48 -0000 X-IronPort-AV: E=Sophos;i="5.01,725,1400025600"; d="scan'208";a="155886526" Received: from accessns.citrite.net (HELO FTLPEX01CL01.citrite.net) ([10.9.154.239]) by FTLPIPO02.CITRIX.COM with ESMTP; 24 Jul 2014 17:34:18 +0000 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.78) with Microsoft SMTP Server id 14.3.181.6; Thu, 24 Jul 2014 13:34:17 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1XAMuC-00067o-Fn; Thu, 24 Jul 2014 18:34:12 +0100 From: Stefano Stabellini To: Date: Thu, 24 Jul 2014 18:33:10 +0100 Message-ID: <1406223192-26267-8-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: MIA2 Cc: julien.grall@citrix.com, Ian.Campbell@citrix.com, Stefano Stabellini Subject: [Xen-devel] [PATCH v9 08/10] xen/arm: take the rank lock before accessing ipriority 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: Currently we read ipriority from vgic_vcpu_inject_irq without taking the rank lock. Fix that by taking the rank lock and reading ipriority at the beginning of the function. As vgic_vcpu_inject_irq is called from the irq.c upon receiving an interrupt, we need to change the implementation of vgic_lock/unlock_rank to spin_lock_irqsave to make it safe in irq context. Signed-off-by: Stefano Stabellini Acked-by: Julien Grall --- Changes in v9: - add explicit flags paramter to vgic_lock_rank and vgic_unlock_rank. Changes in v2: - rebased on ab78724fc5628318b172b4344f7280621a151e1b; - remove warning on changing priority of active irqs. --- xen/arch/arm/vgic-v2.c | 74 +++++++++++++++++++++++--------------------- xen/arch/arm/vgic.c | 10 ++++-- xen/include/asm-arm/vgic.h | 4 +-- 3 files changed, 47 insertions(+), 41 deletions(-) diff --git a/xen/arch/arm/vgic-v2.c b/xen/arch/arm/vgic-v2.c index f9e357c..8b21a13 100644 --- a/xen/arch/arm/vgic-v2.c +++ b/xen/arch/arm/vgic-v2.c @@ -39,6 +39,7 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info) register_t *r = select_user_reg(regs, dabt.reg); struct vgic_irq_rank *rank; int gicd_reg = (int)(info->gpa - v->domain->arch.vgic.dbase); + unsigned long flags; switch ( gicd_reg ) { @@ -77,54 +78,54 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info) if ( dabt.size != DABT_WORD ) goto bad_width; rank = vgic_rank_offset(v, 1, gicd_reg - GICD_ISENABLER, DABT_WORD); if ( rank == NULL) goto read_as_zero; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); *r = rank->ienable; - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; case GICD_ICENABLER ... GICD_ICENABLERN: if ( dabt.size != DABT_WORD ) goto bad_width; rank = vgic_rank_offset(v, 1, gicd_reg - GICD_ICENABLER, DABT_WORD); if ( rank == NULL) goto read_as_zero; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); *r = rank->ienable; - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; case GICD_ISPENDR ... GICD_ISPENDRN: if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width; rank = vgic_rank_offset(v, 1, gicd_reg - GICD_ISPENDR, DABT_WORD); if ( rank == NULL) goto read_as_zero; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); *r = vgic_byte_read(rank->ipend, dabt.sign, gicd_reg); - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; case GICD_ICPENDR ... GICD_ICPENDRN: if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width; rank = vgic_rank_offset(v, 1, gicd_reg - GICD_ICPENDR, DABT_WORD); if ( rank == NULL) goto read_as_zero; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); *r = vgic_byte_read(rank->ipend, dabt.sign, gicd_reg); - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; case GICD_ISACTIVER ... GICD_ISACTIVERN: if ( dabt.size != DABT_WORD ) goto bad_width; rank = vgic_rank_offset(v, 1, gicd_reg - GICD_ISACTIVER, DABT_WORD); if ( rank == NULL) goto read_as_zero; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); *r = rank->iactive; - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; case GICD_ICACTIVER ... GICD_ICACTIVERN: if ( dabt.size != DABT_WORD ) goto bad_width; rank = vgic_rank_offset(v, 1, gicd_reg - GICD_ICACTIVER, DABT_WORD); if ( rank == NULL) goto read_as_zero; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); *r = rank->iactive; - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; case GICD_ITARGETSR ... GICD_ITARGETSRN: @@ -132,12 +133,12 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info) rank = vgic_rank_offset(v, 8, gicd_reg - GICD_ITARGETSR, DABT_WORD); if ( rank == NULL) goto read_as_zero; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); *r = rank->itargets[REG_RANK_INDEX(8, gicd_reg - GICD_ITARGETSR, DABT_WORD)]; if ( dabt.size == DABT_BYTE ) *r = vgic_byte_read(*r, dabt.sign, gicd_reg); - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; case GICD_IPRIORITYR ... GICD_IPRIORITYRN: @@ -145,21 +146,21 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info) rank = vgic_rank_offset(v, 8, gicd_reg - GICD_IPRIORITYR, DABT_WORD); if ( rank == NULL) goto read_as_zero; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); *r = rank->ipriority[REG_RANK_INDEX(8, gicd_reg - GICD_IPRIORITYR, DABT_WORD)]; if ( dabt.size == DABT_BYTE ) *r = vgic_byte_read(*r, dabt.sign, gicd_reg); - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; case GICD_ICFGR ... GICD_ICFGRN: if ( dabt.size != DABT_WORD ) goto bad_width; rank = vgic_rank_offset(v, 2, gicd_reg - GICD_ICFGR, DABT_WORD); if ( rank == NULL) goto read_as_zero; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); *r = rank->icfg[REG_RANK_INDEX(2, gicd_reg - GICD_ICFGR, DABT_WORD)]; - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; case GICD_NSACR ... GICD_NSACRN: @@ -176,18 +177,18 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info) if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width; rank = vgic_rank_offset(v, 1, gicd_reg - GICD_CPENDSGIR, DABT_WORD); if ( rank == NULL) goto read_as_zero; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); *r = vgic_byte_read(rank->pendsgi, dabt.sign, gicd_reg); - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; case GICD_SPENDSGIR ... GICD_SPENDSGIRN: if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width; rank = vgic_rank_offset(v, 1, gicd_reg - GICD_SPENDSGIR, DABT_WORD); if ( rank == NULL) goto read_as_zero; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); *r = vgic_byte_read(rank->pendsgi, dabt.sign, gicd_reg); - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; /* Implementation defined -- read as zero */ @@ -269,6 +270,7 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info) struct vgic_irq_rank *rank; int gicd_reg = (int)(info->gpa - v->domain->arch.vgic.dbase); uint32_t tr; + unsigned long flags; switch ( gicd_reg ) { @@ -295,7 +297,7 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info) if ( dabt.size != DABT_WORD ) goto bad_width; rank = vgic_rank_offset(v, 1, gicd_reg - GICD_ISENABLER, DABT_WORD); if ( rank == NULL) goto write_ignore; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); tr = rank->ienable; rank->ienable |= *r; /* The virtual irq is derived from register offset. @@ -303,14 +305,14 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info) * to get Virtual irq number */ vgic_enable_irqs(v, (*r) & (~tr), (gicd_reg - GICD_ISENABLER) >> DABT_WORD); - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; case GICD_ICENABLER ... GICD_ICENABLERN: if ( dabt.size != DABT_WORD ) goto bad_width; rank = vgic_rank_offset(v, 1, gicd_reg - GICD_ICENABLER, DABT_WORD); if ( rank == NULL) goto write_ignore; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); tr = rank->ienable; rank->ienable &= ~*r; /* The virtual irq is derived from register offset. @@ -318,7 +320,7 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info) * to get Virtual irq number */ vgic_disable_irqs(v, (*r) & tr, (gicd_reg - GICD_ICENABLER) >> DABT_WORD); - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; case GICD_ISPENDR ... GICD_ISPENDRN: @@ -337,18 +339,18 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info) if ( dabt.size != DABT_WORD ) goto bad_width; rank = vgic_rank_offset(v, 1, gicd_reg - GICD_ISACTIVER, DABT_WORD); if ( rank == NULL) goto write_ignore; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); rank->iactive &= ~*r; - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; case GICD_ICACTIVER ... GICD_ICACTIVERN: if ( dabt.size != DABT_WORD ) goto bad_width; rank = vgic_rank_offset(v, 1, gicd_reg - GICD_ICACTIVER, DABT_WORD); if ( rank == NULL) goto write_ignore; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); rank->iactive &= ~*r; - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; case GICD_ITARGETSR ... GICD_ITARGETSR + 7: @@ -379,7 +381,7 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info) !((target & 0xff) && (target & (0xff << 8)) && (target & (0xff << 16)) && (target & (0xff << 24)))) goto write_ignore; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); i = 0; while ( (i = find_next_bit(&target, 32, i)) < 32 ) { @@ -406,7 +408,7 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info) else vgic_byte_write(&rank->itargets[REG_RANK_INDEX(8, gicd_reg - GICD_ITARGETSR, DABT_WORD)], target, gicd_reg); - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; } @@ -414,14 +416,14 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info) if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width; rank = vgic_rank_offset(v, 8, gicd_reg - GICD_IPRIORITYR, DABT_WORD); if ( rank == NULL) goto write_ignore; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); if ( dabt.size == DABT_WORD ) rank->ipriority[REG_RANK_INDEX(8, gicd_reg - GICD_IPRIORITYR, DABT_WORD)] = *r; else vgic_byte_write(&rank->ipriority[REG_RANK_INDEX(8, gicd_reg - GICD_IPRIORITYR, DABT_WORD)], *r, gicd_reg); - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; case GICD_ICFGR: /* SGIs */ @@ -433,9 +435,9 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info) if ( dabt.size != DABT_WORD ) goto bad_width; rank = vgic_rank_offset(v, 2, gicd_reg - GICD_ICFGR, DABT_WORD); if ( rank == NULL) goto write_ignore; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); rank->icfg[REG_RANK_INDEX(2, gicd_reg - GICD_ICFGR, DABT_WORD)] = *r; - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return 1; case GICD_NSACR ... GICD_NSACRN: diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c index 474eebd..a3df18d 100644 --- a/xen/arch/arm/vgic.c +++ b/xen/arch/arm/vgic.c @@ -158,10 +158,11 @@ struct vcpu *vgic_get_target_vcpu(struct vcpu *v, unsigned int irq) struct domain *d = v->domain; struct vcpu *v_target; struct vgic_irq_rank *rank = vgic_rank_irq(v, irq); + unsigned long flags; - vgic_lock_rank(v, rank); + vgic_lock_rank(v, rank, flags); v_target = d->arch.vgic.handler->get_target_vcpu(v, irq); - vgic_unlock_rank(v, rank); + vgic_unlock_rank(v, rank, flags); return v_target; } @@ -367,6 +368,10 @@ void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq) unsigned long flags; bool_t running; + vgic_lock_rank(v, rank, flags); + priority = vgic_byte_read(rank->ipriority[REG_RANK_INDEX(8, irq, DABT_WORD)], 0, irq & 0x3); + vgic_unlock_rank(v, rank, flags); + spin_lock_irqsave(&v->arch.vgic.lock, flags); /* vcpu offline */ @@ -384,7 +389,6 @@ void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq) goto out; } - priority = vgic_byte_read(rank->ipriority[REG_RANK_INDEX(8, irq, DABT_WORD)], 0, irq & 0x3); n->irq = irq; n->priority = priority; diff --git a/xen/include/asm-arm/vgic.h b/xen/include/asm-arm/vgic.h index 9b1db04..338ba03 100644 --- a/xen/include/asm-arm/vgic.h +++ b/xen/include/asm-arm/vgic.h @@ -107,8 +107,8 @@ struct vgic_ops { #define vgic_lock(v) spin_lock_irq(&(v)->domain->arch.vgic.lock) #define vgic_unlock(v) spin_unlock_irq(&(v)->domain->arch.vgic.lock) -#define vgic_lock_rank(v, r) spin_lock(&(r)->lock) -#define vgic_unlock_rank(v, r) spin_unlock(&(r)->lock) +#define vgic_lock_rank(v, r, flags) spin_lock_irqsave(&(r)->lock, flags) +#define vgic_unlock_rank(v, r, flags) spin_unlock_irqrestore(&(r)->lock, flags) /* * Rank containing GICD_ for GICD_ with