From patchwork Thu Dec 7 10:54:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10098489 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 7B25460325 for ; Thu, 7 Dec 2017 11:34:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 644592A442 for ; Thu, 7 Dec 2017 11:34:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5895A2A447; Thu, 7 Dec 2017 11:34:53 +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 D9E132A442 for ; Thu, 7 Dec 2017 11:34:52 +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=47AVjqb+lS+w2pAvsmuDKvhDrZgZFJqaXrQPpohq0Bk=; b=XGr2kgaQSJcaRm98+jK/tXCiAc q7GYise1vo6hcBa+Z5EgFK5Y+TcEzAUKtNaTepdku3fUZDQsx4ssxa9ZBssBfuLfet1OdMRXIZsXz Zwl+to6/rNCslzQZeGCtLGy+Tx26KtaZCfNjBd7FTL7odifV1uQ3J8zdS+5r1fU/LwmM7EWHJ/3Ij exqrQop2ExmiLw9dC1UzjdfjC4kRdk7jZO0ZJnFYhK7LqmIwIfDbtR7jqtKHwes67egp5deksVfdX N/+L9QU/JVs2dszMcfCwTJvFMIDV1Xltryl20QcDFqI6jGW1tGM1XZhUM+r8FguSGRuSHwLqdqD5m 8oDVrTqA==; 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 1eMuRw-0006zR-PJ; Thu, 07 Dec 2017 11:34:44 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMuRh-0006e6-1C for linux-arm-kernel@bombadil.infradead.org; Thu, 07 Dec 2017 11:34:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=k0ti+wWlfKgapDgyfllKZp0uh6W54/sQERNB9ARr7GY=; b=hyKNAz89WgbT+088+UDFZl9Xs afnwCkpSSy/zD+eN9L0DR+MmVVwMW2WJgMXo2or+DWd7zc8sAjy+/6sVCIKhu8Urj81qGQuKbgZMN bBRQC5A1hpFCWKMKORbFqp/vihsdGxX8Jo8qKX8s3IZndw1F8ljo131nOas6Fj1ac1KoGg2M2fsoG TFed/DQe6iK07dK/2AsGgh7vV/JbLZZel7fn7pADj5Tb1fBF/tJ1Dup90SAjmj2O0mQO69b9eehF2 970/m0mXCynWen2XTDtlhW1lsyp6uk+w5hl7mE+XlhtgpZtaCxzLqotQRxN3VWpi54uKRcnxwwx7q HwaXOSvtg==; Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMtpU-0006KC-V1 for linux-arm-kernel@lists.infradead.org; Thu, 07 Dec 2017 10:55:02 +0000 Received: by mail-wm0-x241.google.com with SMTP id f206so12020285wmf.5 for ; Thu, 07 Dec 2017 02:54:38 -0800 (PST) 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=k0ti+wWlfKgapDgyfllKZp0uh6W54/sQERNB9ARr7GY=; b=TBs92JxuKhI6AZMzk+TJLAds9EJ4dWfAyV+nZKb9kGwJzUIOXm7hereSfDG6mBUDjm pU0vfhudyChckEVAYXLZ3T1gnPncFCw174oH0xQmTm13nDIIS42Tudl6hTX5Cu8lPNat GNvr4lqXo9srjYf0/mTt2/14sj3dVFch0CCa4= 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=k0ti+wWlfKgapDgyfllKZp0uh6W54/sQERNB9ARr7GY=; b=GAA4d801+vRndlvMZP18IBgSaXbt/C2hV5JdqY6t5Tuqb/QBm7oyPseHW30F9/qy3+ ayCpLWpTmv6eNqWzBagEKcrY6sqAG6JpS3mz4CDVn4L9ZkeonY4nFq6YSq36hSLYV3A4 So62YJ2AqxR4YZUctARhhaUL//M2mEhRj0e1pWqftLMmk5mY4oU5PD8IBug9eFWLb4Ta /Q2e3VmoEV1ztlRUikUdsoASsYIkw04+GZkNfyOhNGLzxrPCm42qiNcRwHjydU7Osa+o nZK9xhTs+jClTw1KLYLsmawghTfFEVdKfN/pZjTY3lv8OsjpX21x+5DBFUe9Ac2xR8db u7wg== X-Gm-Message-State: AJaThX6OS8+0+LRps+oNNXF5ZhRsVpR92D71RtckwWykf5P469w/IrLA gbBxzqVofOQV2AiGd/GyOxYfKw== X-Google-Smtp-Source: AGs4zMbs6oijZjrA8EWtdCTduDN8T4zFBlikQ62X1Tu0iEtuUobjGhD9MljtvWv1RUKcVxUd/FVQkg== X-Received: by 10.80.170.136 with SMTP id q8mr43920013edc.134.1512644076679; Thu, 07 Dec 2017 02:54:36 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id t23sm2233671edb.70.2017.12.07.02.54.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Dec 2017 02:54:35 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v7 5/8] KVM: arm/arm64: Support a vgic interrupt line level sample function Date: Thu, 7 Dec 2017 11:54:15 +0100 Message-Id: <20171207105418.22428-6-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171207105418.22428-1-christoffer.dall@linaro.org> References: <20171207105418.22428-1-christoffer.dall@linaro.org> 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: kvm@vger.kernel.org, Marc Zyngier , Andre Przywara , Eric Auger , 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. Reviewed-by: Marc Zyngier Signed-off-by: Christoffer Dall Reviewed-by: Eric Auger --- 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);