From patchwork Thu Dec 17 12:12:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 58582 Delivered-To: patch@linaro.org Received: by 10.112.89.199 with SMTP id bq7csp323641lbb; Thu, 17 Dec 2015 04:12:42 -0800 (PST) X-Received: by 10.66.141.142 with SMTP id ro14mr45398107pab.112.1450354362391; Thu, 17 Dec 2015 04:12:42 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d1si16187139pas.96.2015.12.17.04.12.41; Thu, 17 Dec 2015 04:12:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756051AbbLQMMk (ORCPT + 2 others); Thu, 17 Dec 2015 07:12:40 -0500 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]:39032 "EHLO cam-admin0.cambridge.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755763AbbLQMMk (ORCPT ); Thu, 17 Dec 2015 07:12:40 -0500 Received: from edgewater-inn.cambridge.arm.com (edgewater-inn.cambridge.arm.com [10.1.203.29]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id tBHCCJWr004867; Thu, 17 Dec 2015 12:12:19 GMT Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 6C4A41AE3406; Thu, 17 Dec 2015 12:12:17 +0000 (GMT) From: Will Deacon To: iommu@lists.linux-foundation.org Cc: jroedel@suse.de, laurent.pinchart@ideasonboard.com, elfring@users.sourceforge.net, van.freenix@gmail.com, pmallapp@broadcom.com, robin.murphy@arm.com, zhangbo_a@xiaomi.com, Will Deacon , Subject: [PATCH 13/13] iommu/io-pgtable-arm: Ensure we free the final level on teardown Date: Thu, 17 Dec 2015 12:12:13 +0000 Message-Id: <1450354333-27256-14-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1450354333-27256-1-git-send-email-will.deacon@arm.com> References: <1450354333-27256-1-git-send-email-will.deacon@arm.com> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org When tearing down page tables, we return early for the final level since we know that we won't have any table pointers to follow. Unfortunately, this also means that we forget to free the final level, so we end up leaking memory. Fix the issue by always freeing the current level, but just don't bother to iterate over the ptes if we're at the final level. Cc: Reported-by: Zhang Bo Signed-off-by: Will Deacon --- drivers/iommu/io-pgtable-arm.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe stable" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index 937ba23e48d7..8bbcbfe7695c 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -404,17 +404,18 @@ static void __arm_lpae_free_pgtable(struct arm_lpae_io_pgtable *data, int lvl, arm_lpae_iopte *start, *end; unsigned long table_size; - /* Only leaf entries at the last level */ - if (lvl == ARM_LPAE_MAX_LEVELS - 1) - return; - if (lvl == ARM_LPAE_START_LVL(data)) table_size = data->pgd_size; else table_size = ARM_LPAE_GRANULE(data); start = ptep; - end = (void *)ptep + table_size; + + /* Only leaf entries at the last level */ + if (lvl == ARM_LPAE_MAX_LEVELS - 1) + end = ptep; + else + end = (void *)ptep + table_size; while (ptep != end) { arm_lpae_iopte pte = *ptep++;