From patchwork Tue Jan 8 18:42:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 1947321 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 351FC3FED4 for ; Tue, 8 Jan 2013 18:42:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757135Ab3AHSmY (ORCPT ); Tue, 8 Jan 2013 13:42:24 -0500 Received: from mail-vc0-f174.google.com ([209.85.220.174]:57414 "EHLO mail-vc0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757127Ab3AHSmU (ORCPT ); Tue, 8 Jan 2013 13:42:20 -0500 Received: by mail-vc0-f174.google.com with SMTP id d16so720613vcd.19 for ; Tue, 08 Jan 2013 10:42:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:subject:to:from:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=FLrYAu8QOmkDOyMWGWM8IAG8l4xtNCZACq0zL1emu9Q=; b=Al/WRAVT+1gU2gYFlqsr86zg86H9PkcpG2N+CI2Qk6D0bm8CJnOrlPYI803K/6YPur O+tFUNgfowbU0iaJPZsCpWBZYqTpnawPOQ7O/YoyycjQNJX+MCKLLOoBjdkm4C2qxE4/ pnyvEX9PHnLPqt2olgpyvp+cdCp/q95r9X1ArI0FhuWjGKvDHbQXi0c1XjOFND/VFbBA qoJrGxWegTmeAlU1bIi1n0/i4DjlZGGGKoiIJ6CelZX2HgsbYn4qEs+lYgQsXrdTy7BV JfCL4Vm5vPj6Zmdk0n5ZVDy0GjBqSYklak1RIOkl1rMMhoCjKIlEbbz5rm2jbiADPhXl M5KA== X-Received: by 10.220.239.143 with SMTP id kw15mr85661562vcb.62.1357670539641; Tue, 08 Jan 2013 10:42:19 -0800 (PST) Received: from [127.0.1.1] (pool-72-80-83-148.nycmny.fios.verizon.net. [72.80.83.148]) by mx.google.com with ESMTPS id bm2sm54266034vdc.6.2013.01.08.10.42.18 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 08 Jan 2013 10:42:19 -0800 (PST) Subject: [PATCH v5 08/12] ARM: KVM: vgic: retire queued, disabled interrupts To: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu From: Christoffer Dall Cc: Marc Zyngier Date: Tue, 08 Jan 2013 13:42:18 -0500 Message-ID: <20130108184218.46558.21262.stgit@ubuntu> In-Reply-To: <20130108184116.46558.3558.stgit@ubuntu> References: <20130108184116.46558.3558.stgit@ubuntu> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQldy7q7eX1AdXgnwjLbhGkahY6oNf5O8bvJBvgsIvu4fTMWhqDvdB8oxFc0pxXT3v9REFvI Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Marc Zyngier An interrupt may have been disabled after being made pending on the CPU interface (the classic case is a timer running while we're rebooting the guest - the interrupt would kick as soon as the CPU interface gets enabled, with deadly consequences). The solution is to examine already active LRs, and check the interrupt is still enabled. If not, just retire it. Signed-off-by: Marc Zyngier Signed-off-by: Christoffer Dall --- arch/arm/kvm/vgic.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/arm/kvm/vgic.c b/arch/arm/kvm/vgic.c index 58237d5..49e8b27 100644 --- a/arch/arm/kvm/vgic.c +++ b/arch/arm/kvm/vgic.c @@ -71,6 +71,7 @@ #define ACCESS_WRITE_VALUE (3 << 1) #define ACCESS_WRITE_MASK(x) ((x) & (3 << 1)) +static void vgic_retire_disabled_irqs(struct kvm_vcpu *vcpu); static void vgic_update_state(struct kvm *kvm); static void vgic_dispatch_sgi(struct kvm_vcpu *vcpu, u32 reg); @@ -344,6 +345,7 @@ static bool handle_mmio_clear_enable_reg(struct kvm_vcpu *vcpu, if (mmio->is_write) { if (offset < 4) /* Force SGI enabled */ *reg |= 0xffff; + vgic_retire_disabled_irqs(vcpu); vgic_update_state(vcpu->kvm); return true; } @@ -792,6 +794,34 @@ static void vgic_update_state(struct kvm *kvm) (((lr) & GICH_LR_PHYSID_CPUID) >> GICH_LR_PHYSID_CPUID_SHIFT) #define MK_LR_PEND(src, irq) \ (GICH_LR_PENDING_BIT | ((src) << GICH_LR_PHYSID_CPUID_SHIFT) | (irq)) + +/* + * An interrupt may have been disabled after being made pending on the + * CPU interface (the classic case is a timer running while we're + * rebooting the guest - the interrupt would kick as soon as the CPU + * interface gets enabled, with deadly consequences). + * + * The solution is to examine already active LRs, and check the + * interrupt is still enabled. If not, just retire it. + */ +static void vgic_retire_disabled_irqs(struct kvm_vcpu *vcpu) +{ + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; + int lr; + + for_each_set_bit(lr, vgic_cpu->lr_used, vgic_cpu->nr_lr) { + int irq = vgic_cpu->vgic_lr[lr] & GICH_LR_VIRTUALID; + + if (!vgic_irq_is_enabled(vcpu, irq)) { + vgic_cpu->vgic_irq_lr_map[irq] = LR_EMPTY; + clear_bit(lr, vgic_cpu->lr_used); + vgic_cpu->vgic_lr[lr] &= ~GICH_LR_STATE; + if (vgic_irq_is_active(vcpu, irq)) + vgic_irq_clear_active(vcpu, irq); + } + } +} + /* * Queue an interrupt to a CPU virtual interface. Return true on success, * or false if it wasn't possible to queue it.