From patchwork Fri Jun 3 14:02:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9153137 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 28C236074E for ; Fri, 3 Jun 2016 14:02:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B4D728328 for ; Fri, 3 Jun 2016 14:02:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1051B28333; Fri, 3 Jun 2016 14:02:48 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 7709F28328 for ; Fri, 3 Jun 2016 14:02:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932914AbcFCOCm (ORCPT ); Fri, 3 Jun 2016 10:02:42 -0400 Received: from foss.arm.com ([217.140.101.70]:52965 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932897AbcFCOCk (ORCPT ); Fri, 3 Jun 2016 10:02:40 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 35428959; Fri, 3 Jun 2016 07:03:11 -0700 (PDT) Received: from e104803-lin.lan (unknown [10.1.203.153]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E07613F21A; Fri, 3 Jun 2016 07:02:38 -0700 (PDT) From: Andre Przywara To: Marc Zyngier , Christoffer Dall Cc: Eric Auger , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 09/13] KVM: arm64: connect LPIs to the VGIC emulation Date: Fri, 3 Jun 2016 15:02:48 +0100 Message-Id: <1464962572-3925-10-git-send-email-andre.przywara@arm.com> X-Mailer: git-send-email 2.8.2 In-Reply-To: <1464962572-3925-1-git-send-email-andre.przywara@arm.com> References: <1464962572-3925-1-git-send-email-andre.przywara@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP LPIs are dynamically created (mapped) at guest runtime and their actual numbers can be quite high, but is mostly assigned using a very sparse allocation scheme. So arrays are not an ideal data structure to hold the information. We use our equivalent of the "Interrupt Translation Table Entry" (ITTE) to hold the vgic_irq struct for a virtual LPI embedded in in the ITTE. Connect the VGIC core code via an accessor function to help it get the struct vgic_irq for a certain LPI. Signed-off-by: Andre Przywara --- virt/kvm/arm/vgic/vgic-its.c | 34 ++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 2 +- virt/kvm/arm/vgic/vgic.h | 6 ++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index 3ec12ef..4f248ef 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -68,11 +68,29 @@ struct its_collection { struct its_itte { struct list_head itte_list; + struct vgic_irq irq; struct its_collection *collection; u32 lpi; u32 event_id; }; +/* To be used as an iterator this macro misses the enclosing parentheses */ +#define for_each_lpi(dev, itte, its) \ + list_for_each_entry(dev, &(its)->device_list, dev_list) \ + list_for_each_entry(itte, &(dev)->itt, itte_list) + +static struct its_itte *find_itte_by_lpi(struct vgic_its *its, int lpi) +{ + struct its_device *device; + struct its_itte *itte; + + for_each_lpi(device, itte, its) { + if (itte->lpi == lpi) + return itte; + } + return NULL; +} + #define BASER_BASE_ADDRESS(x) ((x) & 0xfffffffff000ULL) #define ITS_FRAME(addr) ((addr) & ~(SZ_64K - 1)) @@ -158,6 +176,22 @@ static unsigned long vgic_mmio_read_its_idregs(struct kvm_vcpu *vcpu, return 0; } +struct vgic_irq *vgic_its_get_lpi(struct kvm *kvm, u32 intid) +{ + struct vgic_its *its; + struct its_itte *itte; + + list_for_each_entry(its, &kvm->arch.vits_list, its_list) { + itte = find_itte_by_lpi(its, intid); + if (!itte) + continue; + + return &itte->irq; + } + + return NULL; +} + static void its_free_itte(struct its_itte *itte) { list_del(&itte->itte_list); diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index 69b61ab..6812ff1 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -58,7 +58,7 @@ struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu, /* LPIs are not yet covered */ if (intid >= VGIC_MIN_LPI) - return NULL; + return vgic_its_get_lpi(kvm, intid); WARN(1, "Looking up struct vgic_irq for reserved INTID"); return NULL; diff --git a/virt/kvm/arm/vgic/vgic.h b/virt/kvm/arm/vgic/vgic.h index 66578d2..6fecd70 100644 --- a/virt/kvm/arm/vgic/vgic.h +++ b/virt/kvm/arm/vgic/vgic.h @@ -78,6 +78,7 @@ bool vgic_has_its(struct kvm *kvm); int vits_init(struct kvm *kvm, struct vgic_its *its); void vits_destroy(struct kvm *kvm, struct vgic_its *its); int kvm_vgic_register_its_device(void); +struct vgic_irq *vgic_its_get_lpi(struct kvm *kvm, u32 intid); #else static inline void vgic_v3_process_maintenance(struct kvm_vcpu *vcpu) { @@ -148,6 +149,11 @@ static int kvm_vgic_register_its_device(void) { return -ENODEV; } + +static inline struct vgic_irq *vgic_its_get_lpi(struct kvm *kvm, u32 intid) +{ + return NULL; +} #endif int kvm_register_vgic_device(unsigned long type);