From: Simon Ser <contact@emersion.fr>
To: dri-devel@lists.freedesktop.org
Cc: "Daniel Vetter" <daniel.vetter@ffwll.ch>,
"Hans de Goede" <hdegoede@redhat.com>,
"Maxime Ripard" <maxime@cerno.tech>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"Tian Tao" <tiantao6@hisilicon.com>,
"Christian König" <christian.koenig@amd.com>
Subject: [PATCH v2 1/2] drm/prime: reject DMA-BUF attach when get_sg_table is missing
Date: Thu, 02 Mar 2023 14:35:09 +0000 [thread overview]
Message-ID: <20230302143502.500661-1-contact@emersion.fr> (raw)
drm_gem_map_dma_buf() requires drm_gem_object_funcs.get_sg_table
to be implemented, or else WARNs.
Allow drivers to leave this hook unimplemented to implement purely
local DMA-BUFs (ie, DMA-BUFs which cannot be imported anywhere
else but the device which allocated them). In that case, reject
imports to other devices in drm_gem_map_attach().
v2: new patch
Signed-off-by: Simon Ser <contact@emersion.fr>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Tian Tao <tiantao6@hisilicon.com>
Cc: Maxime Ripard <maxime@cerno.tech>
Cc: Christian König <christian.koenig@amd.com>
Cc: Hans de Goede <hdegoede@redhat.com>
---
drivers/gpu/drm/drm_prime.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index f924b8b4ab6b..ab1d21d63a03 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -544,7 +544,8 @@ int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
* Optional pinning of buffers is handled at dma-buf attach and detach time in
* drm_gem_map_attach() and drm_gem_map_detach(). Backing storage itself is
* handled by drm_gem_map_dma_buf() and drm_gem_unmap_dma_buf(), which relies on
- * &drm_gem_object_funcs.get_sg_table.
+ * &drm_gem_object_funcs.get_sg_table. If &drm_gem_object_funcs.get_sg_table is
+ * unimplemented, exports into another device are rejected.
*
* For kernel-internal access there's drm_gem_dmabuf_vmap() and
* drm_gem_dmabuf_vunmap(). Userspace mmap support is provided by
@@ -583,6 +584,9 @@ int drm_gem_map_attach(struct dma_buf *dma_buf,
{
struct drm_gem_object *obj = dma_buf->priv;
+ if (!obj->funcs->get_sg_table)
+ return -EOPNOTSUPP;
+
return drm_gem_pin(obj);
}
EXPORT_SYMBOL(drm_gem_map_attach);
--
2.39.2
next reply other threads:[~2023-03-02 14:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-02 14:35 Simon Ser [this message]
2023-03-02 14:35 ` [PATCH v2 2/2] drm/vram-helper: turn on PRIME import/export Simon Ser
2023-03-02 15:05 ` Thomas Zimmermann
2023-03-02 15:03 ` [PATCH v2 1/2] drm/prime: reject DMA-BUF attach when get_sg_table is missing Thomas Zimmermann
2023-03-02 15:05 ` Thomas Zimmermann
2023-03-02 15:56 ` Christian König
2023-06-09 11:31 ` Thomas Zimmermann
2023-06-09 13:04 ` Simon Ser
2023-06-12 15:10 ` Thomas Zimmermann
2024-03-20 14:16 ` Rob Clark
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=20230302143502.500661-1-contact@emersion.fr \
--to=contact@emersion.fr \
--cc=christian.koenig@amd.com \
--cc=daniel.vetter@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=hdegoede@redhat.com \
--cc=maxime@cerno.tech \
--cc=tiantao6@hisilicon.com \
--cc=tzimmermann@suse.de \
/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;
as well as URLs for NNTP newsgroup(s).