From patchwork Sun Nov 23 18:12:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 5362201 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 70A089F319 for ; Sun, 23 Nov 2014 18:17:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9C50520274 for ; Sun, 23 Nov 2014 18:17:43 +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 C06BF20270 for ; Sun, 23 Nov 2014 18:17:42 +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 1XsbhO-0002mq-Rt; Sun, 23 Nov 2014 18:15:50 +0000 Received: from mail-wi0-f181.google.com ([209.85.212.181]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XsbgT-0000yq-I5 for linux-arm-kernel@lists.infradead.org; Sun, 23 Nov 2014 18:14:54 +0000 Received: by mail-wi0-f181.google.com with SMTP id r20so3739804wiv.2 for ; Sun, 23 Nov 2014 10:14:31 -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=uEWwJTp0r14n3gdg6qEoc4GlMUp8H/uPvg4lAU2HBws=; b=X8XQEItSKk1jSa8NwxzUwy6PXoPvnnZre+p2dkerMVw1SgJ3E6ZjjGBJw+4sO5F7Hn DAXBIkKAoLK7X0v3ujM5OI2fL0rPvnnjQc7zf2o54nuwwmoNABMriUlm99mKK03i7Ovi FlBkB066M+UOaCPrib2hjwMY8+Fdp4bSVcqa8KKHW1yuUTd8I6Nx0GqtnUNQeJFqw73g B/+WuZ56O3hC+Wx/iQKcpYnnPMEECejPZy1IO8w7S3sPcW3s3/DGuE95s2b+yjuVUbnp oaFH2c2WBdc6tY2kK90yzJX3NMeBNHa8FykrYcHOSFSGfj9dLyrwvPyYYQJMzqjwlxDC yhew== X-Gm-Message-State: ALoCoQlF4T6RtjIxbn24vMGLLXokQSX/Q2ToZiSt/awDHvvdvgPbRc5qDoNAIcN86Wk2cQDpgrHz X-Received: by 10.180.95.37 with SMTP id dh5mr15054002wib.64.1416766471702; Sun, 23 Nov 2014 10:14:31 -0800 (PST) Received: from gnx2579.gnb.st.com (weg38-3-78-232-41-119.fbx.proxad.net. [78.232.41.119]) by mx.google.com with ESMTPSA id bf6sm17489823wjb.13.2014.11.23.10.14.29 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:14:31 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, christoffer.dall@linaro.org, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, alex.williamson@redhat.com, joel.schopp@amd.com, kim.phillips@freescale.com, paulus@samba.org, gleb@kernel.org, pbonzini@redhat.com Subject: [RFC 4/4] KVM: arm: vgic: handle irqfd forwarded IRQ injection before vgic readiness Date: Sun, 23 Nov 2014 19:12:53 +0100 Message-Id: <1416766373-13569-5-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416766373-13569-1-git-send-email-eric.auger@linaro.org> References: <1416766373-13569-1-git-send-email-eric.auger@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141123_101453_745200_E7C33386 X-CRM114-Status: GOOD ( 13.51 ) X-Spam-Score: -0.7 (/) Cc: feng.wu@intel.com, patches@linaro.org, john.liuli@huawei.com, ming.lei@canonical.com, will.deacon@arm.com, a.rigo@virtualopensystems.com, linux-kernel@vger.kernel.org, a.motakis@virtualopensystems.com 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=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 This patch handles the case where irqfd attempts to inject a forwarded IRQ before the vgic is ready to accept it. We cannot simply return pretending nothing happened since the IRQ will never be deactivated by the guest. Indeed, the corresponding virtual IRQ cannot be injected into the guest and the host must deactivate it. Signed-off-by: Eric Auger --- virt/kvm/arm/vgic.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index 21419ac..27394b0 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -2672,6 +2672,13 @@ int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level, bool line_status) { unsigned int spi = irq + VGIC_NR_PRIVATE_IRQS; + struct kvm_vcpu *vcpu = kvm_get_vcpu(kvm, 0); + int phys_irq = vgic_get_phys_irq(vcpu, spi); + bool is_forwarded = (phys_irq >= 0); + unsigned long flags; + struct irq_desc *desc; + struct irq_data *d; + struct irq_chip *chip; kvm_debug("irqfd sets vIRQ %d to %d\n", irq, level); @@ -2679,6 +2686,19 @@ int kvm_set_irq(struct kvm *kvm, int irq_source_id, if (spi > kvm->arch.vgic.nr_irqs) return -EINVAL; return kvm_vgic_inject_irq(kvm, 0, spi, level); + } + + if (level && is_forwarded) { + /* + * the virtual IRQ never is injected into the guest + * it must be manually completed on host side. + */ + desc = irq_to_desc(phys_irq); + raw_spin_lock_irqsave(&desc->lock, flags); + d = &desc->irq_data; + chip = desc->irq_data.chip; + chip->irq_eoi(d); + raw_spin_unlock_irqrestore(&desc->lock, flags); } else if (level && kvm_irq_has_notifier(kvm, 0, irq)) { /* * any IRQ injected before vgic readiness is