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: Eric Auger X-Patchwork-Id: 5362191 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7CC8BC11AC for ; Sun, 23 Nov 2014 18:17:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 997802026D for ; Sun, 23 Nov 2014 18:17:29 +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 B565F20268 for ; Sun, 23 Nov 2014 18:17:28 +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 1Xsbh5-0002Kv-9s; Sun, 23 Nov 2014 18:15:31 +0000 Received: from mail-wg0-f42.google.com ([74.125.82.42]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XsbgQ-0000ym-DL for linux-arm-kernel@lists.infradead.org; Sun, 23 Nov 2014 18:14:51 +0000 Received: by mail-wg0-f42.google.com with SMTP id z12so10661578wgg.29 for ; Sun, 23 Nov 2014 10:14: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=6lBzPsd5QrucqG06iXBROrMrGLo388RO+Ymr61mn6K4=; b=G34sDtE3kAoWiLnpKEjZ6UvJCQT7oQjIhHmSQKsQFbqxwK2fa0vLldNER7Sf5HjAFc hN1++FvQUl176gTFFkeo9mym7ru00maeA+0h06OPjnvioi4B7FOGrBVjIM/hhpAiEnkN p8Mv7donQyDrpsPcRfn+hoCZ6NVyvS1hJsULfqWRIrpe7nPr77Y5CgtfYVhzs/zT/Drs yJMunpJNtJeVt7piscCxIi7fReJPSmSe5cbb7KK+xB8aADhPUNlDmVWWAWBGF/YeY564 RIzVZba9l/KteDPNKu33L4NXLaJ27nOb0C5n2ChPwezW0J8EEUp+MJdfbp52eAvvNfbr MkSQ== X-Gm-Message-State: ALoCoQkXsjOVeGv2M8gTjAwN2w+gc/dzEPRes6npt+IOIPWqLZLNmlN44sNCBYYoQZ0QS3dQrpDw 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141123_101450_639101_9EE0D29A X-CRM114-Status: GOOD ( 12.38 ) X-Spam-Score: -0.7 (/) Cc: feng.wu@intel.com, patches@linaro.org, john.liuli@huawei.com, ming.lei@canonical.com, will.deacon@arm.com, a.rigo@virtualopensystems.com, linux-kernel@vger.kernel.org, a.motakis@virtualopensystems.com 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=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 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);