From patchwork Thu May 11 17:53:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9722633 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 E8F376031B for ; Thu, 11 May 2017 17:53:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E89DC286D0 for ; Thu, 11 May 2017 17:53:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD778286E5; Thu, 11 May 2017 17:53:28 +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 6889B286D0 for ; Thu, 11 May 2017 17:53:28 +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 1d8sFr-0000wY-Kh; Thu, 11 May 2017 17:51:59 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d8sFq-0000sQ-1m for xen-devel@lists.xenproject.org; Thu, 11 May 2017 17:51:58 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id FA/66-03920-DB4A4195; Thu, 11 May 2017 17:51:57 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRWlGSWpSXmKPExsVysyfVTXfPEpF Ig8O7dCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozlN60KJhtUTFixja2BsVu1i5GLQ0hgM6PE /86dzBDOckaJ7zsPM3UxcnKwCehK7Lj5mhnEFhEIlXi64DtYEbPAGkaJc4t+soEkhAUsJGZ82 cAOYrMIqEpcfD8HrIFXwFpi17LPLCC2hICcRMP5+2BxTqD4kumzwOJCAlYSu3afZp3AyL2AkW EVo3pxalFZapGupV5SUWZ6RkluYmaOrqGBmV5uanFxYnpqTmJSsV5yfu4mRqB/GYBgB+PdTQG HGCU5mJREeRknikQK8SXlp1RmJBZnxBeV5qQWH2KU4eBQkuC1B4aLkGBRanpqRVpmDjDQYNIS HDxKIrz3FwOleYsLEnOLM9MhUqcYFaXEeQVB+gRAEhmleXBtsOC+xCgrJczLCHSIEE9BalFuZ gmq/CtGcQ5GJWFeY5ApPJl5JXDTXwEtZgJa3P9HGGRxSSJCSqqBccr12ZWiNUd7+QO+yds5ZA vEftCfanQ/5Ndt5cqYqXPfPr+5zE3F8/+2o37/H57efM8rqlHTpv+qZrFqFLeS3vqAZdfiHIv +F+pVTLspGn1ATJthyRlbSRYul9jck37Z5bMj18b+v2x089+vh1skrM/KXTv1bGpoQS73PN1J 8WzP3rxf5FZzXomlOCPRUIu5qDgRAA34sXdpAgAA X-Env-Sender: andre.przywara@arm.com X-Msg-Ref: server-15.tower-27.messagelabs.com!1494525116!48806459!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.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 16411 invoked from network); 11 May 2017 17:51:56 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-15.tower-27.messagelabs.com with SMTP; 11 May 2017 17:51:56 -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 D32621B95; Thu, 11 May 2017 10:51:55 -0700 (PDT) Received: from e104803-lin.lan (unknown [10.1.207.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8BE513F4FF; Thu, 11 May 2017 10:51:54 -0700 (PDT) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Thu, 11 May 2017 18:53:34 +0100 Message-Id: <20170511175340.8448-23-andre.przywara@arm.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170511175340.8448-1-andre.przywara@arm.com> References: <20170511175340.8448-1-andre.przywara@arm.com> Cc: xen-devel@lists.xenproject.org, Vijaya Kumar K , Vijay Kilari , Shanker Donthineni Subject: [Xen-devel] [PATCH v9 22/28] ARM: vITS: handle MOVI 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 MOVI command moves the interrupt affinity from one redistributor (read: VCPU) to another. For now migration of "live" LPIs is not yet implemented, but we store the changed affinity in the host LPI structure and in our virtual ITTE. Signed-off-by: Andre Przywara --- xen/arch/arm/gic-v3-its.c | 30 ++++++++++++++++++++ xen/arch/arm/gic-v3-lpi.c | 15 ++++++++++ xen/arch/arm/vgic-v3-its.c | 59 ++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/gic_v3_its.h | 4 +++ 4 files changed, 108 insertions(+) diff --git a/xen/arch/arm/gic-v3-its.c b/xen/arch/arm/gic-v3-its.c index 8a50f7d..f00597e 100644 --- a/xen/arch/arm/gic-v3-its.c +++ b/xen/arch/arm/gic-v3-its.c @@ -915,6 +915,36 @@ struct pending_irq *gicv3_assign_guest_event(struct domain *d, return pirq; } +/* Changes the target VCPU for a given host LPI assigned to a domain. */ +int gicv3_lpi_change_vcpu(struct domain *d, paddr_t vdoorbell, + uint32_t vdevid, uint32_t veventid, + unsigned int vcpu_id) +{ + uint32_t host_lpi; + struct its_device *dev; + + spin_lock(&d->arch.vgic.its_devices_lock); + dev = get_its_device(d, vdoorbell, vdevid); + if ( dev ) + host_lpi = get_host_lpi(dev, veventid); + else + host_lpi = 0; + spin_unlock(&d->arch.vgic.its_devices_lock); + + if ( !host_lpi ) + return -ENOENT; + + /* + * TODO: This just changes the virtual affinity, the physical LPI + * still stays on the same physical CPU. + * Consider to move the physical affinity to the pCPU running the new + * vCPU. However this requires scheduling a host ITS command. + */ + gicv3_lpi_update_host_vcpuid(host_lpi, vcpu_id); + + return 0; +} + /* 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 d427539..6af5ad9 100644 --- a/xen/arch/arm/gic-v3-lpi.c +++ b/xen/arch/arm/gic-v3-lpi.c @@ -225,6 +225,21 @@ void gicv3_lpi_update_host_entry(uint32_t host_lpi, int domain_id, write_u64_atomic(&hlpip->data, hlpi.data); } +int gicv3_lpi_update_host_vcpuid(uint32_t host_lpi, unsigned int vcpu_id) +{ + union host_lpi *hlpip; + + 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]; + + write_u16_atomic(&hlpip->vcpu_id, vcpu_id); + + return 0; +} + 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 c5c0e5e..ef7c78f 100644 --- a/xen/arch/arm/vgic-v3-its.c +++ b/xen/arch/arm/vgic-v3-its.c @@ -670,6 +670,59 @@ out_remove_mapping: return ret; } +static int its_handle_movi(struct virt_its *its, uint64_t *cmdptr) +{ + uint32_t devid = its_cmd_get_deviceid(cmdptr); + uint32_t eventid = its_cmd_get_id(cmdptr); + uint16_t collid = its_cmd_get_collection(cmdptr); + unsigned long flags; + struct pending_irq *p; + struct vcpu *ovcpu, *nvcpu; + uint32_t vlpi; + int ret = -1; + + spin_lock(&its->its_lock); + /* Check for a mapped LPI and get the LPI number. */ + if ( !read_itte_locked(its, devid, eventid, &ovcpu, &vlpi) ) + goto out_unlock; + + if ( vlpi == INVALID_LPI ) + goto out_unlock; + + /* Check the new collection ID and get the new VCPU pointer */ + nvcpu = get_vcpu_from_collection(its, collid); + if ( !nvcpu ) + goto out_unlock; + + p = gicv3_its_get_event_pending_irq(its->d, its->doorbell_address, + devid, eventid); + if ( unlikely(!p) ) + goto out_unlock; + + spin_lock_irqsave(&ovcpu->arch.vgic.lock, flags); + + /* Update our cached vcpu_id in the pending_irq. */ + p->lpi_vcpu_id = nvcpu->vcpu_id; + + spin_unlock_irqrestore(&ovcpu->arch.vgic.lock, flags); + + /* Now store the new collection in the translation table. */ + if ( !write_itte_locked(its, devid, eventid, collid, vlpi, &nvcpu) ) + goto out_unlock; + + spin_unlock(&its->its_lock); + + /* TODO: lookup currently-in-guest virtual IRQs and migrate them? */ + + return gicv3_lpi_change_vcpu(its->d, its->doorbell_address, + devid, eventid, nvcpu->vcpu_id); + +out_unlock: + spin_unlock(&its->its_lock); + + return ret; +} + #define ITS_CMD_BUFFER_SIZE(baser) ((((baser) & 0xff) + 1) << 12) #define ITS_CMD_OFFSET(reg) ((reg) & GENMASK(19, 5)) @@ -715,6 +768,12 @@ static int vgic_its_handle_cmds(struct domain *d, struct virt_its *its) case GITS_CMD_MAPTI: ret = its_handle_mapti(its, command); break; + case GITS_CMD_MOVALL: + gdprintk(XENLOG_G_INFO, "vGITS: ignoring MOVALL command\n"); + break; + case GITS_CMD_MOVI: + ret = its_handle_movi(its, command); + break; case GITS_CMD_SYNC: /* We handle ITS commands synchronously, so we ignore SYNC. */ break; diff --git a/xen/include/asm-arm/gic_v3_its.h b/xen/include/asm-arm/gic_v3_its.h index 9c08cee..82d788c 100644 --- a/xen/include/asm-arm/gic_v3_its.h +++ b/xen/include/asm-arm/gic_v3_its.h @@ -178,8 +178,12 @@ int gicv3_remove_guest_event(struct domain *d, paddr_t vdoorbell_address, 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); +int gicv3_lpi_change_vcpu(struct domain *d, paddr_t doorbell, + uint32_t devid, uint32_t eventid, + unsigned int vcpu_id); void gicv3_lpi_update_host_entry(uint32_t host_lpi, int domain_id, unsigned int vcpu_id, uint32_t virt_lpi); +int gicv3_lpi_update_host_vcpuid(uint32_t host_lpi, unsigned int vcpu_id); #else