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: 5362121 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3363E9F319 for ; Sun, 23 Nov 2014 18:14:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 534C92026D for ; Sun, 23 Nov 2014 18:14:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 620AB20272 for ; Sun, 23 Nov 2014 18:14:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752126AbaKWSOe (ORCPT ); Sun, 23 Nov 2014 13:14:34 -0500 Received: from mail-wi0-f177.google.com ([209.85.212.177]:37898 "EHLO mail-wi0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751958AbaKWSOc (ORCPT ); Sun, 23 Nov 2014 13:14:32 -0500 Received: by mail-wi0-f177.google.com with SMTP id l15so3686513wiw.16 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=hg20S74ZFq4/FWWn5hez4rJV8I8lA6e4wUn9LaIhRSepGZ8O04eBjLp9gNoHhVe65K eJbWEIV9b6DIgav0zIBOTxN+QXV5mz5Qp6U/EpLyLW0N7EdI1My4HxAT80gMVGwO3juq GZRoIrTkKPeGehqvplRn2aR+YNGeC/Npw8ZvPdmhld/yRbQqOHkb96hcD9eZhpcGQULS twR4LVxxfIAqQya1TtzXgUUQVXa6uCejXjDXdGNPWFLn8f+hzm47sHtcMsMHN3qhGkca TTeBSddIXQb6vf2zn5Uc29PaxpMP/VRC2uDX8AbMR1lP5/cVqez/4MyD9iowYW1EBRiT Lg2w== X-Gm-Message-State: ALoCoQkt+KSMdfgYQzNrlMVNstayQcbAYVUvxH4fXsU2HccfSyjFw+SLc1IKShyiN+uyeG/HA8sH 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 Cc: linux-kernel@vger.kernel.org, patches@linaro.org, will.deacon@arm.com, a.motakis@virtualopensystems.com, a.rigo@virtualopensystems.com, john.liuli@huawei.com, ming.lei@canonical.com, feng.wu@intel.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> 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 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