Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp583037ybl; Fri, 16 Aug 2019 00:23:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkX9CfC3ZmLyLkSGOywgf93Y2fxM+fb/C+/XmGSttd2wjaIEaQsD0EbmzC0uuIQ19rGAsT X-Received: by 2002:a63:290:: with SMTP id 138mr6022312pgc.402.1565940191006; Fri, 16 Aug 2019 00:23:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565940191; cv=none; d=google.com; s=arc-20160816; b=WCIn/WVcnhs0x7lvgfU1pzAUzs8y8kqSQaurK0cvqdgJJkbx9jU46cyLLqslJOQScR TZkzX3lpLoBYork8ADsGDLI8pXr+tQR3NfdOWIESXUb9H4ULNzrJ1C6JGoTgR4RSIGf8 dmSGMra2ePy2diql7lX2x2GCy+9u/KQXJSdbeiOFgE0bcfU313fgK4JGLkuClOLe1PLm Yiaxl/jc0BqDiXiKrVaUDpVC4HuUX0RqNrdTmI3npXDOyUFDrgnsK36h8ynJj/2n/bqx N74SVfvKcpaHG0oJA5O1g88IG0zo/6b4LnOTuYXU8u6JY1mK2Z8m9bNV4Hv96gvRz+5A YSqw== 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=93/+ko3Du/V64K+y2AaxEF8szX3mmmGeAKtqr4Af7n4=; b=ljrH1LUETMuU5Ek+qn8+MiiIALT+ojp3Wq3XEszzaSepC9xp+tT/yaPQ4a/ToBQOcd Vj0L24YH9nvmw84Kbq4WkYijUO95aIXLqt5uFgPkw0Ez2hy6UiqF/vnDtUILPOxx409v 4+nR604V6ljPa5vu6xlcWzQH+Paq0ZM4vXJaYMheaTFzk9reblRb4JpmGkW38HQsL6H6 HFlWhum1pL7IyjRyEKOzbyJ7rTL6zngH5EKxIUJnqLlhio6jwsiG9roAYzKqzREVC7/L +irMpgEeB3YtSM0/Dp3C71SlbXyQNFEgQmz0hBF296t8sBY5NIC6CR+zN2pQ23rg9yDD 1KcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="uD64//zC"; 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 f40si2962425plb.316.2019.08.16.00.22.41; Fri, 16 Aug 2019 00:23:10 -0700 (PDT) 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="uD64//zC"; 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 S1726688AbfHPHV1 (ORCPT + 99 others); Fri, 16 Aug 2019 03:21:27 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:42412 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726482AbfHPHV1 (ORCPT ); Fri, 16 Aug 2019 03:21:27 -0400 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=93/+ko3Du/V64K+y2AaxEF8szX3mmmGeAKtqr4Af7n4=; b=uD64//zCEadY8MVXbMxmYL0wF5 JL8NpGWh01hpr1xDUQ3pQ/X/LOcdegwW571SEMAsM75acLv+MiSA6BTrcLsJdQsS5xpvm675K0nDL 6Za/4ML9/MzwOpVprTl36eyRZpRJgVv4sxzr1kvP8fremDTyT8YyyKJHzgf0jPHvTk97LheZTk0HG eGStRpYLFKpQvMY3YPCEdoJh9Xz5AK1AojqEe1mz7Yxg27cm8j8zc4ztOUXa4ray0w5GDb/ke91Lu /fEt8DcaI+QuHnxHdxCFB9YlNC7HHpBtm4WxewG3P25WjEVM7ieTk+Dqct7D4Xi+xbvSZxwsGak8f TlvdexdA==; Received: from 089144199030.atnat0008.highway.a1.net ([89.144.199.30] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1hyWXz-0002li-Gr; Fri, 16 Aug 2019 07:21:16 +0000 From: Christoph Hellwig To: iommu@lists.linux-foundation.org Cc: Guan Xuetao , Shawn Anastasio , Russell King , Catalin Marinas , Will Deacon , Robin Murphy , Paul Burton , James Hogan , Geert Uytterhoeven , linuxppc-dev@lists.ozlabs.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/6] dma-mapping: make dma_atomic_pool_init self-contained Date: Fri, 16 Aug 2019 09:07:53 +0200 Message-Id: <20190816070754.15653-6-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190816070754.15653-1-hch@lst.de> References: <20190816070754.15653-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 The memory allocated for the atomic pool needs to have the same mapping attributes that we use for remapping, so use pgprot_dmacoherent instead of open coding it. Also deduct a suitable zone to allocate the memory from based on the presence of the DMA zones. Signed-off-by: Christoph Hellwig --- arch/arc/mm/dma.c | 6 ------ arch/arm64/mm/dma-mapping.c | 6 ------ arch/csky/mm/dma-mapping.c | 6 ------ arch/nds32/kernel/dma.c | 6 ------ include/linux/dma-mapping.h | 1 - kernel/dma/remap.c | 17 ++++++++++++++--- 6 files changed, 14 insertions(+), 28 deletions(-) diff --git a/arch/arc/mm/dma.c b/arch/arc/mm/dma.c index 62c210e7ee4c..ff4a5752f8cc 100644 --- a/arch/arc/mm/dma.c +++ b/arch/arc/mm/dma.c @@ -104,9 +104,3 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, dev_info(dev, "use %sncoherent DMA ops\n", dev->dma_coherent ? "" : "non"); } - -static int __init atomic_pool_init(void) -{ - return dma_atomic_pool_init(GFP_KERNEL, pgprot_noncached(PAGE_KERNEL)); -} -postcore_initcall(atomic_pool_init); diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index 676efcda51e6..a1d05f669f67 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -28,12 +28,6 @@ void arch_dma_prep_coherent(struct page *page, size_t size) __dma_flush_area(page_address(page), size); } -static int __init arm64_dma_init(void) -{ - return dma_atomic_pool_init(GFP_DMA32, __pgprot(PROT_NORMAL_NC)); -} -arch_initcall(arm64_dma_init); - #ifdef CONFIG_IOMMU_DMA void arch_teardown_dma_ops(struct device *dev) { diff --git a/arch/csky/mm/dma-mapping.c b/arch/csky/mm/dma-mapping.c index 80783bb71c5c..602a60d47a94 100644 --- a/arch/csky/mm/dma-mapping.c +++ b/arch/csky/mm/dma-mapping.c @@ -14,12 +14,6 @@ #include #include -static int __init atomic_pool_init(void) -{ - return dma_atomic_pool_init(GFP_KERNEL, pgprot_noncached(PAGE_KERNEL)); -} -postcore_initcall(atomic_pool_init); - void arch_dma_prep_coherent(struct page *page, size_t size) { if (PageHighMem(page)) { diff --git a/arch/nds32/kernel/dma.c b/arch/nds32/kernel/dma.c index 490e3720d694..4206d4b6c8ce 100644 --- a/arch/nds32/kernel/dma.c +++ b/arch/nds32/kernel/dma.c @@ -80,9 +80,3 @@ void arch_dma_prep_coherent(struct page *page, size_t size) { cache_op(page_to_phys(page), size, cpu_dma_wbinval_range); } - -static int __init atomic_pool_init(void) -{ - return dma_atomic_pool_init(GFP_KERNEL, pgprot_noncached(PAGE_KERNEL)); -} -postcore_initcall(atomic_pool_init); diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index f7d1eea32c78..48ebe8295987 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -624,7 +624,6 @@ void *dma_common_pages_remap(struct page **pages, size_t size, const void *caller); void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags); -int __init dma_atomic_pool_init(gfp_t gfp, pgprot_t prot); bool dma_in_atomic_pool(void *start, size_t size); void *dma_alloc_from_pool(size_t size, struct page **ret_page, gfp_t flags); bool dma_free_from_pool(void *start, size_t size); diff --git a/kernel/dma/remap.c b/kernel/dma/remap.c index ffe78f0b2fe4..838123f79639 100644 --- a/kernel/dma/remap.c +++ b/kernel/dma/remap.c @@ -105,7 +105,16 @@ static int __init early_coherent_pool(char *p) } early_param("coherent_pool", early_coherent_pool); -int __init dma_atomic_pool_init(gfp_t gfp, pgprot_t prot) +static gfp_t dma_atomic_pool_gfp(void) +{ + if (IS_ENABLED(CONFIG_ZONE_DMA)) + return GFP_DMA; + if (IS_ENABLED(CONFIG_ZONE_DMA32)) + return GFP_DMA32; + return GFP_KERNEL; +} + +static int __init dma_atomic_pool_init(void) { unsigned int pool_size_order = get_order(atomic_pool_size); unsigned long nr_pages = atomic_pool_size >> PAGE_SHIFT; @@ -117,7 +126,7 @@ int __init dma_atomic_pool_init(gfp_t gfp, pgprot_t prot) page = dma_alloc_from_contiguous(NULL, nr_pages, pool_size_order, false); else - page = alloc_pages(gfp, pool_size_order); + page = alloc_pages(dma_atomic_pool_gfp(), pool_size_order); if (!page) goto out; @@ -128,7 +137,8 @@ int __init dma_atomic_pool_init(gfp_t gfp, pgprot_t prot) goto free_page; addr = dma_common_contiguous_remap(page, atomic_pool_size, VM_USERMAP, - prot, __builtin_return_address(0)); + pgprot_dmacoherent(PAGE_KERNEL), + __builtin_return_address(0)); if (!addr) goto destroy_genpool; @@ -155,6 +165,7 @@ int __init dma_atomic_pool_init(gfp_t gfp, pgprot_t prot) atomic_pool_size / 1024); return -ENOMEM; } +postcore_initcall(dma_atomic_pool_init); bool dma_in_atomic_pool(void *start, size_t size) { -- 2.20.1