From patchwork Sun Nov 23 18:12:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 41384 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 5A9D12036A for ; Sun, 23 Nov 2014 18:14:27 +0000 (UTC) Received: by mail-la0-f69.google.com with SMTP id gd6sf4601496lab.4 for ; Sun, 23 Nov 2014 10:14:26 -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=kzdHupxMlOe74QVaCgVFk2+Bs6vlMoftykmLACZkxjA=; b=VtJKYOcO0hTb3eaImKd3tSo0M+DKqjK7UON/DF/hFtYKWYrWkmHqZxLJ3UKDWeDE5k 0E+Vw4FbK2arCgmZIbj7ysg353BiroAUxpwuDyuI0dkNe0doAagycMNowS4qD98qALyn lItX+DwjBIXqGc0agduod4Av95dBLfGaXmA+c+6KOTt+SGNmmqtwPSvrndiwKWRSTLJE ZGIXlvZEUTATcPJTE0Wl+jiOa08AFLoqGlhfmfdv+lXY9u9JDJIhkWt1MQ+44Yw/uhWL 9E1OBbITKNHwpKzfhgGQ9S9z9yXersNR7Md4cHewG4knyr72XIv8JxWAI0albt9NA+tG fdYA== X-Gm-Message-State: ALoCoQnY4v3PKD4su6DoZh/1IOM3Tb0LFWsxi12GDrkbZPUXEl+xrV3RwCNjnLYuyyHP/OrLpysD X-Received: by 10.194.178.163 with SMTP id cz3mr5072967wjc.1.1416766466224; Sun, 23 Nov 2014 10:14:26 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.38 with SMTP id w6ls210430laa.49.gmail; Sun, 23 Nov 2014 10:14:25 -0800 (PST) X-Received: by 10.112.136.164 with SMTP id qb4mr16637271lbb.62.1416766465634; Sun, 23 Nov 2014 10:14:25 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id vy6si5715513lbb.88.2014.11.23.10.14.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:14:25 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id n15so633893lbi.30 for ; Sun, 23 Nov 2014 10:14:25 -0800 (PST) X-Received: by 10.112.235.196 with SMTP id uo4mr16229803lbc.66.1416766465499; Sun, 23 Nov 2014 10:14:25 -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.184.201 with SMTP id ew9csp154412lbc; Sun, 23 Nov 2014 10:14:25 -0800 (PST) X-Received: by 10.194.209.180 with SMTP id mn20mr26847294wjc.49.1416766464842; Sun, 23 Nov 2014 10:14:24 -0800 (PST) Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com. [209.85.212.180]) by mx.google.com with ESMTPS id dk6si8621638wib.44.2014.11.23.10.14.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:14:24 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.180 as permitted sender) client-ip=209.85.212.180; Received: by mail-wi0-f180.google.com with SMTP id n3so3715656wiv.7 for ; Sun, 23 Nov 2014 10:14:24 -0800 (PST) X-Received: by 10.180.39.65 with SMTP id n1mr14984768wik.13.1416766464633; Sun, 23 Nov 2014 10:14:24 -0800 (PST) Received: from gnx2579.gnb.st.com (weg38-3-78-232-41-119.fbx.proxad.net. [78.232.41.119]) by mx.google.com with ESMTPSA id bf6sm17489823wjb.13.2014.11.23.10.14.22 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:14:24 -0800 (PST) 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, ming.lei@canonical.com, feng.wu@intel.com Subject: [RFC 2/4] KVM: arm: vgic: add forwarded irq rbtree lock Date: Sun, 23 Nov 2014 19:12:51 +0100 Message-Id: <1416766373-13569-3-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416766373-13569-1-git-send-email-eric.auger@linaro.org> References: <1416766373-13569-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.171 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 ea31ac6..9b3290b 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 5484e3d..f592219 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -1750,9 +1750,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) { @@ -1764,19 +1777,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; } @@ -1805,24 +1815,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; } @@ -2078,6 +2103,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;