From patchwork Sun Apr 30 14:36:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shanker Donthineni X-Patchwork-Id: 9706115 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 889BB602BE for ; Sun, 30 Apr 2017 14:37:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E272203C0 for ; Sun, 30 Apr 2017 14:37:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F52F22376; Sun, 30 Apr 2017 14:37:27 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham 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 CBD06203C0 for ; Sun, 30 Apr 2017 14:37:26 +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: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:In-Reply-To: References:List-Owner; bh=uqI9mHZHisxwFKu809btORrEUM5ghij4wFWJXW0vtxg=; b=kKJ Yy+MB9D7xkIhRzn8/NBTWRETglGNvQ+zoAyzepJwCot/+igIuR9ziPbwNZmfs6OqgyrFud2cLcQxo nuKX+BIYsGcw6PZoUUfeLSdASo1T0fpFF1bh+ZD9MqNIR46d5ELba/cci8gh1nGjoFTqcf8+mZv5S bl6h+7vQdi8a1a3InON1gVZji7om5hsIR9NLC++cZxA4zxK0OreVHIuL4IXkvixcOkwBQIgSVC1km Mz3eWavzCzmnZiFt9wRrKJTSDi2JCzGIKevKhj14ZlUJEaXECrjLsSSX7eoD6NGrS4xVbRAawcBFh eXb92ytbaX25ZTG4A+w76xEJxCNEpXw==; 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 1d4pyT-00007h-Sj; Sun, 30 Apr 2017 14:37:21 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d4pyR-0008Nn-7m for linux-arm-kernel@lists.infradead.org; Sun, 30 Apr 2017 14:37:20 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id A180A61254; Sun, 30 Apr 2017 14:36:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1493563017; bh=Of6HhKnQUBBqblqCVEXxBIelIEmYbT/62Wj5NGmQkaw=; h=From:To:Cc:Subject:Date:From; b=Gk24hUJDYht9x/0gUnGCDWH8NCJqeZfT8ikzwaJmmAI34c0Vol26Jtet8dHYnuVY+ zbMkvUYaxmzKtGh9BPqSPYrWeKcV1eei01FR9r46ShSWtTMhKuQVKPh/+ls5/T77/L eGO3LAXyW/3LrziXeSeHeXxwNnAwi56BBDL+PT2o= Received: from shankerd-ubuntu.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: shankerd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 44D5960F62; Sun, 30 Apr 2017 14:36:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1493563016; bh=Of6HhKnQUBBqblqCVEXxBIelIEmYbT/62Wj5NGmQkaw=; h=From:To:Cc:Subject:Date:From; b=Me94ZTuGtbqXrlQvblETN9hWcCd9dbSGE7Iap1+9TCZrWcz6JpLsV33lni4jSp0xp iOJ1aiHFuimfuNKW/7LqziJoMIBOR+5+kGo4zWnqadqrSuYz/tqVfm22bBt/1uh3cG LLx1Ivk9m69Ua7/TC6/CNuSNYubSl1U9JJotdBYM= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 44D5960F62 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=shankerd@codeaurora.org From: Shanker Donthineni To: Marc Zyngier , linux-kernel , linux-arm-kernel Subject: [PATCH v4] irqchip/gicv3-its: Avoid memory over allocation for ITEs Date: Sun, 30 Apr 2017 09:36:15 -0500 Message-Id: <1493562975-14365-1-git-send-email-shankerd@codeaurora.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170430_073719_439787_B3AB6B1B X-CRM114-Status: GOOD ( 11.09 ) 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: Thomas Gleixner , Shanker Donthineni , Jason Cooper , Vikram Sethi 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 are always allocating extra 255Bytes of memory to handle ITE physical address alignment requirement. The kmalloc() satisfies the ITE alignment since the ITS driver is requesting a minimum size of ITS_ITT_ALIGN bytes. Let's try to allocate the exact amount of memory that is required for ITEs to avoid wastage. Signed-off-by: Shanker Donthineni --- Changes: v2: removed 'Change-Id: Ia8084189833f2081ff13c392deb5070c46a64038' from commit. v3: changed from IITE to ITE. v3: removed fallback since kmalloc() guarantees the right alignment. drivers/irqchip/irq-gic-v3-its.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index 45ea1933..72e56f03 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -261,7 +261,6 @@ static struct its_collection *its_build_mapd_cmd(struct its_cmd_block *cmd, u8 size = ilog2(desc->its_mapd_cmd.dev->nr_ites); itt_addr = virt_to_phys(desc->its_mapd_cmd.dev->itt); - itt_addr = ALIGN(itt_addr, ITS_ITT_ALIGN); its_encode_cmd(cmd, GITS_CMD_MAPD); its_encode_devid(cmd, desc->its_mapd_cmd.dev->device_id); @@ -1329,13 +1328,14 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id, */ nr_ites = max(2UL, roundup_pow_of_two(nvecs)); sz = nr_ites * its->ite_size; - sz = max(sz, ITS_ITT_ALIGN) + ITS_ITT_ALIGN - 1; + sz = max(sz, ITS_ITT_ALIGN); itt = kzalloc(sz, GFP_KERNEL); lpi_map = its_lpi_alloc_chunks(nvecs, &lpi_base, &nr_lpis); if (lpi_map) col_map = kzalloc(sizeof(*col_map) * nr_lpis, GFP_KERNEL); - if (!dev || !itt || !lpi_map || !col_map) { + if (!dev || !itt || !lpi_map || !col_map || + !IS_ALIGNED(virt_to_phys(itt), ITS_ITT_ALIGN)) { kfree(dev); kfree(itt); kfree(lpi_map);