From nobody Fri Dec 19 13:48:09 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 277192F9D89; Mon, 13 Oct 2025 08:35:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760344524; cv=none; b=GKTcSZBpzXr7zvQMewQZAouII5B1+fBbSFYJkrdld8i1d15xYTT+jws7ylTDuJYssDZG0wNigUR3Fhok/d0m78ObEtfzo1xn51OlUk6dCXJxYwvE2V4Voku2lB2JAxEyop5aT2nwP4qkCT2iTukRN+AlQMRV3ZmXpf1ehv38nMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760344524; c=relaxed/simple; bh=LajQOzk5GurvfMLYf/AkXrRyTeYx/Rv5O6zLtZAh0eM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o0p7eDXgWrkBiSAr+K46ZyoxFfaLmHtgA3dyC7wDhDYESDTGyaBTyVyhwotRbqHqzjbGVvyJcr89lnSV3vCrOLZL/v4E1Fq99vN3hd2xgJk9m0xJWKJO6YINcy4EU4hFxXSCs0gEQtMeKjsWJkZsb1LQoZxmIyJb25WgkEA6gEc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PoKMEbD7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PoKMEbD7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B2A3C4CEFE; Mon, 13 Oct 2025 08:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760344523; bh=LajQOzk5GurvfMLYf/AkXrRyTeYx/Rv5O6zLtZAh0eM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PoKMEbD7W7BvsFwuUR4NZOpmLGVqH3UTQkCAWknoduVynmpAKzMHMwUWeyKxWahzb x09EBSmy88L4bwEun0kHl+ctSTqkbW2jCEA+nusK/xSke2aerDalu063VBP0Ic7OKR O0ryxoWQ9gUHfI9uRrQ40KcRHD1KsXfQayvlXHpmPwiIQHfCD0KhzzgtMXs8Jr9YTn pS2xw3/MRz+Xvd2GQiCsOup591MTBB4UDDAMxh6WCFbVYnfK7Oik9PQRcZQOUFuO0R CJ/E+mK3zQ+jWuBLwJHtsyGESV8nYXJWUDhP7KZwX+97oP8XCHDTyJ+ithGbwrCU9k y1ffjnDqAhDRA== From: Maxime Ripard Date: Mon, 13 Oct 2025 10:35:16 +0200 Subject: [PATCH v8 1/5] doc: dma-buf: List the heaps by name Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251013-dma-buf-ecc-heap-v8-1-04ce150ea3d9@kernel.org> References: <20251013-dma-buf-ecc-heap-v8-0-04ce150ea3d9@kernel.org> In-Reply-To: <20251013-dma-buf-ecc-heap-v8-0-04ce150ea3d9@kernel.org> To: Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , Jonathan Corbet , =?utf-8?q?Christian_K=C3=B6nig?= , Marek Szyprowski , Robin Murphy Cc: Andrew Davis , Jared Kangas , Mattijs Korpershoek , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, Maxime Ripard X-Mailer: b4 0.14.2 Since we're going to introduce multiple instances of the CMA heap driver, there's no single CMA heap anymore. Let's use the heap name instead to differentiate between all the heaps available in the system. While we're at it, let's also rework the backward compatibility part to make it easier to amend later on. Reviewed-by: T.J. Mercier Signed-off-by: Maxime Ripard --- Documentation/userspace-api/dma-buf-heaps.rst | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Documentation/userspace-api/dma-buf-heaps.rst b/Documentation/= userspace-api/dma-buf-heaps.rst index 1dfe5e7acd5a3c674323775176d81944147e40c0..17bf6829efd7963bc849765db54= d327644e8c395 100644 --- a/Documentation/userspace-api/dma-buf-heaps.rst +++ b/Documentation/userspace-api/dma-buf-heaps.rst @@ -14,15 +14,16 @@ Heaps A heap represents a specific allocator. The Linux kernel currently support= s the following heaps: =20 - The ``system`` heap allocates virtually contiguous, cacheable, buffers. =20 - - The ``cma`` heap allocates physically contiguous, cacheable, - buffers. Only present if a CMA region is present. Such a region is - usually created either through the kernel commandline through the - ``cma`` parameter, a memory region Device-Tree node with the - ``linux,cma-default`` property set, or through the ``CMA_SIZE_MBYTES`` = or - ``CMA_SIZE_PERCENTAGE`` Kconfig options. The heap's name in devtmpfs is - ``default_cma_region``. For backwards compatibility, when the - ``DMABUF_HEAPS_CMA_LEGACY`` Kconfig option is set, a duplicate node is - created following legacy naming conventions; the legacy name might be - ``reserved``, ``linux,cma``, or ``default-pool``. + - The ``default_cma_region`` heap allocates physically contiguous, + cacheable, buffers. Only present if a CMA region is present. Such a + region is usually created either through the kernel commandline + through the ``cma`` parameter, a memory region Device-Tree node with + the ``linux,cma-default`` property set, or through the + ``CMA_SIZE_MBYTES`` or ``CMA_SIZE_PERCENTAGE`` Kconfig options. Prior + to Linux 6.17, its name wasn't stable and could be called + ``reserved``, ``linux,cma``, or ``default-pool``, depending on the + platform. From Linux 6.17 onwards, the creation of these heaps is + controlled through the ``DMABUF_HEAPS_CMA_LEGACY`` Kconfig option for + backwards compatibility. --=20 2.51.0 From nobody Fri Dec 19 13:48:09 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B6952F8BF6; Mon, 13 Oct 2025 08:35:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760344527; cv=none; b=FJbLIf7occQ0vX/qZRaZeQwCoHS3MJX4MkhSad3ypdhX8hx9EPGlRkvHAqjVgKHX0eWhdgBR2qJA/jJOFKPKQC/LvHxClzB74//SY5vt22Mt6Mv1Gajv2V56EH1mSqWoi/0doXId81Yx3ndFsPYwQqgt7FZ4n/q9BXzhpk8612s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760344527; c=relaxed/simple; bh=lUw9GHG4vdm6ouZncuqfKqupuE9bzmklFJzA4Z/pqzg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pDUdrYwkEbR43w/uT02skZOOQqIPpyKOaVRedzSZkdD/w/JM5dwo78W/gGuPylGgnsmobf+kOebv7UIpPpEHyIVmvR6u4paVXGtX+zQ7tucOtJahxPSrDRnyVrKmsB9g5XLxiao0nc6q9h8UE++1fySG5ryA69Auqa+Zp5sWglA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ar36uzXP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ar36uzXP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76092C116B1; Mon, 13 Oct 2025 08:35:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760344526; bh=lUw9GHG4vdm6ouZncuqfKqupuE9bzmklFJzA4Z/pqzg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ar36uzXPghn/6XpfCNjCmvOdqTHBYAt0yZtSKxOeTfb8iSPc6AW078/YPCytyh/NK uqSMbumS5lFRZDZuunYla3fzj49PpXjYHIwGE9CAtoauqqc75fA/JiXsUpPOjODKSQ bXSNYablIiFUbEY2p3OmDDJagf7NxlJf+z+Sf3ZNC2fqzloEFNlluP8+qv1eDZ9OCN VndYhufDiZ594L2Tk2lV/tWkgudaAtunB8UDwaIaxf1Xb2oqxQqYY0NKXzXVCnoriT LgPfMcZKDgKDCmRJcFocHjSllRSL7zm1CXynLnqk7XZHQjJuUq3Juq8oSOEQzLvLwh 2Vcoh3qxPMNrg== From: Maxime Ripard Date: Mon, 13 Oct 2025 10:35:17 +0200 Subject: [PATCH v8 2/5] dma-buf: heaps: cma: Register list of CMA regions at boot Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251013-dma-buf-ecc-heap-v8-2-04ce150ea3d9@kernel.org> References: <20251013-dma-buf-ecc-heap-v8-0-04ce150ea3d9@kernel.org> In-Reply-To: <20251013-dma-buf-ecc-heap-v8-0-04ce150ea3d9@kernel.org> To: Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , Jonathan Corbet , =?utf-8?q?Christian_K=C3=B6nig?= , Marek Szyprowski , Robin Murphy Cc: Andrew Davis , Jared Kangas , Mattijs Korpershoek , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, Maxime Ripard X-Mailer: b4 0.14.2 In order to create a CMA heap instance for each CMA region found in the system, we need to register each of these instances. While it would appear trivial, the CMA regions are created super early in the kernel boot process, before most of the subsystems are initialized. Thus, we can't just create an exported function to create a heap from the CMA region being initialized. What we can do however is create a two-step process, where we collect all the CMA regions into an array early on, and then when we initialize the heaps we iterate over that array and create the heaps from the CMA regions we collected. Reviewed-by: T.J. Mercier Signed-off-by: Maxime Ripard --- MAINTAINERS | 1 + drivers/dma-buf/heaps/cma_heap.c | 14 ++++++++++++++ include/linux/dma-buf/heaps/cma.h | 16 ++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 46126ce2f968e4f9260263f1574ee29f5ff0de1c..c4edcc29368eec722432a85ac5c= 420a08c2680ea 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7306,10 +7306,11 @@ T: git https://gitlab.freedesktop.org/drm/misc/kern= el.git F: Documentation/driver-api/dma-buf.rst F: Documentation/userspace-api/dma-buf-alloc-exchange.rst F: drivers/dma-buf/ F: include/linux/*fence.h F: include/linux/dma-buf.h +F: include/linux/dma-buf/ F: include/linux/dma-resv.h K: \bdma_(?:buf|fence|resv)\b =20 DMA GENERIC OFFLOAD ENGINE SUBSYSTEM M: Vinod Koul diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_h= eap.c index 0df007111975447d555714d61ead9699287fd65a..2a901af635ed76cdb085915c032= 58c235e302792 100644 --- a/drivers/dma-buf/heaps/cma_heap.c +++ b/drivers/dma-buf/heaps/cma_heap.c @@ -12,10 +12,11 @@ =20 #define pr_fmt(fmt) "cma_heap: " fmt =20 #include #include +#include #include #include #include #include #include @@ -25,10 +26,23 @@ #include #include =20 #define DEFAULT_CMA_NAME "default_cma_region" =20 +static struct cma *dma_areas[MAX_CMA_AREAS] __initdata; +static unsigned int dma_areas_num __initdata; + +int __init dma_heap_cma_register_heap(struct cma *cma) +{ + if (dma_areas_num >=3D ARRAY_SIZE(dma_areas)) + return -EINVAL; + + dma_areas[dma_areas_num++] =3D cma; + + return 0; +} + struct cma_heap { struct dma_heap *heap; struct cma *cma; }; =20 diff --git a/include/linux/dma-buf/heaps/cma.h b/include/linux/dma-buf/heap= s/cma.h new file mode 100644 index 0000000000000000000000000000000000000000..e751479e21e703e24a5f799b4a7= fc8bd0df3c1c4 --- /dev/null +++ b/include/linux/dma-buf/heaps/cma.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef DMA_BUF_HEAP_CMA_H_ +#define DMA_BUF_HEAP_CMA_H_ + +struct cma; + +#ifdef CONFIG_DMABUF_HEAPS_CMA +int dma_heap_cma_register_heap(struct cma *cma); +#else +static inline int dma_heap_cma_register_heap(struct cma *cma) +{ + return 0; +} +#endif // CONFIG_DMABUF_HEAPS_CMA + +#endif // DMA_BUF_HEAP_CMA_H_ --=20 2.51.0 From nobody Fri Dec 19 13:48:09 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28D2A2F9C32; Mon, 13 Oct 2025 08:35:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760344530; cv=none; b=TbxPjEWwTXCmCD9f940oVw5/uNeGUAtwYAbPyYHqEjslkRwCnAARTtML2mIVW1rEz+WW/JRgFDkSxBQ/ADO9zcrvfaTqYJsYX6lxnxNhTgUa6tSkWtFzWGl3GJBChCq+5RbCjUgfhxjj59ROIbJWPybhQbdAW+9zClL3Cs8Yx/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760344530; c=relaxed/simple; bh=M2vThTE/nI9A0eTijjOxBfcDZbixVCE8PiHlBxnoWQA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mtb05i4kEBv9Eg4OI1zScGqkbsVdBZhdlgrQUNGj0BNQqgUNpit1EAhhg06dsh2ZtFzKMtJdJ0YN/bZ4PV0qqvYA+5m19y1XULjhvc3CS6f6ahXpgB/Nsa8AcVrESdj4O1dW4VrF5ZaNanloBa5CFu6sRe0HC+iTG/u7BH7MA0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=udRzakzM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="udRzakzM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CCE1C4CEFE; Mon, 13 Oct 2025 08:35:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760344529; bh=M2vThTE/nI9A0eTijjOxBfcDZbixVCE8PiHlBxnoWQA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=udRzakzMd65x34EnOiiJO3y0lmwBPB59JEsxf5CiiZGpioeiYJ2Z1WkKEAfdwPcSv Y25ihnMa3oxJIV79BNsn3ZKjjqXaBYwzBtpJhmQZP4onwtG2wtoLNTH+eQDs2dxnfn +1Mrwpopx9n9OrTNCi5M6vdZXhKwsn70zWwQCfL6R+AaTUKzmYhQjb4g/tePHoa5wN /+CSa2Kbnisjnx1m+8ePqyi3EkHGDshcQ81sZ1iHIi7VHY5QcE47KKfoIS/vhzm5xH e1y/V7epIlUYbY5eE3cQworkNeLzsbU4PmS72hjmcqL3M9fex5e+B4J/z37VpCMiVj zI5bn+jm7XRhw== From: Maxime Ripard Date: Mon, 13 Oct 2025 10:35:18 +0200 Subject: [PATCH v8 3/5] dma: contiguous: Register reusable CMA regions at boot Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251013-dma-buf-ecc-heap-v8-3-04ce150ea3d9@kernel.org> References: <20251013-dma-buf-ecc-heap-v8-0-04ce150ea3d9@kernel.org> In-Reply-To: <20251013-dma-buf-ecc-heap-v8-0-04ce150ea3d9@kernel.org> To: Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , Jonathan Corbet , =?utf-8?q?Christian_K=C3=B6nig?= , Marek Szyprowski , Robin Murphy Cc: Andrew Davis , Jared Kangas , Mattijs Korpershoek , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, Maxime Ripard X-Mailer: b4 0.14.2 In order to create a CMA dma-buf heap instance for each CMA heap region in the system, we need to collect all of them during boot. They are created from two main sources: the reserved-memory regions in the device tree, and the default CMA region created from the configuration or command line parameters, if no default region is provided in the device tree. Let's collect all the device-tree defined CMA regions flagged as reusable. Reviewed-by: T.J. Mercier Signed-off-by: Maxime Ripard Acked-by: Marek Szyprowski --- kernel/dma/contiguous.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index d9b9dcba6ff7cf5904ac93b72c061fd59072c41b..d67e95094749d45f43c1809c175= e491a3f55b2e1 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -40,10 +40,11 @@ #include =20 #include #include #include +#include #include #include #include =20 #ifdef CONFIG_CMA_SIZE_MBYTES @@ -491,9 +492,13 @@ static int __init rmem_cma_setup(struct reserved_mem *= rmem) rmem->priv =3D cma; =20 pr_info("Reserved memory: created CMA memory pool at %pa, size %ld MiB\n", &rmem->base, (unsigned long)rmem->size / SZ_1M); =20 + err =3D dma_heap_cma_register_heap(cma); + if (err) + pr_warn("Couldn't register CMA heap."); + return 0; } RESERVEDMEM_OF_DECLARE(cma, "shared-dma-pool", rmem_cma_setup); #endif --=20 2.51.0 From nobody Fri Dec 19 13:48:09 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D4582F8BF7; Mon, 13 Oct 2025 08:35:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760344534; cv=none; b=SWwFP5xY1gA08kVBlBJdEYR92zqUeBKi5fNnFKsgmSR2ulX5q3aMMr09vdO2KikU9h7yShiZSfq/ve58PnnpSAPkcE62iYzKz3M9faoZFWzbKf4ok/7jiD/sItckQInrw0+J7pM1gaJCjde9iL6AJPtBztahgDBeafff1kP9eLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760344534; c=relaxed/simple; bh=86W+tMqIGJ9AE1Kqrh+zL9da/Dha/yDtcLOGrEf75Ss=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kg9OinK3h5vN+v2L/nbClEd3Ko7ju86ecf1vjfXJVeBLOmR6YvJDSYaRAFUlOtDpaprUiaTaacft4ZQB2oeJEJiq8m44aay2RV4urGIlJZYf+aRhUgu4xia1eQgpJSbYirJ+YypR01KfnBQTpCkhI7+S5a14ANaA/+/C4QJLfj8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XWiLvI7J; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XWiLvI7J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B715C4CEE7; Mon, 13 Oct 2025 08:35:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760344532; bh=86W+tMqIGJ9AE1Kqrh+zL9da/Dha/yDtcLOGrEf75Ss=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XWiLvI7JXavv2mgEVXeUOzPMjY+KBbO+7mMEdBx6I35dBuc41wnN/wTfkd899wAek xxVLhIT86GOTeK8YeNP/hmMfP/xO8wgUmxfu4rHa+rG0QL7TBMEUkQb3u3XnTsUcvB OJNh+SsL1SnzH2G7tattrwNfm/T8CkSvuxsyV4XYK+CYh5W4smRW03MdXuJ/k+p0h6 ZszoBCReQlhGFhJKmjVVmSJvARYZ7lpepzifbp6vpCggzfbzvQW5Gxfjk5NoRVi/j9 5INvGi+N3jc4JNGGG2kEtNdGB23rvI5czBKQqAK/r5l06Ygl2uCFk1ijeFJuW5Zyt3 WafdFcjzgWndQ== From: Maxime Ripard Date: Mon, 13 Oct 2025 10:35:19 +0200 Subject: [PATCH v8 4/5] dma: contiguous: Reserve default CMA heap Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251013-dma-buf-ecc-heap-v8-4-04ce150ea3d9@kernel.org> References: <20251013-dma-buf-ecc-heap-v8-0-04ce150ea3d9@kernel.org> In-Reply-To: <20251013-dma-buf-ecc-heap-v8-0-04ce150ea3d9@kernel.org> To: Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , Jonathan Corbet , =?utf-8?q?Christian_K=C3=B6nig?= , Marek Szyprowski , Robin Murphy Cc: Andrew Davis , Jared Kangas , Mattijs Korpershoek , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, Maxime Ripard X-Mailer: b4 0.14.2 The CMA code, in addition to the reserved-memory regions in the device tree, will also register a default CMA region if the device tree doesn't provide any, with its size and position coming from either the kernel command-line or configuration. Let's register that one for use to create a heap for it. Reviewed-by: T.J. Mercier Signed-off-by: Maxime Ripard --- kernel/dma/contiguous.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index d67e95094749d45f43c1809c175e491a3f55b2e1..d8fd6f779f797f711b8e0fd628f= 868d644b8f784 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -240,17 +240,23 @@ void __init dma_contiguous_reserve(phys_addr_t limit) selected_size =3D max(size_bytes, cma_early_percent_memory()); #endif } =20 if (selected_size && !dma_contiguous_default_area) { + int ret; + pr_debug("%s: reserving %ld MiB for global area\n", __func__, (unsigned long)selected_size / SZ_1M); =20 dma_contiguous_reserve_area(selected_size, selected_base, selected_limit, &dma_contiguous_default_area, fixed); + + ret =3D dma_heap_cma_register_heap(dma_contiguous_default_area); + if (ret) + pr_warn("Couldn't register default CMA heap."); } } =20 void __weak dma_contiguous_early_fixup(phys_addr_t base, unsigned long size) --=20 2.51.0 From nobody Fri Dec 19 13:48:09 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3ED992FB97F; Mon, 13 Oct 2025 08:35:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760344536; cv=none; b=VfOAei1APVb1Nx9J5RN6gVDuUAci+ka7M5Xx8NPAaXn1z3wYrGCMstqF2N9RA4DYKqGe/8l4Ou139A839FgrMDWcBpoHfYfqhL9dLUZEpOA4DMrVODJ9jcruHzdrndTVI5azUeC/AxotXlAJbzjJ6R1sb1X0vvVUH+a3/aCF4uI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760344536; c=relaxed/simple; bh=KLq6UV149iWlcbOb9BAgyPNNCpzPtwQ5QaRQCIh5ebk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Bd6RroZ1p5ZbFLBKreWss+fiN5ttAfQklrRAY0sauQ8KaYqe6Y3Hutqz4ykk2X2tnwEcdUwJEcoShBybhWA5A0MrJZxAIQLKYNwUqMxWAqz7/OoOIcpTs+RthupyhlFVFzMKd+TQXcfd4Rr2x9Wego0DFvzY6x/hr+uK6eLC+nA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Sl+YtXJN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Sl+YtXJN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6ABFAC116B1; Mon, 13 Oct 2025 08:35:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760344535; bh=KLq6UV149iWlcbOb9BAgyPNNCpzPtwQ5QaRQCIh5ebk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Sl+YtXJNxiPzUTKnj5nq7CzD43piYS7wBecQAXfiXUxaN94nXtUgXkTFnKXYLWHJ2 //ttm99e5QkvlcJSSlRjvk2r9KxeHpidc/j/xyNP4xZdsmAaLg+e2Cf7s9AtBqnO3C pSDXZGssVOarVlUO1MmNkp7PO/mQoofCC3ur/DX1n3LkOXiLEhvBgUevaaD7in4059 rbgkE5z1rRx6XiG2IjkZty8gHd8FPYtqHixT7yFWMWDhuJ/iXCAc4S/eMw8KQlxMFc oFSXtPJSwsYIiXrcFSRAfN4eLWO4bJ0rAXdSg5aSjTmIhlPo3ZQk+0ZGJmOjZSjRzM tWecRHFZNPHQg== From: Maxime Ripard Date: Mon, 13 Oct 2025 10:35:20 +0200 Subject: [PATCH v8 5/5] dma-buf: heaps: cma: Create CMA heap for each CMA reserved region Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251013-dma-buf-ecc-heap-v8-5-04ce150ea3d9@kernel.org> References: <20251013-dma-buf-ecc-heap-v8-0-04ce150ea3d9@kernel.org> In-Reply-To: <20251013-dma-buf-ecc-heap-v8-0-04ce150ea3d9@kernel.org> To: Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , Jonathan Corbet , =?utf-8?q?Christian_K=C3=B6nig?= , Marek Szyprowski , Robin Murphy Cc: Andrew Davis , Jared Kangas , Mattijs Korpershoek , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, Maxime Ripard X-Mailer: b4 0.14.2 Aside from the main CMA region, it can be useful to allow userspace to allocate from the other CMA reserved regions. Indeed, those regions can have specific properties that can be useful to a specific us-case. For example, one of them platform I've been with has ECC enabled on the entire memory but for a specific region. Using that region to allocate framebuffers can be particular beneficial because enabling the ECC has a performance and memory footprint cost. Thus, exposing these regions as heaps user-space can allocate from and import wherever needed allows to cover that use-case. For now, only shared-dma-pools regions with the reusable property (ie, backed by CMA) are supported, but eventually we'll want to support other DMA pools types. Since we collected all the CMA regions created during boot, we can simply iterate over all of them to create the heaps. This has a weird interaction with the recent work on the CMA name, in particular the backward compatibility code created by commit 854acbe75ff4 ("dma-buf: heaps: Give default CMA heap a fixed name"). Indeed, the old name was either 'reserved', or the name of the reserved-memory region device tree node if the linux,cma-default property was set. In both these cases, we have now collected this region during boot, and we're using the same name. So we're now largely redundant with the code to handle backward compatibility code, and we can thus remove it and the associated Kconfig option. Reviewed-by: T.J. Mercier Signed-off-by: Maxime Ripard --- Documentation/userspace-api/dma-buf-heaps.rst | 9 +++++--- drivers/dma-buf/heaps/Kconfig | 10 -------- drivers/dma-buf/heaps/cma_heap.c | 33 +++++++++++++----------= ---- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/Documentation/userspace-api/dma-buf-heaps.rst b/Documentation/= userspace-api/dma-buf-heaps.rst index 17bf6829efd7963bc849765db54d327644e8c395..b78d2faeba62cda721a1f49d49e= 02bcb520ad429 100644 --- a/Documentation/userspace-api/dma-buf-heaps.rst +++ b/Documentation/userspace-api/dma-buf-heaps.rst @@ -22,8 +22,11 @@ following heaps: through the ``cma`` parameter, a memory region Device-Tree node with the ``linux,cma-default`` property set, or through the ``CMA_SIZE_MBYTES`` or ``CMA_SIZE_PERCENTAGE`` Kconfig options. Prior to Linux 6.17, its name wasn't stable and could be called ``reserved``, ``linux,cma``, or ``default-pool``, depending on the - platform. From Linux 6.17 onwards, the creation of these heaps is - controlled through the ``DMABUF_HEAPS_CMA_LEGACY`` Kconfig option for - backwards compatibility. + platform. + + - A heap will be created for each reusable region in the device tree + with the ``shared-dma-pool`` compatible, using the full device tree + node name as its name. The buffer semantics are identical to + ``default-cma-region``. diff --git a/drivers/dma-buf/heaps/Kconfig b/drivers/dma-buf/heaps/Kconfig index bb369b38b001af51721b56e065df92825022f1f1..a5eef06c422644e8aadaf5aff2b= d9a33c49c1ba3 100644 --- a/drivers/dma-buf/heaps/Kconfig +++ b/drivers/dma-buf/heaps/Kconfig @@ -10,15 +10,5 @@ config DMABUF_HEAPS_CMA depends on DMABUF_HEAPS && DMA_CMA help Choose this option to enable dma-buf CMA heap. This heap is backed by the Contiguous Memory Allocator (CMA). If your system has these regions, you should say Y here. - -config DMABUF_HEAPS_CMA_LEGACY - bool "Legacy DMA-BUF CMA Heap" - default y - depends on DMABUF_HEAPS_CMA - help - Add a duplicate CMA-backed dma-buf heap with legacy naming derived - from the CMA area's devicetree node, or "reserved" if the area is not - defined in the devicetree. This uses the same underlying allocator as - CONFIG_DMABUF_HEAPS_CMA. diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_h= eap.c index 2a901af635ed76cdb085915c03258c235e302792..42f88193eab9f8f4571064c7b3b= 8a73bca20fdf4 100644 --- a/drivers/dma-buf/heaps/cma_heap.c +++ b/drivers/dma-buf/heaps/cma_heap.c @@ -20,10 +20,12 @@ #include #include #include #include #include +#include +#include #include #include #include =20 #define DEFAULT_CMA_NAME "default_cma_region" @@ -407,35 +409,32 @@ static int __init __add_cma_heap(struct cma *cma, con= st char *name) } =20 return 0; } =20 -static int __init add_default_cma_heap(void) +static int __init add_cma_heaps(void) { struct cma *default_cma =3D dev_get_cma_area(NULL); - const char *legacy_cma_name; + unsigned int i; int ret; =20 - if (!default_cma) - return 0; + if (default_cma) { + ret =3D __add_cma_heap(default_cma, DEFAULT_CMA_NAME); + if (ret) + return ret; + } =20 - ret =3D __add_cma_heap(default_cma, DEFAULT_CMA_NAME); - if (ret) - return ret; + for (i =3D 0; i < dma_areas_num; i++) { + struct cma *cma =3D dma_areas[i]; =20 - if (IS_ENABLED(CONFIG_DMABUF_HEAPS_CMA_LEGACY)) { - legacy_cma_name =3D cma_get_name(default_cma); - if (!strcmp(legacy_cma_name, DEFAULT_CMA_NAME)) { - pr_warn("legacy name and default name are the same, skipping legacy hea= p\n"); - return 0; + ret =3D __add_cma_heap(cma, cma_get_name(cma)); + if (ret) { + pr_warn("Failed to add CMA heap %s", cma_get_name(cma)); + continue; } =20 - ret =3D __add_cma_heap(default_cma, legacy_cma_name); - if (ret) - pr_warn("failed to add legacy heap: %pe\n", - ERR_PTR(ret)); } =20 return 0; } -module_init(add_default_cma_heap); +module_init(add_cma_heaps); MODULE_DESCRIPTION("DMA-BUF CMA Heap"); --=20 2.51.0