From: Karl Mehltretter <kmehltretter@gmail.com>
To: Gerd Hoffmann <kraxel@redhat.com>,
Vivek Kasireddy <vivek.kasireddy@intel.com>
Cc: "Karl Mehltretter" <kmehltretter@gmail.com>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org
Subject: [PATCH] udmabuf: respect the device's maximum segment size
Date: Sat, 26 Sep 2026 09:12:58 +0200 [thread overview]
Message-ID: <20260926071258.77202-1-kmehltretter@gmail.com> (raw)
get_sg_table() merges physically contiguous pages without accounting
for the mapping device's maximum segment size. This affects both
importer mappings and the udmabuf misc device mapping used for CPU
access.
With DMA_API_DEBUG enabled, DMA_BUF_IOCTL_SYNC on a 64 MiB udmabuf
reports:
DMA-API: misc udmabuf: mapping sg segment longer than device claims to support [len=65884160] [max=65536]
Use sg_alloc_table_from_pages_segment() with the mapping device's
maximum segment size. Keep a PAGE_SIZE minimum because the allocator
warns and returns -EINVAL for smaller limits.
Before commit 5bf888673e0d ("udmabuf: Do not create malformed
scatterlists"), each entry covered one page.
Fixes: 5bf888673e0d ("udmabuf: Do not create malformed scatterlists")
Assisted-by: LLM
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
Notes:
Tested on v7.3-rc4-70-gfe2ec83746e5 in QEMU (x86_64, TCG) with
DMA_API_DEBUG (all_errors=1) and DMABUF_DEBUG, A/B against the same
base:
before after
DMA_BUF_IOCTL_SYNC, 64 MiB udmabuf 1 report 0
vivid import, 4 MiB udmabuf 2 reports 0
vivid import, 2 MiB hugetlb udmabuf 2 reports 0
frames captured 5/5 5/5
vb2-dma-contig rejected the non-contiguous import in both runs.
drivers/dma-buf/udmabuf.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index df6dd00462423..09f1eb8432f19 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -139,9 +139,13 @@ static struct sg_table *get_sg_table(struct device *dev, struct dma_buf *buf,
if (!sg)
return ERR_PTR(-ENOMEM);
- ret = sg_alloc_table_from_pages(sg, ubuf->pages, ubuf->pagecount, 0,
- ubuf->pagecount << PAGE_SHIFT,
- GFP_KERNEL);
+ /* The SG allocator requires a segment limit of at least PAGE_SIZE. */
+ ret = sg_alloc_table_from_pages_segment(sg, ubuf->pages, ubuf->pagecount,
+ 0, ubuf->pagecount << PAGE_SHIFT,
+ max_t(unsigned int,
+ dma_get_max_seg_size(dev),
+ PAGE_SIZE),
+ GFP_KERNEL);
if (ret < 0)
goto err_alloc;
--
2.53.0
next reply other threads:[~2026-09-26 7:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-26 7:12 Karl Mehltretter [this message]
2026-09-28 8:27 ` Christian König
2026-09-28 12:58 ` Jason Gunthorpe
2026-09-29 12:08 ` Christian König
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=20260926071258.77202-1-kmehltretter@gmail.com \
--to=kmehltretter@gmail.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jgg@ziepe.ca \
--cc=kraxel@redhat.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=vivek.kasireddy@intel.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®