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: Auger Eric X-Patchwork-Id: 44554 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 676842151F for ; Wed, 11 Feb 2015 08:23:25 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id n3sf1713420wiv.0 for ; Wed, 11 Feb 2015 00:23:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=HUrTnou8XGs3ECUFukwX5JwMonQYtFKydDq8Yg3W070=; b=Yzh8C0s7X6ktPKinhFfdwNhHPWxBSUVjqnhURRtWz6GfiP6rrpRyE8hV4DtIR3hFaU 9QJ6e93muLjmwjXb4LYOU/+XVZfBiRz9hhYQXf1W4EM18f9suOuDS0kCjJfTMrU07Wvg P5R9SRyEiV8nCNcyH+kpcbs8U5c5aTjNTO+ooALVw3jD4XMmTGZ9/32do4BHFY/iQyVh B6UiB/t+Jn30U/9HpI0e9Q9Y3G+WdlVUIZBTVh5httVDZtsY2ysSGdsuQhxfb3/KEEv0 J9c3CoF2OSyDxezF1Jr4jCHnZ79lHA81o8I0rqLErZ82gS4jeFPZ/eFJtfAydU1inCBl GePg== X-Gm-Message-State: ALoCoQn26T9bYD1oYtMajq8X0NLtFWCd/azf9Zs+uzZMxIJ0EUZKgal7FzCqrIX+Ah2OZrNH3SMx X-Received: by 10.194.178.234 with SMTP id db10mr3248238wjc.2.1423643004738; Wed, 11 Feb 2015 00:23:24 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.74 with SMTP id q10ls32119laq.43.gmail; Wed, 11 Feb 2015 00:23:24 -0800 (PST) X-Received: by 10.152.7.38 with SMTP id g6mr26934645laa.65.1423643004583; Wed, 11 Feb 2015 00:23:24 -0800 (PST) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id h2si35897lbv.95.2015.02.11.00.23.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Feb 2015 00:23:24 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id w7so1737673lbi.10 for ; Wed, 11 Feb 2015 00:23:24 -0800 (PST) X-Received: by 10.112.162.167 with SMTP id yb7mr26220152lbb.76.1423643004473; Wed, 11 Feb 2015 00:23:24 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1105347lbj; Wed, 11 Feb 2015 00:23:23 -0800 (PST) X-Received: by 10.107.151.80 with SMTP id z77mr37480848iod.51.1423643003164; Wed, 11 Feb 2015 00:23:23 -0800 (PST) Received: from mail-ig0-f180.google.com (mail-ig0-f180.google.com. [209.85.213.180]) by mx.google.com with ESMTPS id i4si1295938igj.1.2015.02.11.00.23.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Feb 2015 00:23:23 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.213.180 as permitted sender) client-ip=209.85.213.180; Received: by mail-ig0-f180.google.com with SMTP id b16so2917522igk.1 for ; Wed, 11 Feb 2015 00:23:22 -0800 (PST) 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> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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; }