From patchwork Sun May 3 20:49:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 6322301 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A7E94BEEED for ; Sun, 3 May 2015 20:53:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B4CAF203A4 for ; Sun, 3 May 2015 20:53:51 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 07838203AC for ; Sun, 3 May 2015 20:53:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yp0qS-0006g0-E5; Sun, 03 May 2015 20:50:36 +0000 Received: from mail-wi0-x22b.google.com ([2a00:1450:400c:c05::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yp0q9-0005TK-Es for linux-arm-kernel@lists.infradead.org; Sun, 03 May 2015 20:50:18 +0000 Received: by widdi4 with SMTP id di4so92410033wid.0 for ; Sun, 03 May 2015 13:49:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=7q9AZyae4rvYfHZ6XE+dy2aJVmtFNHp7QjaCTcyMgHA=; b=dr8UDRb2bGivClMwhPzXXnvVYeqblgFcd5oU7oiXXfMHWx6Ox/4aqQHWRNKAG7iNgf BFkeFNHwN0LGIRgcO1PJ8+/EIWL8uCrjd39DOAws9lJR8eB6/1aLIH16c5j2otajYkKR WXBqpbskFAFALmS/NQYVUp8r+P+DMRoAvWYGZQWI55RiY7ZCfc1fJO28RkDrOFHKZtic 1FKU4KcmFrADEq23HqS38puWB+sTJ0sdVKuCK7EZD9daOv24yUuXMVbqo0NlWdrleK7N +gm0D/hW0U9iLrdTvpbXgK2OTdSg6wVoLwpqz/eh6FEl/jCmclwBx51rfEskkEfA69u3 qyYQ== X-Received: by 10.180.211.102 with SMTP id nb6mr14055546wic.32.1430686194608; Sun, 03 May 2015 13:49:54 -0700 (PDT) Received: from rric.localhost (x5ce0c090.dyn.telefonica.de. [92.224.192.144]) by mx.google.com with ESMTPSA id js3sm17527661wjc.5.2015.05.03.13.49.53 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 03 May 2015 13:49:53 -0700 (PDT) From: Robert Richter To: Marc Zyngier , Thomas Gleixner , Jason Cooper Subject: [PATCH 2/4] arm64: gicv3: its: Add range check for number of allocated pages Date: Sun, 3 May 2015 22:49:30 +0200 Message-Id: <1430686172-18222-3-git-send-email-rric@kernel.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1430686172-18222-1-git-send-email-rric@kernel.org> References: <1430686172-18222-1-git-send-email-rric@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150503_135017_651951_0B40943B X-CRM114-Status: GOOD ( 12.78 ) X-Spam-Score: -0.4 (/) Cc: Robert Richter , linux-kernel@vger.kernel.org, Robert Richter , Tirumalesh Chalamarla , Radha Mohan Chintakuntla , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Robert Richter The number of pages for the its table may exceed the maximum of 256. Adding a range check and limitting the number to its maximum. Based on a patch from Tirumalesh Chalamarla . Signed-off-by: Robert Richter Reviewed-by: Marc Zyngier --- drivers/irqchip/irq-gic-v3-its.c | 11 ++++++++++- include/linux/irqchip/arm-gic-v3.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index e30b4de04c6c..a2619a1d5bb3 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -810,6 +810,7 @@ static int its_alloc_tables(struct its_node *its) u64 entry_size = GITS_BASER_ENTRY_SIZE(val); int order = get_order(psz); int alloc_size; + int alloc_pages; u64 tmp; void *base; @@ -837,6 +838,14 @@ static int its_alloc_tables(struct its_node *its) } alloc_size = (1 << order) * PAGE_SIZE; + alloc_pages = (alloc_size / psz); + if (alloc_pages > GITS_BASER_PAGES_MAX) { + alloc_pages = GITS_BASER_PAGES_MAX; + order = get_order(GITS_BASER_PAGES_MAX * psz); + pr_warn("%s: Device Table too large, reduce its page order to %u (%u pages)\n", + its->msi_chip.of_node->full_name, order, alloc_pages); + } + base = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, order); if (!base) { err = -ENOMEM; @@ -865,7 +874,7 @@ static int its_alloc_tables(struct its_node *its) break; } - val |= (alloc_size / psz) - 1; + val |= alloc_pages - 1; writeq_relaxed(val, its->base + GITS_BASER + i * 8); tmp = readq_relaxed(its->base + GITS_BASER + i * 8); diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h index ffbc034c8810..f28da189c4aa 100644 --- a/include/linux/irqchip/arm-gic-v3.h +++ b/include/linux/irqchip/arm-gic-v3.h @@ -229,6 +229,7 @@ #define GITS_BASER_PAGE_SIZE_16K (1UL << GITS_BASER_PAGE_SIZE_SHIFT) #define GITS_BASER_PAGE_SIZE_64K (2UL << GITS_BASER_PAGE_SIZE_SHIFT) #define GITS_BASER_PAGE_SIZE_MASK (3UL << GITS_BASER_PAGE_SIZE_SHIFT) +#define GITS_BASER_PAGES_MAX 256 #define GITS_BASER_TYPE_NONE 0 #define GITS_BASER_TYPE_DEVICE 1