Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp491138imu; Mon, 5 Nov 2018 04:22:03 -0800 (PST) X-Google-Smtp-Source: AJdET5cytsUbcym0qsxJArKs326kMh8XrmHGdyNCnSvwJPWipD7tRPM2W3q66pSFHfinzaLyMmW2 X-Received: by 2002:a62:4151:: with SMTP id o78-v6mr22016198pfa.66.1541420523910; Mon, 05 Nov 2018 04:22:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541420523; cv=none; d=google.com; s=arc-20160816; b=NiD7F6O7/bkzfFia+9qZphQtHDw/Iu7FgNg4HMDhKF5rf9ZdzrHE8igvhfEafQemKc LSZ93dh0L68n6AK/hkl6C12Mtm0Jy//O3wLdBcund2vrJ9ZQKefFdkK4Z27im7m6weWG USfKHmWtBvaGuldsTQbpsW/OR5nmKGRwaUhdLznAXG5XzJSqeRlIvYPFsnWSIhytwBm1 RWwHUQ0AuAbTey0bvBeB5ZCXGydLbSc5DfNT6Dyq4ZQb5MngfIxUHCUsH2FbMLdCXJBJ DZjsWM9fbLkv5PBdhqSWWWoEeHzVItU9YG+Is6cUu9tMbsBjK2kaC7IaGffMUxbDdKj0 STag== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dHJev5ruQT89a3tvMNGOu1k6+5bwOUgwC2qREzrAI5U=; b=x7gtLsNKhSFtN2ndDUg6k9HVH9fsmDVJoy7voKKDbH4V2KCrAAgKUaBjIv15gjQrYq bUG8FFMGQqI1K2TpvoGYbd5nDt1tqv9KAnylqUXSFPRSI6b4E0fhEUF7Ad3OHLo9uq+f RP/pWNVeIZnZLOFrhk+DUFwWI2FpYQz+vBldT3w3/PvtzcB1lvnvmUPCbOJAyP44ix7L xE9lUqU7yiLNaeGQgdGmjZCpEt5LYxsmalmgBNjt1tyL69+Sr5vZRE1cy+CAphfSBL3Y 7GKzQbwXunYSkhSCk2IUA8MsgSjmhXJz7HnYkqKmQVDwDOWfo39RJdpYoOWxZR3d5P4Z T09w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=sSwVWIg7; 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 s198-v6si1948072pfs.248.2018.11.05.04.21.49; Mon, 05 Nov 2018 04:22:03 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=sSwVWIg7; 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 S1729714AbeKEVj2 (ORCPT + 99 others); Mon, 5 Nov 2018 16:39:28 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:43268 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726358AbeKEVj1 (ORCPT ); Mon, 5 Nov 2018 16:39:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=dHJev5ruQT89a3tvMNGOu1k6+5bwOUgwC2qREzrAI5U=; b=sSwVWIg7YnQrgJbbGKF8Gjb1mz Y90MwFiaVMCXI29NriTv0D9l/dLlNW7Rye58nhOjsCSMp3lbHm77DwaNvAg42DOWKBqeVNk/+UOzQ 2bKEsFJe5L4Wdf/GAs3S+1+/NUhDolkFqFayeVlPpt9gPXk2MqubyyZIrXngBu9yvUqjL95RBDG0O cv7S/MqshJ5COAal4GvjefjnnkIZVTmsFAu4SRHVeQYzl3lp9zgLeDKjMLgLBPCNs9yKyD+dUIzaQ eAv6YyE3w9Ik2CzdzRIklRewm05Y83yHa0db7GW/KtZENVqpAYYVyUunFPbPY0zvqRfp/yAb17cgw IVUJz4RQ==; Received: from 213-225-37-95.nat.highway.a1.net ([213.225.37.95] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gJdrE-0003e4-BB; Mon, 05 Nov 2018 12:19:52 +0000 From: Christoph Hellwig To: iommu@lists.linux-foundation.org Cc: Robin Murphy , Catalin Marinas , Will Deacon , Guo Ren , Laura Abbott , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/9] dma-remap: support DMA_ATTR_NO_KERNEL_MAPPING Date: Mon, 5 Nov 2018 13:19:28 +0100 Message-Id: <20181105121931.13481-7-hch@lst.de> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181105121931.13481-1-hch@lst.de> References: <20181105121931.13481-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 */ + /* 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)); -- 2.19.1