From patchwork Wed Feb 11 08:20:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 5810861 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8D7BD9F39D for ; Wed, 11 Feb 2015 08:27:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AD9DD2011D for ; Wed, 11 Feb 2015 08:27:47 +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 DF67120107 for ; Wed, 11 Feb 2015 08:27:46 +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 1YLScM-0003Hq-JE; Wed, 11 Feb 2015 08:25:54 +0000 Received: from mail-ie0-f177.google.com ([209.85.223.177]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YLSaT-00017c-1f for linux-arm-kernel@lists.infradead.org; Wed, 11 Feb 2015 08:24:03 +0000 Received: by iecrd18 with SMTP id rd18so2277521iec.8 for ; Wed, 11 Feb 2015 00:23:34 -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=7KZU1PeW8/PKSX37B6r6mLls0XBoauifKbe34KAtAqg=; b=PJCbVJz2UjBzKdX1b++ff1CJtQvmV2It1NtDhPsOaxZ6SdSVaPRlZVdsOyJPPjiZYr w60bdQdsS8BKY3aVEeBZwYcEwhgNq9BL/o0nIn1ZVDESkmNEnUEO+V0Npir66H28faFo EhfkX9BtibxRIqDVOUlK89QWtby2elSlaCgQIw9F4kPps9ycIwLSTqaXqR62obj+qJy+ veZr6+6Abvz1Yb9zxdbXUommTyID6c0/cF5w1M2a8RN7pzopgImGhObheQegkDAZlm7/ /ShHk4rUnEk6KXj87iO8AJSVHA/v9ihmU1VMLBz0YP/k/C+WPf0lb1gmZ3KR9QNGsqmr BEOA== X-Gm-Message-State: ALoCoQlN0pl7UMMWKmrin7mofdgr8S6ysSxxFsyq26Ja/e+xO5sJj6XbM6YSBaVzr/APzCP1sRDr X-Received: by 10.42.88.9 with SMTP id a9mr1876427icm.34.1423643014145; Wed, 11 Feb 2015 00:23:34 -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.29 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Feb 2015 00:23:33 -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 4/4] KVM: arm: vgic: cleanup forwarded IRQs on destroy Date: Wed, 11 Feb 2015 09:20:57 +0100 Message-Id: <1423642857-24240-5-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_002357_196066_2CABB1F0 X-CRM114-Status: GOOD ( 11.72 ) 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 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 --- v1 -> v2: - remove vgic_clean_irq_phys_map call in kvm_vgic_destroy (useless since already called in kvm_vgic_vcpu_destroy) --- virt/kvm/arm/vgic.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index dd72ca2..ace8e46 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): @@ -103,6 +104,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; @@ -1819,6 +1822,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; @@ -1861,6 +1894,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;