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: Eric Auger X-Patchwork-Id: 5810851 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 86135BF440 for ; Wed, 11 Feb 2015 08:27:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9CCFA200CA for ; Wed, 11 Feb 2015 08:27:16 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B64C2200F3 for ; Wed, 11 Feb 2015 08:27:15 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YLSbq-000337-Dd; Wed, 11 Feb 2015 08:25:22 +0000 Received: from mail-ie0-f175.google.com ([209.85.223.175]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YLSaM-0000yp-D4 for linux-arm-kernel@lists.infradead.org; Wed, 11 Feb 2015 08:23:53 +0000 Received: by iecvy18 with SMTP id vy18so2235643iec.13 for ; Wed, 11 Feb 2015 00:23:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OVAPiyU89qrx2TIh2PayiUrlFiO1OYRmDQohgWI3Fn0=; b=PVgR/hQ7ibRIijdJ4lo5pvruT4pvZPDhwxYow/4yB2eCOAT5jDuf1W6OTUX2Ik5Z8T dzid5j0CuuaLFpuVUM0Pj41EvPSRHLFVqUUvoA0A4sYAwt07WTL+jwmjnuI78TZeHos9 BW0zUnew8EBkZIUl9w3IscBmxi9XpaGLnW4yi+l0epIOeL945b1ZBrL4W9bWYb55jVCT Oh0vkiMndFbtXy+QgTVk53idN+ulOO6EVbzMPoxyRTCIcdeAnIYrtvXcJzf3vR7A15ly dErLhRVcOw++wQqwj/U6YlZsQ5HK8JVlvTfvqf6cO1rarg3xHx3UpPgMH7mFkeJ8MPXm R/2g== X-Gm-Message-State: ALoCoQkbPRa6HyYZuwtYqFVA4wRWO0Q92/AYFm770MGaQFrgGFzGKJgVoXABWjJjegDqySaJ2mtN 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150211_002350_521891_849C88E0 X-CRM114-Status: GOOD ( 14.97 ) X-Spam-Score: -0.7 (/) Cc: a.motakis@virtualopensystems.com, b.reynal@virtualopensystems.com, a.rigo@virtualopensystems.com, patches@linaro.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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;