From patchwork Thu Mar 16 11:20:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9627947 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 9486A6048C for ; Thu, 16 Mar 2017 11:20:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87F40285B5 for ; Thu, 16 Mar 2017 11:20:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CCFD28604; Thu, 16 Mar 2017 11:20:51 +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 13A45285B5 for ; Thu, 16 Mar 2017 11:20:51 +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 1coTRI-00008P-8M; Thu, 16 Mar 2017 11:19:28 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coTRG-0008UD-8Y for xen-devel@lists.xenproject.org; Thu, 16 Mar 2017 11:19:26 +0000 Received: from [85.158.139.211] by server-5.bemta-5.messagelabs.com id 1E/9E-29481-DB47AC85; Thu, 16 Mar 2017 11:19:25 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRWlGSWpSXmKPExsVysyfVTXdPyak IgwdtFhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bqh3uZCjp0Kx4+28vSwLhdoYuRi0NIYDOj xKUHDUwQznJGicPNL1m7GDk52AR0JXbcfM0MYosIhErM+fkIzGYWqJS4+GE/G4gtLGAlMW/eM 7A4i4CqxI5tD1hAbF4BG4nT2+6wg9gSAnISDefvg9VwAsU7Tu4B6xUSsJb4fPQz+wRG7gWMDK sYNYpTi8pSi3SNDfSSijLTM0pyEzNzdA0NTPVyU4uLE9NTcxKTivWS83M3MQI9XM/AwLiDccI qv0OMkhxMSqK8KoInIoT4kvJTKjMSizPii0pzUosPMcpwcChJ8LqUAOUEi1LTUyvSMnOAoQaT luDgURLh3QSS5i0uSMwtzkyHSJ1iVJQS51UGSQiAJDJK8+DaYOF9iVFWSpiXkYGBQYinILUoN 7MEVf4VozgHo5Iw7zaQKTyZeSVw018BLWYCWpz48wjI4pJEhJRUA+NGtRrZ2IsOu5/MvMS7zX /WvM95M44dqg1Xaap1qjVUav3DfPzan2MTT0bvWc++ZsuDuzoLS649/C64qmIvn/HPxgzx7z1 XDx/bMEFIwSXZbIr95T/B1sbuMQbXQp3iAlcs8T3zUp1T3O5fxrIvX9s5PmiVveHcHrRbZl3o J8EHt6VPRlzkLPdXYinOSDTUYi4qTgQALoDg62oCAAA= X-Env-Sender: andre.przywara@arm.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1489663164!71983675!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 27423 invoked from network); 16 Mar 2017 11:19:24 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-11.tower-206.messagelabs.com with SMTP; 16 Mar 2017 11:19:24 -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 F1ACD150C; Thu, 16 Mar 2017 04:19:23 -0700 (PDT) Received: from e104803-lin.lan (unknown [10.1.207.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EA9EF3F5C9; Thu, 16 Mar 2017 04:19:22 -0700 (PDT) From: Andre Przywara To: Stefano Stabellini , Julien Grall Date: Thu, 16 Mar 2017 11:20:30 +0000 Message-Id: <20170316112030.20419-28-andre.przywara@arm.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170316112030.20419-1-andre.przywara@arm.com> References: <20170316112030.20419-1-andre.przywara@arm.com> Cc: xen-devel@lists.xenproject.org, Shanker Donthineni , Vijay Kilari Subject: [Xen-devel] [PATCH v2 27/27] ARM: vGIC: advertise LPI support 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 To let a guest know about the availability of virtual LPIs, set the respective bits in the virtual GIC registers and let a guest control the LPI enable bit. Only report the LPI capability if the host has initialized at least one ITS. Signed-off-by: Andre Przywara --- xen/arch/arm/vgic-v3.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/vgic-v3.c b/xen/arch/arm/vgic-v3.c index 8faec95..6d5b7f4 100644 --- a/xen/arch/arm/vgic-v3.c +++ b/xen/arch/arm/vgic-v3.c @@ -169,8 +169,10 @@ static int __vgic_v3_rdistr_rd_mmio_read(struct vcpu *v, mmio_info_t *info, switch ( gicr_reg ) { case VREG32(GICR_CTLR): - /* We have not implemented LPI's, read zero */ - goto read_as_zero_32; + if ( dabt.size != DABT_WORD ) goto bad_width; + *r = vgic_reg32_extract(!!(v->arch.vgic.flags & VGIC_V3_LPIS_ENABLED), + info); + return 1; case VREG32(GICR_IIDR): if ( dabt.size != DABT_WORD ) goto bad_width; @@ -182,16 +184,19 @@ static int __vgic_v3_rdistr_rd_mmio_read(struct vcpu *v, mmio_info_t *info, uint64_t typer, aff; if ( !vgic_reg64_check_access(dabt) ) goto bad_width; - /* TBD: Update processor id in [23:8] when ITS support is added */ aff = (MPIDR_AFFINITY_LEVEL(v->arch.vmpidr, 3) << 56 | MPIDR_AFFINITY_LEVEL(v->arch.vmpidr, 2) << 48 | MPIDR_AFFINITY_LEVEL(v->arch.vmpidr, 1) << 40 | MPIDR_AFFINITY_LEVEL(v->arch.vmpidr, 0) << 32); typer = aff; + typer |= (v->vcpu_id & 0xffff) << 8; if ( v->arch.vgic.flags & VGIC_V3_RDIST_LAST ) typer |= GICR_TYPER_LAST; + if ( v->domain->arch.vgic.has_its ) + typer |= GICR_TYPER_PLPIS; + *r = vgic_reg64_extract(typer, info); return 1; @@ -502,6 +507,40 @@ bool vgic_can_inject_lpi(struct vcpu *vcpu, uint32_t vlpi) return false; } +static void vgic_vcpu_enable_lpis(struct vcpu *v) +{ + uint64_t reg = v->domain->arch.vgic.rdist_propbase; + unsigned int nr_lpis = BIT((reg & 0x1f) + 1) - LPI_OFFSET; + int nr_pages; + + /* The first VCPU to enable LPIs maps the property table. */ + if ( !v->domain->arch.vgic.proptable ) + { + v->domain->arch.vgic.nr_lpis = nr_lpis; + nr_pages = DIV_ROUND_UP(nr_lpis, PAGE_SIZE); + + get_guest_pages(v->domain, reg & GENMASK(51, 12), nr_pages); + v->domain->arch.vgic.proptable = map_guest_pages(v->domain, + reg & GENMASK(51, 12), + nr_pages); + printk("VGIC-v3: VCPU%d mapped %d pages for property table\n", + v->vcpu_id, nr_pages); + } + nr_pages = DIV_ROUND_UP(((nr_lpis + LPI_OFFSET) / 8), PAGE_SIZE); + reg = v->arch.vgic.rdist_pendbase; + + get_guest_pages(v->domain, reg & GENMASK(51, 12), nr_pages); + v->arch.vgic.pendtable = map_guest_pages(v->domain, + reg & GENMASK(51, 12), nr_pages); + + printk("VGIC-v3: VCPU%d mapped %d pages for pending table\n", + v->vcpu_id, nr_pages); + + v->arch.vgic.flags |= VGIC_V3_LPIS_ENABLED; + + printk("VGICv3: enabled %d LPIs for VCPU%d\n", nr_lpis, v->vcpu_id); +} + static int __vgic_v3_rdistr_rd_mmio_write(struct vcpu *v, mmio_info_t *info, uint32_t gicr_reg, register_t r) @@ -512,8 +551,18 @@ static int __vgic_v3_rdistr_rd_mmio_write(struct vcpu *v, mmio_info_t *info, switch ( gicr_reg ) { case VREG32(GICR_CTLR): - /* LPI's not implemented */ - goto write_ignore_32; + if ( dabt.size != DABT_WORD ) goto bad_width; + if ( !v->domain->arch.vgic.has_its ) + return 1; + + /* LPIs can only be enabled once, but never disabled again. */ + if ( !(r & GICR_CTLR_ENABLE_LPIS) || + (v->arch.vgic.flags & VGIC_V3_LPIS_ENABLED) ) + return 1; + + vgic_vcpu_enable_lpis(v); + + return 1; case VREG32(GICR_IIDR): /* RO */ @@ -1113,6 +1162,11 @@ static int vgic_v3_distr_mmio_read(struct vcpu *v, mmio_info_t *info, typer = ((ncpus - 1) << GICD_TYPE_CPUS_SHIFT | DIV_ROUND_UP(v->domain->arch.vgic.nr_spis, 32)); + if ( v->domain->arch.vgic.has_its ) + { + typer |= GICD_TYPE_LPIS; + irq_bits = 16; + } typer |= (irq_bits - 1) << GICD_TYPE_ID_BITS_SHIFT; *r = vgic_reg32_extract(typer, info); @@ -1729,6 +1783,30 @@ static int vgic_v3_domain_init(struct domain *d) static void vgic_v3_domain_free(struct domain *d) { + int nr_pages; + struct vcpu *v; + + if ( d->arch.vgic.proptable ) + { + nr_pages = DIV_ROUND_UP(d->arch.vgic.nr_lpis, PAGE_SIZE); + + unmap_guest_pages(d->arch.vgic.proptable, nr_pages); + put_guest_pages(d, d->arch.vgic.rdist_propbase & GENMASK(51, 12), + nr_pages); + printk("VGICv3: freeing PROPBASE for Domain%d\n", d->domain_id); + } + + nr_pages = DIV_ROUND_UP((d->arch.vgic.nr_lpis + LPI_OFFSET) / 8, PAGE_SIZE); + for_each_vcpu(d, v) + { + if ( !v->arch.vgic.pendtable ) + continue; + + unmap_guest_pages(v->arch.vgic.pendtable, nr_pages); + put_guest_pages(d, v->arch.vgic.rdist_pendbase & GENMASK(51, 12), + nr_pages); + printk("VGICv3: freeing PENDBASE for VCPU%d\n", v->vcpu_id); + } xfree(d->arch.vgic.rdist_regions); }