From patchwork Sun Nov 23 18:12:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 41385 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 179B22036A for ; Sun, 23 Nov 2014 18:14:31 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf4865960eek.1 for ; Sun, 23 Nov 2014 10:14:29 -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=6lBzPsd5QrucqG06iXBROrMrGLo388RO+Ymr61mn6K4=; b=P/Pdswe6jp2JELcUZK/ji0GRJ/WZiMPaBBpqk6G+yQWHcnsnQFhBcx7rao7enmmatm fQO73Qtsbzb1xpp4FpsFeon/gM+ENk+ROitsPHvzTlL5Xl3EBhp87EHqwyMcCJDOv3XH dNv9wp/q42ibRdXuf9BVuYSM8pCqkmt0HdIuMRBLrakzP0s0eoHo7ljea5sfRM6gq3rQ Dkjr6733DEhr2UyPJre4ufnhPNyqU1KyOXhRjsRh71ooXqiEBeZJuDkaPDsisQzdC59C QJZNQ61a1O5OHdwrqpmG8VwsirfmdHRIi7GhOVr4JtxB5gGEy1CG9fpbVUm42bxnlwNu am7g== X-Gm-Message-State: ALoCoQntBlW00X30iJluXlpRsufU9zUdjQ8FMiW2btSJaTeGqFochma1altDbS2N3JOvwv09Q0su X-Received: by 10.112.32.163 with SMTP id k3mr34340lbi.17.1416766469870; Sun, 23 Nov 2014 10:14:29 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.22.130 with SMTP id d2ls403564laf.32.gmail; Sun, 23 Nov 2014 10:14:29 -0800 (PST) X-Received: by 10.152.6.228 with SMTP id e4mr16397293laa.71.1416766469556; Sun, 23 Nov 2014 10:14:29 -0800 (PST) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id i7si12748122lbs.116.2014.11.23.10.14.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:14:29 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id w7so6472979lbi.33 for ; Sun, 23 Nov 2014 10:14:29 -0800 (PST) X-Received: by 10.112.138.137 with SMTP id qq9mr16357756lbb.80.1416766469441; Sun, 23 Nov 2014 10:14:29 -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 ew9csp154422lbc; Sun, 23 Nov 2014 10:14:28 -0800 (PST) X-Received: by 10.194.238.3 with SMTP id vg3mr26229545wjc.69.1416766468791; Sun, 23 Nov 2014 10:14:28 -0800 (PST) Received: from mail-wg0-f43.google.com (mail-wg0-f43.google.com. [74.125.82.43]) by mx.google.com with ESMTPS id ge3si19418698wjb.92.2014.11.23.10.14.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:14:28 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.43 as permitted sender) client-ip=74.125.82.43; Received: by mail-wg0-f43.google.com with SMTP id l18so10702592wgh.30 for ; Sun, 23 Nov 2014 10:14:28 -0800 (PST) X-Received: by 10.194.87.131 with SMTP id ay3mr27465459wjb.66.1416766468573; Sun, 23 Nov 2014 10:14:28 -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.26 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:14:27 -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 3/4] KVM: arm: vgic: cleanup forwarded IRQs on destroy Date: Sun, 23 Nov 2014 19:12:52 +0100 Message-Id: <1416766373-13569-4-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.174 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: , When the VGIC is destroyed it must take care of - restoring the forwarded IRQs in non forwarded state, - deactivating the IRQ in case the guest left without doing it - cleaning nodes of the phys_map rbtree Signed-off-by: Eric Auger --- virt/kvm/arm/vgic.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index f592219..21419ac 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -32,6 +32,7 @@ #include #include #include +#include /* * How the whole thing works (courtesy of Christoffer Dall): @@ -102,6 +103,8 @@ static struct vgic_lr vgic_get_lr(const struct kvm_vcpu *vcpu, int lr); static void vgic_set_lr(struct kvm_vcpu *vcpu, int lr, struct vgic_lr lr_desc); static void vgic_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); static void vgic_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr); +static void vgic_clean_irq_phys_map(struct kvm_vcpu *vcpu, + struct rb_root *root); static const struct vgic_ops *vgic_ops; static const struct vgic_params *vgic; @@ -1813,6 +1816,36 @@ static struct irq_phys_map *vgic_irq_map_search(struct kvm_vcpu *vcpu, return NULL; } +static void vgic_clean_irq_phys_map(struct kvm_vcpu *vcpu, + struct rb_root *root) +{ + unsigned long flags; + + while (1) { + struct rb_node *node = rb_first(root); + struct irq_phys_map *map; + struct irq_desc *desc; + struct irq_data *d; + struct irq_chip *chip; + + if (!node) + break; + + map = container_of(node, struct irq_phys_map, node); + desc = irq_to_desc(map->phys_irq); + + raw_spin_lock_irqsave(&desc->lock, flags); + d = &desc->irq_data; + chip = desc->irq_data.chip; + irqd_clr_irq_forwarded(d); + chip->irq_eoi(d); + raw_spin_unlock_irqrestore(&desc->lock, flags); + + rb_erase(node, root); + kfree(map); + } +} + int vgic_get_phys_irq(struct kvm_vcpu *vcpu, int virt_irq) { struct irq_phys_map *map; @@ -1855,6 +1888,7 @@ void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu) { struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; + vgic_clean_irq_phys_map(vcpu, &vgic_cpu->irq_phys_map); kfree(vgic_cpu->pending_shared); kfree(vgic_cpu->vgic_irq_lr_map); vgic_cpu->pending_shared = NULL; @@ -1920,6 +1954,8 @@ void kvm_vgic_destroy(struct kvm *kvm) kvm_for_each_vcpu(i, vcpu, kvm) kvm_vgic_vcpu_destroy(vcpu); + vgic_clean_irq_phys_map(vcpu, &dist->irq_phys_map); + vgic_free_bitmap(&dist->irq_enabled); vgic_free_bitmap(&dist->irq_level); vgic_free_bitmap(&dist->irq_pending);