From patchwork Wed Feb 11 08:20:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 5810841 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 281909F39D for ; Wed, 11 Feb 2015 08:26:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5A38720107 for ; Wed, 11 Feb 2015 08:26:52 +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 73E5B200F3 for ; Wed, 11 Feb 2015 08:26:51 +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 1YLSbO-0001jh-Cd; Wed, 11 Feb 2015 08:24:54 +0000 Received: from mail-ie0-f174.google.com ([209.85.223.174]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YLSaG-0000ju-W4 for linux-arm-kernel@lists.infradead.org; Wed, 11 Feb 2015 08:23:49 +0000 Received: by iebtr6 with SMTP id tr6so2315984ieb.4 for ; Wed, 11 Feb 2015 00:23:22 -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=HUrTnou8XGs3ECUFukwX5JwMonQYtFKydDq8Yg3W070=; b=VprC5thwdy54kjjCrW5mvALMaYK6XBBC0S/qQVN55ivxTk8are5/IrY87scFDnkkqI TjV4ueAO0JykiMy8e3UAA6kzBUhQJj5XZOLCUJ+b34uIlO7R5EU80Z0lD8PQRzwHB5qC 41+SgY9h2YnSNYgfQ+pVeC+vrYn4zqZ5qfAVRM22p3FcN9jA6GQntCZK5gybrSC1K9vt jqg8RUTIygJNWlkVoPgAAeFmo9zU6+0t1YD/LVdrIgQHzFCOZ/NgHOQ12Gtr/wup4wuV GSqKei9jXvEZe0F7lFBY3aVl9GTJ8rnkLIOrWdhKFpbfHJXpT1G3ix3wDKqjatFadoWC LLyQ== X-Gm-Message-State: ALoCoQnmChgRf7IiVTVCtODBTkSgK0j/Is46LC50dR360NO2igxRRyoZl2PYe40kCgPt4vGEi4ul X-Received: by 10.50.30.130 with SMTP id s2mr2224467igh.11.1423643002418; Wed, 11 Feb 2015 00:23:22 -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.18 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Feb 2015 00:23:21 -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 2/4] KVM: arm: vgic: fix state machine for forwarded IRQ Date: Wed, 11 Feb 2015 09:20:55 +0100 Message-Id: <1423642857-24240-3-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_002345_090945_B6A5F744 X-CRM114-Status: GOOD ( 12.86 ) 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 Fix multiple injection of level sensitive forwarded IRQs. With current code, the second injection fails since the state bitmaps are not reset (process_maintenance is not called anymore). New implementation follows those principles: - A forwarded IRQ only can be sampled when it is pending - when queueing the IRQ (programming the LR), the pending state is removed as for edge sensitive IRQs - an injection of a forwarded IRQ is considered always valid since coming from the HW and level always is 1. Signed-off-by: Eric Auger --- v1 -> v2: - integration in new vgic_can_sample_irq - remove the pending state when programming the LR --- virt/kvm/arm/vgic.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index cd00cf2..433ecba 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -361,7 +361,10 @@ static void vgic_cpu_irq_clear(struct kvm_vcpu *vcpu, int irq) static bool vgic_can_sample_irq(struct kvm_vcpu *vcpu, int irq) { - return vgic_irq_is_edge(vcpu, irq) || !vgic_irq_is_queued(vcpu, irq); + bool is_forwarded = (vgic_get_phys_irq(vcpu, irq) >= 0); + + return vgic_irq_is_edge(vcpu, irq) || !vgic_irq_is_queued(vcpu, irq) || + (is_forwarded && vgic_dist_irq_is_pending(vcpu, irq)); } static u32 mmio_data_read(struct kvm_exit_mmio *mmio, u32 mask) @@ -1296,6 +1299,7 @@ static bool vgic_queue_irq(struct kvm_vcpu *vcpu, u8 sgi_source_id, int irq) struct vgic_dist *dist = &vcpu->kvm->arch.vgic; struct vgic_lr vlr; int lr; + bool is_forwarded = (vgic_get_phys_irq(vcpu, irq) >= 0); /* Sanitize the input... */ BUG_ON(sgi_source_id & ~7); @@ -1331,7 +1335,7 @@ static bool vgic_queue_irq(struct kvm_vcpu *vcpu, u8 sgi_source_id, int irq) vlr.irq = irq; vlr.source = sgi_source_id; vlr.state = LR_STATE_PENDING; - if (!vgic_irq_is_edge(vcpu, irq)) + if (!vgic_irq_is_edge(vcpu, irq) && !is_forwarded) vlr.state |= LR_EOI_INT; vgic_set_lr(vcpu, lr, vlr); @@ -1372,11 +1376,12 @@ static bool vgic_queue_sgi(struct kvm_vcpu *vcpu, int irq) static bool vgic_queue_hwirq(struct kvm_vcpu *vcpu, int irq) { + bool is_forwarded = (vgic_get_phys_irq(vcpu, irq) >= 0); if (!vgic_can_sample_irq(vcpu, irq)) return true; /* level interrupt, already queued */ if (vgic_queue_irq(vcpu, 0, irq)) { - if (vgic_irq_is_edge(vcpu, irq)) { + if (vgic_irq_is_edge(vcpu, irq) || is_forwarded) { vgic_dist_irq_clear_pending(vcpu, irq); vgic_cpu_irq_clear(vcpu, irq); } else { @@ -1626,14 +1631,17 @@ static int vgic_update_irq_pending(struct kvm *kvm, int cpuid, int edge_triggered, level_triggered; int enabled; bool ret = true; + bool is_forwarded; spin_lock(&dist->lock); vcpu = kvm_get_vcpu(kvm, cpuid); + is_forwarded = (vgic_get_phys_irq(vcpu, irq_num) >= 0); + edge_triggered = vgic_irq_is_edge(vcpu, irq_num); level_triggered = !edge_triggered; - if (!vgic_validate_injection(vcpu, irq_num, level)) { + if (!vgic_validate_injection(vcpu, irq_num, level) && !is_forwarded) { ret = false; goto out; }