From patchwork Fri Sep 15 22:19:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9953887 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 8E463601E7 for ; Fri, 15 Sep 2017 22:23:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78F032957A for ; Fri, 15 Sep 2017 22:23:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DF742957D; Fri, 15 Sep 2017 22:23:11 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED 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 C6A7429580 for ; Fri, 15 Sep 2017 22:23:10 +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=ikD1Eai5B2+YxCGjgl+8tGY6Q6b+Vrnqp/8pIi8a93A=; b=OItDFYXIuviJ0KBie7TqAYvkex SQtCM4WipzSoUleuaZVYRO2q4hRjm34XgffjVsEDSn92EQgAsLIY5ABiy+vLse3U9D5oOD1in9kUc CklwuFwHNArHTp0E4JOf27NMybdrnDGgMFeU0ZKY9oGdbirIZaFxC5Wl3EWkk02qVSrpj7NhiqdE1 YaG8jcPJQ3s5/lFL/C9LV1k1ANYkc47+I7R5VioBhBXU4laIMLKThpHtH1eS0v2DX1vaBnfUvrJ8E kMYdLB77JowzBvAsoAyoHBkOCcyFaeauyZ9nrCJPy37Xfign3MCYl0tUrBr95RE7ul/M0l0Wkgh2V 1/q7dqqw==; 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 1dsz0e-00052Q-Sm; Fri, 15 Sep 2017 22:22:52 +0000 Received: from mail-ua0-x231.google.com ([2607:f8b0:400c:c08::231]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dsyyP-0002y0-TK for linux-arm-kernel@lists.infradead.org; Fri, 15 Sep 2017 22:20:45 +0000 Received: by mail-ua0-x231.google.com with SMTP id l94so1921137ual.11 for ; Fri, 15 Sep 2017 15:20: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=+kyMEhBl3HAXU4TWMgfzFBgUgItsjgs0BwLlVC8tbWA=; b=M+ikZeJAh1e3qTHi3w3EYVAxnZ4fT55DypdntTqFJ+L4+8HQroFr4RQbmWdD7CJzyt pFyEq2wMbValT1l/12Ux4PyjLj7IVUzkPToBy3S7Co/+jI9YiR83sb8RfhKjN0TAeZME kx4iGDJSlVc9xZseKf4+7PI6sFhuQtaLWwocQ= 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=+kyMEhBl3HAXU4TWMgfzFBgUgItsjgs0BwLlVC8tbWA=; b=gaMi95FtAOQyKVgnPha+uxA5dXC1fRcT8LlYN2JtsdxxlaVI/yEqgg9HNzxFq6KeSI nnWIz80Du8eNXHl28UND/ifZB8b4E3FkSEHL/oGlPnmAQ/HXTPT02oIykO6GJOhIrwVT b5uC9uGfJoUhFcEAEDZXkVldPGDrdTMq1CY6UUDNSKMjMHJM79l7y3QWXSVDMUmAIz03 eq5cqBDmwYLnZ81tdRNl+uwIlDM/Fd2a+0vQQxrzTPKCcjtijJ7r5kxoiw2opd1A404H rDlq6LYAwFY8jkGA3G4liCSpGMbpCSrmK50nm2IY89fh33E7b3I4Kpj64mJBoQY5AkRo GAKQ== X-Gm-Message-State: AHPjjUiyokD8mhFEqw1wJL0U8miVoPd52KOUDM11xcaLWwrop2p268eR YeE4BjA3ys0js4EB X-Google-Smtp-Source: ADKCNb4yOKDcvkZWfxw8WpxaJey3as7Upr31R39OkcoiVgR8bEn2UsV8/5a/80uQomxVhV6GhGGUNw== X-Received: by 10.176.27.34 with SMTP id d34mr23260961uai.57.1505514012463; Fri, 15 Sep 2017 15:20:12 -0700 (PDT) Received: from localhost.localdomain ([12.145.98.253]) by smtp.gmail.com with ESMTPSA id q64sm399435uaq.13.2017.09.15.15.20.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Sep 2017 15:20:11 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 6/7] KVM: arm/arm64: Provide a vgic interrupt line level sample function Date: Fri, 15 Sep 2017 15:19:53 -0700 Message-Id: <1505513994-77939-7-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505513994-77939-1-git-send-email-christoffer.dall@linaro.org> References: <1505513994-77939-1-git-send-email-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170915_152034_853443_23518624 X-CRM114-Status: GOOD ( 17.46 ) 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: Marc Zyngier , Eric Auger , kvm@vger.kernel.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 From: Christoffer Dall 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_arch_timer.h | 2 ++ include/kvm/arm_vgic.h | 13 ++++++++++++- virt/kvm/arm/arch_timer.c | 16 +++++++++++++++- virt/kvm/arm/vgic/vgic.c | 12 +++++++++--- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index f0053f8..2bce387 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm/arm_arch_timer.h @@ -82,6 +82,8 @@ void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu); void kvm_timer_init_vhe(void); +bool kvm_arch_timer_get_input_level(int vintid); + #define vcpu_vtimer(v) (&(v)->arch.timer_cpu.vtimer) #define vcpu_ptimer(v) (&(v)->arch.timer_cpu.ptimer) #endif 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..4dccb4f 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; } +bool kvm_arch_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, + kvm_arch_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 8072969..af0de3d 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -147,6 +147,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)); @@ -430,7 +433,8 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, /* @irq->irq_lock must be held */ static int kvm_vgic_map_irq(struct kvm_vcpu *vcpu, struct vgic_irq *irq, - unsigned int host_irq) + unsigned int host_irq, + bool (*get_input_level)(int vindid)) { struct irq_desc *desc; struct irq_data *data; @@ -450,6 +454,7 @@ static int kvm_vgic_map_irq(struct kvm_vcpu *vcpu, struct vgic_irq *irq, irq->hw = true; irq->host_irq = host_irq; irq->hwintid = data->hwirq; + irq->get_input_level = get_input_level; return 0; } @@ -458,10 +463,11 @@ static inline void kvm_vgic_unmap_irq(struct vgic_irq *irq) { irq->hw = false; irq->hwintid = 0; + irq->get_input_level = NULL; } 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); int ret; @@ -469,7 +475,7 @@ int kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, unsigned int host_irq, BUG_ON(!irq); spin_lock(&irq->irq_lock); - ret = kvm_vgic_map_irq(vcpu, irq, host_irq); + ret = kvm_vgic_map_irq(vcpu, irq, host_irq, get_input_level); spin_unlock(&irq->irq_lock); vgic_put_irq(vcpu->kvm, irq);