From patchwork Mon Sep 1 12:52:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 36357 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 8E9B72032B for ; Mon, 1 Sep 2014 12:53:36 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id i7sf32218433oag.0 for ; Mon, 01 Sep 2014 05:53:36 -0700 (PDT) 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=ytw4kWXX3Q0vmGNKn1Bp30oUS/HpPaMEjZYKNua2u08=; b=evBr9Sz+Krkd3QlPBslIhPY+lPjA8pGwmjoqDRL1YRKX/Fu7CWYkzFmU2PQCqyAsbX eepi4aQhy6cRemRmMD3ECGIVjPsxcfG1i1mhKaPjnfBLgcHDIyJoCzujOqRbwmXWwSO/ CmPN/tPxPzMHRfxb9e+MbUoGvIFKh7gXlPOBFVnkG+pAtn3p4genui8OkiyDeZNxQv2s MW3AQBxvAC3p/Tljs5OH9j+ABrLtNKycUeAf/lEOJngyydgb1MY0MB/SlvQazSDqPNVZ sL4ThB20Ii6S6Wi9DHZNlZEffTRx4KydWFvsZZQHXy+ZtfW7wBvaJ3/bvH+b51K4Ryy2 sPHA== X-Gm-Message-State: ALoCoQn85nGNMxG0STHmGME8/rG5YmrAyjCrgxIm0wZuWCiF2jLhqi1EW1JgtoyZGLMX1w+rrKyW X-Received: by 10.182.213.105 with SMTP id nr9mr15996743obc.36.1409576016190; Mon, 01 Sep 2014 05:53:36 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.106.136 with SMTP id e8ls1900205qgf.36.gmail; Mon, 01 Sep 2014 05:53:36 -0700 (PDT) X-Received: by 10.220.168.210 with SMTP id v18mr25407936vcy.3.1409576016113; Mon, 01 Sep 2014 05:53:36 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id sl18si303352vdb.42.2014.09.01.05.53.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Sep 2014 05:53:36 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id lf12so5347844vcb.20 for ; Mon, 01 Sep 2014 05:53:36 -0700 (PDT) X-Received: by 10.52.248.232 with SMTP id yp8mr107442vdc.83.1409576016023; Mon, 01 Sep 2014 05:53:36 -0700 (PDT) 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.221.45.67 with SMTP id uj3csp383134vcb; Mon, 1 Sep 2014 05:53:35 -0700 (PDT) X-Received: by 10.180.103.234 with SMTP id fz10mr21705071wib.76.1409576014500; Mon, 01 Sep 2014 05:53:34 -0700 (PDT) Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com [209.85.212.176]) by mx.google.com with ESMTPS id r5si990508wjw.137.2014.09.01.05.53.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Sep 2014 05:53:34 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.176 as permitted sender) client-ip=209.85.212.176; Received: by mail-wi0-f176.google.com with SMTP id bs8so12509683wib.3 for ; Mon, 01 Sep 2014 05:53:33 -0700 (PDT) X-Received: by 10.194.172.137 with SMTP id bc9mr9356659wjc.72.1409576013892; Mon, 01 Sep 2014 05:53:33 -0700 (PDT) Received: from gnx2579.gnb.st.com (LCaen-156-56-7-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by mx.google.com with ESMTPSA id y5sm1928678wje.32.2014.09.01.05.53.32 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Sep 2014 05:53:33 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, christoffer.dall@linaro.org, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, alex.williamson@redhat.com, joel.schopp@amd.com, kim.phillips@freescale.com, paulus@samba.org, gleb@kernel.org, pbonzini@redhat.com Cc: linux-kernel@vger.kernel.org, patches@linaro.org, will.deacon@arm.com, a.motakis@virtualopensystems.com, a.rigo@virtualopensystems.com, john.liuli@huawei.com Subject: [RFC v2 2/9] KVM: ARM: VGIC: add forwarded irq rbtree lock Date: Mon, 1 Sep 2014 14:52:41 +0200 Message-Id: <1409575968-5329-3-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1409575968-5329-1-git-send-email-eric.auger@linaro.org> References: <1409575968-5329-1-git-send-email-eric.auger@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@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.220.175 as permitted sender) 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: , add a lock related to the rb tree manipulation. The rb tree can be searched in one thread (irqfd handler for instance) and map/unmap happen in another. Signed-off-by: Eric Auger --- include/kvm/arm_vgic.h | 1 + virt/kvm/arm/vgic.c | 46 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index 743020f..3da244f 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -177,6 +177,7 @@ struct vgic_dist { unsigned long irq_pending_on_cpu; struct rb_root irq_phys_map; + spinlock_t rb_tree_lock; #endif }; diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index 8ef495b..dbc2a5a 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -1630,9 +1630,15 @@ static struct rb_root *vgic_get_irq_phys_map(struct kvm_vcpu *vcpu, int vgic_map_phys_irq(struct kvm_vcpu *vcpu, int virt_irq, int phys_irq) { - struct rb_root *root = vgic_get_irq_phys_map(vcpu, virt_irq); - struct rb_node **new = &root->rb_node, *parent = NULL; + struct rb_root *root; + struct rb_node **new, *parent = NULL; struct irq_phys_map *new_map; + struct vgic_dist *dist = &vcpu->kvm->arch.vgic; + + spin_lock(&dist->rb_tree_lock); + + root = vgic_get_irq_phys_map(vcpu, virt_irq); + new = &root->rb_node; /* Boilerplate rb_tree code */ while (*new) { @@ -1644,13 +1650,17 @@ int vgic_map_phys_irq(struct kvm_vcpu *vcpu, int virt_irq, int phys_irq) new = &(*new)->rb_left; else if (this->virt_irq > virt_irq) new = &(*new)->rb_right; - else + else { + spin_unlock(&dist->rb_tree_lock); return -EEXIST; + } } new_map = kzalloc(sizeof(*new_map), GFP_KERNEL); - if (!new_map) + if (!new_map) { + spin_unlock(&dist->rb_tree_lock); return -ENOMEM; + } new_map->virt_irq = virt_irq; new_map->phys_irq = phys_irq; @@ -1658,6 +1668,8 @@ int vgic_map_phys_irq(struct kvm_vcpu *vcpu, int virt_irq, int phys_irq) rb_link_node(&new_map->node, parent, new); rb_insert_color(&new_map->node, root); + spin_unlock(&dist->rb_tree_lock); + return 0; } @@ -1685,24 +1697,39 @@ static struct irq_phys_map *vgic_irq_map_search(struct kvm_vcpu *vcpu, int vgic_get_phys_irq(struct kvm_vcpu *vcpu, int virt_irq) { - struct irq_phys_map *map = vgic_irq_map_search(vcpu, virt_irq); + struct irq_phys_map *map; + struct vgic_dist *dist = &vcpu->kvm->arch.vgic; + int ret; + + spin_lock(&dist->rb_tree_lock); + map = vgic_irq_map_search(vcpu, virt_irq); if (map) - return map->phys_irq; + ret = map->phys_irq; + else + ret = -ENOENT; + + spin_unlock(&dist->rb_tree_lock); + return ret; - return -ENOENT; } int vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, int virt_irq, int phys_irq) { - struct irq_phys_map *map = vgic_irq_map_search(vcpu, virt_irq); + struct irq_phys_map *map; + struct vgic_dist *dist = &vcpu->kvm->arch.vgic; + + spin_lock(&dist->rb_tree_lock); + + map = vgic_irq_map_search(vcpu, virt_irq); if (map && map->phys_irq == phys_irq) { rb_erase(&map->node, vgic_get_irq_phys_map(vcpu, virt_irq)); kfree(map); + spin_unlock(&dist->rb_tree_lock); return 0; } - + spin_unlock(&dist->rb_tree_lock); return -ENOENT; } @@ -1898,6 +1925,7 @@ int kvm_vgic_create(struct kvm *kvm) } spin_lock_init(&kvm->arch.vgic.lock); + spin_lock_init(&kvm->arch.vgic.rb_tree_lock); kvm->arch.vgic.in_kernel = true; kvm->arch.vgic.vctrl_base = vgic->vctrl_base; kvm->arch.vgic.vgic_dist_base = VGIC_ADDR_UNDEF;