From patchwork Mon Sep 4 10:24:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9936961 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 81DC360237 for ; Mon, 4 Sep 2017 10:25:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 725C3287B8 for ; Mon, 4 Sep 2017 10:25:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67505287BA; Mon, 4 Sep 2017 10:25:24 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0CD6287B8 for ; Mon, 4 Sep 2017 10:25:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753443AbdIDKZO (ORCPT ); Mon, 4 Sep 2017 06:25:14 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:34488 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753438AbdIDKZN (ORCPT ); Mon, 4 Sep 2017 06:25:13 -0400 Received: by mail-wm0-f45.google.com with SMTP id 137so14638040wmj.1 for ; Mon, 04 Sep 2017 03:25:12 -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=sEM33C6OtmbNF09QXOIpOWPuGTKq0Q8ypyGkWVhxqbA=; b=L9n4ZlzHXKyylKSGPLREtTu5AGgAt9HNCdj/jvtLzNTwG73VdUTT4B97sj9UdS6XzV BbdnpUSt6TZSswJCFNfw2xUMlUMfnjYtXdXOtM3gNaS/406nlugas0CPN7CHrA+JLRlk YTjuB8iQh1lJ2xgTqv2UzHGnYNK4JEEyUzyFw= 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=sEM33C6OtmbNF09QXOIpOWPuGTKq0Q8ypyGkWVhxqbA=; b=fqu2T0ngD28ffkNx17S5YKBvLoWOryCkX4j28Sd893LPPoSu5foEIsU4+EgjgJNfFz dSm6EJo8hdvtq4N9D2C6dnijVezJszbpkLdKBHwDmf+XYJUFyBw4kav4epokXyrX1Ba3 HpS+Xfg0NCro5/bDnS7FfbK9EhsGW1oKcmfSU/jeJxzk8EKDM0Z6nihscPK3F31Adbh4 EwRvhmDUh9lOea+Fu/QMOKiroNhPcj2GoeQxPTL1fmafR7CJfrZl0Sg44nW/U1Ll2j+W NvXUiRin2k6nxAllMhpssvuC0LhiU1NrfnVTzDsM4yhSX50boaZ4XOP5J8QcT8qfFy7H oFOg== X-Gm-Message-State: AHPjjUj/RclUuhkvirQwbGMret9PFSMvt4hRIFpXiqxIJYRuRNH3oRUA 7oUIn6iex/41nd5n X-Google-Smtp-Source: ADKCNb6NjkI/DZTQ49pAuKoKCC6Qo497KcDt6LE1nX7L2nMdlTsYq/7XCvUDk65JyshsOn6WMv75mQ== X-Received: by 10.80.177.162 with SMTP id m31mr116966edd.71.1504520711766; Mon, 04 Sep 2017 03:25:11 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id h64sm3406924edc.67.2017.09.04.03.25.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 03:25:11 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, Eric Auger , Marc Zyngier Cc: Andre Przywara , linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Christoffer Dall Subject: [PATCH v2 6/6] KVM: arm/arm64: Provide a vgic interrupt line level sample function Date: Mon, 4 Sep 2017 12:24:56 +0200 Message-Id: <20170904102456.9025-7-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170904102456.9025-1-cdall@linaro.org> References: <20170904102456.9025-1-cdall@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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..7f76c9e 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 (*get_input_level)(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 c4fa675..5cb96ca 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -645,6 +645,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; @@ -666,7 +679,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 b704ff5..202938c 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -154,6 +154,9 @@ bool vgic_get_phys_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)); @@ -436,7 +439,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 (*get_input_level)(int vindid)) { struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, vintid); struct irq_desc *desc; @@ -463,6 +466,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 = get_input_level; out: spin_unlock(&irq->irq_lock); @@ -483,6 +487,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);