From patchwork Tue Aug 5 11:26:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 34945 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 91D2523B13 for ; Tue, 5 Aug 2014 11:29:24 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lf10sf5321119pab.9 for ; Tue, 05 Aug 2014 04:29:23 -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=QMQoBhihzUrt+GUJEz9iKsi8jyJJ7HxQOwH/7s1B+fk=; b=R/yjp38ihDGLSSxUyI53VlGorrYOTTiVVh1N/r3cQr3j8360gyW9Wm41vA0C+AWoZL pzFxuVncqUFZfXPHsSVOf708vfCvkiDKCkpeUaWcRq98iXC6oIF3XZjz+SdCL33hGPTG GI+M5sYDtyEO/DpkrobCRQ3tpJTw8JOk1pZqz6LoDcr8piekBZ/cciRKo2aCyLjNJjwS 6rbGCIyygA54FM9JpDD54cHYSZpeNHjX11/0dBRx6LUr96JU9W1w75FL/WAEmz2iJS9D NhN1gunyb0rx4ci3s1ifiFWNwbU2pgLLCw0kONJSkls8yRtcBlUEnBllSd5MLT+fDEhD XsIw== X-Gm-Message-State: ALoCoQnfkFrsWkBOjNr9LMyRnRnTWKEsbCuSZqB4oisBlsauEexlE6UAR2XbDeoI1SwXoVrlzrHB X-Received: by 10.66.66.3 with SMTP id b3mr1609074pat.6.1407238162548; Tue, 05 Aug 2014 04:29:22 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.42.117 with SMTP id b108ls261518qga.19.gmail; Tue, 05 Aug 2014 04:29:22 -0700 (PDT) X-Received: by 10.220.130.131 with SMTP id t3mr2632358vcs.30.1407238162432; Tue, 05 Aug 2014 04:29:22 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id o5si841086vcj.31.2014.08.05.04.29.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 05 Aug 2014 04:29:22 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id hq11so1170609vcb.38 for ; Tue, 05 Aug 2014 04:29:22 -0700 (PDT) X-Received: by 10.220.118.136 with SMTP id v8mr1197708vcq.50.1407238162361; Tue, 05 Aug 2014 04:29:22 -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 tc5csp379327vcb; Tue, 5 Aug 2014 04:29:21 -0700 (PDT) X-Received: by 10.42.84.76 with SMTP id k12mr4976700icl.18.1407238161093; Tue, 05 Aug 2014 04:29:21 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id o7si3440311icu.68.2014.08.05.04.29.20 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 05 Aug 2014 04:29:21 -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 1XEcuL-0004gQ-NK; Tue, 05 Aug 2014 11:27:57 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XEcuI-0004Yy-AK for xen-devel@lists.xensource.com; Tue, 05 Aug 2014 11:27:54 +0000 Received: from [85.158.143.35:9535] by server-3.bemta-4.messagelabs.com id 41/02-06192-7BFB0E35; Tue, 05 Aug 2014 11:27:51 +0000 X-Env-Sender: Stefano.Stabellini@citrix.com X-Msg-Ref: server-6.tower-21.messagelabs.com!1407238067!13490174!4 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.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17262 invoked from network); 5 Aug 2014 11:27:50 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-6.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 5 Aug 2014 11:27:50 -0000 X-IronPort-AV: E=Sophos;i="5.01,804,1400025600"; d="scan'208";a="158837274" 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; Tue, 5 Aug 2014 07:27:46 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1XEcu5-0002cW-J2; Tue, 05 Aug 2014 12:27:41 +0100 From: Stefano Stabellini To: Date: Tue, 5 Aug 2014 12:26:27 +0100 Message-ID: <1407237989-27654-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 v10 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.179 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 | 11 ++++--- xen/include/asm-arm/vgic.h | 4 +-- 3 files changed, 47 insertions(+), 42 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 ce4457e..f86a91b 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,8 +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