From patchwork Tue Aug 29 09:39:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9927017 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2D2396022E for ; Tue, 29 Aug 2017 09:41:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22069288A9 for ; Tue, 29 Aug 2017 09:41:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16DC7288B5; Tue, 29 Aug 2017 09:41:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 94ED8288A9 for ; Tue, 29 Aug 2017 09:41:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=CbuFtiRlSfyxuNJWEt4jc5CAF976Mocp7FyCCTSSBik=; b=Y9xEFAK88pYJyZpHVkbWS8GVxS O1/v/aHD7uZXvbMim7Y92g3WA2WLVfH1mVG0GqY3+jpJXx75V++lx65ovH4legSpe6FbNp5T2bWLA f3KkQBg2t5uhN8EmTkjvydOXnremHRzvKCQVckKlpbmmLyBSJPJ+uhXLCHEaDUjWfmhPXEKuwkmcy 3dkLbxCBRXJiE9Ngrl2z62nRwgt7EPJFHRW/oM3DBDX5Z4iKFDIrH7Fgdhcr0h3O/h8xhhxUEPf5U Br+oebLaS3+rGeW2B3VzCgp/dscSnkO9B2Q8rafln9RmuEonHmAndpTf/6uyeD6BceNdiSdHu/Iqi ALjMJdjg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dmd1O-0000UA-6W; Tue, 29 Aug 2017 09:41:22 +0000 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dmczg-0006G4-QS for linux-arm-kernel@lists.infradead.org; Tue, 29 Aug 2017 09:39:42 +0000 Received: by mail-wm0-x22f.google.com with SMTP id y71so17263454wmd.0 for ; Tue, 29 Aug 2017 02:39:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XMFEatBNW8N0HyhMiVho7fl6INPu12VqLJdIvV6orcM=; b=dAYvAi93yRStxtmzBUnyUoIQMMcNnmtX8yOJsncowWsTqT5NK4COI4ii+kdkd/pzaF 497Tj+afald4NKzNiEQNwt/ZuAktE/yOv1TUf6Qj8fiRT67h65zOcf5vymdPM9Bp0u7q O2gHSB3cc80vca96p0Z1RaUdfL/7WNTEqoyDM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XMFEatBNW8N0HyhMiVho7fl6INPu12VqLJdIvV6orcM=; b=tTS5SY8mv8L8P/LlbV39iIJSfV2ZZ8yj4CSdpawFkv9URqejoM1uzcB770KHRtMRcO i1HCTeHDbFmLa5v0IA5GHGH0JFwCMo4UYCAV9ZSPL1HF/AefzyvCaNydbt7gqVleitle TMJzkAFAqbYQ8KocXkxhiHxDubUMvDqv7Sh+5z3ggD//krKc9Vn/x71GVUGlmOW/XAbc 3MhYh4kirL5Wt3qKxKN6aMugAFl7L1z9qt+CR+qnJ13639aasWKQrtv4/O8L8ymTBoXo K9YkQKwwQ/iizf3znm6grMcu+AXcRvRK4ngILS8vqln5s5WbEZxEHQPqjaFxPAq2jCsi rFew== X-Gm-Message-State: AHYfb5h7r/py+BcOAJZAWIIKBRXIdRR9FmZrNvpzuI54OepokaR35JCK GTS4PIW7dgvmv6fl X-Received: by 10.80.218.137 with SMTP id q9mr3114769edj.210.1503999551717; Tue, 29 Aug 2017 02:39:11 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id k34sm1149879edc.2.2017.08.29.02.39.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 Aug 2017 02:39:11 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, Eric Auger , Marc Zyngier Subject: [RFC PATCH 4/4] KVM: arm/arm64: Provide a vgic interrupt line level sample function Date: Tue, 29 Aug 2017 11:39:02 +0200 Message-Id: <20170829093902.15379-5-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170829093902.15379-1-cdall@linaro.org> References: <20170829093902.15379-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170829_023937_433372_E29D1ACA X-CRM114-Status: GOOD ( 15.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andre Przywara , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Christoffer Dall MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The GIC sometimes need to sample the physical line of a mapped interrupt. As we know this to be notoriously slow, provide a callback function for devices (such as the timer) which can do this much faster than talking to the distributor, for example by comparing a few in-memory values. Fall back to the good old method of poking the physical GIC if no callback is provided. Signed-off-by: Christoffer Dall Reviewed-by: Marc Zyngier --- include/kvm/arm_vgic.h | 13 ++++++++++++- virt/kvm/arm/arch_timer.c | 16 +++++++++++++++- virt/kvm/arm/vgic/vgic.c | 7 ++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index 53f631b..a52990b 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -125,6 +125,17 @@ struct vgic_irq { u8 priority; enum vgic_irq_config config; /* Level or edge */ + /* + * Callback function pointer to in-kernel devices that can tell us the + * state of the input level of mapped level-triggered IRQ faster than + * peaking into the physical GIC. + * + * Always called in non-preemptible section and the functions can use + * kvm_arm_get_running_vcpu() to get the vcpu pointer for private + * IRQs. + */ + bool (*get_input_level)(int vintid); + void *owner; /* Opaque pointer to reserve an interrupt for in-kernel devices. */ }; @@ -309,7 +320,7 @@ void kvm_vgic_init_cpu_hardware(void); int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, bool level, void *owner); int kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, unsigned int host_irq, - u32 vintid); + u32 vintid, bool (*callback)(int vindid)); int kvm_vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, unsigned int vintid); bool kvm_vgic_map_is_active(struct kvm_vcpu *vcpu, unsigned int vintid); diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index b24e2f7..82169ef 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -643,6 +643,19 @@ static bool timer_irqs_are_valid(struct kvm_vcpu *vcpu) return true; } +static bool timer_get_input_level(int vintid) +{ + struct kvm_vcpu *vcpu = kvm_arm_get_running_vcpu(); + struct arch_timer_context *timer; + + if (vintid == vcpu_vtimer(vcpu)->irq.irq) + timer = vcpu_vtimer(vcpu); + else + BUG(); /* We only map the vtimer so far */ + + return kvm_timer_should_fire(timer); +} + int kvm_timer_enable(struct kvm_vcpu *vcpu) { struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; @@ -664,7 +677,8 @@ int kvm_timer_enable(struct kvm_vcpu *vcpu) return -EINVAL; } - ret = kvm_vgic_map_phys_irq(vcpu, host_vtimer_irq, vtimer->irq.irq); + ret = kvm_vgic_map_phys_irq(vcpu, host_vtimer_irq, vtimer->irq.irq, + &timer_get_input_level); if (ret) return ret; diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index e3ce2fa..0466c10 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -147,6 +147,9 @@ bool vgic_irq_line_level(struct vgic_irq *irq) BUG_ON(!irq->hw); + if (irq->get_input_level) + return irq->get_input_level(irq->intid); + WARN_ON(irq_get_irqchip_state(irq->host_irq, IRQCHIP_STATE_PENDING, &line_level)); @@ -429,7 +432,7 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, } int kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, unsigned int host_irq, - u32 vintid) + u32 vintid, bool (*callback)(int vindid)) { struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, vintid); struct irq_desc *desc; @@ -456,6 +459,7 @@ int kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, unsigned int host_irq, irq->hw = true; irq->host_irq = host_irq; irq->hwintid = data->hwirq; + irq->get_input_level = callback; out: spin_unlock(&irq->irq_lock); @@ -476,6 +480,7 @@ int kvm_vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, unsigned int vintid) spin_lock(&irq->irq_lock); irq->hw = false; irq->hwintid = 0; + irq->get_input_level = NULL; spin_unlock(&irq->irq_lock); vgic_put_irq(vcpu->kvm, irq);