drm/prime: reject DMA-BUF attach when get_sg_table is missing
Subsystems (2)
PATCH v2 1/2 drm/prime: reject DMA-BUF attach when get_sg_table is missing
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
--- drivers/gpu/drm/drm_prime.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_prime.c +5 -1
@@ -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);
Signature · 1 line
2.39.2
PATCH v2 2/2 drm/vram-helper: turn on PRIME import/export
We don't populate drm_driver.gem_prime_import_sg_table so only DMA-BUFs exported from our own device can be imported. We don't populate drm_gem_object_funcs.get_sg_table so DMA-BUFs cannot be imported into another device. Still, this is useful to user-space to share buffers between processes and between API boundaries (e.g. wlroots hard-requires PRIME import/export support).
v2: expand commit message
--- include/drm/drm_gem_vram_helper.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/drm/drm_gem_vram_helper.h +3 -1
@@ -160,7 +160,9 @@ void drm_gem_vram_simple_display_pipe_cleanup_fb( .debugfs_init = drm_vram_mm_debugfs_init, \ .dumb_create = drm_gem_vram_driver_dumb_create, \ .dumb_map_offset = drm_gem_ttm_dumb_map_offset, \ - .gem_prime_mmap = drm_gem_prime_mmap + .gem_prime_mmap = drm_gem_prime_mmap, \ + .prime_handle_to_fd = drm_gem_prime_handle_to_fd, \ + .prime_fd_to_handle = drm_gem_prime_fd_to_handle/* * VRAM memory manager
Signature · 1 line
2.39.2
Re: [PATCH v2 2/2] drm/vram-helper: turn on PRIME import/export
Am 02.03.23 um 15:35 schrieb Simon Ser:
Quoted 25 lines
We don't populate drm_driver.gem_prime_import_sg_table so only DMA-BUFs exported from our own device can be imported. We don't populate drm_gem_object_funcs.get_sg_table so DMA-BUFs cannot be imported into another device. Still, this is useful to user-space to share buffers between processes and between API boundaries (e.g. wlroots hard-requires PRIME import/export support).
v2: expand commit message
Signed-off-by Simon Ser <[email protected]>Cc Daniel Vetter <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc Tian Tao <[email protected]>Cc Maxime Ripard <[email protected]>Cc Christian König <[email protected]>Cc Hans de Goede <[email protected]>--- include/drm/drm_gem_vram_helper.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)include/drm/drm_gem_vram_helper.h +0
-0
include/drm/drm_gem_vram_helper.h void drm_gem_vram_simple_display_pipe_cleanup_fb( · line 165
Quoted 7 lines
include/drm/drm_gem_vram_helper.h +3
-1@@ -160,7 +160,9 @@ void drm_gem_vram_simple_display_pipe_cleanup_fb( .debugfs_init = drm_vram_mm_debugfs_init, \ .dumb_create = drm_gem_vram_driver_dumb_create, \ .dumb_map_offset = drm_gem_ttm_dumb_map_offset, \ - .gem_prime_mmap = drm_gem_prime_mmap + .gem_prime_mmap = drm_gem_prime_mmap, \ + .prime_handle_to_fd = drm_gem_prime_handle_to_fd, \ + .prime_fd_to_handle = drm_gem_prime_fd_to_handle
Quoted 3 lines
include/drm/drm_gem_vram_helper.h +0
-0/* * VRAM memory manager
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Thomas Zimmermann
maintainerHi
Am 02.03.23 um 15:35 schrieb Simon Ser:
Quoted 36 lines
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 <[email protected]>Cc Daniel Vetter <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc Tian Tao <[email protected]>Cc Maxime Ripard <[email protected]>Cc Christian König <[email protected]>Cc Hans de Goede <[email protected]>--- drivers/gpu/drm/drm_prime.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_prime.c +2
-1@@ -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
drivers/gpu/drm/drm_prime.c int drm_gem_map_attach(struct dma_buf *dma_buf, · line 588
Quoted 5 lines
drivers/gpu/drm/drm_prime.c +2
-0@@ -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 ;
-ENOSYS please.
Best regards
Thomas
Quoted 4 lines
drivers/gpu/drm/drm_prime.c +1
-0+return drm_gem_pin (obj); }EXPORT_SYMBOL (drm_gem_map_attach);
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Hi
Am 02.03.23 um 16:03 schrieb Thomas Zimmermann:
Quoted 39 lines
Hi
Am 02.03.23 um 15:35 schrieb Simon Ser:
Quoted 36 lines
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 <[email protected]>Cc Daniel Vetter <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc Tian Tao <[email protected]>Cc Maxime Ripard <[email protected]>Cc Christian König <[email protected]>Cc Hans de Goede <[email protected]>---
drivers/gpu/drm/drm_prime.c| 6 +++++-1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_prime.c +1
-1@@ -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'sdrm_gem_dmabuf_vmap()and
Quoted 8 lines
drivers/gpu/drm/drm_prime.c int drm_gem_map_attach(struct dma_buf *dma_buf, · line 587
Quoted 6 lines
*
drm_gem_dmabuf_vunmap(). Userspace mmap support is provided bydrivers/gpu/drm/drm_prime.c +2
-0@@ -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;
-ENOSYSplease.
With this changed:
Quoted 9 lines
Best regards
ThomasQuoted 4 lines
drivers/gpu/drm/drm_prime.c +1
-0+ return drm_gem_pin(obj); } EXPORT_SYMBOL(drm_gem_map_attach);
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Am 02.03.23 um 15:35 schrieb Simon Ser:
Quoted 10 lines
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
Quoted 7 lines
Signed-off-by Simon Ser <[email protected]>Cc Daniel Vetter <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc Tian Tao <[email protected]>Cc Maxime Ripard <[email protected]>Cc Christian König <[email protected]>Cc Hans de Goede <[email protected]>
With Thomas comment addressed: Reviewed-by: Christian König <[email protected]> for the series.
Quoted 28 lines
--- drivers/gpu/drm/drm_prime.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_prime.c +5
-1@@ -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);
Thomas Zimmermann
maintainerHi Simon
Am 02.03.23 um 15:35 schrieb Simon Ser:
Quoted 9 lines
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
Is there a v3 of this patchset? It was Acked with the one errno code changed.
Best regards
Thomas
Quoted 36 lines
Signed-off-by Simon Ser <[email protected]>Cc Daniel Vetter <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc Tian Tao <[email protected]>Cc Maxime Ripard <[email protected]>Cc Christian König <[email protected]>Cc Hans de Goede <[email protected]>--- drivers/gpu/drm/drm_prime.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_prime.c +5
-1@@ -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);
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstrasse 146, 90461 Nuernberg, Germany GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman HRB 36809 (AG Nuernberg)
Hi,
Quoted 2 lines · Thomas Zimmermann
Is there a v3 of this patchset? It was Acked with the one errno code changed.
Since this was a minor change, I did it locally and pushed the patch to drm-misc-next already.
Simon
Thomas Zimmermann
maintainerHi
Am 09.06.23 um 15:04 schrieb Simon Ser:
Quoted 9 lines
Hi,
Quoted 2 lines · Thomas Zimmermann
Is there a v3 of this patchset? It was Acked with the one errno code changed.
Since this was a minor change, I did it locally and pushed the patch to drm-misc-next already.
Found it. Thanks for committing and sorry for the noise.
Best regards
Thomas
Quoted 2 lines
Simon
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstrasse 146, 90461 Nuernberg, Germany GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman HRB 36809 (AG Nuernberg)
Quoted 37 lines · Simon Ser
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 <[email protected]>Cc Daniel Vetter <[email protected]>Cc Thomas Zimmermann <[email protected]>Cc Tian Tao <[email protected]>Cc Maxime Ripard <[email protected]>Cc Christian König <[email protected]>Cc Hans de Goede <[email protected]>--- drivers/gpu/drm/drm_prime.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_prime.c +2
-1@@ -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
drivers/gpu/drm/drm_prime.c int drm_gem_map_attach(struct dma_buf *dma_buf, · line 588
Quoted 5 lines
drivers/gpu/drm/drm_prime.c +2
-0@@ -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 ;
This breaks virtgpu, where buffers may not necessarily have guest backing pages, but still may be shared with other virtual devices (because the host side buffer _does_ have backing pages)
BR,
-R
Quoted 8 lines
drivers/gpu/drm/drm_prime.c +1
-1+return drm_gem_pin (obj); }EXPORT_SYMBOL (drm_gem_map_attach); --2.39.2