Skip to contentSkip to conversation

drm/i915: Implement dma-buf mmap() for userspace access

PATCH In review Ander Conselvan de Oliveira 3 participants 4 messages Jun 19, 2014 – Jun 23, 2014

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

PATCH v3 1/1 drm/i915: Implement dma-buf mmap() for userspace access

From: Rob Bradford <[email protected]>

The aim is that this is functionally equivalent to using the I915_GEM_MMAP ioctl.

v2: Add aperture check limit, limit to SNB+ and improve error handling.

v3 (anderco): Map without using the GTT.

---
 drivers/gpu/drm/i915/i915_gem_dmabuf.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem_dmabuf.c +18 -1
index 580aa42..2d31fca 100644
@@ -193,7 +193,24 @@ static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n
 
 static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma)
 {
-	return -EINVAL;
+	struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
+	struct drm_device *dev = obj->base.dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	int ret;
+
+	if (INTEL_INFO(dev)->gen < 6)
+		return -EINVAL;
+
+	ret = i915_mutex_lock_interruptible(dev);
+	if (ret)
+		return ret;
+
+	ret = obj->base.filp->f_op->mmap(obj->base.filp, vma);
+	fput(vma->vm_file);
+	vma->vm_file = get_file(obj->base.filp);
+
+	mutex_unlock(&dev->struct_mutex);
+	return ret;
 }
 
 static int i915_gem_begin_cpu_access(struct dma_buf *dma_buf, size_t start, size_t length, enum dma_data_direction direction)
Signature · 1 line
1.8.3.2
#1 lore raw
Quoted 8 lines · Ander Conselvan de Oliveira

From: Rob Bradford <[email protected]>

The aim is that this is functionally equivalent to using the I915_GEM_MMAP ioctl.

v2: Add aperture check limit, limit to SNB+ and improve error handling.

v3 (anderco): Map without using the GTT.

Why that? This means you'll have a non-coherent mapping and atm dma-buf doesn't expose and invalidate/flushing ioctls. Which really you want for this.
-Daniel

Quoted 44 lines
---
 drivers/gpu/drm/i915/i915_gem_dmabuf.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem_dmabuf.c +18 -1
index 580aa42..2d31fca 100644
@@ -193,7 +193,24 @@ static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n
 
 static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma)
 {
-	return -EINVAL;
+	struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
+	struct drm_device *dev = obj->base.dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	int ret;
+
+	if (INTEL_INFO(dev)->gen < 6)
+		return -EINVAL;
+
+	ret = i915_mutex_lock_interruptible(dev);
+	if (ret)
+		return ret;
+
+	ret = obj->base.filp->f_op->mmap(obj->base.filp, vma);
+	fput(vma->vm_file);
+	vma->vm_file = get_file(obj->base.filp);
+
+	mutex_unlock(&dev->struct_mutex);
+	return ret;
 }
 
 static int i915_gem_begin_cpu_access(struct dma_buf *dma_buf, size_t start, size_t length, enum dma_data_direction direction)
Signature · 6 lines
1.8.3.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#3 lore raw
In reply to Ander Conselvan de Oliveira
Quoted 21 lines · Ander Conselvan de Oliveira

From: Rob Bradford <[email protected]>

The aim is that this is functionally equivalent to using the I915_GEM_MMAP ioctl.

v2: Add aperture check limit, limit to SNB+ and improve error handling.

v3 (anderco): Map without using the GTT.

---
 drivers/gpu/drm/i915/i915_gem_dmabuf.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem_dmabuf.c +0 -0
index 580aa42..2d31fca 100644
@@ -193,7 +193,24 @@ static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n
 

drivers/gpu/drm/i915/i915_gem_dmabuf.c static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n · line 202

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_dmabuf.c +7 -1
 static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma)
 {
-	return -EINVAL;
+	struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
+	struct drm_device *dev = obj->base.dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	int ret;
+
+	if (INTEL_INFO(dev)->gen < 6)
+		return -EINVAL;

For cpu mmapings, the check can die.

drivers/gpu/drm/i915/i915_gem_dmabuf.c static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n · line 206

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_dmabuf.c +4 -0
+
+	ret = i915_mutex_lock_interruptible(dev);
+	if (ret)
+		return ret;

This lock doesn't actually do anything useful.

obj->base.filp can be NULL.

drivers/gpu/drm/i915/i915_gem_dmabuf.c static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n · line 210

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_dmabuf.c +4 -0
+
+	ret = obj->base.filp->f_op->mmap(obj->base.filp, vma);
+	fput(vma->vm_file);
+	vma->vm_file = get_file(obj->base.filp);

Talk to me about how the user is expected to control coherency since that appears to be outside of the scope of this function. -Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#2 lore raw
In reply to Daniel Vetter
Quoted 6 lines · Daniel Vetter
Quoted 5 lines · Ander Conselvan de Oliveira

From: Rob Bradford <[email protected]>

The aim is that this is functionally equivalent to using the I915_GEM_MMAP ioctl.

Quoted 7 lines
Quoted 3 lines

v2: Add aperture check limit, limit to SNB+ and improve error handling.

v3 (anderco): Map without using the GTT.

Why that? This means you'll have a non-coherent mapping and atm dma-buf doesn't expose and invalidate/flushing ioctls. Which really you want for this.

Hmm. I completely overlooked that important detail. In a discussion with Rob, we came to the conclusion we didn't want to use the GTT because of the performance penalty. Now I see that just modifying the mmap() support is not enough.

Thanks,
Ander

Quoted 47 lines

-Daniel

Quoted 44 lines
---
  drivers/gpu/drm/i915/i915_gem_dmabuf.c | 19 ++++++++++++++++++-
  1 file changed, 18 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem_dmabuf.c +18 -2
index 580aa42..2d31fca 100644
@@ -193,7 +193,24 @@ static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n
 
  static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma)
  {
-	return -EINVAL;
+	struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
+	struct drm_device *dev = obj->base.dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	int ret;
+
+	if (INTEL_INFO(dev)->gen < 6)
+		return -EINVAL;
+
+	ret = i915_mutex_lock_interruptible(dev);
+	if (ret)
+		return ret;
+
+	ret = obj->base.filp->f_op->mmap(obj->base.filp, vma);
+	fput(vma->vm_file);
+	vma->vm_file = get_file(obj->base.filp);
+
+	mutex_unlock(&dev->struct_mutex);
+	return ret;
  }
 
  static int i915_gem_begin_cpu_access(struct dma_buf *dma_buf, size_t start, size_t length, enum dma_data_direction direction)
--

1.8.3.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx