From patchwork Mon Apr 3 20:28:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9660577 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 2C83E6032D for ; Mon, 3 Apr 2017 20:29:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D03728403 for ; Mon, 3 Apr 2017 20:29:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11CD92841C; Mon, 3 Apr 2017 20:29:19 +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, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6C8D628403 for ; Mon, 3 Apr 2017 20:29:18 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cv8Yy-0005I2-4W; Mon, 03 Apr 2017 20:26:56 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cv8Yw-0005Ao-P2 for xen-devel@lists.xenproject.org; Mon, 03 Apr 2017 20:26:54 +0000 Received: from [85.158.143.35] by server-8.bemta-6.messagelabs.com id C6/6D-03648-E00B2E85; Mon, 03 Apr 2017 20:26:54 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRWlGSWpSXmKPExsVysyfVTZd3w6M Ig+PzJS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oz2qS1MBQ9dK9oXzWZtYNxq1sXIxSEksIlR 4vSSdWwQznJGic0Xelm7GDk52AR0JXbcfM0MYosIhEo8XfAdzGYWUJLYf/YaYxcjB4ewgKXEl lVGIGEWAVWJl+/OgZXwClhLLO1oYAOxJQTkJBrO3weLcwLFWz8eZQSxhQSsJCY8bGKawMi9gJ FhFaNGcWpRWWqRrrGBXlJRZnpGSW5iZo6uoYGZXm5qcXFiempOYlKxXnJ+7iZGoH8ZgGAH49+ 1gYcYJTmYlER51Sc9ihDiS8pPqcxILM6ILyrNSS0+xCjDwaEkwXtsHVBOsCg1PbUiLTMHGGgw aQkOHiUR3s0gad7igsTc4sx0iNQpRkUpcd4MkIQASCKjNA+uDRbclxhlpYR5GYEOEeIpSC3Kz SxBlX/FKM7BqCTMewNkCk9mXgnc9FdAi5mAFj+58xBkcUkiQkqqgdFpwmnjkPmBv8tE+ldFez BUmkZXz726XUf48GqXSnX7gkBmNlcJjbed/v8Uk5af7JnXymF5KdHmw9rSEynl6RtCcwTaD/e d/aXPW3FKjSe9+YLcb/HU9zPVCiY8T2V/W/6fsWZ1m5fIsY0T7CuKtOcvr5/CY+wizHA+/v7V /gm6z302LnZUUGIpzkg01GIuKk4EANBuE3tpAgAA X-Env-Sender: andre.przywara@arm.com X-Msg-Ref: server-14.tower-21.messagelabs.com!1491251212!55248975!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 54780 invoked from network); 3 Apr 2017 20:26:53 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-14.tower-21.messagelabs.com with SMTP; 3 Apr 2017 20:26:53 -0000 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 8BE7C80D; Mon, 3 Apr 2017 13:26:52 -0700 (PDT) Received: from e104803-lin.lan (unknown [10.1.207.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C911D3F4FF; Mon, 3 Apr 2017 13:26:51 -0700 (PDT) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Mon, 3 Apr 2017 21:28:22 +0100 Message-Id: <20170403202829.7278-21-andre.przywara@arm.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170403202829.7278-1-andre.przywara@arm.com> References: <20170403202829.7278-1-andre.przywara@arm.com> Cc: xen-devel@lists.xenproject.org Subject: [Xen-devel] [PATCH v4 20/27] ARM: vITS: handle MAPTI command X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The MAPTI commands associates a DeviceID/EventID pair with a LPI/CPU pair and actually instantiates LPI interrupts. We connect the already allocated host LPI to this virtual LPI, so that any triggering IRQ on the host can be quickly forwarded to a guest. Beside entering the VCPU and the virtual LPI number in the respective host LPI entry, we also initialize and add the already allocated struct pending_irq to our radix tree, so that we can now easily find it by its virtual LPI number. This exports the vgic_init_pending_irq() function for that purpose. As write_itte() is now eventually used, we can now add the static tag. Signed-off-by: Andre Przywara --- xen/arch/arm/gic-v3-its.c | 70 ++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/gic-v3-lpi.c | 18 +++++++++++ xen/arch/arm/vgic-v3-its.c | 36 +++++++++++++++++++-- xen/arch/arm/vgic.c | 2 +- xen/include/asm-arm/gic_v3_its.h | 6 ++++ xen/include/asm-arm/vgic.h | 1 + 6 files changed, 130 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/gic-v3-its.c b/xen/arch/arm/gic-v3-its.c index 880c7fc..3bc1e58 100644 --- a/xen/arch/arm/gic-v3-its.c +++ b/xen/arch/arm/gic-v3-its.c @@ -765,6 +765,76 @@ void gicv3_its_unmap_all_devices(struct domain *d) spin_unlock(&d->arch.vgic.its_devices_lock); } +/* Must be called with the its_device_lock held. */ +static struct its_devices *get_its_device(struct domain *d, paddr_t doorbell, + uint32_t devid) +{ + struct rb_node *node = d->arch.vgic.its_devices.rb_node; + struct its_devices *dev; + + while (node) + { + int cmp; + + dev = rb_entry(node, struct its_devices, rbnode); + cmp = compare_its_guest_devices(dev, doorbell, devid); + + if ( !cmp ) + return dev; + + if ( cmp > 0 ) + node = node->rb_left; + else + node = node->rb_right; + } + + return NULL; +} + +static uint32_t get_host_lpi(struct its_devices *dev, uint32_t eventid) +{ + uint32_t host_lpi = 0; + + if ( dev && (eventid < dev->eventids) ) + host_lpi = dev->host_lpi_blocks[eventid / LPI_BLOCK] + + (eventid % LPI_BLOCK); + + return host_lpi; +} + +/* + * Connects the event ID for an already assigned device to the given VCPU/vLPI + * pair. The corresponding physical LPI is already mapped on the host side + * (when assigning the physical device to the guest), so we just connect the + * target VCPU/vLPI pair to that interrupt to inject it properly if it fires. + */ +struct pending_irq *gicv3_assign_guest_event(struct domain *d, + paddr_t doorbell_address, + uint32_t vdevid, uint32_t veventid, + struct vcpu *v, uint32_t virt_lpi) +{ + struct its_devices *dev; + struct pending_irq *pirq = NULL; + uint32_t host_lpi = 0; + + spin_lock(&d->arch.vgic.its_devices_lock); + dev = get_its_device(d, doorbell_address, vdevid); + if ( dev ) + { + host_lpi = get_host_lpi(dev, veventid); + pirq = &dev->pend_irqs[veventid]; + } + spin_unlock(&d->arch.vgic.its_devices_lock); + + if ( !host_lpi || !pirq ) + return NULL; + + gicv3_lpi_update_host_entry(host_lpi, d->domain_id, + v ? v->vcpu_id : -1, virt_lpi); + + return pirq; +} + /* Scan the DT for any ITS nodes and create a list of host ITSes out of it. */ void gicv3_its_dt_init(const struct dt_device_node *node) { diff --git a/xen/arch/arm/gic-v3-lpi.c b/xen/arch/arm/gic-v3-lpi.c index a86fcf5..067ccb2 100644 --- a/xen/arch/arm/gic-v3-lpi.c +++ b/xen/arch/arm/gic-v3-lpi.c @@ -188,6 +188,24 @@ void do_LPI(unsigned int lpi) rcu_unlock_domain(d); } +void gicv3_lpi_update_host_entry(uint32_t host_lpi, int domain_id, + unsigned int vcpu_id, uint32_t virt_lpi) +{ + union host_lpi *hlpip, hlpi; + + ASSERT(host_lpi >= LPI_OFFSET); + + host_lpi -= LPI_OFFSET; + + hlpip = &lpi_data.host_lpis[host_lpi / HOST_LPIS_PER_PAGE][host_lpi % HOST_LPIS_PER_PAGE]; + + hlpi.virt_lpi = virt_lpi; + hlpi.dom_id = domain_id; + hlpi.vcpu_id = vcpu_id; + + write_u64_atomic(&hlpip->data, hlpi.data); +} + static int gicv3_lpi_allocate_pendtable(uint64_t *reg) { uint64_t val; diff --git a/xen/arch/arm/vgic-v3-its.c b/xen/arch/arm/vgic-v3-its.c index 0e636de..e9a309d 100644 --- a/xen/arch/arm/vgic-v3-its.c +++ b/xen/arch/arm/vgic-v3-its.c @@ -264,8 +264,8 @@ static bool read_itte(struct virt_its *its, uint32_t devid, uint32_t evid, * This function takes care of the locking by taking the its_lock itself, so * a caller shall not hold this. Upon returning, the lock is dropped again. */ -bool write_itte(struct virt_its *its, uint32_t devid, uint32_t evid, - uint32_t collid, uint32_t vlpi, struct vcpu **vcpu) +static bool write_itte(struct virt_its *its, uint32_t devid, uint32_t evid, + uint32_t collid, uint32_t vlpi, struct vcpu **vcpu) { struct vits_itte *itte; @@ -427,6 +427,34 @@ static int its_handle_mapd(struct virt_its *its, uint64_t *cmdptr) return ret; } +static int its_handle_mapti(struct virt_its *its, uint64_t *cmdptr) +{ + uint32_t devid = its_cmd_get_deviceid(cmdptr); + uint32_t eventid = its_cmd_get_id(cmdptr); + uint32_t intid = its_cmd_get_physical_id(cmdptr); + uint16_t collid = its_cmd_get_collection(cmdptr); + struct pending_irq *pirq; + struct vcpu *vcpu; + + if ( its_cmd_get_command(cmdptr) == GITS_CMD_MAPI ) + intid = eventid; + + pirq = gicv3_assign_guest_event(its->d, its->doorbell_address, + devid, eventid, vcpu, intid); + if ( !pirq ) + return -1; + + vgic_init_pending_irq(pirq, intid); + write_lock(&its->d->arch.vgic.pend_lpi_tree_lock); + radix_tree_insert(&its->d->arch.vgic.pend_lpi_tree, intid, pirq); + write_unlock(&its->d->arch.vgic.pend_lpi_tree_lock); + + if ( !write_itte(its, devid, eventid, collid, intid, &vcpu) ) + return -1; + + return 0; +} + #define ITS_CMD_BUFFER_SIZE(baser) ((((baser) & 0xff) + 1) << 12) static int vgic_its_handle_cmds(struct domain *d, struct virt_its *its, @@ -476,6 +504,10 @@ static int vgic_its_handle_cmds(struct domain *d, struct virt_its *its, case GITS_CMD_MAPD: ret = its_handle_mapd(its, cmdptr); break; + case GITS_CMD_MAPI: + case GITS_CMD_MAPTI: + ret = its_handle_mapti(its, cmdptr); + break; case GITS_CMD_SYNC: /* We handle ITS commands synchronously, so we ignore SYNC. */ break; diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c index 4720f46..3cab790 100644 --- a/xen/arch/arm/vgic.c +++ b/xen/arch/arm/vgic.c @@ -60,7 +60,7 @@ struct vgic_irq_rank *vgic_rank_irq(struct vcpu *v, unsigned int irq) return vgic_get_rank(v, rank); } -static void vgic_init_pending_irq(struct pending_irq *p, unsigned int virq) +void vgic_init_pending_irq(struct pending_irq *p, unsigned int virq) { INIT_LIST_HEAD(&p->inflight); INIT_LIST_HEAD(&p->lr_queue); diff --git a/xen/include/asm-arm/gic_v3_its.h b/xen/include/asm-arm/gic_v3_its.h index b2a9586..eeffd58 100644 --- a/xen/include/asm-arm/gic_v3_its.h +++ b/xen/include/asm-arm/gic_v3_its.h @@ -166,6 +166,12 @@ void gicv3_its_unmap_all_devices(struct domain *d); int gicv3_allocate_host_lpi_block(struct domain *d, uint32_t *first_lpi); void gicv3_free_host_lpi_block(uint32_t first_lpi); +struct pending_irq *gicv3_assign_guest_event(struct domain *d, paddr_t doorbell, + uint32_t devid, uint32_t eventid, + struct vcpu *v, uint32_t virt_lpi); +void gicv3_lpi_update_host_entry(uint32_t host_lpi, int domain_id, + unsigned int vcpu_id, uint32_t virt_lpi); + #else static LIST_HEAD(host_its_list); diff --git a/xen/include/asm-arm/vgic.h b/xen/include/asm-arm/vgic.h index b5ae3e9..8c7d896 100644 --- a/xen/include/asm-arm/vgic.h +++ b/xen/include/asm-arm/vgic.h @@ -300,6 +300,7 @@ extern struct vcpu *vgic_get_target_vcpu(struct vcpu *v, unsigned int virq); extern void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int virq); extern void vgic_vcpu_inject_spi(struct domain *d, unsigned int virq); extern void vgic_clear_pending_irqs(struct vcpu *v); +extern void vgic_init_pending_irq(struct pending_irq *p, unsigned int virq); extern struct pending_irq *irq_to_pending(struct vcpu *v, unsigned int irq); extern struct pending_irq *spi_to_pending(struct domain *d, unsigned int irq); extern struct pending_irq *lpi_to_pending(struct domain *d, unsigned int irq);