From patchwork Wed Aug 22 12:52:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hiroshi Doyu X-Patchwork-Id: 10875 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 5F6B323F70 for ; Wed, 22 Aug 2012 12:53:19 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 91DDDA180F9 for ; Wed, 22 Aug 2012 12:53:07 +0000 (UTC) Received: by ggmi2 with SMTP id i2so616959ggm.11 for ; Wed, 22 Aug 2012 05:53:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :x-pgp-universal:from:to:date:thread-topic:thread-index:message-id :references:in-reply-to:accept-language:x-ms-has-attach :x-ms-tnef-correlator:x-nvconfidentiality:acceptlanguage :mime-version:cc:subject:x-beenthere:x-mailman-version:precedence :list-id:list-unsubscribe:list-archive:list-post:list-help :list-subscribe:content-type:content-transfer-encoding:sender :errors-to:x-gm-message-state; bh=+X0sgQFrNGm22Gt1OIP/cDy1TalJ9qdHC7spO1qxxFA=; b=RhLUONrALpy5r+EDvsXrSW4O/LieSE6o4cP/jcLjerG0op+m4OGghvClI1kMhzx4Vm emM6oMHPLe4S4OoTQ7V2pvLIVbJ0eUzcNkzPjvXSEKuQo4qEruMK4Nthn6SEWUomBqgE 0m7NM0NufAJavWp1sazvvuRGBDqq1RrMWkmj+uhxhVYkCdCi6HUyDYrho7ZQgTDVMla7 6sM9Y9h/fTuOD5/EAmh2lIbYGZtKX9YITuW4ly7HqDxp0W9uaJ1bmTiu/m9oaATE2X13 XZeV6A9m/viz25rfE5A7qbLmUnXRNqF7e6iA8Bggo9JOB40culnpdcnT5IkX7ZsjWyLy n54w== Received: by 10.50.87.164 with SMTP id az4mr1952655igb.43.1345639997783; Wed, 22 Aug 2012 05:53:17 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp200723igc; Wed, 22 Aug 2012 05:53:16 -0700 (PDT) Received: by 10.180.93.8 with SMTP id cq8mr5703623wib.16.1345639996234; Wed, 22 Aug 2012 05:53:16 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id u63si5837459wee.52.2012.08.22.05.53.15; Wed, 22 Aug 2012 05:53:16 -0700 (PDT) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1T4AQl-0001gY-EL; Wed, 22 Aug 2012 12:53:08 +0000 Received: from hqemgate04.nvidia.com ([216.228.121.35]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1T4AQf-0001gG-AZ for linaro-mm-sig@lists.linaro.org; Wed, 22 Aug 2012 12:53:02 +0000 Received: from hqnvupgp06.nvidia.com (Not Verified[216.228.121.13]) by hqemgate04.nvidia.com id ; Wed, 22 Aug 2012 05:52:01 -0700 Received: from hqemhub01.nvidia.com ([172.17.108.22]) by hqnvupgp06.nvidia.com (PGP Universal service); Wed, 22 Aug 2012 05:52:40 -0700 X-PGP-Universal: processed; by hqnvupgp06.nvidia.com on Wed, 22 Aug 2012 05:52:40 -0700 Received: from deemhub02.nvidia.com (10.21.69.138) by hqemhub01.nvidia.com (172.20.150.30) with Microsoft SMTP Server (TLS) id 8.3.264.0; Wed, 22 Aug 2012 05:52:40 -0700 Received: from DEMAIL01.nvidia.com ([10.21.69.140]) by deemhub02.nvidia.com ([10.21.69.138]) with mapi; Wed, 22 Aug 2012 14:52:36 +0200 From: Hiroshi Doyu To: "m.szyprowski@samsung.com" Date: Wed, 22 Aug 2012 14:52:28 +0200 Thread-Topic: [RFC 2/4] ARM: dma-mapping: IOMMU allocates pages from pool with GFP_ATOMIC Thread-Index: Ac2AZQDahdqmGf/JQJyv1KfuJ++hkQ== Message-ID: <20120822.155228.1203479129187316092.hdoyu@nvidia.com> References: <1345630830-9586-1-git-send-email-hdoyu@nvidia.com><1345630830-9586-3-git-send-email-hdoyu@nvidia.com><005a01cd8061$d58998c0$809cca40$%szyprowski@samsung.com> In-Reply-To: <005a01cd8061$d58998c0$809cca40$%szyprowski@samsung.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-nvconfidentiality: public acceptlanguage: en-US MIME-Version: 1.0 Cc: "linux@arm.linux.org.uk" , "arnd@arndb.de" , "konrad.wilk@oracle.com" , "minchan@kernel.org" , "linux-kernel@vger.kernel.org" , "linaro-mm-sig@lists.linaro.org" , "linux-mm@kvack.org" , "kyungmin.park@samsung.com" , "linux-arm-kernel@lists.infradead.org" Subject: Re: [Linaro-mm-sig] [RFC 2/4] ARM: dma-mapping: IOMMU allocates pages from pool with GFP_ATOMIC X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQkYjldv3/sskqq2ld4D5gEt0ecCA+ciOr07AAkIoxakXRz/objxRArP2CAOv4+NzinXcm1i Marek Szyprowski wrote @ Wed, 22 Aug 2012 14:29:47 +0200: > Hello, > > On Wednesday, August 22, 2012 12:20 PM Hiroshi Doyu wrote: > > > Makes use of the same atomic pool from DMA, and skips kernel page > > mapping which can involves sleep'able operation at allocating a kernel > > page table. > > > > Signed-off-by: Hiroshi Doyu > > --- > > arch/arm/mm/dma-mapping.c | 22 ++++++++++++++++++---- > > 1 files changed, 18 insertions(+), 4 deletions(-) > > > > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > > index aec0c06..9260107 100644 > > --- a/arch/arm/mm/dma-mapping.c > > +++ b/arch/arm/mm/dma-mapping.c > > @@ -1028,7 +1028,6 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t > > size, > > struct page **pages; > > int count = size >> PAGE_SHIFT; > > int array_size = count * sizeof(struct page *); > > - int err; > > > > if (array_size <= PAGE_SIZE) > > pages = kzalloc(array_size, gfp); > > @@ -1037,9 +1036,20 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t > > size, > > if (!pages) > > return NULL; > > > > - err = __alloc_fill_pages(&pages, count, gfp); > > - if (err) > > - goto error > > + if (gfp & GFP_ATOMIC) { > > + struct page *page; > > + int i; > > + void *addr = __alloc_from_pool(size, &page); > > + if (!addr) > > + goto err_out; > > + > > + for (i = 0; i < count; i++) > > + pages[i] = page + i; > > + } else { > > + int err = __alloc_fill_pages(&pages, count, gfp); > > + if (err) > > + goto error; > > + } > > > > return pages; > > error: > > @@ -1055,6 +1065,10 @@ static int __iommu_free_buffer(struct device *dev, struct page **pages, > > size_t s > > int count = size >> PAGE_SHIFT; > > int array_size = count * sizeof(struct page *); > > int i; > > + > > + if (__free_from_pool(page_address(pages[0]), size)) > > + return 0; > > You leak memory here. pages array should be also freed. Right, I'll fix as below: Modified arch/arm/mm/dma-mapping.c diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 47c4978..4656c0f 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1121,11 +1121,12 @@ static int __iommu_free_buffer(struct device *dev, struct page **pages, size_t s int i; if (__free_from_pool(page_address(pages[0]), size)) - return 0; + goto out; for (i = 0; i < count; i++) if (pages[i]) __free_pages(pages[i], 0); +out: if (array_size <= PAGE_SIZE) kfree(pages); else