From patchwork Thu Mar 5 00:18:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mitchel Humpherys X-Patchwork-Id: 5941461 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 75136BF440 for ; Thu, 5 Mar 2015 00:21:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B0F7A2035C for ; Thu, 5 Mar 2015 00:21:07 +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 DBE792034C for ; Thu, 5 Mar 2015 00:21:06 +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 1YTJV1-0005jm-5O; Thu, 05 Mar 2015 00:18:47 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YTJUx-0005em-3B for linux-arm-kernel@lists.infradead.org; Thu, 05 Mar 2015 00:18:43 +0000 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 8C2E313FF0E; Thu, 5 Mar 2015 00:18:21 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 486) id 5D4E213FF15; Thu, 5 Mar 2015 00:18:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from mitchelh-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mitchelh@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id E057013FF0E; Thu, 5 Mar 2015 00:18:20 +0000 (UTC) From: Mitchel Humpherys To: linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, Will Deacon Subject: [PATCH] iommu/arm-smmu: fix leak in arm_smmu_flush_pgtable Date: Wed, 4 Mar 2015 16:18:05 -0800 Message-Id: <1425514685-23831-1-git-send-email-mitchelh@codeaurora.org> X-Mailer: git-send-email 2.3.0 X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150304_161843_163106_D3C004EE X-CRM114-Status: GOOD ( 13.24 ) X-Spam-Score: -0.0 (/) Cc: Mitchel Humpherys , Laura Abbott 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-Virus-Scanned: ClamAV using ClamSMTP We're currently mapping a page in arm_smmu_flush_pgtable without ever unmapping it. Fix this by calling dma_unmap_page on the returned dma address. Since the only reason we're calling dma_map_page is to make sure it actually gets flushed out to RAM, we can just call dma_unmap_page immediately following the map. Without this, eventually swiotlb runs out of memory and starts printing things like: [ 35.545076] arm-smmu d00000.arm,smmu: swiotlb buffer is full (sz: 128 bytes) Signed-off-by: Mitchel Humpherys --- drivers/iommu/arm-smmu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index fc13dd56953e..2ff8f35cf533 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -627,8 +627,13 @@ static void arm_smmu_flush_pgtable(void *addr, size_t size, void *cookie) * recursion here as the SMMU table walker will not be wired * through another SMMU. */ - dma_map_page(smmu->dev, virt_to_page(addr), offset, size, - DMA_TO_DEVICE); + dma_addr_t handle = dma_map_page(smmu->dev, virt_to_page(addr), + offset, size, DMA_TO_DEVICE); + if (handle == DMA_ERROR_CODE) + dev_err(smmu->dev, + "Couldn't flush page tables at %p!\n", addr); + else + dma_unmap_page(smmu->dev, handle, size, DMA_TO_DEVICE); } }