From patchwork Wed Oct 11 09:41:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Punit Agrawal X-Patchwork-Id: 9999169 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 2A58D60244 for ; Wed, 11 Oct 2017 09:51:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 163EC289B6 for ; Wed, 11 Oct 2017 09:51:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B2A2289BA; Wed, 11 Oct 2017 09:51:11 +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,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 86162289B6 for ; Wed, 11 Oct 2017 09:51:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=AJJbljJSnEWE8BnXY9X+95/rn7qdWhT32P2FZObibbo=; b=ivPcS2wG5R3NXiWkSzm19Iyg/C g13dWIJmzi8v3fHKt+BIBnR9JbJd/XruhKNtzPZL7BIFjPtHnbuad3VJrwrx9TJzz9UG/XTpwOeft uSE7u0sKXuYJq6uNaASA7zXGo005mJFYZvrPxhDyqak4o26TpfB+zxe53R1wXrkbjBOVw4uW4bagR lTDxi5EVBffYa//Am8tPcEzzqLkmUfbVhRalC585ZJ441opyM5X/5iQCBqv6rv7TQuXOu69ZQPEpa mLEKbW/ERdT/jfJ+gz1Tm94OiLNoLkCVAIoN7Y059IKLFAUxshZ1RBWM17bXJLECDg4a+IGH7iakO tBlg1Khg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e2DfR-0002fG-CV; Wed, 11 Oct 2017 09:51:09 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e2DXH-0004Wq-5E for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2017 09:42:48 +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 B21FD1435; Wed, 11 Oct 2017 02:42:26 -0700 (PDT) Received: from localhost (e105922-lin.cambridge.arm.com [10.1.207.29]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 56BBC3F3E1; Wed, 11 Oct 2017 02:42:26 -0700 (PDT) From: Punit Agrawal To: linux-kernel@vger.kernel.org Subject: [PATCH 1/3] irqchip/gic-v3: Use resource structure to store redistributor regions Date: Wed, 11 Oct 2017 10:41:46 +0100 Message-Id: <20171011094148.15674-2-punit.agrawal@arm.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171011094148.15674-1-punit.agrawal@arm.com> References: <20171011094148.15674-1-punit.agrawal@arm.com> X-ARM-No-Footer: FoSSMail X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171011_024244_002394_3396768B X-CRM114-Status: GOOD ( 13.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marc.zyngier@arm.com, Punit Agrawal , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We don't store the size of the redistributor region required to prevent out of bounds accesses to incorrectly sized regions provided by the firmware. Instead of only storing the base address, store the redistributor region as a resource structure. The resource structure will be used in subsequent commits to add bounds checking to redistributor region accesses. Signed-off-by: Punit Agrawal Cc: Marc Zyngier --- drivers/irqchip/irq-gic-v3.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c index b5df99c6f680..8cb383b6e605 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -43,7 +43,7 @@ struct redist_region { void __iomem *redist_base; - phys_addr_t phys_base; + struct resource res; bool single_redist; }; @@ -481,7 +481,7 @@ static int __gic_populate_rdist(struct redist_region *region, void __iomem *ptr) if ((typer >> 32) == aff) { u64 offset = ptr - region->redist_base; gic_data_rdist_rd_base() = ptr; - gic_data_rdist()->phys_base = region->phys_base + offset; + gic_data_rdist()->phys_base = region->res.start + offset; pr_info("CPU%d: found redistributor %lx region %d:%pa\n", smp_processor_id(), mpidr, @@ -1206,17 +1206,18 @@ static int __init gic_of_init(struct device_node *node, struct device_node *pare } for (i = 0; i < nr_redist_regions; i++) { - struct resource res; + struct resource *res; int ret; - ret = of_address_to_resource(node, 1 + i, &res); - rdist_regs[i].redist_base = of_iomap(node, 1 + i); + res = &rdist_regs[i].res; + + ret = of_address_to_resource(node, 1 + i, res); + rdist_regs[i].redist_base = ioremap(res->start, resource_size(res)); if (ret || !rdist_regs[i].redist_base) { pr_err("%pOF: couldn't map region %d\n", node, i); err = -ENODEV; goto out_unmap_rdist; } - rdist_regs[i].phys_base = res.start; } if (of_property_read_u64(node, "redistributor-stride", &redist_stride)) @@ -1256,11 +1257,11 @@ static struct } acpi_data __initdata; static void __init -gic_acpi_register_redist(phys_addr_t phys_base, void __iomem *redist_base) +gic_acpi_register_redist(struct resource *res, void __iomem *redist_base) { static int count = 0; - acpi_data.redist_regs[count].phys_base = phys_base; + acpi_data.redist_regs[count].res = *res; acpi_data.redist_regs[count].redist_base = redist_base; acpi_data.redist_regs[count].single_redist = acpi_data.single_redist; count++; @@ -1273,6 +1274,10 @@ gic_acpi_parse_madt_redist(struct acpi_subtable_header *header, struct acpi_madt_generic_redistributor *redist = (struct acpi_madt_generic_redistributor *)header; void __iomem *redist_base; + struct resource redist_res; + + redist_res.start = redist->base_address; + redist_res.end = redist_res.start + redist->length - 1; redist_base = ioremap(redist->base_address, redist->length); if (!redist_base) { @@ -1280,7 +1285,7 @@ gic_acpi_parse_madt_redist(struct acpi_subtable_header *header, return -ENOMEM; } - gic_acpi_register_redist(redist->base_address, redist_base); + gic_acpi_register_redist(&redist_res, redist_base); return 0; } @@ -1293,12 +1298,16 @@ gic_acpi_parse_madt_gicc(struct acpi_subtable_header *header, u32 reg = readl_relaxed(acpi_data.dist_base + GICD_PIDR2) & GIC_PIDR2_ARCH_MASK; u32 size = reg == GIC_PIDR2_ARCH_GICv4 ? SZ_64K * 4 : SZ_64K * 2; void __iomem *redist_base; + struct resource res; redist_base = ioremap(gicc->gicr_base_address, size); if (!redist_base) return -ENOMEM; - gic_acpi_register_redist(gicc->gicr_base_address, redist_base); + res.start = gicc->gicr_base_address; + res.end = res.start + size - 1; + + gic_acpi_register_redist(&res, redist_base); return 0; }