Skip to contentSkip to conversation

drm/vram-helper: turn on PRIME import/export

PATCH In review Simon Ser 3 participants 9 messages Mar 1, 2023 – Mar 2, 2023

Subsystems (2)
lore
Share & tools
lore

Simon Ser

author
#0 lore raw

PATCH 1/1 drm/vram-helper: turn on PRIME import/export

We don't populate gem_prime_import_sg_table so only DMA-BUFs exported from our own device can be imported. Still, this is useful to user-space.

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 +3 -1
index d3e8920c0b64..f4aab64411d8 100644
@@ -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
#1 lore raw

Am 01.03.23 um 23:29 schrieb Simon Ser:

Quoted 3 lines

We don't populate gem_prime_import_sg_table so only DMA-BUFs exported from our own device can be imported. Still, this is useful to user-space.

But what happens if one of your BOs is imported into another device?

Regards,
Christian.

Quoted 27 lines
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 +3 -1
index d3e8920c0b64..f4aab64411d8 100644
@@ -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
author
#2 lore raw
Quoted 7 lines · Christian König

Am 01.03.23 um 23:29 schrieb Simon Ser:

Quoted 3 lines

We don't populate gem_prime_import_sg_table so only DMA-BUFs exported from our own device can be imported. Still, this is useful to user-space.

But what happens if one of your BOs is imported into another device?

Is there a way to make this fail, always?

#3 lore raw

Am 02.03.23 um 11:14 schrieb Simon Ser:

Quoted 9 lines · Christian König
Quoted 7 lines

Am 01.03.23 um 23:29 schrieb Simon Ser:

Quoted 3 lines

We don't populate gem_prime_import_sg_table so only DMA-BUFs exported from our own device can be imported. Still, this is useful to user-space.

But what happens if one of your BOs is imported into another device?

Is there a way to make this fail, always?

Well you could return an error from the attach callback if I'm not completely mistaken.

But that's certainly not a standard function of the DRM helpers.

Regards,
Christian.

author
#4 lore raw
Quoted 6 lines · Christian König

Am 02.03.23 um 11:14 schrieb Simon Ser:

Quoted 4 lines · On Thursday, March 2nd, 2023 at 08:11, Christian König…
Quoted 3 lines

Am 01.03.23 um 23:29 schrieb Simon Ser:

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

We don't populate gem_prime_import_sg_table so only DMA-BUFs exported from our own device can be imported. Still, this is useful to user-space.
But what happens if one of your BOs is imported into another device? Is there a way to make this fail, always?

Well you could return an error from the attach callback if I'm not completely mistaken.

Hmm, but with GEM helpers this is handled by drm_gem_map_attach(). That function calls drm_gem_object_funcs.pin but doesn't pass along the dma_buf_attachment so there no way to reject the attach based on the other device there…

Would it be unreasonable to add a drm_driver.gem_prime_attach hook? Or is there a better way to implement this?

#5 lore raw

Am 02.03.23 um 14:37 schrieb Simon Ser:

Quoted 15 lines · Christian König
Quoted 7 lines

Am 02.03.23 um 11:14 schrieb Simon Ser:

Quoted 4 lines · On Thursday, March 2nd, 2023 at 08:11, Christian König…
Quoted 3 lines

Am 01.03.23 um 23:29 schrieb Simon Ser:

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

We don't populate gem_prime_import_sg_table so only DMA-BUFs exported from our own device can be imported. Still, this is useful to user-space.
But what happens if one of your BOs is imported into another device? Is there a way to make this fail, always?

Well you could return an error from the attach callback if I'm not completely mistaken.

Quoted 7 lines

Hmm, but with GEM helpers this is handled by drm_gem_map_attach(). That function calls drm_gem_object_funcs.pin but doesn't pass along the dma_buf_attachment so there no way to reject the attach based on the other device there…

Would it be unreasonable to add a drm_driver.gem_prime_attach hook? Or is there a better way to implement this?

That would be the mid layering we usually try hard to avoid.

Your obj doesn't implement the obj->funcs->get_sg_table() callback doesn't it? In this case drm_gem_map_dma_buf() would fail just a little bit later anyway.

What you could do is to add a check for the get_sg_table callback a bit earlier in drm_gem_map_attach() and if that's not implemented reject the attachment.

Regards,
Christian.

author
#6 lore raw
Quoted 22 lines · Christian König

Am 02.03.23 um 14:37 schrieb Simon Ser:

Quoted 20 lines · On Thursday, March 2nd, 2023 at 14:21, Christian König…
Quoted 18 lines

Am 02.03.23 um 11:14 schrieb Simon Ser:

Quoted 15 lines · On Thursday, March 2nd, 2023 at 08:11, Christian König…
Quoted 14 lines

Am 01.03.23 um 23:29 schrieb Simon Ser:

Quoted 11 lines

We don't populate gem_prime_import_sg_table so only DMA-BUFs exported from our own device can be imported. Still, this is useful to user-space.
But what happens if one of your BOs is imported into another device? Is there a way to make this fail, always?
Well you could return an error from the attach callback if I'm not completely mistaken.
Hmm, but with GEM helpers this is handled by drm_gem_map_attach(). That function calls drm_gem_object_funcs.pin but doesn't pass along the dma_buf_attachment so there no way to reject the attach based on the other device there…

Quoted 4 lines
Quoted 2 lines

Would it be unreasonable to add a drm_driver.gem_prime_attach hook? Or is there a better way to implement this?

That would be the mid layering we usually try hard to avoid.

Indeed!

Quoted 7 lines

Your obj doesn't implement the obj->funcs->get_sg_table() callback doesn't it? In this case drm_gem_map_dma_buf() would fail just a little bit later anyway.

What you could do is to add a check for the get_sg_table callback a bit earlier in drm_gem_map_attach() and if that's not implemented reject the attachment.

That's a good idea, thanks for the suggestion! Done in v2.

#7 lore raw
In reply to Simon Ser

Hi

Am 01.03.23 um 23:29 schrieb Simon Ser:

Quoted 3 lines

We don't populate gem_prime_import_sg_table so only DMA-BUFs exported from our own device can be imported. Still, this is useful to user-space.

VRAM helpers don't really offer much flexibility or control in where to place a BO. What happens if the BO is located in device video ram and cannot be used by the other participant? A blank screen?

I'd also consider VRAM helpers as deprecated. The remaining few drivers can be converted to SHMEM helpers; except maybe bochs could get its own TTM-based memory management.

Best regards
Thomas

Quoted 27 lines
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 +3 -1
index d3e8920c0b64..f4aab64411d8 100644
@@ -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 · 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
author
#8 lore raw
Quoted 8 lines · Thomas Zimmermann

Am 01.03.23 um 23:29 schrieb Simon Ser:

Quoted 3 lines

We don't populate gem_prime_import_sg_table so only DMA-BUFs exported from our own device can be imported. Still, this is useful to user-space.

VRAM helpers don't really offer much flexibility or control in where to place a BO.

That's fine. The goal here is purely export/import to the exact same device.

Quoted 2 lines

What happens if the BO is located in device video ram and cannot be used by the other participant? A blank screen?

A failure at import-time should happen. But maybe this patch isn't enough to make this happen?