drivers/dma-buf/heaps/Kconfig | 8 + drivers/dma-buf/heaps/Makefile | 1 + drivers/dma-buf/heaps/carveout_heap.c | 360 ++++++++++++++++++++++++++++++++++ drivers/dma-buf/heaps/system_heap.c | 3 +- 4 files changed, 370 insertions(+), 2 deletions(-)
Hi, This series is the follow-up of the discussion that John and I had some time ago here: https://lore.kernel.org/all/CANDhNCquJn6bH3KxKf65BWiTYLVqSd9892-xtFDHHqqyrroCMQ@mail.gmail.com/ The initial problem we were discussing was that I'm currently working on a platform which has a memory layout with ECC enabled. However, enabling the ECC has a number of drawbacks on that platform: lower performance, increased memory usage, etc. So for things like framebuffers, the trade-off isn't great and thus there's a memory region with ECC disabled to allocate from for such use cases. After a suggestion from John, I chose to first start using heap allocations flags to allow for userspace to ask for a particular ECC setup. This is then backed by a new heap type that runs from reserved memory chunks flagged as such, and the existing DT properties to specify the ECC properties. After further discussion, it was considered that flags were not the right solution, and relying on the names of the heaps would be enough to let userspace know the kind of buffer it deals with. Thus, even though the uAPI part of it has been dropped in this second version, we still need a driver to create heaps out of carved-out memory regions. In addition to the original usecase, a similar driver can be found in BSPs from most vendors, so I believe it would be a useful addition to the kernel. I submitted a draft PR to the DT schema for the bindings used in this PR: https://github.com/devicetree-org/dt-schema/pull/138 Let me know what you think, Maxime Signed-off-by: Maxime Ripard <mripard@kernel.org> --- Changes in v3: - Reworked global variable patch - Link to v2: https://lore.kernel.org/r/20250401-dma-buf-ecc-heap-v2-0-043fd006a1af@kernel.org Changes in v2: - Add vmap/vunmap operations - Drop ECC flags uapi - Rebase on top of 6.14 - Link to v1: https://lore.kernel.org/r/20240515-dma-buf-ecc-heap-v1-0-54cbbd049511@kernel.org --- Maxime Ripard (2): dma-buf: heaps: system: Remove global variable dma-buf: heaps: Introduce a new heap for reserved memory drivers/dma-buf/heaps/Kconfig | 8 + drivers/dma-buf/heaps/Makefile | 1 + drivers/dma-buf/heaps/carveout_heap.c | 360 ++++++++++++++++++++++++++++++++++ drivers/dma-buf/heaps/system_heap.c | 3 +- 4 files changed, 370 insertions(+), 2 deletions(-) --- base-commit: fcbf30774e82a441890b722bf0c26542fb82150f change-id: 20240515-dma-buf-ecc-heap-28a311d2c94e Best regards, -- Maxime Ripard <mripard@kernel.org>
Hi, On Mon, Apr 07, 2025 at 06:29:06PM +0200, Maxime Ripard wrote: > Hi, > > This series is the follow-up of the discussion that John and I had some > time ago here: > > https://lore.kernel.org/all/CANDhNCquJn6bH3KxKf65BWiTYLVqSd9892-xtFDHHqqyrroCMQ@mail.gmail.com/ > > The initial problem we were discussing was that I'm currently working on > a platform which has a memory layout with ECC enabled. However, enabling > the ECC has a number of drawbacks on that platform: lower performance, > increased memory usage, etc. So for things like framebuffers, the > trade-off isn't great and thus there's a memory region with ECC disabled > to allocate from for such use cases. > > After a suggestion from John, I chose to first start using heap > allocations flags to allow for userspace to ask for a particular ECC > setup. This is then backed by a new heap type that runs from reserved > memory chunks flagged as such, and the existing DT properties to specify > the ECC properties. > > After further discussion, it was considered that flags were not the > right solution, and relying on the names of the heaps would be enough to > let userspace know the kind of buffer it deals with. > > Thus, even though the uAPI part of it has been dropped in this second > version, we still need a driver to create heaps out of carved-out memory > regions. In addition to the original usecase, a similar driver can be > found in BSPs from most vendors, so I believe it would be a useful > addition to the kernel. > > I submitted a draft PR to the DT schema for the bindings used in this > PR: > https://github.com/devicetree-org/dt-schema/pull/138 One thing the discussion about the CMA heap naming[1] with John made me realize is that if we have both a region that is exported as a carved-out heap, and with devices pointing to it with reserved-memory, we wouldn't use the same allocator in both cases. It looks like we have four cases: - We have a shared-dma-pool region with the reusable property: the region is registered as a CMA area, the devices will allocate from that. - We have a shared-dma-pool region without the reusable property: the region is registered as a coherent DMA area, and the devices will allocate from that pool. - We have a restricted-dma-pool region, devices will allocate from swiotlb - We have any other region, we can do whatever. So, the driver only supports the fourth case, and should be significantly more complicated. I'll work on that. Maxime 1: https://lore.kernel.org/dri-devel/20250422191939.555963-1-jkangas@redhat.com/
© 2016 - 2025 Red Hat, Inc.