From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EC8ACC98310 for ; Thu, 24 Sep 2026 06:10:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ph8ZaMkef6X77VP8HjBqCGVpBP/LyeZaoJkKLrTpCr0=; b=VMn1HwMkV8vHzE PeMdXqHF8GgOrmLhJYdm3ezpZpWhKaBc8e/kIrys00RaSmk2pDoYBf8qLRMi/rNsigMnYs9EaBOM4 GbXRoO7S6g3NT5SJvslIe64WVFWz+dwxhFCRtVbXd10zaj0E8vC8Hmonbf1Fha6rSzwq2kucurM3t +WviKzhj8iextRyLjxkfunW4Z4FEpZlTMoCCvsWxGXhvnGXbL71xXFkbcMiqBZQU6As5+KHqOXRkB 1Fq2J9tbvQbW3SxqnF3THLXycdk2sfmE8UkdKuQv1qhQDlEIr4bJySjo2fHkKlP3w8myrcEcdQyrW +Dt2Z48qf6/wsiT3FEow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x9cfM-0000000A7o8-33Pp; Thu, 24 Sep 2026 06:10:44 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x9cfE-0000000A7kS-20cw; Thu, 24 Sep 2026 06:10:39 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 30EFE40211; Thu, 24 Sep 2026 06:10:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 857421F00899; Thu, 24 Sep 2026 06:10:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1790230236; bh=jX6aIZrBXbttG8mDoIDDZezQu+BWHDQT5zvSSYON3kI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mv7QZcUKekVi8xEIBYldkeMJ63fZXB3dnKscuE25jnwxzYrV7YpOlQV/JJ7nfqg3x SfDLbl+mDW1GI/N7TXv5KGeZNR8MKIL21WpefTE9MXcFmkl7CaqykwTkTliHDnqqvk 4Ym75PMMk7c3iX1NgY2p6jy3VU+TVpCMyMg1HNZpwafhoMM5GRvepJ1E6t1Wn57j6r mMLod8Y2tm4uoakNX4QCVAPga4nscd5K68nbDB46LddC7N68bEyQWZtWIn7HmZ8RE9 Iw+XQ3et9bhPrJLeaeGRWXA0GWgj6znxqt3YA7o5wCWlj+y1mYkFRwWC7aLuqtrqtN cXVDy/0hxqblA== From: "Aneesh Kumar K.V (Arm)" To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Cc: "Aneesh Kumar K.V (Arm)" , Robin Murphy , Marek Szyprowski , Jonathan Corbet , Shuah Khan , Randy Dunlap , Will Deacon , Mark Rutland , Marc Zyngier , Steven Price , Suzuki K Poulose , Catalin Marinas , Jiri Pirko , Jason Gunthorpe , Mostafa Saleh , Petr Tesarik , Alexey Kardashevskiy , Dan Williams , Xu Yilun , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , "Ritesh Harjani (IBM)" , Shrikanth Hegde , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , Stefano Stabellini , Russell King , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Jiaxun Yang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, x86@kernel.org Subject: [PATCH v6 8/8] dma: swiotlb: Remove SWIOTLB_ANY Date: Thu, 24 Sep 2026 11:37:56 +0530 Message-ID: <20260924060756.1325156-9-aneesh.kumar@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260924060756.1325156-1-aneesh.kumar@kernel.org> References: <20260924060756.1325156-1-aneesh.kumar@kernel.org> MIME-Version: 1.0 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org swiotlb pools are currently allocated below the architecture's low address limit by default. SWIOTLB_ANY overrides this and permits allocation anywhere in directly mapped memory. SWIOTLB_INIT_ADDRESSING_LIMIT now explicitly identifies callers which need a pool that is reachable by devices with limited DMA addressing. Use it as the placement constraint and remove SWIOTLB_ANY. This changes the default behavior for callers which do not set either flag. Previously, omitting SWIOTLB_ANY placed the default pool below the architecture's low address limit and also constrained dynamically allocated pools to the same range. After this change, omitting SWIOTLB_INIT_ADDRESSING_LIMIT permits both static and dynamic pools to use any directly mapped memory. Reviewed-by: Robin Murphy Reviewed-by: Catalin Marinas Cc: Jonathan Corbet Cc: Shuah Khan Cc: Randy Dunlap Cc: Madhavan Srinivasan Cc: Michael Ellerman Cc: Nicholas Piggin Cc: "Christophe Leroy (CS GROUP)" Cc: "Ritesh Harjani (IBM)" Cc: Shrikanth Hegde Cc: Paul Walmsley Cc: Palmer Dabbelt Cc: Albert Ou Cc: Alexandre Ghiti Cc: Alexander Gordeev Cc: Gerald Schaefer Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Christian Borntraeger Cc: Sven Schnelle Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Cc: "H. Peter Anvin" Cc: Marek Szyprowski Cc: Robin Murphy Signed-off-by: Aneesh Kumar K.V (Arm) --- Documentation/core-api/swiotlb.rst | 8 ++++---- arch/powerpc/mm/mem.c | 6 ++++-- arch/riscv/mm/init.c | 16 ---------------- arch/s390/mm/init.c | 2 +- arch/x86/kernel/pci-dma.c | 2 +- include/linux/swiotlb.h | 7 +++---- kernel/dma/swiotlb.c | 17 ++++++----------- 7 files changed, 19 insertions(+), 39 deletions(-) diff --git a/Documentation/core-api/swiotlb.rst b/Documentation/core-api/swiotlb.rst index 71b4e4c27eb5..06d9f88fdf7b 100644 --- a/Documentation/core-api/swiotlb.rst +++ b/Documentation/core-api/swiotlb.rst @@ -148,10 +148,10 @@ may also be adjusted due to other conditions, such as running in a CoCo VM, as described above. If CONFIG_SWIOTLB_DYNAMIC is enabled, additional pools may be allocated later in the life of the system. Each pool must be a contiguous range of physical -memory. The default pool is allocated below the 4 GiB physical address line so -it works for devices that can only address 32-bits of physical memory (unless -architecture-specific code provides the SWIOTLB_ANY flag). In a CoCo VM, the -pool memory must be decrypted before swiotlb is used. +memory. The default pool is allocated below the architecture's low address +limit when it is needed for devices with limited DMA addressing. Otherwise, +it may be allocated anywhere in directly mapped memory. In a CoCo VM, the pool +memory must be decrypted before swiotlb is used. Each pool is divided into "slots" of size IO_TLB_SIZE, which is 2 KiB with current definitions. IO_TLB_SEGSIZE contiguous slots (128 slots) constitute diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c index 006ed41097e9..1bdea6c03848 100644 --- a/arch/powerpc/mm/mem.c +++ b/arch/powerpc/mm/mem.c @@ -295,9 +295,11 @@ void __init arch_mm_preinit(void) /* * Since the guest memory is inaccessible to the host, * devices always need to use the SWIOTLB buffer for DMA - * even if dma_capable() says otherwise. + * even if dma_capable() says otherwise. The hypervisor has + * no addressing limitation, so the buffer may be allocated + * anywhere. */ - ppc_swiotlb_flags |= SWIOTLB_ANY; + ppc_swiotlb_flags &= ~SWIOTLB_INIT_ADDRESSING_LIMIT; } /* diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 96856114b387..734712230f35 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -165,27 +165,11 @@ static void print_vm_layout(void) { } void __init arch_mm_preinit(void) { - bool swiotlb = max_pfn > PFN_DOWN(dma32_phys_limit) && - memblock_start_of_DRAM() < dma32_phys_limit; unsigned int swiotlb_flags = SWIOTLB_VERBOSE; #ifdef CONFIG_FLATMEM BUG_ON(!mem_map); #endif /* CONFIG_FLATMEM */ - if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && !swiotlb && - dma_cache_alignment != 1) { - /* - * No 32-bit DMA bouncing needed (either all DRAM is within - * the 32-bit limit, or it all starts above it), but - * kmalloc() buffers whose sizes are not cache-line-aligned - * still require bouncing for non-coherent DMA. Use - * SWIOTLB_ANY so that the buffer can be allocated from high - * memory when DRAM starts above dma32_phys_limit. Allocate - * ~1 MB per 1 GB of RAM. - */ - swiotlb_flags |= SWIOTLB_ANY; - } - if ((max_pfn > PFN_DOWN(dma32_phys_limit)) && (memblock_start_of_DRAM() < dma32_phys_limit)) swiotlb_flags |= SWIOTLB_INIT_ADDRESSING_LIMIT; diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c index 78f507e24ceb..ce10292447f1 100644 --- a/arch/s390/mm/init.c +++ b/arch/s390/mm/init.c @@ -166,7 +166,7 @@ static void __init pv_init(void) virtio_set_mem_acc_cb(virtio_require_restricted_mem_acc); /* make sure bounce buffers are shared */ - swiotlb_init(SWIOTLB_VERBOSE | SWIOTLB_ANY); + swiotlb_init(SWIOTLB_VERBOSE); swiotlb_update_mem_attributes(); } diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c index ce257b20ea9c..74e92b457758 100644 --- a/arch/x86/kernel/pci-dma.c +++ b/arch/x86/kernel/pci-dma.c @@ -90,7 +90,7 @@ static void __init pci_xen_swiotlb_init(void) /* Xen can use a SWIOTLB pool anywhere in directly mapped memory. */ x86_swiotlb_flags &= ~(SWIOTLB_INIT_ADDRESSING_LIMIT | SWIOTLB_INIT_DEFAULT_OFF); - x86_swiotlb_flags |= SWIOTLB_INIT_REMAP | SWIOTLB_ANY; + x86_swiotlb_flags |= SWIOTLB_INIT_REMAP; swiotlb_init_remap(x86_swiotlb_flags, xen_swiotlb_fixup); dma_ops = &xen_swiotlb_dma_ops; if (IS_ENABLED(CONFIG_PCI)) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index f5ce45f2994b..3c3f9d93d400 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -15,13 +15,12 @@ struct page; struct scatterlist; #define SWIOTLB_VERBOSE (1 << 0) /* verbose initialization */ -#define SWIOTLB_ANY (1 << 1) /* allow any memory for the buffer */ /* Initialize a default-sized pool for devices with limited DMA addressing. */ -#define SWIOTLB_INIT_ADDRESSING_LIMIT (1 << 2) +#define SWIOTLB_INIT_ADDRESSING_LIMIT (1 << 1) /* Initialize a default-sized pool that requires architecture remapping. */ -#define SWIOTLB_INIT_REMAP (1 << 3) +#define SWIOTLB_INIT_REMAP (1 << 2) /* Do not initialize a pool unless SWIOTLB is explicitly required. */ -#define SWIOTLB_INIT_DEFAULT_OFF (1 << 4) +#define SWIOTLB_INIT_DEFAULT_OFF (1 << 3) /* * Maximum allowable number of contiguous slabs to map, diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 130a13eb85b0..4d13421c3901 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -437,15 +437,10 @@ static void __init *swiotlb_memblock_alloc(unsigned long nslabs, size_t bytes = PAGE_ALIGN(nslabs << IO_TLB_SHIFT); void *tlb; - /* - * By default allocate the bounce buffer memory from low memory, but - * allow to pick a location everywhere for hypervisors with guest - * memory encryption. - */ - if (flags & SWIOTLB_ANY) - tlb = memblock_alloc(bytes, PAGE_SIZE); - else + if (flags & SWIOTLB_INIT_ADDRESSING_LIMIT) tlb = memblock_alloc_low(bytes, PAGE_SIZE); + else + tlb = memblock_alloc(bytes, PAGE_SIZE); if (!tlb) { pr_warn("%s: Failed to allocate %zu bytes tlb structure\n", @@ -567,10 +562,10 @@ void __init swiotlb_init_remap(unsigned int flags, #ifdef CONFIG_SWIOTLB_DYNAMIC if (!remap) io_tlb_default_mem.can_grow = true; - if (flags & SWIOTLB_ANY) - io_tlb_default_mem.phys_limit = virt_to_phys(high_memory - 1); - else + if (flags & SWIOTLB_INIT_ADDRESSING_LIMIT) io_tlb_default_mem.phys_limit = ARCH_LOW_ADDRESS_LIMIT; + else + io_tlb_default_mem.phys_limit = virt_to_phys(high_memory - 1); #endif /* if we have host or guest memory encryption */ -- 2.43.0 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv