From patchwork Tue Aug 1 06:24:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Tesarik X-Patchwork-Id: 13335818 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 3A3CDC0015E for ; Tue, 1 Aug 2023 06:27:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.573674.898602 (Exim 4.92) (envelope-from ) id 1qQiqN-0003KX-Tp; Tue, 01 Aug 2023 06:26:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 573674.898602; Tue, 01 Aug 2023 06:26:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qQiqN-0003KM-QF; Tue, 01 Aug 2023 06:26:55 +0000 Received: by outflank-mailman (input) for mailman id 573674; Tue, 01 Aug 2023 06:26:54 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qQiqL-00011l-Vz for xen-devel@lists.xenproject.org; Tue, 01 Aug 2023 06:26:53 +0000 Received: from frasgout13.his.huawei.com (unknown [14.137.139.46]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 67279f3d-3034-11ee-8613-37d641c3527e; Tue, 01 Aug 2023 08:26:52 +0200 (CEST) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout13.his.huawei.com (SkyGuard) with ESMTP id 4RFPws4yyWz9y3D6 for ; Tue, 1 Aug 2023 14:15:25 +0800 (CST) Received: from A2101119013HW2.china.huawei.com (unknown [10.81.220.249]) by APP1 (Coremail) with SMTP id LxC2BwCHOroapchkgAwYAA--.27948S7; Tue, 01 Aug 2023 07:26:15 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 67279f3d-3034-11ee-8613-37d641c3527e From: Petr Tesarik To: Stefano Stabellini , Russell King , Thomas Bogendoerfer , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , Greg Kroah-Hartman , "Rafael J. Wysocki" , Juergen Gross , Oleksandr Tyshchenko , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Petr Tesarik , Jonathan Corbet , Andy Shevchenko , Hans de Goede , James Seo , James Clark , Kees Cook , xen-devel@lists.xenproject.org (moderated list:XEN HYPERVISOR ARM), linux-arm-kernel@lists.infradead.org (moderated list:ARM PORT), linux-kernel@vger.kernel.org (open list), linux-mips@vger.kernel.org (open list:MIPS), iommu@lists.linux.dev (open list:XEN SWIOTLB SUBSYSTEM), linux-mm@kvack.org (open list:SLAB ALLOCATOR) Cc: Roberto Sassu , petr@tesarici.cz Subject: [PATCH v7 5/9] swiotlb: add a flag whether SWIOTLB is allowed to grow Date: Tue, 1 Aug 2023 08:24:00 +0200 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: LxC2BwCHOroapchkgAwYAA--.27948S7 X-Coremail-Antispam: 1UD129KBjvJXoWxWrW8XF1fKr1fZr13Wr4UArb_yoWrWry5pF 15JF4rXF42qF1xArWxCw1xGF9akw4vkrW3ur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DUUUU X-CM-SenderInfo: hshw23xhvd2x3n6k3tpzhluzxrxghudrp/ X-CFilter-Loop: Reflected From: Petr Tesarik Add a config option (CONFIG_SWIOTLB_DYNAMIC) to enable or disable dynamic allocation of additional bounce buffers. If this option is set, mark the default SWIOTLB as able to grow and restricted DMA pools as unable. However, if the address of the default memory pool is explicitly queried, make the default SWIOTLB also unable to grow. This is currently used to set up PCI BAR movable regions on some Octeon MIPS boards which may not be able to use a SWIOTLB pool elsewhere in physical memory. See octeon_pci_setup() for more details. If a remap function is specified, it must be also called on any dynamically allocated pools, but there are some issues: - The remap function may block, so it should not be called from an atomic context. - There is no corresponding unremap() function if the memory pool is freed. - The only in-tree implementation (xen_swiotlb_fixup) requires that the number of slots in the memory pool is a multiple of SWIOTLB_SEGSIZE. Keep it simple for now and disable growing the SWIOTLB if a remap function was specified. Signed-off-by: Petr Tesarik --- include/linux/swiotlb.h | 4 ++++ kernel/dma/Kconfig | 13 +++++++++++++ kernel/dma/swiotlb.c | 13 +++++++++++++ 3 files changed, 30 insertions(+) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 247f0ab8795a..57be2a0a9fbf 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -100,6 +100,7 @@ struct io_tlb_pool { * @debugfs: The dentry to debugfs. * @force_bounce: %true if swiotlb bouncing is forced * @for_alloc: %true if the pool is used for memory allocation + * @can_grow: %true if more pools can be allocated dynamically. * @total_used: The total number of slots in the pool that are currently used * across all areas. Used only for calculating used_hiwater in * debugfs. @@ -112,6 +113,9 @@ struct io_tlb_mem { struct dentry *debugfs; bool force_bounce; bool for_alloc; +#ifdef CONFIG_SWIOTLB_DYNAMIC + bool can_grow; +#endif #ifdef CONFIG_DEBUG_FS atomic_long_t total_used; atomic_long_t used_hiwater; diff --git a/kernel/dma/Kconfig b/kernel/dma/Kconfig index 562463fe30ea..4c1e9a3c0ab6 100644 --- a/kernel/dma/Kconfig +++ b/kernel/dma/Kconfig @@ -90,6 +90,19 @@ config SWIOTLB bool select NEED_DMA_MAP_STATE +config SWIOTLB_DYNAMIC + bool "Dynamic allocation of DMA bounce buffers" + default n + depends on SWIOTLB + help + This enables dynamic resizing of the software IO TLB. The kernel + starts with one memory pool at boot and it will allocate additional + pools as needed. To reduce run-time kernel memory requirements, you + may have to specify a smaller size of the initial pool using + "swiotlb=" on the kernel command line. + + If unsure, say N. + config DMA_BOUNCE_UNALIGNED_KMALLOC bool depends on SWIOTLB diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 6fc2606e014b..767c8fb36a6b 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -330,6 +330,11 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags, io_tlb_default_mem.force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE); +#ifdef CONFIG_SWIOTLB_DYNAMIC + if (!remap) + io_tlb_default_mem.can_grow = true; +#endif + if (!default_nareas) swiotlb_adjust_nareas(num_possible_cpus()); @@ -400,6 +405,11 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask, io_tlb_default_mem.force_bounce = swiotlb_force_bounce; +#ifdef CONFIG_SWIOTLB_DYNAMIC + if (!remap) + io_tlb_default_mem.can_grow = true; +#endif + if (!default_nareas) swiotlb_adjust_nareas(num_possible_cpus()); @@ -1073,6 +1083,9 @@ bool is_swiotlb_active(struct device *dev) */ phys_addr_t default_swiotlb_base(void) { +#ifdef CONFIG_SWIOTLB_DYNAMIC + io_tlb_default_mem.can_grow = false; +#endif return io_tlb_default_mem.defpool.start; }