From patchwork Mon Dec 4 20:05:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10091429 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 4B3CC6035E for ; Mon, 4 Dec 2017 20:05:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D91E28AF0 for ; Mon, 4 Dec 2017 20:05:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3283528BCD; Mon, 4 Dec 2017 20:05: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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 DB09D28AF0 for ; Mon, 4 Dec 2017 20:05:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752179AbdLDUFU (ORCPT ); Mon, 4 Dec 2017 15:05:20 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35630 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751754AbdLDUFQ (ORCPT ); Mon, 4 Dec 2017 15:05:16 -0500 Received: by mail-wm0-f68.google.com with SMTP id f9so16571240wmh.0 for ; Mon, 04 Dec 2017 12:05:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=christofferdall-dk.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=QkkBWLGtCEAx2nXZ675QjHUbxRv/Dl4XvAadU6Q95Fw=; b=TiaghoO0Stft/byjDfhzZ64rn0Qmkrc/dtEnO5mj1i4jwpeBu52tySJzm3MVsrECni feRVwFk/jwfynRjkaCGmTJNmUivnns/rP6fvwG6bnDdQFTbv7ejsRN6sFdgVRVZ3GEfn pZUvevE5wFrLi52tCFT9TvidjDsO+ZSawNfpU3ZQ8g9VuNh0kBs6es5fxELhG4IWLpwp GPA6yOupLWKr47C+5hzQEnjBOEO/iCFTWb1xO0CCuWK+kjNXGeetIM3m9Tc8U583oXc1 8igNYiER87IKbRtc4W2C3heq7cJEwbudVdXX7+d0O3sPJjUJPXBYV5FuZKqS9x1/6Ngz WItg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=QkkBWLGtCEAx2nXZ675QjHUbxRv/Dl4XvAadU6Q95Fw=; b=k5ZCtYRYuw3MXapmADuXp12pNEGpHK3XwE3jYYa/5XAANd5qM2bcQkQVwTveT+HOmq 6fF8gE94LC55GfuKHkBRlnvDhbXwSMXIdYPf27BzJAMWMVFB68znLddN5RjtfffD7Bdg uZhhNO6eW/qEJzOw7JK24TqklUaiPPvACqeNV2RUDz1TSB66Hqx1z+vZibDe5zDM3Vw7 8Yz7fwrANpPTJe9MyXrSNuF1+IJTL5ed22Y/kUnJXFV9hVU9Q5RW7evAbMV1GKMaKCm8 8eP/mW6Mo0a98eeS4coqaQaVL4rNAqXqCGAmc2XDwKt5gx9yrtAIjvoyw4EZBP1Zzk2A iBHQ== X-Gm-Message-State: AJaThX6/2lKEc/KXohiyD9ewFbtr255EG2b+qia2LCRcXqlsLUcSYT/l Wds7+0i0S8E7ieug2GML4rf7emOfGl4= X-Google-Smtp-Source: AGs4zMY9B4wlu/2pAPZbpoy3inPVXl4tmLyYUGToluJ4Wko1xy+Ha5dGRDuSmBUxOLRRy42uAKt21Q== X-Received: by 10.80.141.9 with SMTP id s9mr32707827eds.238.1512417915472; Mon, 04 Dec 2017 12:05:15 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id 26sm8374578eds.67.2017.12.04.12.05.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Dec 2017 12:05:14 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu Cc: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Marc Zyngier , Andre Przywara , Eric Auger , Christoffer Dall Subject: [PATCH v6 5/8] KVM: arm/arm64: Support a vgic interrupt line level sample function Date: Mon, 4 Dec 2017 21:05:03 +0100 Message-Id: <20171204200506.3224-6-cdall@kernel.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171204200506.3224-1-cdall@kernel.org> References: <20171204200506.3224-1-cdall@kernel.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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. Reviewed-by: Marc Zyngier Signed-off-by: Christoffer Dall --- include/kvm/arm_vgic.h | 13 ++++++++++++- virt/kvm/arm/arch_timer.c | 3 ++- virt/kvm/arm/vgic/vgic.c | 12 +++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index 8c896540a72c..cdbd142ca7f2 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -130,6 +130,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. */ }; @@ -331,7 +342,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 dd5aca05c500..e78ba5e20f74 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c @@ -840,7 +840,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, + NULL); if (ret) return ret; diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index 607cbbc27a1c..eadabb249d2a 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -151,6 +151,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,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; @@ -456,6 +460,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; } @@ -464,10 +469,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); unsigned long flags; @@ -476,7 +482,7 @@ int kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, unsigned int host_irq, BUG_ON(!irq); spin_lock_irqsave(&irq->irq_lock, flags); - ret = kvm_vgic_map_irq(vcpu, irq, host_irq); + ret = kvm_vgic_map_irq(vcpu, irq, host_irq, get_input_level); spin_unlock_irqrestore(&irq->irq_lock, flags); vgic_put_irq(vcpu->kvm, irq);