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: 2840935 Return-Path: X-Original-To: patchwork-linux-samsung-soc@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 3E3E1BF535 for ; Thu, 8 Aug 2013 09:42:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3984B2047E for ; Thu, 8 Aug 2013 09:42:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3849920483 for ; Thu, 8 Aug 2013 09:42:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934214Ab3HHJhs (ORCPT ); Thu, 8 Aug 2013 05:37:48 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:50265 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934210Ab3HHJhp (ORCPT ); Thu, 8 Aug 2013 05:37:45 -0400 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>; 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 Cc: 'Joerg Roedel' , 'Kukjin Kim' , 'Prathyush' , 'Rahul Sharma' , 'Subash Patel' , 'Grant Grundler' , 'Antonios Motakis' , kvmarm@lists.cs.columbia.edu, 'Sachin Kamat' 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 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit 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/kAYWAVWJ12efsoCEeQUsJRasiQUJ8woISvyY fI8FxGYGmrl+53EmCFteYvOat1AXKUjsOPsa7G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rJefnbmIEJ5ZnUjsY 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 Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,KHOP_BIG_TO_CC, RCVD_IN_DNSWL_HI, 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,