From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755017AbdEEWE1 (ORCPT ); Fri, 5 May 2017 18:04:27 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:41188 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751323AbdEEWE0 (ORCPT ); Fri, 5 May 2017 18:04:26 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 18DA06089E 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 Reply-To: shankerd@codeaurora.org Subject: Re: [PATCH v4] irqchip/gicv3-its: Avoid memory over allocation for ITEs References: <1493562975-14365-1-git-send-email-shankerd@codeaurora.org> <87lgqfmdy7.fsf@on-the-bus.cambridge.arm.com> To: Marc Zyngier Cc: Vikram Sethi , Thomas Gleixner , linux-kernel , linux-arm-kernel , Jason Cooper From: Shanker Donthineni Message-ID: Date: Fri, 5 May 2017 17:04:22 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <87lgqfmdy7.fsf@on-the-bus.cambridge.arm.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Marc, On 05/02/2017 11:16 AM, Marc Zyngier wrote: > On Sun, Apr 30 2017 at 3:36:15 pm BST, Shanker Donthineni wrote: >> 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); > I'm confused. Either the alignment is guaranteed (and you should > document why it is so), or it is not, and we need to handle the > non-alignment (instead of failing). Sorry for confusion, alignment is guaranteed by kmalloc(), added a check for readability purpose only can be removed. > Thanks, > > M. -- Shanker Donthineni Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.