Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4110174imu; Fri, 30 Nov 2018 11:08:52 -0800 (PST) X-Google-Smtp-Source: AFSGD/UziSnFHYgZ5YfvbkoG/rxD2burEVBT8Cr/DHDsLW10qQ25SrgdRX8yAFDI3wYKjuMO61xN X-Received: by 2002:a62:6143:: with SMTP id v64mr6780258pfb.142.1543604932861; Fri, 30 Nov 2018 11:08:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543604932; cv=none; d=google.com; s=arc-20160816; b=Yg9zefb2B5s3Xzztg+F+QwkOiZoGlRoHJr+p8KVfE/3pJQAoSz9d6XziNpMehRajib i+bi0vPNEVGuVgsTSMFnlnYCsBq21wNU4QNfqRTskeTOm8ZEhDYIKyrg7IfGmhOD8waB pvYFUnTvnfbShrEQGdAai7iw7a6O3Lru0was85vnqWnuUdtA4VfAUYbm8H5MxbOkIBVA cDNQRP1L4UQcmllRAWAFN6sh4umkFqX3KDqhdR2PSFrg13EGOEFE6Eia18BMNoS8xQMT xaJSUShujxxarTUPYfwAquDikUSEGOKMSDqKORmdv32OYwuU/l2eAGZroDyELh/a4lce 3odA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=DcYsHeRtGlcCsAz1hTNxClKhKhvZpSEdeIBzH+ZF6dg=; b=CxT2x89mb9F0lTO/03OSiB4y0AhiL/CXehSjuwvzUBFkp4wG1h3ARDHqZzhbaGvBDr YOOozFFixcV6cyHAz4M/BvwA59fZLDCqX316Qb6CIHRWmUfAkq8cd5cbS9+o0gavA81Q FTOFnuO5yzXSQEjJb61Roc6ZAzfiUG79/wNsc26D4L8flwn3OVP3PXF5+G++YS6PFvcg cG6tHSw+4RE4ORUCO8RzrxMWbI1rCh1uiXCOwvEONoXCMkuObWc+5aAQHkb77HCGMpZl sAEAaL7LHk52kDC7QgyVECvSmc22Z/4O++DUJuo9DwW4IutPInUf1dtZAGun0+3meXeR t9FA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o10si5847340pls.76.2018.11.30.11.08.36; Fri, 30 Nov 2018 11:08:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727040AbeLAGP7 (ORCPT + 99 others); Sat, 1 Dec 2018 01:15:59 -0500 Received: from foss.arm.com ([217.140.101.70]:35196 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726554AbeLAGP7 (ORCPT ); Sat, 1 Dec 2018 01:15:59 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 860A61684; Fri, 30 Nov 2018 11:05:43 -0800 (PST) Received: from [10.1.196.75] (e110467-lin.cambridge.arm.com [10.1.196.75]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 27EFC3F575; Fri, 30 Nov 2018 11:05:42 -0800 (PST) Subject: Re: [PATCH 6/9] dma-remap: support DMA_ATTR_NO_KERNEL_MAPPING To: Christoph Hellwig , iommu@lists.linux-foundation.org Cc: Catalin Marinas , Will Deacon , Guo Ren , Laura Abbott , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20181105121931.13481-1-hch@lst.de> <20181105121931.13481-7-hch@lst.de> From: Robin Murphy Message-ID: Date: Fri, 30 Nov 2018 19:05:40 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181105121931.13481-7-hch@lst.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/11/2018 12:19, Christoph Hellwig wrote: > Do not waste vmalloc space on allocations that do not require a mapping > into the kernel address space. > > Signed-off-by: Christoph Hellwig > --- > kernel/dma/remap.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/kernel/dma/remap.c b/kernel/dma/remap.c > index 8f1fca34b894..10a545126b0b 100644 > --- a/kernel/dma/remap.c > +++ b/kernel/dma/remap.c > @@ -200,7 +200,8 @@ void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, > > size = PAGE_ALIGN(size); > > - if (!gfpflags_allow_blocking(flags)) { > + if (!gfpflags_allow_blocking(flags) && > + !(attrs & DMA_ATTR_NO_KERNEL_MAPPING)) { > ret = dma_alloc_from_pool(size, &page, flags); > if (!ret) > return NULL; > @@ -215,6 +216,9 @@ void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, > /* remove any dirty cache lines on the kernel alias */ > arch_dma_prep_coherent(page, size); > > + if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) > + return page; /* opaqueue cookie */ Best to preempt the inevitable patch fixing that typo in 3 months' time. Otherwise, Reviewed-by: Robin Murphy > + > /* create a coherent mapping */ > ret = dma_common_contiguous_remap(page, size, VM_USERMAP, > arch_dma_mmap_pgprot(dev, PAGE_KERNEL, attrs), > @@ -227,7 +231,10 @@ void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, > void arch_dma_free(struct device *dev, size_t size, void *vaddr, > dma_addr_t dma_handle, unsigned long attrs) > { > - if (!dma_free_from_pool(vaddr, PAGE_ALIGN(size))) { > + if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) { > + /* vaddr is a struct page cookie, not a kernel address */ > + __dma_direct_free_pages(dev, size, vaddr); > + } else if (!dma_free_from_pool(vaddr, PAGE_ALIGN(size))) { > phys_addr_t phys = dma_to_phys(dev, dma_handle); > struct page *page = pfn_to_page(__phys_to_pfn(phys)); > >