Message ID | 20231126162528.2411-1-jszhang@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp2570850vqx; Sun, 26 Nov 2023 08:38:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGax+fD10sCPX6r5fJ4lQvDBCPeB7tndfo8CygApIJUbQlBb1QOhNXKGxfW6T7Py7SkN7nv X-Received: by 2002:a17:90b:3b91:b0:285:a204:fc47 with SMTP id pc17-20020a17090b3b9100b00285a204fc47mr6008815pjb.17.1701016688293; Sun, 26 Nov 2023 08:38:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701016688; cv=none; d=google.com; s=arc-20160816; b=FAyZZY6YR43b9/Y0Fcv82kw1xmHYPqaUC/zIDD+p/s0k4M5C9nL016Nnm4vL94o54q LT4cwyHokqcIxbBrUmVM+cWprlGuvbpknEzaFSrpTJq6MBjnNHvGoi7Ty9nuSy3FURZL aeSJywKfvBdMLvAL38+Kd5MNRBhzAiEF5+6DVKFW9CaKSzD2E+PKJ3cCykcXQz8AmG82 skFOk+C0CIxYnS4AF4RWZHN/i2wYJTL9R0fLgmw8RO2tdcpVjAYQNmWY7Nz1x/uRfk9s FE1lPSWbDPZ7lYzJoUFoE/TCDaj+aPoRN8tCVcg2N8v2ciuoPYbZaL0i++jjWyv91zRr nzlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=HoDHMvBTwzlL/shZNkgjd+sDjEEkwNSSI5DYUmueemU=; fh=srb/EijQIrMEdOeqn3qQX6qrsAGyqHAqeSFkl/qDdLM=; b=xdmCgsyNusbUDs1P0vnrIU2NbsTRhLvgVaIDWbtkhwsmL2PWc2fXZIyXzCXTe+BQNv K5Z+9Lc04iwpx2OELmUjNDfHyaQcyEjhzYZlhQkndglUf6tYrIWPrrgs2fbAGxN7JDHf C1g32fjimZ/Rjeb4eL0ZJ9SY1uM5p3EpsLlXYQI/TqiGGw8+b1ZuFHfu7W6ipYXsd36e RAv+7/PT9WfWBXrDnMsgIkYp2Y1SFNJU2V9z7qHnm/Af1JuAcytYiqA7X7Rmhj0eYkE2 p8gi1GkUEr4zOctP0iPHChVcxaP16gK6NyDj4H5RHGKQtkQKGyB1kntxkshQJzwJnw3w cmCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mt7oHGf9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id p3-20020a17090adf8300b002851a01b0absi7934549pjv.151.2023.11.26.08.38.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 08:38:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mt7oHGf9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id DB66380608E1; Sun, 26 Nov 2023 08:38:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229562AbjKZQht (ORCPT <rfc822;kernel.ruili@gmail.com> + 99 others); Sun, 26 Nov 2023 11:37:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjKZQhs (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 26 Nov 2023 11:37:48 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22BB0D7 for <linux-kernel@vger.kernel.org>; Sun, 26 Nov 2023 08:37:55 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2236C433C7; Sun, 26 Nov 2023 16:37:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701016674; bh=14LKXLMt/+5p7qNVS51zb2f8quhJJfzs+4w5ju16qQE=; h=From:To:Cc:Subject:Date:From; b=mt7oHGf9eqanTX1nkP81wW4zCU1I2igViCVsXynMsPOkiJ6FEJmGV3NY3UUTdBhbj 1Pj5QIjP6KqCyvS7c2o5SObZ73Os35SJblEnA86rrUC2Pq/Q6cRqf/pLj2r8cvXTKI J9ojaEZvebtfR1eAn00K/dtPAx6ldxX9WhHRCOP7ZYJ4D5xWD/dd2sk0MTqLmpR2sf y0FH0hkb9xRAWaNDFq91uV+HkipxIhLnGdQGEZe4pCGvxQaVoyrhPSsE07JFRUwqTa icYlYgsGQWf5zPKFq/5j2XdxddlL7yX5q4BjVli5kdSgsECw7Dtbrwfta+pHqpCYXi yfPhtdRPfHtjw== From: Jisheng Zhang <jszhang@kernel.org> To: Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu> Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] riscv: mm: still create swiotlb buffer for kmalloc() bouncing if required Date: Mon, 27 Nov 2023 00:25:28 +0800 Message-Id: <20231126162528.2411-1-jszhang@kernel.org> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Sun, 26 Nov 2023 08:38:06 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783645274892817709 X-GMAIL-MSGID: 1783645274892817709 |
Series |
riscv: mm: still create swiotlb buffer for kmalloc() bouncing if required
|
|
Commit Message
Jisheng Zhang
Nov. 26, 2023, 4:25 p.m. UTC
After commit f51f7a0fc2f4 ("riscv: enable DMA_BOUNCE_UNALIGNED_KMALLOC
for !dma_coherent"), for non-coherent platforms with less than 4GB
memory, we rely on users to pass "swiotlb=mmnn,force" kernel parameters
to enable DMA bouncing for unaligned kmalloc() buffers. Now let's go
further: If no bouncing needed for ZONE_DMA, let kernel automatically
allocate 1MB swiotlb buffer per 1GB of RAM for kmalloc() bouncing on
non-coherent platforms, so that no need to pass "swiotlb=mmnn,force"
any more.
The math of "1MB swiotlb buffer per 1GB of RAM for kmalloc() bouncing"
is taken from arm64. Users can still force smaller swiotlb buffer by
passing "swiotlb=mmnn".
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
arch/riscv/mm/init.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
Comments
Hi Jisheng, kernel test robot noticed the following build errors: [auto build test ERROR on linus/master] [also build test ERROR on v6.7-rc2 next-20231124] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Jisheng-Zhang/riscv-mm-still-create-swiotlb-buffer-for-kmalloc-bouncing-if-required/20231127-014531 base: linus/master patch link: https://lore.kernel.org/r/20231126162528.2411-1-jszhang%40kernel.org patch subject: [PATCH] riscv: mm: still create swiotlb buffer for kmalloc() bouncing if required config: riscv-allnoconfig (https://download.01.org/0day-ci/archive/20231127/202311270934.fETTDQTa-lkp@intel.com/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231127/202311270934.fETTDQTa-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202311270934.fETTDQTa-lkp@intel.com/ All errors (new ones prefixed by >>): >> arch/riscv/mm/init.c:171:6: error: use of undeclared identifier 'dma_cache_alignment'; did you mean 'dma_get_cache_alignment'? 171 | dma_cache_alignment != 1) { | ^~~~~~~~~~~~~~~~~~~ | dma_get_cache_alignment include/linux/dma-mapping.h:541:19: note: 'dma_get_cache_alignment' declared here 541 | static inline int dma_get_cache_alignment(void) | ^ 1 error generated. vim +171 arch/riscv/mm/init.c 169 170 if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && !swiotlb && > 171 dma_cache_alignment != 1) { 172 /* 173 * If no bouncing needed for ZONE_DMA, allocate 1MB swiotlb 174 * buffer per 1GB of RAM for kmalloc() bouncing on 175 * non-coherent platforms. 176 */ 177 unsigned long size = 178 DIV_ROUND_UP(memblock_phys_mem_size(), 1024); 179 swiotlb_adjust_size(min(swiotlb_size_or_default(), size)); 180 swiotlb = true; 181 } 182 183 swiotlb_init(swiotlb, SWIOTLB_VERBOSE); 184 memblock_free_all(); 185 186 print_vm_layout(); 187 } 188
Hi Jisheng, kernel test robot noticed the following build errors: [auto build test ERROR on linus/master] [also build test ERROR on v6.7-rc3 next-20231127] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Jisheng-Zhang/riscv-mm-still-create-swiotlb-buffer-for-kmalloc-bouncing-if-required/20231127-014531 base: linus/master patch link: https://lore.kernel.org/r/20231126162528.2411-1-jszhang%40kernel.org patch subject: [PATCH] riscv: mm: still create swiotlb buffer for kmalloc() bouncing if required config: riscv-randconfig-002-20231127 (https://download.01.org/0day-ci/archive/20231127/202311271323.n71NKhJ5-lkp@intel.com/config) compiler: riscv64-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231127/202311271323.n71NKhJ5-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202311271323.n71NKhJ5-lkp@intel.com/ All errors (new ones prefixed by >>): arch/riscv/mm/init.c: In function 'mem_init': >> arch/riscv/mm/init.c:171:13: error: 'dma_cache_alignment' undeclared (first use in this function); did you mean 'dma_get_cache_alignment'? 171 | dma_cache_alignment != 1) { | ^~~~~~~~~~~~~~~~~~~ | dma_get_cache_alignment arch/riscv/mm/init.c:171:13: note: each undeclared identifier is reported only once for each function it appears in vim +171 arch/riscv/mm/init.c 169 170 if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && !swiotlb && > 171 dma_cache_alignment != 1) { 172 /* 173 * If no bouncing needed for ZONE_DMA, allocate 1MB swiotlb 174 * buffer per 1GB of RAM for kmalloc() bouncing on 175 * non-coherent platforms. 176 */ 177 unsigned long size = 178 DIV_ROUND_UP(memblock_phys_mem_size(), 1024); 179 swiotlb_adjust_size(min(swiotlb_size_or_default(), size)); 180 swiotlb = true; 181 } 182 183 swiotlb_init(swiotlb, SWIOTLB_VERBOSE); 184 memblock_free_all(); 185 186 print_vm_layout(); 187 } 188
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 2e011cbddf3a..cbcb9918f721 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -162,11 +162,25 @@ static void print_vm_layout(void) { } void __init mem_init(void) { + bool swiotlb = max_pfn > PFN_DOWN(dma32_phys_limit); #ifdef CONFIG_FLATMEM BUG_ON(!mem_map); #endif /* CONFIG_FLATMEM */ - swiotlb_init(max_pfn > PFN_DOWN(dma32_phys_limit), SWIOTLB_VERBOSE); + if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && !swiotlb && + dma_cache_alignment != 1) { + /* + * If no bouncing needed for ZONE_DMA, allocate 1MB swiotlb + * buffer per 1GB of RAM for kmalloc() bouncing on + * non-coherent platforms. + */ + unsigned long size = + DIV_ROUND_UP(memblock_phys_mem_size(), 1024); + swiotlb_adjust_size(min(swiotlb_size_or_default(), size)); + swiotlb = true; + } + + swiotlb_init(swiotlb, SWIOTLB_VERBOSE); memblock_free_all(); print_vm_layout();