From patchwork Mon Dec 19 20:26:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nate Watterson X-Patchwork-Id: 9480733 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 3CFE6606DB for ; Mon, 19 Dec 2016 20:32:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BBE52022C for ; Mon, 19 Dec 2016 20:32:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 203D02621B; Mon, 19 Dec 2016 20:32:39 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C980C2022C for ; Mon, 19 Dec 2016 20:32:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cJ4Zt-0005oA-4L; Mon, 19 Dec 2016 20:30:33 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cJ4Zm-0004uM-SL for linux-arm-kernel@lists.infradead.org; Mon, 19 Dec 2016 20:30:27 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id EF12E615A9; Mon, 19 Dec 2016 20:30:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1482179406; bh=iHB5rJs3v+DmQLE2GpvREAIirdAoQZCtveUPbjGkc38=; h=From:To:Cc:Subject:Date:From; b=nyZIYD75v/CND6VsE4SelgsfD6KLPvux+EbURt7PafpAZTn0o1Yk4AfXlDA/2UhlL XOl3rDPKe2UpukSUqQs1InbVrC8BWSnATc7ZIr5jusHiUackfmQyitHSXigzCC5IQV jY1vdnh6u+/GzCGzZbhlO7J7TO5XTNTYRSd/taoQ= Received: from ssd-mint172.qualcomm.com (global_nat1_iad_fw.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: nwatters@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 9B682613B2; Mon, 19 Dec 2016 20:30:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1482179405; bh=iHB5rJs3v+DmQLE2GpvREAIirdAoQZCtveUPbjGkc38=; h=From:To:Cc:Subject:Date:From; b=OuOAV7AFLc+a2e+Yh62dsWzaIDhvpxLQP3pJ4uPkNW77b9/JdyvvlgjJS72v5zmXx M/smQfa4DUjXJhQHA85E1EhbHJifsgsn4wiJggGrpwqCw9EjkD6qG/7uVC6JnCLpDi 5iyDQdLh1PslvU28/61Fw+Ff+j5LK4Uzbd7tVgT0= DMARC-Filter: OpenDMARC Filter v1.3.1 smtp.codeaurora.org 9B682613B2 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=pass smtp.mailfrom=nwatters@codeaurora.org From: Nate Watterson To: Will Deacon , Robin Murphy , Joerg Roedel , linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH] iommu/arm-smmu-v3: avoid over allocating for l2 stream tables Date: Mon, 19 Dec 2016 15:26:40 -0500 Message-Id: <1482179200-4264-1-git-send-email-nwatters@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-20161219_123027_044886_7F43341E X-CRM114-Status: GOOD ( 12.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nate Watterson 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 Currently, all l2 stream tables are being allocated with space for (1< --- drivers/iommu/arm-smmu-v3.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 4d6ec44..5dca671 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -1129,6 +1129,7 @@ static void arm_smmu_init_bypass_stes(u64 *strtab, unsigned int nent) static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) { + u8 span; size_t size; void *strtab; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; @@ -1137,10 +1138,11 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) if (desc->l2ptr) return 0; - size = 1 << (STRTAB_SPLIT + ilog2(STRTAB_STE_DWORDS) + 3); + span = (smmu->sid_bits < STRTAB_SPLIT) ? smmu->sid_bits : STRTAB_SPLIT; + size = 1 << (span + ilog2(STRTAB_STE_DWORDS) + 3); strtab = &cfg->strtab[(sid >> STRTAB_SPLIT) * STRTAB_L1_DESC_DWORDS]; - desc->span = STRTAB_SPLIT + 1; + desc->span = span + 1; desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, &desc->l2ptr_dma, GFP_KERNEL | __GFP_ZERO); if (!desc->l2ptr) { @@ -1150,7 +1152,7 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) return -ENOMEM; } - arm_smmu_init_bypass_stes(desc->l2ptr, 1 << STRTAB_SPLIT); + arm_smmu_init_bypass_stes(desc->l2ptr, 1 << span); arm_smmu_write_strtab_l1_desc(strtab, desc); return 0; } @@ -2001,6 +2003,8 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) dev_warn(smmu->dev, "2-level strtab only covers %u/%u bits of SID\n", size, smmu->sid_bits); + else if (smmu->sid_bits < size) + size = smmu->sid_bits; l1size = cfg->num_l1_ents * (STRTAB_L1_DESC_DWORDS << 3); strtab = dmam_alloc_coherent(smmu->dev, l1size, &cfg->strtab_dma,