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: Auger Eric X-Patchwork-Id: 41386 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1C1582036A for ; Sun, 23 Nov 2014 18:14:34 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id n15sf417286lbi.8 for ; Sun, 23 Nov 2014 10:14:33 -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=uEWwJTp0r14n3gdg6qEoc4GlMUp8H/uPvg4lAU2HBws=; b=f9lJS/W9vWB+rSxF489B3DVC+a2RT7V5nkN7ZTN/6f6vyLUYAlplvXMGsz5OSrxkcN JlQl2bF1sENGYnz+ZRYE1bl9HKliESXDpm1dRyV6+wypHdEhi9IoYSWyWnvUQ4khkrI8 v5CinOm8eFCTIu5WBbyNfs2vZkzNcFodkc3IpWbzcdYJcb8PwLVsyOjKrqCJB3hwAD9w sLGaY38rowjpO37aIrBJm1yE3OPRLBIbDnDTU/yh44jWPJkji0exooUZNPtZs5ivpc37 oohDunuR490JIQd1d3zYJ//owbWKh0ATYgjzjPlJw8x8Alxf3D4jCp+YEIBpqj6ZBrLz zOUA== X-Gm-Message-State: ALoCoQlxHKxswKOEtszbHrU1zbykTr0BW8c6ib6djUvMi7H/8yzPFJ5xCGqUj8eeu464+yRpF/uV X-Received: by 10.180.106.67 with SMTP id gs3mr2931773wib.3.1416766472980; Sun, 23 Nov 2014 10:14:32 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.170 with SMTP id l10ls298159lah.18.gmail; Sun, 23 Nov 2014 10:14:32 -0800 (PST) X-Received: by 10.112.52.73 with SMTP id r9mr4212383lbo.15.1416766472661; Sun, 23 Nov 2014 10:14:32 -0800 (PST) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id bg6si12843632lbc.42.2014.11.23.10.14.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:14:32 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by mail-lb0-f180.google.com with SMTP id l4so823736lbv.11 for ; Sun, 23 Nov 2014 10:14:32 -0800 (PST) X-Received: by 10.112.189.10 with SMTP id ge10mr16235984lbc.23.1416766472585; Sun, 23 Nov 2014 10:14:32 -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.184.201 with SMTP id ew9csp154425lbc; Sun, 23 Nov 2014 10:14:32 -0800 (PST) X-Received: by 10.194.58.205 with SMTP id t13mr25869462wjq.55.1416766471944; Sun, 23 Nov 2014 10:14:31 -0800 (PST) Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com. [209.85.212.172]) by mx.google.com with ESMTPS id h6si8697098wie.27.2014.11.23.10.14.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:14:31 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.172 as permitted sender) client-ip=209.85.212.172; Received: by mail-wi0-f172.google.com with SMTP id n3so3653389wiv.11 for ; Sun, 23 Nov 2014 10:14:31 -0800 (PST) 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> 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.180 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: , 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