From patchwork Fri Nov 30 17:15:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 152574 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3907129ljp; Fri, 30 Nov 2018 09:17:26 -0800 (PST) X-Google-Smtp-Source: AFSGD/UUV8lAUp2VZKuRSW8aSgRVs5/XwdNXTHvmcralhHHDmChUtfGHme9pF1ozqmxjs7SEVMNr X-Received: by 2002:a81:34d3:: with SMTP id b202mr6488323ywa.241.1543598246011; Fri, 30 Nov 2018 09:17:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543598246; cv=none; d=google.com; s=arc-20160816; b=b7iR3C1CZIJYCPA7hym2RiFN7oYJKQi4pruCda3V64HWUznBAGbGWEjR73gp3CPGkV oDeyWdiA6MBbs2ua3rTWtCAFN8LH8Lr0FUuX8r1iOhsKyfXPn2f43y7xhcLQgBY/Z7bu h7z5BZYGBk3gQyzwYv2Z6bXwr8y6E4+kldcM3QnUNUTIQohUajBpjXVwgPGPFnQN8RoQ tqd++bWhDgvdzFHtM6wZ4spim1bS6uTA1Ha13Ox2ailY+3T4yCAmi+OFRPx5ZNnPjqOd uINgA+HB6qb34ylaWy23ILDs8nyLJtZBQjxWgSPZCOixpzXMRY5Xmn1JsTj/NkRHEc9m HYjQ== 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:message-id:date:to:from; bh=h0Nty3+IyYoMtpTWK0Pn26+IQTUTJzLZ4zY5coumKr8=; b=CIv6ehwnJo0AmwvfhAtmH4ZPfNFfGmcZLgzaB0PDlOKFyRTEz4/vM3PyaLzCZPu2K7 DeMDYbK0v6H+UIbhHMNy9j8q83rIgJyqveUqmzwqIibmyRQfkTP/8m9XxmB9dcDUemLc qwuGpNuYFLnhF8KiF4hjcKAiZvhZ7B6cjRr7UWrBcqqlr3Lubc9qcsLcl5mjBJ2JC+VH jh5c11tH0dKpPceG1eGgbyogR80THGC95IYhDYBApqgNf8EVseBuA6AiZYwssqSlCRtK MIMWFzo6X/3YnOmE+YTH4Ymk/JFWDwwIdbcuGDVPUQv6uRahKiIicAQqKDr2ELFH8EO7 4ZDQ== 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 i192si3455361ywg.284.2018.11.30.09.17.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Nov 2018 09:17:25 -0800 (PST) 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 1gSmOE-0002qZ-Qz; Fri, 30 Nov 2018 17:15:42 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1gSmOD-0002qS-7G for xen-devel@lists.xenproject.org; Fri, 30 Nov 2018 17:15:41 +0000 X-Inumbo-ID: 8f2c0edc-f4c3-11e8-9a16-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 8f2c0edc-f4c3-11e8-9a16-bc764e045a96; Fri, 30 Nov 2018 17:15:39 +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 17740EBD; Fri, 30 Nov 2018 09:15:39 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 074993F5A0; Fri, 30 Nov 2018 09:15:37 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 30 Nov 2018 17:15:33 +0000 Message-Id: <20181130171533.18123-1-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 Subject: [Xen-devel] [PATCH for-4.12] xen/arm: gic: Make sure the number of interrupt lines is valid before using it 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, Jan-Peter Larsson MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" GICv2 and GICv3 supports up to 1020 interrupts. However, the value computed from GICD_TYPER.ITLinesNumber can be up to 1024. On GICv3, we will end up to write in reserved registers that are right after the IROUTERs one as the value is not capped early enough. Cap the number of interrupts as soon as we compute it so we know we can safely using it afterwards. Signed-off-by: Julien Grall Reported-by: Jan-Peter Larsson Reviewed-by: Stefano Stabellini --- This patch should be backport up to Xen 4.9. --- xen/arch/arm/gic-v2.c | 7 ++++--- xen/arch/arm/gic-v3.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/gic-v2.c b/xen/arch/arm/gic-v2.c index 1a744c576f..e9fb8a01ab 100644 --- a/xen/arch/arm/gic-v2.c +++ b/xen/arch/arm/gic-v2.c @@ -353,6 +353,10 @@ static void __init gicv2_dist_init(void) type = readl_gicd(GICD_TYPER); nr_lines = 32 * ((type & GICD_TYPE_LINES) + 1); + /* Only 1020 interrupts are supported */ + nr_lines = min(1020U, nr_lines); + gicv2_info.nr_lines = nr_lines; + gic_cpus = 1 + ((type & GICD_TYPE_CPUS) >> 5); printk("GICv2: %d lines, %d cpu%s%s (IID %8.8x).\n", nr_lines, gic_cpus, (gic_cpus == 1) ? "" : "s", @@ -377,9 +381,6 @@ static void __init gicv2_dist_init(void) for ( i = 32; i < nr_lines; i += 32 ) writel_gicd(~0x0, GICD_ICENABLER + (i / 32) * 4); - /* Only 1020 interrupts are supported */ - gicv2_info.nr_lines = min(1020U, nr_lines); - /* Turn on the distributor */ writel_gicd(GICD_CTL_ENABLE, GICD_CTLR); } diff --git a/xen/arch/arm/gic-v3.c b/xen/arch/arm/gic-v3.c index 6fbc106757..c9200d24e1 100644 --- a/xen/arch/arm/gic-v3.c +++ b/xen/arch/arm/gic-v3.c @@ -607,6 +607,10 @@ static void __init gicv3_dist_init(void) if ( type & GICD_TYPE_LPIS ) gicv3_lpi_init_host_lpis(GICD_TYPE_ID_BITS(type)); + /* Only 1020 interrupts are supported */ + nr_lines = min(1020U, nr_lines); + gicv3_info.nr_lines = nr_lines; + printk("GICv3: %d lines, (IID %8.8x).\n", nr_lines, readl_relaxed(GICD + GICD_IIDR)); @@ -646,9 +650,6 @@ static void __init gicv3_dist_init(void) for ( i = NR_GIC_LOCAL_IRQS; i < nr_lines; i++ ) writeq_relaxed(affinity, GICD + GICD_IROUTER + i * 8); - - /* Only 1020 interrupts are supported */ - gicv3_info.nr_lines = min(1020U, nr_lines); } static int gicv3_enable_redist(void)