From patchwork Wed Feb 11 08:20:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 44555 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0261E2151F for ; Wed, 11 Feb 2015 08:23:32 +0000 (UTC) Received: by lamq1 with SMTP id q1sf1178472lam.0 for ; Wed, 11 Feb 2015 00:23:31 -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=OVAPiyU89qrx2TIh2PayiUrlFiO1OYRmDQohgWI3Fn0=; b=mMXI7D07CMQY+3ptDGbFb3KrL41wpLNWyN+edCPOTPaFrS4CmEsa4aEW0Baw3Iz+LJ JvdAUakl7IP5BG2otQ5kf0RvcRgiczIg79LRssF6L8T5qkMOBkj3xXfXw6gwUbxCVg66 EloKXEoUzEzKjCTT+aRBxYSuOIbvocaTE7htOcAhPW4zWVfm+lW3HsO7FafRUN0Dd5R0 Jsa3P04yrGuZ+BXsRAu2q7tEcbmg9WiqnIKnTSwMSQ+48oBxBaHUxQcCW+Ax+ZqBJzFP sVUima2nS9YN9qJCyvN63MdLpk/Nf707B5wCLRocDs1j5xhrD8ICRuFffoL3pgTA3tMw sjog== X-Gm-Message-State: ALoCoQkrK4ocJ4h5pSkTE4eJ3i7TwMKgWSG/CVzxS9pU+QQiQN93QNlJAOpcyJgErBFWj6hy/3pd X-Received: by 10.152.5.3 with SMTP id o3mr2319273lao.6.1423643010974; Wed, 11 Feb 2015 00:23:30 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.20.67 with SMTP id l3ls32769lae.93.gmail; Wed, 11 Feb 2015 00:23:30 -0800 (PST) X-Received: by 10.152.20.129 with SMTP id n1mr15670438lae.120.1423643010738; Wed, 11 Feb 2015 00:23:30 -0800 (PST) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id es2si102571lac.5.2015.02.11.00.23.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Feb 2015 00:23:30 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id w7so1738087lbi.10 for ; Wed, 11 Feb 2015 00:23:30 -0800 (PST) X-Received: by 10.152.28.227 with SMTP id e3mr26428242lah.117.1423643010563; Wed, 11 Feb 2015 00:23:30 -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.112.35.133 with SMTP id h5csp1105389lbj; Wed, 11 Feb 2015 00:23:29 -0800 (PST) X-Received: by 10.107.152.209 with SMTP id a200mr18689497ioe.14.1423643009100; Wed, 11 Feb 2015 00:23:29 -0800 (PST) Received: from mail-ig0-f176.google.com (mail-ig0-f176.google.com. [209.85.213.176]) by mx.google.com with ESMTPS id s15si1237165icm.50.2015.02.11.00.23.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Feb 2015 00:23:29 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.213.176 as permitted sender) client-ip=209.85.213.176; Received: by mail-ig0-f176.google.com with SMTP id hl2so29247010igb.3 for ; Wed, 11 Feb 2015 00:23:28 -0800 (PST) X-Received: by 10.43.126.67 with SMTP id gv3mr1829869icc.31.1423643008363; Wed, 11 Feb 2015 00:23:28 -0800 (PST) Received: from gnx2579.solutionip.com ([113.28.134.59]) by mx.google.com with ESMTPSA id g11sm56703iod.28.2015.02.11.00.23.24 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Feb 2015 00:23:27 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, christoffer.dall@linaro.org, marc.zyngier@arm.com, andre.przywara@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, alex.williamson@redhat.com Cc: patches@linaro.org, a.motakis@virtualopensystems.com, a.rigo@virtualopensystems.com, b.reynal@virtualopensystems.com Subject: [RFC v2 3/4] KVM: arm: vgic: add forwarded irq rbtree lock Date: Wed, 11 Feb 2015 09:20:56 +0100 Message-Id: <1423642857-24240-4-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1423642857-24240-1-git-send-email-eric.auger@linaro.org> References: <1423642857-24240-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.217.179 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 may happen in another. Signed-off-by: Eric Auger --- v2 -> v3: re-arrange lock sequence in vgic_map_phys_irq --- include/kvm/arm_vgic.h | 1 + virt/kvm/arm/vgic.c | 56 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index 1a49108..ad7229b 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -220,6 +220,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 433ecba..dd72ca2 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -1756,9 +1756,22 @@ 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; + + root = vgic_get_irq_phys_map(vcpu, virt_irq); + new = &root->rb_node; + + new_map = kzalloc(sizeof(*new_map), GFP_KERNEL); + if (!new_map) + return -ENOMEM; + + new_map->virt_irq = virt_irq; + new_map->phys_irq = phys_irq; + + spin_lock(&dist->rb_tree_lock); /* Boilerplate rb_tree code */ while (*new) { @@ -1770,19 +1783,16 @@ 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 { + kfree(new_map); + spin_unlock(&dist->rb_tree_lock); return -EEXIST; + } } - new_map = kzalloc(sizeof(*new_map), GFP_KERNEL); - if (!new_map) - return -ENOMEM; - - new_map->virt_irq = virt_irq; - new_map->phys_irq = 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; } @@ -1811,24 +1821,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; } @@ -2071,6 +2096,7 @@ int kvm_vgic_create(struct kvm *kvm) ret = 0; 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;