All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] drm/i915: gracefully reject mmap of huge tiled objects
@ 2016-07-01  0:04 James Xiong
  2016-07-01  5:21 ` ✗ Ro.CI.BAT: failure for series starting with [1/1] " Patchwork
  2016-07-01  7:25 ` [PATCH 1/1] " Chris Wilson
  0 siblings, 2 replies; 4+ messages in thread
From: James Xiong @ 2016-07-01  0:04 UTC (permalink / raw)
  To: intel-gfx; +Cc: Xiong, James

From: "Xiong, James" <james.xiong@intel.com>

currently mmap of a tiled object that is larger than mappable
aperture is rejected in fault handler, and causes sigbus error
and application crash.

This commit rejects it in mmap instead so that the client has
chance to handle the failure.

Signed-off-by: Xiong, James <james.xiong@intel.com>
---
 drivers/gpu/drm/i915/i915_drv.c |  2 +-
 drivers/gpu/drm/i915/i915_drv.h |  1 +
 drivers/gpu/drm/i915/i915_gem.c | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 0b9105cf3..c560406 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -1808,7 +1808,7 @@ static const struct file_operations i915_driver_fops = {
 	.open = drm_open,
 	.release = drm_release,
 	.unlocked_ioctl = drm_ioctl,
-	.mmap = drm_gem_mmap,
+	.mmap = i915_gem_mmap,
 	.poll = drm_poll,
 	.read = drm_read,
 #ifdef CONFIG_COMPAT
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 2e56e97..5867c3a 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -3062,6 +3062,7 @@ void *i915_gem_object_alloc(struct drm_device *dev);
 void i915_gem_object_free(struct drm_i915_gem_object *obj);
 void i915_gem_object_init(struct drm_i915_gem_object *obj,
 			 const struct drm_i915_gem_object_ops *ops);
+int i915_gem_mmap(struct file *filp, struct vm_area_struct *vma);
 struct drm_i915_gem_object *i915_gem_alloc_object(struct drm_device *dev,
 						  size_t size);
 struct drm_i915_gem_object *i915_gem_object_create_from_data(
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index aa4b63b..ce2e09f 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -5986,3 +5986,35 @@ fail:
 	drm_gem_object_unreference(&obj->base);
 	return ERR_PTR(ret);
 }
+
+int i915_gem_mmap(struct file *filp, struct vm_area_struct *vma)
+{
+	struct drm_file *priv = filp->private_data;
+	struct drm_device *dev = priv->minor->dev;
+	struct drm_gem_object *obj = NULL;
+	struct drm_vma_offset_node *node;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+
+	drm_vma_offset_lock_lookup(dev->vma_offset_manager);
+	node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager,
+						vma->vm_pgoff,
+						vma_pages(vma));
+	if (likely(node)) {
+		obj = container_of(node, struct drm_gem_object, vma_node);
+		if (!kref_get_unless_zero(&obj->refcount))
+			obj = NULL;
+	}
+	drm_vma_offset_unlock_lookup(dev->vma_offset_manager);
+
+	if (!obj)
+		return -EINVAL;
+
+	if (obj->size >= dev_priv->ggtt.mappable_end &&
+	    to_intel_bo(obj)->tiling_mode != I915_TILING_NONE) {
+		drm_gem_object_unreference_unlocked(obj);
+		return -ENOSPC;
+	}
+
+	drm_gem_object_unreference_unlocked(obj);
+	return drm_gem_mmap(filp, vma);
+}
-- 
1.9.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* ✗ Ro.CI.BAT: failure for series starting with [1/1] drm/i915: gracefully reject mmap of huge tiled objects
  2016-07-01  0:04 [PATCH 1/1] drm/i915: gracefully reject mmap of huge tiled objects James Xiong
@ 2016-07-01  5:21 ` Patchwork
  2016-07-01  7:25 ` [PATCH 1/1] " Chris Wilson
  1 sibling, 0 replies; 4+ messages in thread
From: Patchwork @ 2016-07-01  5:21 UTC (permalink / raw)
  To: James Xiong; +Cc: intel-gfx

== Series Details ==

Series: series starting with [1/1] drm/i915: gracefully reject mmap of huge tiled objects
URL   : https://patchwork.freedesktop.org/series/9346/
State : failure

== Summary ==

Applying: drm/i915: gracefully reject mmap of huge tiled objects
fatal: sha1 information is lacking or useless (drivers/gpu/drm/i915/i915_drv.c).
error: could not build fake ancestor
Patch failed at 0001 drm/i915: gracefully reject mmap of huge tiled objects
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] drm/i915: gracefully reject mmap of huge tiled objects
  2016-07-01  0:04 [PATCH 1/1] drm/i915: gracefully reject mmap of huge tiled objects James Xiong
  2016-07-01  5:21 ` ✗ Ro.CI.BAT: failure for series starting with [1/1] " Patchwork
@ 2016-07-01  7:25 ` Chris Wilson
  2016-07-01 15:36   ` Xiong, James
  1 sibling, 1 reply; 4+ messages in thread
From: Chris Wilson @ 2016-07-01  7:25 UTC (permalink / raw)
  To: James Xiong; +Cc: intel-gfx

On Thu, Jun 30, 2016 at 05:04:42PM -0700, James Xiong wrote:
> From: "Xiong, James" <james.xiong@intel.com>
> 
> currently mmap of a tiled object that is larger than mappable
> aperture is rejected in fault handler, and causes sigbus error
> and application crash.

Please note that SIGBUS can be returned at any time. If your application
doesn't handle it, please fix that.

> This commit rejects it in mmap instead so that the client has
> chance to handle the failure.

Wrong. Please review the patches to fix this correctly.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] drm/i915: gracefully reject mmap of huge tiled objects
  2016-07-01  7:25 ` [PATCH 1/1] " Chris Wilson
@ 2016-07-01 15:36   ` Xiong, James
  0 siblings, 0 replies; 4+ messages in thread
From: Xiong, James @ 2016-07-01 15:36 UTC (permalink / raw)
  To: Chris Wilson; +Cc: intel-gfx

Thanks,
James

-----Original Message-----
From: Chris Wilson [mailto:chris.ickle.wilson@gmail.com] On Behalf Of Chris Wilson
Sent: Friday, July 1, 2016 12:25 AM
To: Xiong, James <james.xiong@intel.com>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [Intel-gfx] [PATCH 1/1] drm/i915: gracefully reject mmap of huge tiled objects

On Thu, Jun 30, 2016 at 05:04:42PM -0700, James Xiong wrote:
> From: "Xiong, James" <james.xiong@intel.com>
> 
> currently mmap of a tiled object that is larger than mappable aperture 
> is rejected in fault handler, and causes sigbus error and application 
> crash.

Please note that SIGBUS can be returned at any time. If your application doesn't handle it, please fix that.
[JX] I agree, the way I put it like it's a bug is wrong, it's okay to return sigbus in i915 fault handler.

It's a common practice that an application validates a pointer then accesses it directly, in case of SIGBUS,
there is not much signal handler can do other than clearing up before the application aborts(please
correct me if I am wrong). I have seen people use longjump/sigaction to handle sigbus but it has problems:
only be able to jump within the current function, reentrancy etc,etc,. makes it impractical to apply for all accesses.

And sometime the app wants to be able to continue in case of SIGBUG, for example: one test case fails because of
 the buffer size and SIGBUS, with this change, the app is able to either reduce buffer size, re-run test or continue
with the next test. The change helps with these cases.

 Another thing is that when mmap is called to map a tiled/250M+ obj to user space, i915 knows it doesn't have enough
space, shouldn't ENOSPC be returned right there and then? 
> This commit rejects it in mmap instead so that the client has chance 
> to handle the failure.

Wrong. Please review the patches to fix this correctly.
-Chris

--
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-07-01 15:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-01  0:04 [PATCH 1/1] drm/i915: gracefully reject mmap of huge tiled objects James Xiong
2016-07-01  5:21 ` ✗ Ro.CI.BAT: failure for series starting with [1/1] " Patchwork
2016-07-01  7:25 ` [PATCH 1/1] " Chris Wilson
2016-07-01 15:36   ` Xiong, James

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.