Skip to contentSkip to conversation

drm/vgem: virtual GEM provider

RFC PATCH In review Adam Jackson 5 participants 7 messages Jan 11, 2012 – Feb 7, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 drm/vgem: virtual GEM provider

This is about as minimal of a virtual GEM service as possible. My plan is to use this with non-native-3D hardware for buffer sharing between X and DRI.

The current drisw winsys assumes an unmodified X server, which means it's hopelessly inefficient for both the push direction of SwapBuffers/ DrawPixels and the pull direction of GLX_EXT_texture_from_pixmap. I'm still working through the details of what the xserver support will look like, but in broad strokes it's "use vgem for CreatePixmap and optionally the shadowfb".

Obviously alpha quality, mostly looking for feedback on the approach or any glaring bugs. Eventually I'd like to see solutions for sharing gem objects between drm devices and/or the dma_buf API, but that's a ways down the road.

---
 drivers/gpu/drm/Kconfig         |    8 ++
 drivers/gpu/drm/Makefile        |    1 +
 drivers/gpu/drm/vgem/Makefile   |    4 +
 drivers/gpu/drm/vgem/vgem_drv.c |  262 +++++++++++++++++++++++++++++++++++++++
 include/drm/vgem_drm.h          |   51 ++++++++
 5 files changed, 326 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpu/drm/vgem/Makefile
 create mode 100644 drivers/gpu/drm/vgem/vgem_drv.c
 create mode 100644 include/drm/vgem_drm.h
drivers/gpu/drm/Kconfig +8 -0
index 1368826..46322ba 100644
@@ -159,6 +159,14 @@ config DRM_SAVAGE
 	  Choose this option if you have a Savage3D/4/SuperSavage/Pro/Twister
 	  chipset. If M is selected the module will be called savage.
 
+config DRM_VGEM
+	tristate "Virtual GEM provider"
+	depends on DRM
+	help
+	  Choose this option to get a virtual graphics memory manager,
+	  as used by Mesa's software renderer for enhanced performance.
+	  If M is selected the module will be called vgem.
+
 source "drivers/gpu/drm/exynos/Kconfig"
 
 source "drivers/gpu/drm/vmwgfx/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index c0496f6..132de0e 100644
@@ -34,6 +34,7 @@ obj-$(CONFIG_DRM_SIS)   += sis/
 obj-$(CONFIG_DRM_SAVAGE)+= savage/
 obj-$(CONFIG_DRM_VMWGFX)+= vmwgfx/
 obj-$(CONFIG_DRM_VIA)	+=via/
+obj-$(CONFIG_DRM_VGEM)	+= vgem/
 obj-$(CONFIG_DRM_NOUVEAU) +=nouveau/
 obj-$(CONFIG_DRM_EXYNOS) +=exynos/
 obj-y			+= i2c/
drivers/gpu/drm/vgem/Makefile new file +4 -0
new file mode 100644
index 0000000..3f4c7b8
@@ -0,0 +1,4 @@
+ccflags-y := -Iinclude/drm
+vgem-y := vgem_drv.o
+
+obj-$(CONFIG_DRM_VGEM)	+= vgem.o
drivers/gpu/drm/vgem/vgem_drv.c new file +262 -0

262 lines not on this page · raw message

include/drm/vgem_drm.h new file +51 -0

51 lines not on this page · raw message

Signature · 1 line
1.7.7.5
#1 lore raw
Quoted 11 lines · Adam Jackson

This is about as minimal of a virtual GEM service as possible. My plan is to use this with non-native-3D hardware for buffer sharing between X and DRI.

The current drisw winsys assumes an unmodified X server, which means it's hopelessly inefficient for both the push direction of SwapBuffers/ DrawPixels and the pull direction of GLX_EXT_texture_from_pixmap. I'm still working through the details of what the xserver support will look like, but in broad strokes it's "use vgem for CreatePixmap and optionally the shadowfb".

Quoted 4 lines

Obviously alpha quality, mostly looking for feedback on the approach or any glaring bugs. Eventually I'd like to see solutions for sharing gem objects between drm devices and/or the dma_buf API, but that's a ways down the road.

I remember at one point you had a plan along the lines of passing shmem fds across the protocol. I'm curious what happened to that -- too hard to get the passing to work, or something else? I'm just thinking of kernel developer grumbling that you've duplicated something that pretty much existed before.

If you can, I recommend using the intel gtt mapping type of mmap ioctl, where it gives you back an offset that you use the mmap syscall on, and implement the vgem_gem_fault to map its pages, instead. It should avoid tricking userland tools like valgrind, which really sucks with the do_mmap()-calling ioctl we have today.

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

#2 lore raw
Quoted 5 lines · Eric Anholt

I remember at one point you had a plan along the lines of passing shmem fds across the protocol. I'm curious what happened to that -- too hard to get the passing to work, or something else? I'm just thinking of kernel developer grumbling that you've duplicated something that pretty much existed before.

There's no way to pass an fd without passing an extra byte of in-stream data, and it's weirdly invasive to try to thread that into the existing protocol. Sort of the same way getting socket peer credentials with recvmsg(SCM_CREDENTIALS) sucks, which is why we have getsockopt(SO_PEERCRED) instead. But unlike process credentials, SCM_RIGHTS is a queue, which is a funny kind of API to bolt into setsockopt.

Making something that looked like a hardware driver seemed way more symmetric. And, in the long-range future of being able to pass GEM objects among DRM devices, you'll probably want to apply any constraints like tiling round-up at object creation time. Doing it the other way around - xserver allocates with shm_open() then promotes to GEM - just introduces a way userspace can get it wrong.

Quoted 5 lines

If you can, I recommend using the intel gtt mapping type of mmap ioctl, where it gives you back an offset that you use the mmap syscall on, and implement the vgem_gem_fault to map its pages, instead. It should avoid tricking userland tools like valgrind, which really sucks with the do_mmap()-calling ioctl we have today.

That makes sense. Having two paths by which you could hit drm_gem_mmap() seemed weird when I was writing it.

I think the clean way of doing that requires exporting at least shmem_fault and possibly some other shmfs details.

- ajax

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

#3 lore raw
Quoted 29 lines · Adam Jackson
Quoted 5 lines · Eric Anholt

I remember at one point you had a plan along the lines of passing shmem fds across the protocol. I'm curious what happened to that -- too hard to get the passing to work, or something else? I'm just thinking of kernel developer grumbling that you've duplicated something that pretty much existed before.

There's no way to pass an fd without passing an extra byte of in-stream data, and it's weirdly invasive to try to thread that into the existing protocol. Sort of the same way getting socket peer credentials with recvmsg(SCM_CREDENTIALS) sucks, which is why we have getsockopt(SO_PEERCRED) instead. But unlike process credentials, SCM_RIGHTS is a queue, which is a funny kind of API to bolt into setsockopt.

Making something that looked like a hardware driver seemed way more symmetric. And, in the long-range future of being able to pass GEM objects among DRM devices, you'll probably want to apply any constraints like tiling round-up at object creation time. Doing it the other way around - xserver allocates with shm_open() then promotes to GEM - just introduces a way userspace can get it wrong.

Quoted 5 lines

If you can, I recommend using the intel gtt mapping type of mmap ioctl, where it gives you back an offset that you use the mmap syscall on, and implement the vgem_gem_fault to map its pages, instead. It should avoid tricking userland tools like valgrind, which really sucks with the do_mmap()-calling ioctl we have today.

Quoted 7 lines

That makes sense. Having two paths by which you could hit drm_gem_mmap() seemed weird when I was writing it.

I think the clean way of doing that requires exporting at least shmem_fault and possibly some other shmfs details.

- ajax

I'm working on this presently unless you've already done it. ~Ben

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

#4 lore raw
Quoted 10 lines · Ben Widawsky
Quoted 9 lines · Adam Jackson
Quoted 5 lines

If you can, I recommend using the intel gtt mapping type of mmap ioctl, where it gives you back an offset that you use the mmap syscall on, and implement the vgem_gem_fault to map its pages, instead. It should avoid tricking userland tools like valgrind, which really sucks with the do_mmap()-calling ioctl we have today.

That makes sense. Having two paths by which you could hit drm_gem_mmap() seemed weird when I was writing it.

Quoted 6 lines
Quoted 4 lines

I think the clean way of doing that requires exporting at least shmem_fault and possibly some other shmfs details.

- ajax

I'm working on this presently unless you've already done it.

Go for it, I've been ratholed getting vesa working again on 1.12.

- ajax

#5 lore raw
In reply to Adam Jackson
Quoted 11 lines · Adam Jackson

This is about as minimal of a virtual GEM service as possible. My plan is to use this with non-native-3D hardware for buffer sharing between X and DRI.

The current drisw winsys assumes an unmodified X server, which means it's hopelessly inefficient for both the push direction of SwapBuffers/ DrawPixels and the pull direction of GLX_EXT_texture_from_pixmap. I'm still working through the details of what the xserver support will look like, but in broad strokes it's "use vgem for CreatePixmap and optionally the shadowfb".

Quoted 6 lines

Obviously alpha quality, mostly looking for feedback on the approach or any glaring bugs. Eventually I'd like to see solutions for sharing gem objects between drm devices and/or the dma_buf API, but that's a ways down the road.

I like this and the userspace abi is pretty much what I expect for such a beast. I think integration with other drivers/dma_buf can just happen with prime, nothing special needed. A few quick comments on the code
- no need to allocate a gem mmap offset if you only expose the direct shm mmap. This also will make the BUG in _fault correct, otherwise userspace could try to mmap well-guessed ranges on the fd and hit this.
- unsigned int in ioctl structs instead if __u32 (and also use __u64).
- I don't see why you have a size arg for the mmap ioctl, simply mapping the entire bo is likely all you ever want.
- The fops is inline instead of separate and constified.

Otherwise I couldn't find anything to complain about ;-)

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
maintainer
#6 lore raw
Quoted 19 lines · Daniel Vetter
Quoted 11 lines · Adam Jackson

This is about as minimal of a virtual GEM service as possible.  My plan is to use this with non-native-3D hardware for buffer sharing between X and DRI.

The current drisw winsys assumes an unmodified X server, which means it's hopelessly inefficient for both the push direction of SwapBuffers/ DrawPixels and the pull direction of GLX_EXT_texture_from_pixmap.  I'm still working through the details of what the xserver support will look like, but in broad strokes it's "use vgem for CreatePixmap and optionally the shadowfb".

Quoted 6 lines

Obviously alpha quality, mostly looking for feedback on the approach or any glaring bugs.  Eventually I'd like to see solutions for sharing gem objects between drm devices and/or the dma_buf API, but that's a ways down the road.

Quoted 10 lines

I like this and the userspace abi is pretty much what I expect for such a beast. I think integration with other drivers/dma_buf can just happen with prime, nothing special needed. A few quick comments on the code
- no need to allocate a gem mmap offset if you only expose the direct shm mmap. This also will make the BUG in _fault correct, otherwise userspace could try to mmap well-guessed ranges on the fd and hit this.
- unsigned int in ioctl structs instead if __u32 (and also use __u64).
- I don't see why you have a size arg for the mmap ioctl, simply mapping the entire bo is likely all you ever want.
- The fops is inline instead of separate and constified.

Not anymore, it just got moved :-)

I'm with Eric implement the mmap the other way, they ioctls look very like the dumb ioctls, maybe just use them if they are.

Dave.