lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Tue, 18 Jun 2024 13:00:04 +0530
From: TaoJiang <tao.jiang_2@....com>
To: mchehab@...nel.org,
	hverkuil-cisco@...all.nl
Cc: nicolas@...fresne.ca,
	shawnguo@...nel.org,
	robh+dt@...nel.org,
	s.hauer@...gutronix.de,
	kernel@...gutronix.de,
	festevam@...il.com,
	linux-imx@....com,
	xiahong.bao@....com,
	eagle.zhou@....com,
	tao.jiang_2@....com,
	ming.qian@....nxp.com,
	imx@...ts.linux.dev,
	linux-media@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	tfiga@...omium.org,
	m.szyprowski@...sung.com,
	sumit.semwal@...aro.org,
	christian.koenig@....com,
	dri-devel@...ts.freedesktop.org,
	linaro-mm-sig@...ts.linaro.org,
	Ming Qian <ming.qian@....com>
Subject: [PATCH] media: videobuf2: sync caches for dmabuf memory

From: Ming Qian <ming.qian@....com>

When the memory type is VB2_MEMORY_DMABUF, the v4l2 device can't know
whether the dma buffer is coherent or synchronized.

The videobuf2-core will skip cache syncs as it think the DMA exporter
should take care of cache syncs

But in fact it's likely that the client doesn't
synchronize the dma buf before qbuf() or after dqbuf(). and it's
difficult to find this type of error directly.

I think it's helpful that videobuf2-core can call
dma_buf_end_cpu_access() and dma_buf_begin_cpu_access() to handle the
cache syncs.

Signed-off-by: Ming Qian <ming.qian@....com>
Signed-off-by: TaoJiang <tao.jiang_2@....com>
---
 .../media/common/videobuf2/videobuf2-core.c   | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
index 358f1fe42975..4734ff9cf3ce 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -340,6 +340,17 @@ static void __vb2_buf_mem_prepare(struct vb2_buffer *vb)
 	vb->synced = 1;
 	for (plane = 0; plane < vb->num_planes; ++plane)
 		call_void_memop(vb, prepare, vb->planes[plane].mem_priv);
+
+	if (vb->memory != VB2_MEMORY_DMABUF)
+		return;
+	for (plane = 0; plane < vb->num_planes; ++plane) {
+		struct dma_buf *dbuf = vb->planes[plane].dbuf;
+
+		if (!dbuf)
+			continue;
+
+		dma_buf_end_cpu_access(dbuf, vb->vb2_queue->dma_dir);
+	}
 }
 
 /*
@@ -356,6 +367,17 @@ static void __vb2_buf_mem_finish(struct vb2_buffer *vb)
 	vb->synced = 0;
 	for (plane = 0; plane < vb->num_planes; ++plane)
 		call_void_memop(vb, finish, vb->planes[plane].mem_priv);
+
+	if (vb->memory != VB2_MEMORY_DMABUF)
+		return;
+	for (plane = 0; plane < vb->num_planes; ++plane) {
+		struct dma_buf *dbuf = vb->planes[plane].dbuf;
+
+		if (!dbuf)
+			continue;
+
+		dma_buf_begin_cpu_access(dbuf, vb->vb2_queue->dma_dir);
+	}
 }
 
 /*
-- 
2.43.0-rc1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ