From nobody Tue Jun 23 20:21:52 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE1C5C433F5 for ; Sun, 27 Feb 2022 14:35:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230353AbiB0OgQ (ORCPT ); Sun, 27 Feb 2022 09:36:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229695AbiB0OgP (ORCPT ); Sun, 27 Feb 2022 09:36:15 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FFA3574BD for ; Sun, 27 Feb 2022 06:35:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=q0ndjvMP0hLxm12+r7z4k6gnIkRIGLE8593pcUK0phE=; b=4PmO+rcnJ0dJa3Hs8TbLyUaKTw 9EqcCHVO8U6JyG0FegmDNIyTL6uS4tEy0VwD/jlCzPpxatW80UbfTK3hEbc8O6d5Q+Kzr6Q3H4E+A SW5oFlt6v7RJdU6kA45aABrS6t1NLVFktuK+WqnmNC3vQftJjusnoQz4aakXF/T8rVk4j5ANwHsw2 CQRIHV9lOkCWi6MwSER0rpIK1aVgsVLop31YWLGKErH+mTSRh28RqRHA4FRPbJmIZbCM7i92xm2nk aWx3pZfOFkX13JSSQ+tqIunp3d7FxeFUGlpBr7HFGzRsc90vGsyM/g6rubJjlzM6HAyEEJM6FT66O ROOCtmXA==; Received: from [213.208.157.39] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nOKe7-009QzL-Ri; Sun, 27 Feb 2022 14:35:36 +0000 From: Christoph Hellwig To: iommu@lists.linux-foundation.org Cc: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] dma-mapping: remove CONFIG_DMA_REMAP Date: Sun, 27 Feb 2022 15:35:33 +0100 Message-Id: <20220227143533.357356-1-hch@lst.de> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" CONFIG_DMA_REMAP is used to build a few helpers around the core vmalloc code, and to use them in case there is a highmem page in dma-direct, and to make dma coherent allocations be able to use non-contiguous pages allocations for DMA allocations in the dma-iommu layer. Right now it needs to be explicitly selected by architectures, and is only done so by architectures that require remapping to deal with devices that are not DMA coherent. Make it unconditional for builds with CONFIG_MMU as it is very little extra code, but makes it much more likely that large DMA allocations succeed on x86. This fixes hot plugging a NVMe thunderbolt SSD for me, which tries to allocate a 1MB buffer that is otherwise hard to obtain due to memory fragmentation on a heavily used laptop. Signed-off-by: Christoph Hellwig Reviewed-by: Robin Murphy --- arch/arm/Kconfig | 2 +- arch/xtensa/Kconfig | 2 +- drivers/iommu/dma-iommu.c | 14 +++++--------- kernel/dma/Kconfig | 7 +------ kernel/dma/Makefile | 2 +- kernel/dma/direct.c | 8 ++++---- 6 files changed, 13 insertions(+), 22 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 4c97cb40eebb6..83fb277e50759 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -47,7 +47,7 @@ config ARM select DMA_DECLARE_COHERENT select DMA_GLOBAL_POOL if !MMU select DMA_OPS - select DMA_REMAP if MMU + select DMA_NONCOHERENT_MMAP if MMU select EDAC_SUPPORT select EDAC_ATOMIC_SCRUB select GENERIC_ALLOCATOR diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig index 8ac599aa6d994..76438ee313d16 100644 --- a/arch/xtensa/Kconfig +++ b/arch/xtensa/Kconfig @@ -17,7 +17,7 @@ config XTENSA select BUILDTIME_TABLE_SORT select CLONE_BACKWARDS select COMMON_CLK - select DMA_REMAP if MMU + select DMA_NONCOHERENT_MMAP if MMU select GENERIC_ATOMIC64 select GENERIC_IRQ_SHOW select GENERIC_PCI_IOMAP diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index d85d54f2b5496..cebced7ddf390 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -852,7 +852,6 @@ static void *iommu_dma_alloc_remap(struct device *dev, = size_t size, return NULL; } =20 -#ifdef CONFIG_DMA_REMAP static struct sg_table *iommu_dma_alloc_noncontiguous(struct device *dev, size_t size, enum dma_data_direction dir, gfp_t gfp, unsigned long attrs) @@ -882,7 +881,6 @@ static void iommu_dma_free_noncontiguous(struct device = *dev, size_t size, sg_free_table(&sh->sgt); kfree(sh); } -#endif /* CONFIG_DMA_REMAP */ =20 static void iommu_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size, enum dma_data_direction dir) @@ -1276,7 +1274,7 @@ static void __iommu_dma_free(struct device *dev, size= _t size, void *cpu_addr) dma_free_from_pool(dev, cpu_addr, alloc_size)) return; =20 - if (IS_ENABLED(CONFIG_DMA_REMAP) && is_vmalloc_addr(cpu_addr)) { + if (is_vmalloc_addr(cpu_addr)) { /* * If it the address is remapped, then it's either non-coherent * or highmem CMA, or an iommu_dma_alloc_remap() construction. @@ -1318,7 +1316,7 @@ static void *iommu_dma_alloc_pages(struct device *dev= , size_t size, if (!page) return NULL; =20 - if (IS_ENABLED(CONFIG_DMA_REMAP) && (!coherent || PageHighMem(page))) { + if (!coherent || PageHighMem(page)) { pgprot_t prot =3D dma_pgprot(dev, PAGE_KERNEL, attrs); =20 cpu_addr =3D dma_common_contiguous_remap(page, alloc_size, @@ -1350,7 +1348,7 @@ static void *iommu_dma_alloc(struct device *dev, size= _t size, =20 gfp |=3D __GFP_ZERO; =20 - if (IS_ENABLED(CONFIG_DMA_REMAP) && gfpflags_allow_blocking(gfp) && + if (gfpflags_allow_blocking(gfp) && !(attrs & DMA_ATTR_FORCE_CONTIGUOUS)) { return iommu_dma_alloc_remap(dev, size, handle, gfp, dma_pgprot(dev, PAGE_KERNEL, attrs), attrs); @@ -1391,7 +1389,7 @@ static int iommu_dma_mmap(struct device *dev, struct = vm_area_struct *vma, if (off >=3D nr_pages || vma_pages(vma) > nr_pages - off) return -ENXIO; =20 - if (IS_ENABLED(CONFIG_DMA_REMAP) && is_vmalloc_addr(cpu_addr)) { + if (is_vmalloc_addr(cpu_addr)) { struct page **pages =3D dma_common_find_pages(cpu_addr); =20 if (pages) @@ -1413,7 +1411,7 @@ static int iommu_dma_get_sgtable(struct device *dev, = struct sg_table *sgt, struct page *page; int ret; =20 - if (IS_ENABLED(CONFIG_DMA_REMAP) && is_vmalloc_addr(cpu_addr)) { + if (is_vmalloc_addr(cpu_addr)) { struct page **pages =3D dma_common_find_pages(cpu_addr); =20 if (pages) { @@ -1445,10 +1443,8 @@ static const struct dma_map_ops iommu_dma_ops =3D { .free =3D iommu_dma_free, .alloc_pages =3D dma_common_alloc_pages, .free_pages =3D dma_common_free_pages, -#ifdef CONFIG_DMA_REMAP .alloc_noncontiguous =3D iommu_dma_alloc_noncontiguous, .free_noncontiguous =3D iommu_dma_free_noncontiguous, -#endif .mmap =3D iommu_dma_mmap, .get_sgtable =3D iommu_dma_get_sgtable, .map_page =3D iommu_dma_map_page, diff --git a/kernel/dma/Kconfig b/kernel/dma/Kconfig index 1b02179758cbc..56866aaa2ae1a 100644 --- a/kernel/dma/Kconfig +++ b/kernel/dma/Kconfig @@ -110,15 +110,10 @@ config DMA_GLOBAL_POOL select DMA_DECLARE_COHERENT bool =20 -config DMA_REMAP - bool - depends on MMU - select DMA_NONCOHERENT_MMAP - config DMA_DIRECT_REMAP bool - select DMA_REMAP select DMA_COHERENT_POOL + select DMA_NONCOHERENT_MMAP =20 config DMA_CMA bool "DMA Contiguous Memory Allocator" diff --git a/kernel/dma/Makefile b/kernel/dma/Makefile index 0dd65ec1d234b..21926e46ef4fb 100644 --- a/kernel/dma/Makefile +++ b/kernel/dma/Makefile @@ -8,5 +8,5 @@ obj-$(CONFIG_DMA_DECLARE_COHERENT) +=3D coherent.o obj-$(CONFIG_DMA_API_DEBUG) +=3D debug.o obj-$(CONFIG_SWIOTLB) +=3D swiotlb.o obj-$(CONFIG_DMA_COHERENT_POOL) +=3D pool.o -obj-$(CONFIG_DMA_REMAP) +=3D remap.o +obj-$(CONFIG_MMU) +=3D remap.o obj-$(CONFIG_DMA_MAP_BENCHMARK) +=3D map_benchmark.o diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 50f48e9e45987..fe1682fecdd57 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -269,10 +269,10 @@ void *dma_direct_alloc(struct device *dev, size_t siz= e, /* * Depending on the cma=3D arguments and per-arch setup, * dma_alloc_contiguous could return highmem pages. - * Without remapping there is no way to return them here, so - * log an error and fail. + * Without MMU-based remapping there is no way to return them + * here, so log an error and fail. */ - if (!IS_ENABLED(CONFIG_DMA_REMAP)) { + if (!IS_ENABLED(CONFIG_MMU)) { dev_info(dev, "Rejecting highmem page from CMA.\n"); goto out_free_pages; } @@ -349,7 +349,7 @@ void dma_direct_free(struct device *dev, size_t size, dma_free_from_pool(dev, cpu_addr, PAGE_ALIGN(size))) return; =20 - if (IS_ENABLED(CONFIG_DMA_REMAP) && is_vmalloc_addr(cpu_addr)) { + if (is_vmalloc_addr(cpu_addr)) { vunmap(cpu_addr); } else { if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_CLEAR_UNCACHED)) --=20 2.30.2