From: Karl Mehltretter <kmehltretter@gmail.com>
To: Tomasz Figa <tfiga@chromium.org>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Hans de Goede <hansg@kernel.org>,
Hans Verkuil <hverkuil@kernel.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: "Karl Mehltretter" <kmehltretter@gmail.com>,
"Christian König" <christian.koenig@amd.com>,
"Nicolas Dufresne" <nicolas@ndufresne.ca>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 0/3] media: synchronize CPU access to imported DMA-BUFs
Date: Sat, 7 Nov 2026 11:47:00 +0100 [thread overview]
Message-ID: <20261107104703.44111-1-kmehltretter@gmail.com> (raw)
uvcvideo and vivid (when using vb2-vmalloc) access imported DMA-BUFs
through a kernel vmap without cache synchronization. When a non-coherent
importer such as V3D maps the same DMA-BUF persistently, captured data
remains in the CPU cache while physical RAM holds stale bytes.
Add an opt-in uses_cpu_access queue flag for vb2-vmalloc queues to
bracket the interval from buf_prepare() through buf_finish() with
dma_buf_begin_cpu_access() and dma_buf_end_cpu_access(). Keep this
opt-in because some vb2-vmalloc drivers pass imported buffers to
hardware, and end CPU access in process context because DMA-BUF
callbacks may sleep.
This follows the per-queue flag proposed here:
https://lore.kernel.org/r/CAAFQd5Am5jBev5P1HmsdeHoJfROZat3bi1W=UsN7wpVqw-XUQQ@mail.gmail.com/
Based on Linux 7.4-rc1 with prerequisite patch "media: videobuf2: finish
prepared buffers in VIDIOC_REMOVE_BUFS":
https://lore.kernel.org/r/20261026071735.37220-1-kmehltretter@gmail.com/
Changes in v2:
- Split patch 1 of v1 into the standalone VIDIOC_REMOVE_BUFS patch above
and use its __vb2_buf_cancel() helper so queue cancellation and
VIDIOC_REMOVE_BUFS share the finish path (Tomasz).
- Scope uses_cpu_access to vb2-vmalloc queues and drop the attach_dmabuf
dma_dir parameter from vb2_mem_ops, videobuf2-dma-contig,
videobuf2-dma-sg and videobuf2-vmalloc (Tomasz).
- Enable uses_cpu_access in vivid only when vivid uses
vb2_vmalloc_memops (Tomasz).
Link to v1:
https://lore.kernel.org/r/cover.1792392288.git.kmehltretter@gmail.com/
Testing:
- Raspberry Pi 500+ (6.18.34+rpt-rpi-2712, aarch64, 16 KiB pages,
Sunplus UVC camera 1bcf:2701 and Broadcom V3D 7.1 GPU), backport of
the prerequisite patch plus patches 1 and 2: eight 640x480 YUYV frames
(614,400 B) captured into DMA-BUFs pre-seeded with 0xA5 and imported
into persistent EGL_LINUX_DMA_BUF_EXT textures before VIDIOC_STREAMON,
then copied by V3D 7.1 immediately after VIDIOC_DQBUF:
Heap Baseline stale Patched v2 stale
/dev/dma_heap/linux,cma 8/8 (329,890 B) 0/8 (0 B)
/dev/dma_heap/system 8/8 (509,818 B) 0/8 (0 B)
- QEMU virt (arm64, Linux 7.4-rc1 with the prerequisite patch and
patches 1-3, VIDEO_ADV_DEBUG=y, DEBUG_ATOMIC_SLEEP=y): six vivid
lifecycle cases (stream, streamoff-queued, prepare-reqbufs0,
prepare-remove, close-streaming, replace-dmabuf) across single-planar
and multi-planar queues with kprobe counters on
dma_buf_begin_cpu_access() and dma_buf_end_cpu_access():
Queue begin/end calls Unbalanced Warnings
vivid vb2-vmalloc (SP) 34 / 34 0 0
vivid vb2-vmalloc (MP) 34 / 34 0 0
vivid vb2-dma-contig (SP) 0 / 0 0 0
vivid vb2-dma-contig (MP) 0 / 0 0 0
20x prepare-remove (vmalloc) 20 / 20 0 0
Assisted by an LLM for code changes, test harnesses and commit message
drafting.
Karl Mehltretter (3):
media: videobuf2: add opt-in DMA-BUF CPU access
media: uvcvideo: synchronize imported DMA-BUFs for CPU access
media: vivid: synchronize imported DMA-BUFs for CPU access
.../media/common/videobuf2/videobuf2-core.c | 76 +++++++++++++++++++
drivers/media/test-drivers/vivid/vivid-core.c | 4 +-
drivers/media/usb/uvc/uvc_queue.c | 1 +
include/media/videobuf2-core.h | 5 ++
4 files changed, 85 insertions(+), 1 deletion(-)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
prerequisite-patch-id: aa99d5c3c27082cbe003ed94a195e3de415777c9
--
2.39.5 (Apple Git-154)
next reply other threads:[~2026-11-07 10:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 10:47 Karl Mehltretter [this message]
2026-11-07 10:47 ` [PATCH v2 1/3] media: videobuf2: add opt-in DMA-BUF CPU access Karl Mehltretter
2026-11-07 10:47 ` [PATCH v2 2/3] media: uvcvideo: synchronize imported DMA-BUFs for " Karl Mehltretter
2026-11-07 10:47 ` [PATCH v2 3/3] media: vivid: " Karl Mehltretter
2026-11-07 10:59 ` [PATCH v2 0/3] media: synchronize CPU access to imported DMA-BUFs Laurent Pinchart
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=20261107104703.44111-1-kmehltretter@gmail.com \
--to=kmehltretter@gmail.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=hansg@kernel.org \
--cc=hverkuil@kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@kernel.org \
--cc=nicolas@ndufresne.ca \
--cc=sumit.semwal@linaro.org \
--cc=tfiga@chromium.org \
/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®