From: Thomas Zimmermann <tzimmermann@suse.de>
To: airlied@redhat.com, daniel@ffwll.ch,
maarten.lankhorst@linux.intel.com, mripard@kernel.org,
hdegoede@redhat.com, christian.koenig@amd.com,
sumit.semwal@linaro.org
Cc: dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
linaro-mm-sig@lists.linaro.org,
Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH v2 7/7] dma-buf: Write down some rules for vmap usage
Date: Thu, 3 Dec 2020 15:02:59 +0100 [thread overview]
Message-ID: <20201203140259.26580-8-tzimmermann@suse.de> (raw)
In-Reply-To: <20201203140259.26580-1-tzimmermann@suse.de>
Dma-buf's vmap and vunmap callbacks are undocumented and various
exporters currently have slightly different semantics for them. Add
documentation on how to implement and use these interfaces correctly.
v2:
* document vmap semantics in struct dma_buf_ops
* add TODO item for reviewing and maybe fixing dma-buf exporters
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
Documentation/gpu/todo.rst | 15 +++++++++++++
include/drm/drm_gem.h | 4 ++++
include/linux/dma-buf.h | 45 ++++++++++++++++++++++++++++++++++++++
3 files changed, 64 insertions(+)
diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst
index 009d8e6c7e3c..32bb797a84fc 100644
--- a/Documentation/gpu/todo.rst
+++ b/Documentation/gpu/todo.rst
@@ -505,6 +505,21 @@ Contact: Thomas Zimmermann <tzimmermann@suse.de>, Christian König, Daniel Vette
Level: Intermediate
+Enforce rules for dma-buf vmap and pin ops
+------------------------------------------
+
+Exporter implementations of vmap and pin in struct dma_buf_ops (and consequently
+struct drm_gem_object_funcs) use a variety of locking semantics. Some rely on
+the caller holding the dma-buf's reservation lock, some do their own locking,
+some don't require any locking. VRAM helpers even used to pin as part of vmap.
+
+We need to review each exporter and enforce the documented rules.
+
+Contact: Christian König, Daniel Vetter, Thomas Zimmermann <tzimmermann@suse.de>
+
+Level: Advanced
+
+
Core refactorings
=================
diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
index 5e6daa1c982f..1864c6a721b1 100644
--- a/include/drm/drm_gem.h
+++ b/include/drm/drm_gem.h
@@ -138,6 +138,8 @@ struct drm_gem_object_funcs {
* drm_gem_dmabuf_vmap() helper.
*
* This callback is optional.
+ *
+ * See also struct dma_buf_ops.vmap
*/
int (*vmap)(struct drm_gem_object *obj, struct dma_buf_map *map);
@@ -148,6 +150,8 @@ struct drm_gem_object_funcs {
* drm_gem_dmabuf_vunmap() helper.
*
* This callback is optional.
+ *
+ * See also struct dma_buf_ops.vunmap
*/
void (*vunmap)(struct drm_gem_object *obj, struct dma_buf_map *map);
diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
index cf72699cb2bc..dc81fdc01dda 100644
--- a/include/linux/dma-buf.h
+++ b/include/linux/dma-buf.h
@@ -267,7 +267,52 @@ struct dma_buf_ops {
*/
int (*mmap)(struct dma_buf *, struct vm_area_struct *vma);
+ /**
+ * @vmap:
+ *
+ * Returns a virtual address for the buffer.
+ *
+ * Notes to callers:
+ *
+ * - Callers must hold the struct dma_buf.resv lock before calling
+ * this interface.
+ *
+ * - Callers must provide means to prevent the mappings from going
+ * stale, such as holding the reservation lock or providing a
+ * move-notify callback to the exporter.
+ *
+ * Notes to implementors:
+ *
+ * - Implementations must expect pairs of @vmap and @vunmap to be
+ * called frequently and should optimize for this case.
+ *
+ * - Implementations should avoid additional operations, such as
+ * pinning.
+ *
+ * - Implementations may expect the caller to hold the dma-buf's
+ * reservation lock to protect against concurrent calls and
+ * relocation.
+ *
+ * - Implementations may provide additional guarantees, such as working
+ * without holding the reservation lock.
+ *
+ * This callback is optional.
+ *
+ * Returns:
+ *
+ * 0 on success or a negative error code on failure.
+ */
int (*vmap)(struct dma_buf *dmabuf, struct dma_buf_map *map);
+
+ /**
+ * @vunmap:
+ *
+ * Releases the address previously returned by @vmap.
+ *
+ * This callback is optional.
+ *
+ * See also @vmap()
+ */
void (*vunmap)(struct dma_buf *dmabuf, struct dma_buf_map *map);
};
--
2.29.2
next prev parent reply other threads:[~2020-12-03 14:04 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-03 14:02 [PATCH v2 0/7] drm/vram-helper: Lock GEM BOs while they are mapped Thomas Zimmermann
2020-12-03 14:02 ` [PATCH v2 1/7] drm/ast: Don't pin cursor source BO explicitly during update Thomas Zimmermann
2020-12-03 14:02 ` [PATCH v2 2/7] drm/ast: Only map cursor BOs during updates Thomas Zimmermann
2020-12-03 14:02 ` [PATCH v2 3/7] drm/vram-helper: Move BO locking from vmap code into callers Thomas Zimmermann
2020-12-03 14:02 ` [PATCH v2 4/7] drm/vram-helper: Remove pinning from drm_gem_vram_{vmap,vunmap}() Thomas Zimmermann
2020-12-03 14:02 ` [PATCH v2 5/7] drm/vram-helper: Remove vmap reference counting Thomas Zimmermann
2020-12-03 14:02 ` [PATCH v2 6/7] drm/vram-helper: Simplify vmap implementation Thomas Zimmermann
2020-12-03 14:02 ` Thomas Zimmermann [this message]
2020-12-03 15:26 ` [PATCH v2 7/7] dma-buf: Write down some rules for vmap usage Daniel Vetter
2020-12-03 18:59 ` Thomas Zimmermann
2020-12-03 20:41 ` Daniel Vetter
2020-12-04 8:32 ` Thomas Zimmermann
2020-12-04 8:47 ` Christian König
2020-12-09 0:13 ` Daniel Vetter
2020-12-09 9:32 ` Thomas Zimmermann
2020-12-09 10:16 ` Daniel Vetter
2020-12-09 11:06 ` Christian König
2020-12-03 14:05 ` [PATCH v2 0/7] drm/vram-helper: Lock GEM BOs while they are mapped Thomas Zimmermann
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=20201203140259.26580-8-tzimmermann@suse.de \
--to=tzimmermann@suse.de \
--cc=airlied@redhat.com \
--cc=christian.koenig@amd.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=hdegoede@redhat.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-media@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=sumit.semwal@linaro.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