From patchwork Thu Aug 8 09:37:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cho KyongHo X-Patchwork-Id: 2840914 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9E1B5BF535 for ; Thu, 8 Aug 2013 09:39:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4B1EB20431 for ; Thu, 8 Aug 2013 09:39:48 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1B5562042B for ; Thu, 8 Aug 2013 09:39:47 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V7MgH-0001LI-9H; Thu, 08 Aug 2013 09:38:54 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V7Mfq-0004wT-Sb; Thu, 08 Aug 2013 09:38:26 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V7MfQ-0004qi-8b for linux-arm-kernel@lists.infradead.org; Thu, 08 Aug 2013 09:38:02 +0000 Received: from epcpsbgr1.samsung.com (u141.gpu120.samsung.co.kr [203.254.230.141]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MR7003AXHECKLC0@mailout4.samsung.com> for linux-arm-kernel@lists.infradead.org; Thu, 08 Aug 2013 18:37:44 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [203.254.230.49]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id BE.73.17404.7E663025; Thu, 08 Aug 2013 18:37:43 +0900 (KST) X-AuditID: cbfee68d-b7f096d0000043fc-66-520366e7686d Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id BA.18.32250.7E663025; Thu, 08 Aug 2013 18:37:43 +0900 (KST) Received: from DOPULLIPCHO07 ([12.23.118.94]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MR70020VHEVH150@mmp1.samsung.com>; Thu, 08 Aug 2013 18:37:43 +0900 (KST) From: Cho KyongHo To: 'Linux ARM Kernel' , 'Linux IOMMU' , 'Linux Kernel' , 'Linux Samsung SOC' , devicetree@vger.kernel.org Subject: [PATCH v9 03/16] iommu/exynos: fix page table maintenance Date: Thu, 08 Aug 2013 18:37:43 +0900 Message-id: <002701ce941a$eecebdb0$cc6c3910$@samsung.com> MIME-version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-index: Ac6UF1wiqpgTyfXjSuapcrtO0oW7xA== Content-language: ko X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrPIsWRmVeSWpSXmKPExsVy+t8zQ90XacxBBm0iFnfunmO1mH8ESLw6 8oPJYsF+a4vO2RvYLXoXXGWz+HjqOLvFpsfXWC0u75rDZjHj/D4miwsrNrJbTFl0mNXi5J9e RouW671MDnweTw7OY/KY3XCRxePOtT1sHuc3rWH22Lyk3mPyjeWMHn1bVjF6fN4k53Hl6Bmm AM4oLpuU1JzMstQifbsEroxJJ5azFLxQr1h94AtLA+Nb+S5GTg4JAROJH0f2MULYYhIX7q1n 62Lk4hASWMYo8Wj+U2a4ouanrBCJRYwSx7buYYJw/jJKNE77xApSxSagJbF67nFGkISIwG9G iVvP5oC1MAv8Z5LYeruJvYuRg0NYwEli/xx/kAYWAVWJ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ic7bexghakQk9r14 xziBUWAWklGzkIyahWTULCQtCxhZVjGKphYkFxQnpeca6hUn5haX5qXrJefnbmIEJ5ZnUjsY VzZYHGIU4GBU4uHtCGAKEmJNLCuuzD3EKMHBrCTCe7EYKMSbklhZlVqUH19UmpNafIgxGejR icxSosn5wKSXVxJvaGxiZmRpZGZhZGJuTpqwkjjvgVbrQCGB9MSS1OzU1ILUIpgtTBycUg2M IfVqp2PO1kf8vcdmtv6K/g9GxdcXYtgYosv3z3Ga5y94Nvb53Ij5tuek78048++MTJxtbZ/7 xqp+w9wgIWWXaH7L1c+Un2831bVmEGIx21rrHnMo7a7nmV1p55qYBa7sfzw9Za458/uJE/yU ptrNnyfK265x5cn6jP/9vM3BgstT/WJ3eVUrsRRnJBpqMRcVJwIAvXDga3ADAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130808_053801_211665_30397969 X-CRM114-Status: GOOD ( 13.79 ) X-Spam-Score: -5.1 (-----) Cc: 'Kukjin Kim' , 'Prathyush' , 'Grant Grundler' , 'Joerg Roedel' , 'Subash Patel' , 'Sachin Kamat' , 'Antonios Motakis' , kvmarm@lists.cs.columbia.edu, 'Rahul Sharma' X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,KHOP_BIG_TO_CC, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This prevents allocating lv2 page table for the lv1 page table entry that already has 1MB page mapping. In addition, changed to BUG_ON instead of returning -EADDRINUSE. Signed-off-by: Cho KyongHo --- drivers/iommu/exynos-iommu.c | 68 ++++++++++++++++++++++++----------------- 1 files changed, 40 insertions(+), 28 deletions(-) diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index d545a25..d90e6fa 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -52,11 +52,11 @@ #define lv2ent_large(pent) ((*(pent) & 3) == 1) #define section_phys(sent) (*(sent) & SECT_MASK) -#define section_offs(iova) ((iova) & 0xFFFFF) +#define section_offs(iova) ((iova) & ~SECT_MASK) #define lpage_phys(pent) (*(pent) & LPAGE_MASK) -#define lpage_offs(iova) ((iova) & 0xFFFF) +#define lpage_offs(iova) ((iova) & ~LPAGE_MASK) #define spage_phys(pent) (*(pent) & SPAGE_MASK) -#define spage_offs(iova) ((iova) & 0xFFF) +#define spage_offs(iova) ((iova) & ~SPAGE_MASK) #define lv1ent_offset(iova) ((iova) >> SECT_ORDER) #define lv2ent_offset(iova) (((iova) & 0xFF000) >> SPAGE_ORDER) @@ -856,13 +856,15 @@ finish: static unsigned long *alloc_lv2entry(unsigned long *sent, unsigned long iova, short *pgcounter) { + BUG_ON(lv1ent_section(sent)); + if (lv1ent_fault(sent)) { unsigned long *pent; pent = kzalloc(LV2TABLE_SIZE, GFP_ATOMIC); BUG_ON((unsigned long)pent & (LV2TABLE_SIZE - 1)); if (!pent) - return NULL; + return ERR_PTR(-ENOMEM); *sent = mk_lv1ent_page(__pa(pent)); *pgcounter = NUM_LV2ENTRIES; @@ -875,15 +877,11 @@ static unsigned long *alloc_lv2entry(unsigned long *sent, unsigned long iova, static int lv1set_section(unsigned long *sent, phys_addr_t paddr, short *pgcnt) { - if (lv1ent_section(sent)) - return -EADDRINUSE; + BUG_ON(lv1ent_section(sent)); if (lv1ent_page(sent)) { - if (*pgcnt != NUM_LV2ENTRIES) - return -EADDRINUSE; - + BUG_ON(*pgcnt != NUM_LV2ENTRIES); kfree(page_entry(sent, 0)); - *pgcnt = 0; } @@ -894,24 +892,24 @@ static int lv1set_section(unsigned long *sent, phys_addr_t paddr, short *pgcnt) return 0; } +static void clear_page_table(unsigned long *ent, int n) +{ + if (n > 0) + memset(ent, 0, sizeof(*ent) * n); +} + static int lv2set_page(unsigned long *pent, phys_addr_t paddr, size_t size, short *pgcnt) { if (size == SPAGE_SIZE) { - if (!lv2ent_fault(pent)) - return -EADDRINUSE; - + BUG_ON(!lv2ent_fault(pent)); *pent = mk_lv2ent_spage(paddr); pgtable_flush(pent, pent + 1); *pgcnt -= 1; } else { /* size == LPAGE_SIZE */ int i; for (i = 0; i < SPAGES_PER_LPAGE; i++, pent++) { - if (!lv2ent_fault(pent)) { - memset(pent, 0, sizeof(*pent) * i); - return -EADDRINUSE; - } - + BUG_ON(!lv2ent_fault(pent)); *pent = mk_lv2ent_lpage(paddr); } pgtable_flush(pent - SPAGES_PER_LPAGE, pent); @@ -944,17 +942,16 @@ static int exynos_iommu_map(struct iommu_domain *domain, unsigned long iova, pent = alloc_lv2entry(entry, iova, &priv->lv2entcnt[lv1ent_offset(iova)]); - if (!pent) - ret = -ENOMEM; + if (IS_ERR(pent)) + ret = PTR_ERR(pent); else ret = lv2set_page(pent, paddr, size, &priv->lv2entcnt[lv1ent_offset(iova)]); } - if (ret) { - pr_debug("%s: Failed to map iova 0x%lx/0x%x bytes\n", - __func__, iova, size); - } + if (ret) + pr_err("%s: Failed(%d) to map 0x%#x bytes @ %#lx\n", + __func__, ret, size, iova); spin_unlock_irqrestore(&priv->pgtablelock, flags); @@ -968,6 +965,7 @@ static size_t exynos_iommu_unmap(struct iommu_domain *domain, struct sysmmu_drvdata *data; unsigned long flags; unsigned long *ent; + size_t err_pgsize; BUG_ON(priv->pgtable == NULL); @@ -976,7 +974,10 @@ static size_t exynos_iommu_unmap(struct iommu_domain *domain, ent = section_entry(priv->pgtable, iova); if (lv1ent_section(ent)) { - BUG_ON(size < SECT_SIZE); + if (WARN_ON(size < SECT_SIZE)) { + err_pgsize = SECT_SIZE; + goto err; + } *ent = 0; pgtable_flush(ent, ent + 1); @@ -1008,9 +1009,12 @@ static size_t exynos_iommu_unmap(struct iommu_domain *domain, } /* lv1ent_large(ent) == true here */ - BUG_ON(size < LPAGE_SIZE); + if (WARN_ON(size < LPAGE_SIZE)) { + err_pgsize = LPAGE_SIZE; + goto err; + } - memset(ent, 0, sizeof(*ent) * SPAGES_PER_LPAGE); + clear_page_table(ent, SPAGES_PER_LPAGE); pgtable_flush(ent, ent + SPAGES_PER_LPAGE); size = LPAGE_SIZE; @@ -1023,8 +1027,16 @@ done: sysmmu_tlb_invalidate_entry(data->dev, iova); spin_unlock_irqrestore(&priv->lock, flags); - return size; +err: + spin_unlock_irqrestore(&priv->pgtablelock, flags); + + pr_err("%s: Failed due to size(%#x) @ %#lx is"\ + " smaller than page size %#x\n", + __func__, size, iova, err_pgsize); + + return 0; + } static phys_addr_t exynos_iommu_iova_to_phys(struct iommu_domain *domain,