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-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190114133839.29967-2-paul.kocialkowski@bootlin.com>
Date:   Mon, 14 Jan 2019 14:38:36 +0100
From:   Paul Kocialkowski <paul.kocialkowski@...tlin.com>
To:     linux-media@...r.kernel.org, linux-kernel@...r.kernel.org,
        devel@...verdev.osuosl.org, linux-arm-kernel@...ts.infradead.org,
        linux-sunxi@...glegroups.com
Cc:     Pawel Osciak <pawel@...iak.com>,
        Marek Szyprowski <m.szyprowski@...sung.com>,
        Kyungmin Park <kyungmin.park@...sung.com>,
        Mauro Carvalho Chehab <mchehab@...nel.org>,
        Maxime Ripard <maxime.ripard@...tlin.com>,
        Paul Kocialkowski <paul.kocialkowski@...tlin.com>,
        Randy Li <ayaka@...lik.info>,
        Hans Verkuil <hverkuil@...all.nl>,
        Ezequiel Garcia <ezequiel@...labora.com>,
        Tomasz Figa <tfiga@...omium.org>,
        Alexandre Courbot <acourbot@...omium.org>,
        Philipp Zabel <p.zabel@...gutronix.de>,
        Laurent Pinchart <laurent.pinchart@...asonboard.com>,
        Sakari Ailus <sakari.ailus@...ux.intel.com>,
        Thomas Petazzoni <thomas.petazzoni@...tlin.com>
Subject: [PATCH RFC 1/4] media: vb2: Add helpers to access unselected buffers

Introduce helpers to request and release access to buffers that are
not currently selected as current output or capture buffers.

This is useful to ensure proper access to buffers imported via dma-buf
that are used as reference and thus require associated map/unmap calls
before access.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@...tlin.com>
---
 .../media/common/videobuf2/videobuf2-core.c   | 46 +++++++++++++++++++
 include/media/videobuf2-core.h                | 15 ++++++
 2 files changed, 61 insertions(+)

diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
index 70e8c3366f9c..2a0c5de4d683 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -986,6 +986,52 @@ void vb2_discard_done(struct vb2_queue *q)
 }
 EXPORT_SYMBOL_GPL(vb2_discard_done);
 
+int vb2_buffer_access_request(struct vb2_buffer *vb)
+{
+	struct vb2_queue *q = vb->vb2_queue;
+	unsigned int plane;
+	int ret;
+
+	/* Only dmabuf-imported buffers need to be mapped before access. */
+	if (q->memory != VB2_MEMORY_DMABUF)
+		return -EINVAL;
+
+	for (plane = 0; plane < vb->num_planes; ++plane) {
+		if (vb->planes[plane].dbuf_mapped)
+			continue;
+
+		ret = call_memop(vb, map_dmabuf, vb->planes[plane].mem_priv);
+		if (ret) {
+			dprintk(1, "failed to map dmabuf for plane %d\n",
+				plane);
+			return ret;
+		}
+		vb->planes[plane].dbuf_mapped = 1;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(vb2_buffer_access_request);
+
+void vb2_buffer_access_release(struct vb2_buffer *vb)
+{
+	struct vb2_queue *q = vb->vb2_queue;
+	unsigned int plane;
+
+	/* Only dmabuf-imported buffers need to be unmapped after access. */
+	if (q->memory != VB2_MEMORY_DMABUF)
+		return;
+
+	for (plane = 0; plane < vb->num_planes; ++plane) {
+		if (!vb->planes[plane].dbuf_mapped)
+			continue;
+
+		call_void_memop(vb, unmap_dmabuf, vb->planes[plane].mem_priv);
+		vb->planes[plane].dbuf_mapped = 0;
+	}
+}
+EXPORT_SYMBOL_GPL(vb2_buffer_access_release);
+
 /*
  * __prepare_mmap() - prepare an MMAP buffer
  */
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 4a737b2c610b..bf378c1e718b 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -1199,4 +1199,19 @@ bool vb2_request_object_is_buffer(struct media_request_object *obj);
  */
 unsigned int vb2_request_buffer_cnt(struct media_request *req);
 
+/**
+ * vb2_buffer_access_request() - request out-of-band data access to a buffer
+ *
+ * @vb:		buffer to request data access for
+ */
+int vb2_buffer_access_request(struct vb2_buffer *vb);
+
+
+/**
+ * vb2_buffer_access_release() - release out-of-band data access to a buffer
+ *
+ * @vb:		buffer to release data access for
+ */
+void vb2_buffer_access_release(struct vb2_buffer *vb);
+
 #endif /* _MEDIA_VIDEOBUF2_CORE_H */
-- 
2.20.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ