From patchwork Mon Oct 1 16:42:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 147921 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp4131078lji; Mon, 1 Oct 2018 09:44:47 -0700 (PDT) X-Google-Smtp-Source: ACcGV63DWKXPL+HM2vKtyrK+Ym/i0co3kz8bbdmWyfc5q8mzk3LbXkiLd1+VlyKZU0gYIRE66bUN X-Received: by 2002:a6b:b7d5:: with SMTP id h204-v6mr8422771iof.164.1538412287338; Mon, 01 Oct 2018 09:44:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538412287; cv=none; d=google.com; s=arc-20160816; b=GlpimfKVnBIGhp0jpfSGLisJvIUsnuCE4frPmliw3y9J2HdDdWrYGZFrhSR3sMkkrp zmGSu7EUVxlyCouh6X3f+zPe/zD+A2Yr9Cu3CgorsNasR+eNJqfc7YYT3M3D0nFCtGe9 QJlZ1QrjgQgC5G+JHEc+LBEhA4xT9mk2fJ6fS0cdiTTKb1/OZp0Jk9LReRfRSdGq3nNl AfKCcbOdCgVbttLnPfuzB/5EAJPk5hdcD4uNYxHKBdQf7HQ9580eF++fTPlPX8YheYt+ aCpK0kAZRgPnptmv/KF3z1LhV7JG3nxMGma5VZnRnPHN3kEC+abjEbYe7/ofPH8nTDdk +VoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=Tyrazoy1zeFyOV+gpOi1ePZQ8Va2MNFVlvDNGvJDRGc=; b=Ved3dioFwrI0otgmqSgIUK4iH5cA3IFxFyjcdBqcNR4zUL7Ao+1UanlrHzo72FAtpl SMa6KnOe00mplqhOL7EKh2Hnl+DqUa39Qy3mnYJMjwPFmxFO4soAyDYdq7m/hzCqU8yv 6+BYGe2kyDAr3nLl4dxwA8oXTvmZb63n398PnoViVSNuda2khGCyWRd12ahCigSLG7ty 2sS6BC6nVZHbVzegC7LS0oTvd/QYEGcS1UM09FYGFEVDQBGGgbGV4AeOUO0bxErjOoQO mszXf2XcnXQkTqsveeyYi9wlG/dLBCAAFktuJRXNnc8P9GE7MiJQMWNVX7ElNdt58ltD a25g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id p205-v6si7030140itc.136.2018.10.01.09.44.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 09:44:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1g71HM-0007VN-Ux; Mon, 01 Oct 2018 16:42:40 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1g71HL-0007V5-1q for xen-devel@lists.xenproject.org; Mon, 01 Oct 2018 16:42:39 +0000 X-Inumbo-ID: 2b9e27fc-c599-11e8-a6a9-d7ebe60f679a Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas1.inumbo.com (Halon) with ESMTP id 2b9e27fc-c599-11e8-a6a9-d7ebe60f679a; Mon, 01 Oct 2018 16:43:48 +0000 (UTC) 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 7FD9215AD; Mon, 1 Oct 2018 09:42:37 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.emea.arm.com [10.4.12.35]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 67F573F5D3; Mon, 1 Oct 2018 09:42:36 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 1 Oct 2018 17:42:27 +0100 Message-Id: <20181001164227.6562-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181001164227.6562-1-julien.grall@arm.com> References: <20181001164227.6562-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v2 2/2] xen/arm: vgic-v3: Don't create empty re-distributor regions X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: andre.przywara@arm.com, Julien Grall , sstabellini@kernel.org, shameerali.kolothum.thodi@huawei.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, Xen is assuming the hardware domain will have the same number of re-distributor regions as the host. However, as the number of CPUs or the stride (e.g on GICv4) may be different we end up exposing regions which does not contain any re-distributors. When booting, Linux will go through all the re-distributor region to check whether a property (e.g vPLIs) is available accross all the re-distributors. This will result to a data abort on empty regions because there are no underlying re-distributor. So we need to limit the number of regions exposed to the hardware domain. The code reworked to only expose the minimun number of regions required by the hardware domain. It is assumed the regions will be populated starting from the first one. Lastly, rename vgic_v3_rdist_count to reflect the value return by the helper. Reported-by: Shameerali Kolothum Thodi Signed-off-by: Julien Grall Tested-by: Shameer Kolothum Reviewed-by: Stefano Stabellini --- Changes in v2: - Rename vgic_v3_rdist_count to vgic_v3_max_rdist_count - Fixup #re-distributors - Fix typoes - Add Shameer's tested tag --- xen/arch/arm/gic-v3.c | 14 +++++++++++--- xen/arch/arm/vgic-v3.c | 21 ++++++++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/gic-v3.c b/xen/arch/arm/gic-v3.c index c98a163ee7..2c1454f425 100644 --- a/xen/arch/arm/gic-v3.c +++ b/xen/arch/arm/gic-v3.c @@ -1265,7 +1265,8 @@ static int gicv3_make_hwdom_dt_node(const struct domain *d, if ( res ) return res; - res = fdt_property_cell(fdt, "#redistributor-regions", gicv3.rdist_count); + res = fdt_property_cell(fdt, "#redistributor-regions", + d->arch.vgic.nr_regions); if ( res ) return res; @@ -1274,8 +1275,10 @@ static int gicv3_make_hwdom_dt_node(const struct domain *d, * GIC has two memory regions: Distributor + rdist regions * CPU interface and virtual cpu interfaces accessesed as System registers * So cells are created only for Distributor and rdist regions + * The hardware domain may not use all the regions. So only copy + * what is necessary. */ - new_len = new_len * (gicv3.rdist_count + 1); + new_len = new_len * (d->arch.vgic.nr_regions + 1); hw_reg = dt_get_property(gic, "reg", &len); if ( !hw_reg ) @@ -1466,6 +1469,7 @@ static inline bool gic_dist_supports_dvis(void) } static int gicv3_make_hwdom_madt(const struct domain *d, u32 offset) + { struct acpi_subtable_header *header; struct acpi_madt_generic_interrupt *host_gicc, *gicc; @@ -1503,7 +1507,11 @@ static int gicv3_make_hwdom_madt(const struct domain *d, u32 offset) /* Add Generic Redistributor */ size = sizeof(struct acpi_madt_generic_redistributor); - for ( i = 0; i < gicv3.rdist_count; i++ ) + /* + * The hardware domain may not used all the regions. So only copy + * what is necessary. + */ + for ( i = 0; i < d->arch.vgic.nr_regions; i++ ) { gicr = (struct acpi_madt_generic_redistributor *)(base_ptr + table_len); gicr->header.type = ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR; diff --git a/xen/arch/arm/vgic-v3.c b/xen/arch/arm/vgic-v3.c index df1bab3a35..efe824c6fb 100644 --- a/xen/arch/arm/vgic-v3.c +++ b/xen/arch/arm/vgic-v3.c @@ -1640,7 +1640,11 @@ static int vgic_v3_vcpu_init(struct vcpu *v) return 0; } -static inline unsigned int vgic_v3_rdist_count(struct domain *d) +/* + * Return the maximum number possible of re-distributor regions for + * a given domain. + */ +static inline unsigned int vgic_v3_max_rdist_count(struct domain *d) { /* * Normally there is only one GICv3 redistributor region. @@ -1662,7 +1666,7 @@ static int vgic_v3_real_domain_init(struct domain *d) int rdist_count, i, ret; /* Allocate memory for Re-distributor regions */ - rdist_count = vgic_v3_rdist_count(d); + rdist_count = vgic_v3_max_rdist_count(d); rdist_regions = xzalloc_array(struct vgic_rdist_region, rdist_count); if ( !rdist_regions ) @@ -1695,8 +1699,19 @@ static int vgic_v3_real_domain_init(struct domain *d) d->arch.vgic.rdist_regions[i].first_cpu = first_cpu; first_cpu += size / GICV3_GICR_SIZE; + + if ( first_cpu >= d->max_vcpus ) + break; } + /* + * The hardware domain may not use all the re-distributors + * regions (e.g when the number of vCPUs does not match the + * number of pCPUs). Update the number of regions to avoid + * exposing unused region as they will not get emulated. + */ + d->arch.vgic.nr_regions = i + 1; + d->arch.vgic.intid_bits = vgic_v3_hw.intid_bits; } else @@ -1825,7 +1840,7 @@ int vgic_v3_init(struct domain *d, int *mmio_count) } /* GICD region + number of Redistributors */ - *mmio_count = vgic_v3_rdist_count(d) + 1; + *mmio_count = vgic_v3_max_rdist_count(d) + 1; /* one region per ITS */ *mmio_count += vgic_v3_its_count(d);