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: 5810801 Return-Path: X-Original-To: patchwork-kvm@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 8C0629F39D for ; Wed, 11 Feb 2015 08:23:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9A98920107 for ; Wed, 11 Feb 2015 08:23:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A6F91200F3 for ; Wed, 11 Feb 2015 08:23:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751804AbbBKIXX (ORCPT ); Wed, 11 Feb 2015 03:23:23 -0500 Received: from mail-ie0-f181.google.com ([209.85.223.181]:33425 "EHLO mail-ie0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751596AbbBKIXX (ORCPT ); Wed, 11 Feb 2015 03:23:23 -0500 Received: by iecar1 with SMTP id ar1so2365507iec.0 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=H3J6sbBULBiL5FbX1QobfLA8lGiuY/XI57LqXegVhQCVbgzHAkuVD4HdTjYs1WXQ3o za8ZDcGArvveW8kJ7YsaBzcorobR2kMf47nnjinP2Lv4MmGnwj3WfRCvIK2/aLeRDT63 OfXD8h2HPCctmGRzEIlfNkZleTqqyJnJT1m12iCRkXZdtG5VeXcmED7CUlNmJaUHU28Q bdRnLQyDvTjpsuIPIGCoC3cBdeTHlok9dew6G7uP765L79otUoNVtPZlsuhKpKpYkqz4 ALvTBKoi0jeybfotsPvy3TObmKhXsI93xEHXh/4f0ZCBwWK4FG1NxmkkSAVb7LGFGt6H C7EA== X-Gm-Message-State: ALoCoQkO3KFI+RBCoMQQlf8IVEqE8jEW5GF2Fo8z4X8DrGfqe7tDAAjN1SOINsIkXsefda47N1iM 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 Cc: patches@linaro.org, a.motakis@virtualopensystems.com, a.rigo@virtualopensystems.com, b.reynal@virtualopensystems.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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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; }