Skip to contentSkip to conversation

drm: Add library for shmem backed GEM objects

PATCH Superseded Rob Herring 2 participants 4 messages Mar 6, 2019 – Mar 7, 2019

Subsystems (3)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v7 1/1 drm: Add library for shmem backed GEM objects

From: Noralf Trønnes <[email protected]>

This adds a library for shmem backed GEM objects.

v7:
- Use write-combine for mmap instead. This is the more common case. (robher)

v6:
- Fix uninitialized variable issue in an error path (anholt).
- Add a drm_gem_shmem_vm_open() to the fops to get proper refcounting of the pages (anholt).

v5:
- Drop drm_gem_shmem_prime_mmap() (Daniel Vetter)
- drm_gem_shmem_mmap(): Subtract drm_vma_node_start() to get the real vma->vm_pgoff
- drm_gem_shmem_fault(): Use vmf->pgoff now that vma->vm_pgoff is correct

v4:
- Drop cache modes (Thomas Hellstrom)
- Add a GEM attached vtable

v3:
- Grammar (Sam Ravnborg)
- s/drm_gem_shmem_put_pages_unlocked/drm_gem_shmem_put_pages_locked/ (Sam Ravnborg)
- Add debug output in error path (Sam Ravnborg)

---
I don't have a user to submit just yet, but we are using this for panfrost which can be seen here[1]. I expect we'll be ready to merge panfrost for 5.2.

Rob

[1] https://gitlab.freedesktop.org/panfrost/linux/blob/panfrost-5.0-rc4/drivers/gpu/drm/panfrost/panfrost_gem.c

 Documentation/gpu/drm-kms-helpers.rst  |  12 +
 drivers/gpu/drm/Kconfig                |   6 +
 drivers/gpu/drm/Makefile               |   1 +
 drivers/gpu/drm/drm_gem_shmem_helper.c | 560 +++++++++++++++++++++++++
 include/drm/drm_gem_shmem_helper.h     | 153 +++++++
 5 files changed, 732 insertions(+)
 create mode 100644 drivers/gpu/drm/drm_gem_shmem_helper.c
 create mode 100644 include/drm/drm_gem_shmem_helper.h
Documentation/gpu/drm-kms-helpers.rst +12 -0
index b422eb8edf16..44e47ddc21d6 100644
@@ -347,3 +347,15 @@ Legacy CRTC/Modeset Helper Functions Reference
 
 .. kernel-doc:: drivers/gpu/drm/drm_crtc_helper.c
    :export:
+
+SHMEM GEM Helper Reference
+==========================
+
+.. kernel-doc:: drivers/gpu/drm/drm_gem_shmem_helper.c
+   :doc: overview
+
+.. kernel-doc:: include/drm/drm_gem_shmem_helper.h
+   :internal:
+
+.. kernel-doc:: drivers/gpu/drm/drm_gem_shmem_helper.c
+   :export:
drivers/gpu/drm/Kconfig +6 -0
index 4385f00e1d05..0dedbc040c77 100644
@@ -177,6 +177,12 @@ config DRM_KMS_CMA_HELPER
 	help
 	  Choose this if you need the KMS CMA helper functions
 
+config DRM_GEM_SHMEM_HELPER
+	bool
+	depends on DRM
+	help
+	  Choose this if you need the GEM shmem helper functions
+
 config DRM_VM
 	bool
 	depends on DRM && MMU
drivers/gpu/drm/Makefile +1 -0
index ce8d1d384319..203b311f12ae 100644
@@ -25,6 +25,7 @@ drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o
 drm-$(CONFIG_DRM_VM) += drm_vm.o
 drm-$(CONFIG_COMPAT) += drm_ioc32.o
 drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
+drm-$(CONFIG_DRM_GEM_SHMEM_HELPER) += drm_gem_shmem_helper.o
 drm-$(CONFIG_PCI) += ati_pcigart.o
 drm-$(CONFIG_DRM_PANEL) += drm_panel.o
 drm-$(CONFIG_OF) += drm_of.o
drivers/gpu/drm/drm_gem_shmem_helper.c new file +560 -0

560 lines not on this page · raw message

include/drm/drm_gem_shmem_helper.h new file +153 -0

153 lines not on this page · raw message

Signature · 6 lines
2.19.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 29 lines · Rob Herring

From: Noralf Trønnes <[email protected]>

This adds a library for shmem backed GEM objects.

v7:
- Use write-combine for mmap instead. This is the more common case. (robher)

v6:
- Fix uninitialized variable issue in an error path (anholt).
- Add a drm_gem_shmem_vm_open() to the fops to get proper refcounting of the pages (anholt).

v5:
- Drop drm_gem_shmem_prime_mmap() (Daniel Vetter)
- drm_gem_shmem_mmap(): Subtract drm_vma_node_start() to get the real vma->vm_pgoff
- drm_gem_shmem_fault(): Use vmf->pgoff now that vma->vm_pgoff is correct

v4:
- Drop cache modes (Thomas Hellstrom)
- Add a GEM attached vtable

v3:
- Grammar (Sam Ravnborg)
- s/drm_gem_shmem_put_pages_unlocked/drm_gem_shmem_put_pages_locked/ (Sam Ravnborg)
- Add debug output in error path (Sam Ravnborg)

Quoted 7 lines

---
I don't have a user to submit just yet, but we are using this for panfrost which can be seen here[1]. I expect we'll be ready to merge panfrost for 5.2.

Excellent. I'm taking a look at this for v3d, and I see that on the panfrost side you're allocating shmem->sgt and doing dma_map_sg() in your MMU map code, with no error handling. And, on MMU unmap I see dma_unmap_sg() unconditionally (won't that unbalance for a prime import which will presumably do its own unmapping?), but it also looks like the sgt is not freed.

Can we do something nicer for handling the driver's desire for the sgt to fill its PTEs, regardless of where the BO came from?

I also hope we can plug this into vkms and turn on prime sharing for it.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw
Quoted 32 lines · Eric Anholt
Quoted 29 lines · Rob Herring

From: Noralf Trønnes <[email protected]>

This adds a library for shmem backed GEM objects.

v7:
- Use write-combine for mmap instead. This is the more common case. (robher)

v6:
- Fix uninitialized variable issue in an error path (anholt).
- Add a drm_gem_shmem_vm_open() to the fops to get proper refcounting of the pages (anholt).

v5:
- Drop drm_gem_shmem_prime_mmap() (Daniel Vetter)
- drm_gem_shmem_mmap(): Subtract drm_vma_node_start() to get the real vma->vm_pgoff
- drm_gem_shmem_fault(): Use vmf->pgoff now that vma->vm_pgoff is correct

v4:
- Drop cache modes (Thomas Hellstrom)
- Add a GEM attached vtable

v3:
- Grammar (Sam Ravnborg)
- s/drm_gem_shmem_put_pages_unlocked/drm_gem_shmem_put_pages_locked/ (Sam Ravnborg)
- Add debug output in error path (Sam Ravnborg)

Quoted 7 lines
Quoted 7 lines

---
I don't have a user to submit just yet, but we are using this for panfrost which can be seen here[1]. I expect we'll be ready to merge panfrost for 5.2.

I need to add exporting drm_gem_shmem_create_with_handle() as well. I was thinking I was just using that in my rockchip conversion attempt, but I need it for panfrost too.

Quoted 6 lines

Excellent. I'm taking a look at this for v3d, and I see that on the panfrost side you're allocating shmem->sgt and doing dma_map_sg() in your MMU map code, with no error handling. And, on MMU unmap I see dma_unmap_sg() unconditionally (won't that unbalance for a prime import which will presumably do its own unmapping?), but it also looks like the sgt is not freed.

Indeed, I'll need to split those.

Error handling? Panfrost doesn't do that. ;)

Quoted 2 lines

Can we do something nicer for handling the driver's desire for the sgt to fill its PTEs, regardless of where the BO came from?

Not sure I follow. You mean do something in shmem helpers? I'm assuming when we pin and dma map will evolve from at BO creation time to on demand.

Quoted 1 line

I also hope we can plug this into vkms and turn on prime sharing for it.

Doesn't seem too hard. I'd assume vkms would be okay with WC mappings as it looks like they are currently cacheable? We could add a dma attrs field to let users customize the mapping, but I'd rather avoid that if possible.

Rob
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
Quoted 54 lines · Rob Herring
Quoted 32 lines · Eric Anholt
Quoted 29 lines · Rob Herring

From: Noralf Trønnes <[email protected]>

This adds a library for shmem backed GEM objects.

v7:
- Use write-combine for mmap instead. This is the more common case. (robher)

v6:
- Fix uninitialized variable issue in an error path (anholt).
- Add a drm_gem_shmem_vm_open() to the fops to get proper refcounting of the pages (anholt).

v5:
- Drop drm_gem_shmem_prime_mmap() (Daniel Vetter)
- drm_gem_shmem_mmap(): Subtract drm_vma_node_start() to get the real vma->vm_pgoff
- drm_gem_shmem_fault(): Use vmf->pgoff now that vma->vm_pgoff is correct

v4:
- Drop cache modes (Thomas Hellstrom)
- Add a GEM attached vtable

v3:
- Grammar (Sam Ravnborg)
- s/drm_gem_shmem_put_pages_unlocked/drm_gem_shmem_put_pages_locked/ (Sam Ravnborg)
- Add debug output in error path (Sam Ravnborg)

Quoted 7 lines
Quoted 7 lines

---
I don't have a user to submit just yet, but we are using this for panfrost which can be seen here[1]. I expect we'll be ready to merge panfrost for 5.2.

I need to add exporting drm_gem_shmem_create_with_handle() as well. I was thinking I was just using that in my rockchip conversion attempt, but I need it for panfrost too.

Quoted 6 lines

Excellent. I'm taking a look at this for v3d, and I see that on the panfrost side you're allocating shmem->sgt and doing dma_map_sg() in your MMU map code, with no error handling. And, on MMU unmap I see dma_unmap_sg() unconditionally (won't that unbalance for a prime import which will presumably do its own unmapping?), but it also looks like the sgt is not freed.

Indeed, I'll need to split those.

Quoted 8 lines

Error handling? Panfrost doesn't do that. ;)

Quoted 2 lines

Can we do something nicer for handling the driver's desire for the sgt to fill its PTEs, regardless of where the BO came from?

Not sure I follow. You mean do something in shmem helpers? I'm assuming when we pin and dma map will evolve from at BO creation time to on demand.

Yeah, basically my driver wants not drm_gem_shmem_get_pages() as its interface but drm_shmem_get_sgt(). I'm imagining a helper for that which has its own refcount that does a get_pages and then, for non-dmabuf-import, the sgt allocation and dma mapping.

Quoted 6 lines
Quoted 1 line

I also hope we can plug this into vkms and turn on prime sharing for it.

Doesn't seem too hard. I'd assume vkms would be okay with WC mappings as it looks like they are currently cacheable? We could add a dma attrs field to let users customize the mapping, but I'd rather avoid that if possible.

WC was my intent. It would make vkms look more like other drivers from a perf perspective, which I think would be reasonable (and then you don't have CPU cache issues when sharing buffers). I've got a patch laying around for converting to the helpers.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel