From patchwork Wed Jan 25 12:53:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 9537007 X-Patchwork-Delegate: geert@linux-m68k.org 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 41247604A0 for ; Wed, 25 Jan 2017 12:56:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33B5C27E22 for ; Wed, 25 Jan 2017 12:56:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27F5227FB1; Wed, 25 Jan 2017 12:56:06 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0C4327F9F for ; Wed, 25 Jan 2017 12:56:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751759AbdAYM4A (ORCPT ); Wed, 25 Jan 2017 07:56:00 -0500 Received: from relmlor4.renesas.com ([210.160.252.174]:43566 "EHLO relmlie3.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751747AbdAYMz6 (ORCPT ); Wed, 25 Jan 2017 07:55:58 -0500 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie3.idc.renesas.com with ESMTP; 25 Jan 2017 21:55:55 +0900 Received: from relmlac3.idc.renesas.com (relmlac3.idc.renesas.com [10.200.69.23]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id B73F2659F1; Wed, 25 Jan 2017 21:55:55 +0900 (JST) Received: by relmlac3.idc.renesas.com (Postfix, from userid 0) id 99CC118070; Wed, 25 Jan 2017 21:55:55 +0900 (JST) Received: from relmlac3.idc.renesas.com (localhost [127.0.0.1]) by relmlac3.idc.renesas.com (Postfix) with ESMTP id 92D8D1806F; Wed, 25 Jan 2017 21:55:55 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac3.idc.renesas.com with ESMTP id XAF29070; Wed, 25 Jan 2017 21:55:55 +0900 X-IronPort-AV: E=Sophos;i="5.33,283,1477926000"; d="scan'208";a="232556347" Received: from mail-sg2apc01lp0247.outbound.protection.outlook.com (HELO APC01-SG2-obe.outbound.protection.outlook.com) ([65.55.88.247]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 25 Jan 2017 21:55:54 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesasgroup.onmicrosoft.com; s=selector1-renesas-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=K7xywejSMDKkoPZiT4HW48xHsH4C64C52dgoVBUduDw=; b=o1DFSms0IaEMEox2r3rokHqttFw4QYJltsALINaQTuwreiFAQY4Eb6U2FKuN5NWppzPVk4DyoCTiIZ4a0yRcBRH8kuikyeUJcLctBcgvwGxPCSVRk2gCkNB+aZRcYkYnXCYQtiNzI2WW0I/xjXlhfJn0/BCYpvr/b6KTYIqawbg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=<>; Received: from localhost.localdomain (211.11.155.144) by HKXPR06MB0552.apcprd06.prod.outlook.com (10.161.177.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.860.13; Wed, 25 Jan 2017 12:55:53 +0000 From: Yoshihiro Shimoda To: CC: , , , Magnus Damm , Yoshihiro Shimoda Subject: [PATCH/RFC 1/4] iommu: dma: track mapped iova Date: Wed, 25 Jan 2017 21:53:59 +0900 Message-ID: <1485348842-23712-2-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1485348842-23712-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1485348842-23712-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: OS2PR01CA0033.jpnprd01.prod.outlook.com (10.164.161.143) To HKXPR06MB0552.apcprd06.prod.outlook.com (10.161.177.142) X-MS-Office365-Filtering-Correlation-Id: b1f2e4b2-6a53-4fd5-a5a5-08d445217f2f X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:HKXPR06MB0552; X-Microsoft-Exchange-Diagnostics: 1; HKXPR06MB0552; 3:ZixqBjWuKPmtgfW0hs8EaKtuG7/CWxLMJG4xJOp4qyHb41aHWYNhsYJA8iliEgEg4vaF7BXFAfvrEb/kN0qDhGhVWuzsu82df1gs0nDH3J9/UiDn6enW8aR7ct+3wKEvRZ95Gl0bN2TnQ0hXng4mMPouNi9Jk8079pLqt7ZAG+KDptPPehGyoO4tmddhtVMqKBnW/2eOIfpoVMsQZgrDhb4I75Ga86id6AnojopOzk6unb8vanaHI/LSg76Tqas2SM+TNZSMj4vOM+P4YBUAyQ== X-Microsoft-Exchange-Diagnostics: 1; HKXPR06MB0552; 25:jCVO6gx1JVCg8ydhzwZKzMmaVVdE3RwJNMUb/yim4J3tzf4cRh65OUqEgN3lpPFd1oEHax7pyd0mFL/QZQ+f+XqHXJxjINR6zujOpQtvxVtTq5qU7ib0NBZe0eBywH8JPn6di8ms6i5G6yORQ37FOrwXPeWw62egAM6JMn4ohLrdy65DSRMBGcFogvkXOgv8GC0V2rALS+uvNyEfuqHAYS1c+pzkFX0TZJr/DQODVavmZQayFQOw+xvO79AlqKNAXFvFD0JKgwfePQ2HJd/tyg2PzmE5lSBfhDWdml6N8rINofdSZQ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orb2jE/q0Q/rAbL2ojTdhBn5dSNOc4FGuerz4N5Sq/Ool90D7Onw25THF51TAj0URO/nIL9A2ZLr6Nr7HXyUj7ACiksGLFN4I7dai3RQJh413FNsUftix9FwMuCt1BkE4bO5TV6wUQXIGJx0gQGxqfnT3FK3t2XV5oUdiWS/tXmNlzfTRENypllgFfagEcs95mFH7fYJf4v1T7Ew3rEo8sD0TktUOGAhTgxbA5IzuKU0RTU/bczru4lydSsP9wxRAgyxR5foXJeXm1TVhll7Vdoh1IByGd3a92wsqZ33ol67oMcTzs2FPYcQSwSc3EY4wJhfkjEo8b35zuT7PN1bYMnQA9Q X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(250305191791016)(22074186197030); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026)(6041248)(20161123560025)(20161123562025)(20161123555025)(20161123564025)(6072148); SRVR:HKXPR06MB0552; BCL:0; PCL:0; RULEID:; SRVR:HKXPR06MB0552; X-Microsoft-Exchange-Diagnostics: 1; HKXPR06MB0552; 4:Yiaf45OTt5IjmgoQMU0Qfg+6w+Lj3MNOp9+0gri0UjbB9Pb4cUZKHeXCrRk98/Gz88iuiVwS3/AyCqQt2nRb3hON1jT1si2aNUVRt0b7o16cBjFIU429h0QheVrZhxszs36kGvNDCcUvKBqhF0/pGc6RSo81UEfQTqGgZe8pzKrqa5IenZL6dOagBFbwz4+w+sFeaKLVfb3wkLEZAYrZHqzEX6l5ou2U/EcbD162Gt7X1IdjTF8LypL+wxpT8fYkvd+kLR/G1TegQlG3DVtE50v44+Jgg4PQFUeO85tGbgFnOVJqLsTNAPNZNSbPBWcvkMtPl1jSKMrYSeul8tpFMi4Lf4xSTMX8FUIJj90HMTk/uuMQoLE3cA6z8XWysX5HLVUJmpRdlG1TO5p3iIRD0Y4pR5qnJO9m/7LmFIv0tXndAouJn5iZlvo9QzoEQ0M9aaeqiprSB7IvjW8WafYTElr7Bm5tYoY0Sy0yYWv+mgK01TLQC56lyecGczVnm4P/e1ovPc/5MGgikJMLYUVWF/Fw3iv3tiQ8yYWpbGK6ul8cdxeCfyzIwvyR5nnrT9VFBt2dC860JbhMfL/AaNFlmc1aZSsG9+8OyjtE6ADZW4lzNvpOzP/PJDvPzj0iwTX7xmx2Z+cB+ymGpfTN4V9nr+NZbgHWJ4Ha9BUEM6FwQN8= X-Forefront-PRVS: 01986AE76B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6069001)(7916002)(39840400002)(39450400003)(39410400002)(39850400002)(39860400002)(199003)(189002)(66066001)(78352004)(42186005)(101416001)(50466002)(48376002)(81156014)(305945005)(50986999)(76176999)(47776003)(5003940100001)(2351001)(7736002)(8676002)(68736007)(97736004)(81166006)(50226002)(107886002)(6506006)(53936002)(575784001)(92566002)(36756003)(106356001)(105586002)(42882006)(38730400001)(5660300001)(2950100002)(189998001)(6486002)(6512007)(39060400001)(4326007)(6306002)(2906002)(25786008)(6916009)(3846002)(33646002)(4001430100002)(110136003)(6116002)(54906002); DIR:OUT; SFP:1102; SCL:1; SRVR:HKXPR06MB0552; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; A:0; MX:0; LANG:en; Received-SPF: None (protection.outlook.com: localhost.localdomain does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HKXPR06MB0552; 23:GyL5K9btj4BkKNH5MKhV0QuubOMiGY3xNOSmICbOG?= =?us-ascii?Q?FXGEXi/5ZH1yUzr73l6J88s6GdFqqpoUkO/ZKepIuylRRDxX8o7VbPG25k9x?= =?us-ascii?Q?bIagMKl9+dL4WOQzTGrURAzSFG9iFeIQdHwrGt+FGh49qEp+uHtmTYob0sh1?= =?us-ascii?Q?6v3xnviW14iEK5+Y0+jBLD5bVXEXiG1QHIra8rixPhW2Bxu6Yt/Kc5/mHW55?= =?us-ascii?Q?KfSWy2fo8jRIFK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0HlQnnmBsD+dRW2cSDuECGNCT0U1R5G5TqO88k8to/IzBk7Z4eXpFKBQ/9rmbuMcJebHcQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HKXPR06MB0552; 7:8ZOiMpPNsamNNNmWtoJuJhcuPtvv3OmH94YdXdV3bbmKtk09Fl5IKLfkk3eNF7QQ5x9HDUKoTq3rg2P0ChM8RBBQsNnf4jq82PmNGfUTSZOVCXiUxNGzkUBMc9ss5upF7cSRq/5HVg1xcWpHEWpMLeV85uuLsqzEZdJxWSV1WhpuoQrLTf5wJRmDevaEZlySU3mosuk86w0+fUIWx3OpB3hyYa9pcFJzlh09Tnvb6JBGpEYU1TD/eK3tTtu26I0sij30MZntrM1c91XOLNWbIWJNRjW85b+PuUNJUM229AFHPYU5ixijB9zesFOgHjGFltT3Qz2ePBfPTQQw1MHouU8An8iQVxOtW/wGzxaa2lHE+dxRFLJeZ+l51koYcCj1OYs1GJK04ndl7ioITlr6XOggebNB5Rmj7QxXMGx02o0F05j9vYacI4QjiPNhHvI+Ax2HxBHa1+kiLK7aKJNA2w==; 20:SBhW69LNcUkCgRwCn8jeGCpNi08JC/8r5eRMAmEGBpaY6MWHBdAwy/oFkwguoGxS0TWuWMQrIlxxYjQqoJbGIv4Rc17euK/lURMGDzV9UMrvjwTW/92+kd0cOFiPtWKyVYcugF3j3Fcgo22qjDWlny5p4JisV5Tu/y9rL+VokBg= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jan 2017 12:55:53.0344 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HKXPR06MB0552 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Magnus Damm To track mapped iova for a workaround code in the future. Signed-off-by: Magnus Damm Signed-off-by: Yoshihiro Shimoda --- drivers/iommu/dma-iommu.c | 29 +++++++++++++++++++++++------ include/linux/iommu.h | 2 ++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 2db0d64..a0b8c0f 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -19,6 +19,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -147,6 +148,7 @@ int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, order = __ffs(domain->pgsize_bitmap); base_pfn = max_t(unsigned long, 1, base >> order); end_pfn = (base + size - 1) >> order; + atomic_set(&domain->iova_pfns_mapped, 0); /* Check the domain allows at least some access to the device... */ if (domain->geometry.force_aperture) { @@ -209,6 +211,7 @@ static struct iova *__alloc_iova(struct iommu_domain *domain, size_t size, struct iova_domain *iovad = cookie_iovad(domain); unsigned long shift = iova_shift(iovad); unsigned long length = iova_align(iovad, size) >> shift; + struct iova *iova; if (domain->geometry.force_aperture) dma_limit = min(dma_limit, domain->geometry.aperture_end); @@ -216,9 +219,23 @@ static struct iova *__alloc_iova(struct iommu_domain *domain, size_t size, * Enforce size-alignment to be safe - there could perhaps be an * attribute to control this per-device, or at least per-domain... */ - return alloc_iova(iovad, length, dma_limit >> shift, true); + iova = alloc_iova(iovad, length, dma_limit >> shift, true); + if (iova) + atomic_add(iova_size(iova), &domain->iova_pfns_mapped); + + return iova; } +void +__free_iova_domain(struct iommu_domain *domain, struct iova *iova) +{ + struct iova_domain *iovad = cookie_iovad(domain); + + atomic_sub(iova_size(iova), &domain->iova_pfns_mapped); + __free_iova(iovad, iova); +} + + /* The IOVA allocator knows what we mapped, so just unmap whatever that was */ static void __iommu_dma_unmap(struct iommu_domain *domain, dma_addr_t dma_addr) { @@ -235,7 +252,7 @@ static void __iommu_dma_unmap(struct iommu_domain *domain, dma_addr_t dma_addr) size -= iommu_unmap(domain, pfn << shift, size); /* ...and if we can't, then something is horribly, horribly wrong */ WARN_ON(size > 0); - __free_iova(iovad, iova); + __free_iova_domain(domain, iova); } static void __iommu_dma_free_pages(struct page **pages, int count) @@ -401,7 +418,7 @@ struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp, out_free_sg: sg_free_table(&sgt); out_free_iova: - __free_iova(iovad, iova); + __free_iova_domain(domain, iova); out_free_pages: __iommu_dma_free_pages(pages, count); return NULL; @@ -447,7 +464,7 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, dma_addr = iova_dma_addr(iovad, iova); if (iommu_map(domain, dma_addr, phys - iova_off, len, prot)) { - __free_iova(iovad, iova); + __free_iova_domain(domain, iova); return DMA_ERROR_CODE; } return dma_addr + iova_off; @@ -613,7 +630,7 @@ int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, return __finalise_sg(dev, sg, nents, dma_addr); out_free_iova: - __free_iova(iovad, iova); + __free_iova_domain(domain, iova); out_restore_sg: __invalidate_sg(sg, nents); return 0; @@ -689,7 +706,7 @@ static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev, return msi_page; out_free_iova: - __free_iova(iovad, iova); + __free_iova_domain(domain, iova); out_free_page: kfree(msi_page); return NULL; diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 0ff5111..91d0159 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -19,6 +19,7 @@ #ifndef __LINUX_IOMMU_H #define __LINUX_IOMMU_H +#include #include #include #include @@ -84,6 +85,7 @@ struct iommu_domain { void *handler_token; struct iommu_domain_geometry geometry; void *iova_cookie; + atomic_t iova_pfns_mapped; }; enum iommu_cap {