From patchwork Fri May 12 09:42:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yajun Deng X-Patchwork-Id: 93057 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4974098vqo; Fri, 12 May 2023 02:54:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42zBHPicnx1bE+C4m4GgWtRJgPULdDamjY+9ZxXzzEgYdxIyi5YvmGaj+wXvmD6Q93ES67 X-Received: by 2002:a17:902:7b87:b0:1aa:da53:dd9b with SMTP id w7-20020a1709027b8700b001aada53dd9bmr24082887pll.28.1683885297116; Fri, 12 May 2023 02:54:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683885297; cv=none; d=google.com; s=arc-20160816; b=VKniJZk/E2x2pHUU3sfk2LCZzN7T6/TeTW+XupAfLl8jBJSy9mZmc9iPqLOpHC2Upz qo7Bf/4CLd0CRQEuV2Zvdi/1wU/ThQxbrHo9vcvvLrf5kzzv2AOY/AB44lQHL3018ZjS rMCXVmh+THir8nu1RN85otKDJQNfvb83b11iuIR+hE5v8u5BtKRqRCtU3wyj7w6kyFPU 3RZ1xOAHyz8y4kww5uvtgNHaQaZnBllf/jayytVMy4ll4J8JXGeqJXwBVyVfmKPV7a6w uZXehlpyzvsJBCXiZZTlYPMpepYF0DeGlTTu2wzc5XLHwGlZMoxL5ZtIwzp25714pz4a Z1lw== 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=+3Cj7WM/5H/yN4K+1lxE1r8ARjSog11gtcnlJ0Ke9Cs=; b=EE0a+6L/m5jaTDgNKPYeC2js2KgrhGwCfv7Q4E6i+bXQ7RovQ1imez8mMFX3fVlg6Z s2C5DE/eftWRwkUrgU2fryDB6d06+5lflMkspM2mCliCSshGMmwA+85UISflXIr55fG6 MZFZtwXWt3IQOAa914RxpGeAJ8fqxrTay3Vg0RNWJD/C8C5tW3gERbgo5YSk5GMjXn0O eWPqzVjEzq3m+8wE8R48NKHS7pOlnqVS1n9LWjABC8c4Yi03JmDrGK921Y7UE7Dzr6NV qZ1jxgItLBcQaSZSvb75iPZOYzbUHshjkP1ifV+pB16IpkydZYh8T1umoGnpz6TAZHfU M5KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=LoyWQci7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h15-20020a17090a604f00b0024e01bbc607si27513919pjm.50.2023.05.12.02.54.40; Fri, 12 May 2023 02:54:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=LoyWQci7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240464AbjELJn6 (ORCPT + 99 others); Fri, 12 May 2023 05:43:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240673AbjELJnQ (ORCPT ); Fri, 12 May 2023 05:43:16 -0400 Received: from out-18.mta0.migadu.com (out-18.mta0.migadu.com [IPv6:2001:41d0:1004:224b::12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5413D12E95 for ; Fri, 12 May 2023 02:42:36 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1683884548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=+3Cj7WM/5H/yN4K+1lxE1r8ARjSog11gtcnlJ0Ke9Cs=; b=LoyWQci7E7aehvM7RvdT5fPZDShGQ0N3hNobaGAYqQcwfBmJdJo6pX3oyMFuEuj73ybj1D kvJRMx80dPfs9ElFWf5o/QxBLIG4as4augYHlH0kmV7lyvL3hJrGCYfvR0m1Joc4JYGGif tnnA3xwaUSyksPgKlMMz11sZeCuICQY= From: Yajun Deng To: corbet@lwn.net, catalin.marinas@arm.com, will@kernel.org, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, paulmck@kernel.org, bp@suse.de, akpm@linux-foundation.org, peterz@infradead.org, rdunlap@infradead.org, kim.phillips@amd.com, rostedt@goodmis.org, thunder.leizhen@huawei.com, ardb@kernel.org, bhe@redhat.com, anshuman.khandual@arm.com, song.bao.hua@hisilicon.com Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, Yajun Deng Subject: [PATCH] dma-contiguous: support per-numa CMA for all architectures Date: Fri, 12 May 2023 17:42:10 +0800 Message-Id: <20230512094210.141540-1-yajun.deng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765681708971737955?= X-GMAIL-MSGID: =?utf-8?q?1765681708971737955?= In the commit b7176c261cdb ("dma-contiguous: provide the ability to reserve per-numa CMA"), Barry adds DMA_PERNUMA_CMA for ARM64. But this feature is architecture independent, so support per-numa CMA for all architectures, and enable it by default if NUMA. Signed-off-by: Yajun Deng Acked-by: Barry Song --- Documentation/admin-guide/kernel-parameters.txt | 2 +- arch/arm64/mm/init.c | 2 -- include/linux/dma-map-ops.h | 6 ------ kernel/dma/Kconfig | 6 +++--- kernel/dma/contiguous.c | 8 +++++++- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 56d9458276a6..ac0002b2e323 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -692,7 +692,7 @@ kernel/dma/contiguous.c cma_pernuma=nn[MG] - [ARM64,KNL,CMA] + [KNL,CMA] Sets the size of kernel per-numa memory area for contiguous memory allocations. A value of 0 disables per-numa CMA altogether. And If this option is not diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 66e70ca47680..d560aef6aafa 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -410,8 +410,6 @@ void __init bootmem_init(void) arm64_hugetlb_cma_reserve(); #endif - dma_pernuma_cma_reserve(); - kvm_hyp_reserve(); /* diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h index 31f114f486c4..7af9949828ff 100644 --- a/include/linux/dma-map-ops.h +++ b/include/linux/dma-map-ops.h @@ -168,12 +168,6 @@ static inline void dma_free_contiguous(struct device *dev, struct page *page, } #endif /* CONFIG_DMA_CMA*/ -#ifdef CONFIG_DMA_PERNUMA_CMA -void dma_pernuma_cma_reserve(void); -#else -static inline void dma_pernuma_cma_reserve(void) { } -#endif /* CONFIG_DMA_PERNUMA_CMA */ - #ifdef CONFIG_DMA_DECLARE_COHERENT int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, dma_addr_t device_addr, size_t size); diff --git a/kernel/dma/Kconfig b/kernel/dma/Kconfig index 6677d0e64d27..79f83091e3a2 100644 --- a/kernel/dma/Kconfig +++ b/kernel/dma/Kconfig @@ -140,10 +140,10 @@ if DMA_CMA config DMA_PERNUMA_CMA bool "Enable separate DMA Contiguous Memory Area for each NUMA Node" - default NUMA && ARM64 + default NUMA help - Enable this option to get pernuma CMA areas so that devices like - ARM64 SMMU can get local memory by DMA coherent APIs. + Enable this option to get pernuma CMA areas so that NUMA devices + can get local memory by DMA coherent APIs. You can set the size of pernuma CMA by specifying "cma_pernuma=size" on the kernel's command line. diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index 6ea80ae42622..26a8e5365fcd 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -128,7 +128,7 @@ static inline __maybe_unused phys_addr_t cma_early_percent_memory(void) #endif #ifdef CONFIG_DMA_PERNUMA_CMA -void __init dma_pernuma_cma_reserve(void) +static void __init dma_pernuma_cma_reserve(void) { int nid; @@ -153,6 +153,10 @@ void __init dma_pernuma_cma_reserve(void) (unsigned long long)pernuma_size_bytes / SZ_1M, nid); } } +#else +static inline void __init dma_pernuma_cma_reserve(void) +{ +} #endif /** @@ -171,6 +175,8 @@ void __init dma_contiguous_reserve(phys_addr_t limit) phys_addr_t selected_limit = limit; bool fixed = false; + dma_pernuma_cma_reserve(); + pr_debug("%s(limit %08lx)\n", __func__, (unsigned long)limit); if (size_cmdline != -1) {