[RFC PATCH 1/2] media: tegra-vde: match DMA direction on cache reuse

From: Florian Krischer

Date: Sun Nov 29 2026 - 12:47:08 EST


The DMA-BUF cache can reuse an attachment mapped in a different
direction. Updating the cached direction does not change the mapping,
and later unmap then uses a direction different from the original map.

Match both the DMA-BUF and its mapping direction before reusing a
cached attachment. This preserves the original direction for unmap
and keeps same-direction cache hits.

Signed-off-by: Florian Krischer <florian.krischer@xxxxxxx>
---
Build-tested for ARM with W=1 on media-committers/next with the
separately submitted mutex fix applied.
Hardware testing of cross-direction DMA-BUF reuse is pending.

diff --git a/drivers/media/platform/nvidia/tegra-vde/dmabuf-cache.c b/drivers/media/platform/nvidia/tegra-vde/dmabuf-cache.c
--- a/drivers/media/platform/nvidia/tegra-vde/dmabuf-cache.c
+++ b/drivers/media/platform/nvidia/tegra-vde/dmabuf-cache.c
@@ -76,14 +76,11 @@
mutex_lock(&vde->map_lock);

list_for_each_entry(entry, &vde->map_list, list) {
- if (entry->a->dmabuf != dmabuf)
+ if (entry->a->dmabuf != dmabuf || entry->dma_dir != dma_dir)
continue;

if (!cancel_delayed_work(&entry->dwork))
continue;
-
- if (entry->dma_dir != dma_dir)
- entry->dma_dir = DMA_BIDIRECTIONAL;

dma_buf_put(dmabuf);