From: Karl Mehltretter <kmehltretter@gmail.com>
To: "Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>
Cc: Karl Mehltretter <kmehltretter@gmail.com>,
Benjamin Gaignard <benjamin.gaignard@collabora.com>,
Brian Starkey <Brian.Starkey@arm.com>,
John Stultz <jstultz@google.com>,
"T . J . Mercier" <tjmercier@google.com>,
Jason Gunthorpe <jgg@nvidia.com>,
Dmitry Osipenko <digetx@gmail.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Thierry Reding <thierry.reding@kernel.org>,
Jonathan Hunter <jonathanh@nvidia.com>,
Russell King <linux@armlinux.org.uk>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linaro-mm-sig@lists.linaro.org, linux-tegra@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] dma-buf: heaps: cma: respect the device's maximum segment size
Date: Mon, 5 Oct 2026 08:46:40 +0200 [thread overview]
Message-ID: <20261005064640.7776-4-kmehltretter@gmail.com> (raw)
In-Reply-To: <20261005064640.7776-1-kmehltretter@gmail.com>
cma_heap_attach() merges the physically contiguous buffer into one
scatterlist entry without considering the importing device's maximum
segment size. With DMA_API_DEBUG, importing a buffer larger than that
limit reports, here with atmel-hlcdc:
DMA-API: atmel-hlcdc-display-controller atmel-hlcdc-dc: mapping sg
segment longer than device claims to support [len=307200] [max=65536]
Build each attachment table using the importing device's segment limit.
Return -EINVAL if the limit is smaller than PAGE_SIZE because the
page-based allocator cannot honor it.
An importer that needs the whole buffer as one entry has to declare a
segment size that covers it. tegra-vde without an IOMMU domain and
armada did not. Their limits must be raised before this change is
applied.
Reproduced with a custom QEMU model of the SAM9X75 Curiosity. Not
tested on real hardware.
Fixes: b61614ec318a ("dma-buf: heaps: Add CMA heap to dmabuf heaps")
Cc: stable+noautosel@kernel.org # needs the tegra-vde and armada segment size changes first
Assisted-by: LLM
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
Notes:
Tested on v7.3-rc4-70-gfe2ec83746e5 with DMA_API_DEBUG and
DMABUF_DEBUG, on a custom QEMU model of the SAM9X75 Curiosity
(ARM926EJ-S, TCG) with an XLCDC model.
vivid captures into three 307200-byte CMA heap buffers, which
atmel-hlcdc imports and scans out. All 8 frames are shown before and
after the patch, with 3 DMA-API reports before and none after.
A test importer maps a 256 KiB CMA heap buffer with different
maximum segment sizes (4 KiB pages):
max segment (bytes) before after
2048 1 x 256 KiB attach returns -EINVAL
4096 1 x 256 KiB 64 x 4 KiB
65536 1 x 256 KiB 4 x 64 KiB
UINT_MAX 1 x 256 KiB 1 x 256 KiB
The first three cases gave a DMA-API report before the patch and
none after it.
drivers/dma-buf/heaps/cma_heap.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
index 3fb4b946c91a..9d61d14688b8 100644
--- a/drivers/dma-buf/heaps/cma_heap.c
+++ b/drivers/dma-buf/heaps/cma_heap.c
@@ -58,16 +58,22 @@ static int cma_heap_attach(struct dma_buf *dmabuf,
{
struct cma_heap_buffer *buffer = dmabuf->priv;
struct dma_heap_attachment *a;
+ unsigned int max_segment;
int ret;
+ max_segment = dma_get_max_seg_size(attachment->dev);
+ /* The SG allocator requires a segment limit of at least PAGE_SIZE. */
+ if (max_segment < PAGE_SIZE)
+ return -EINVAL;
+
a = kzalloc_obj(*a);
if (!a)
return -ENOMEM;
- ret = sg_alloc_table_from_pages(&a->table, buffer->pages,
- buffer->pagecount, 0,
- buffer->pagecount << PAGE_SHIFT,
- GFP_KERNEL);
+ ret = sg_alloc_table_from_pages_segment(&a->table, buffer->pages,
+ buffer->pagecount, 0,
+ buffer->pagecount << PAGE_SHIFT,
+ max_segment, GFP_KERNEL);
if (ret) {
kfree(a);
return ret;
--
2.53.0
prev parent reply other threads:[~2026-10-05 6:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-05 6:46 [PATCH 0/3] dma-buf: heaps: cma: respect the importer's " Karl Mehltretter
2026-10-05 6:46 ` [PATCH 1/3] media: tegra-vde: set an unlimited DMA " Karl Mehltretter
2026-10-05 6:46 ` [PATCH 2/3] drm/armada: " Karl Mehltretter
2026-10-05 6:46 ` Karl Mehltretter [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261005064640.7776-4-kmehltretter@gmail.com \
--to=kmehltretter@gmail.com \
--cc=Brian.Starkey@arm.com \
--cc=airlied@gmail.com \
--cc=benjamin.gaignard@collabora.com \
--cc=christian.koenig@amd.com \
--cc=digetx@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jgg@nvidia.com \
--cc=jonathanh@nvidia.com \
--cc=jstultz@google.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mchehab@kernel.org \
--cc=simona@ffwll.ch \
--cc=sumit.semwal@linaro.org \
--cc=thierry.reding@kernel.org \
--cc=tjmercier@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®