drm/i915: gracefully reject mmap of huge tiled objects
Subsystems (2)
PATCH 1/1 drm/i915: gracefully reject mmap of huge tiled objects
From: "Xiong, James" <[email protected]>
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.
--- 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(-)
drivers/gpu/drm/i915/i915_drv.c +1 -1
@@ -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
drivers/gpu/drm/i915/i915_drv.h +1 -0
@@ -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(
drivers/gpu/drm/i915/i915_gem.c +32 -0
@@ -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); +}
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✗ Ro.CI.BAT: failure for series starting with [1/1] drm/i915: gracefully reject mmap of huge tiled objects
== Series Details ==
== 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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 5 lines · James Xiong
From: "Xiong, James" <[email protected]>
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.
Quoted 2 lines
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
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Thanks,
James
-----Original Message-----
From: Chris Wilson [mailto:[email protected]] On Behalf Of Chris Wilson
Sent: Friday, July 1, 2016 12:25 AM
To: Xiong, James <[email protected]>
Cc: [email protected]
Subject: Re: [Intel-gfx] [PATCH 1/1] drm/i915: gracefully reject mmap of huge tiled objects
Quoted 5 lines · James Xiong
From: "Xiong, James" <[email protected]>
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?
Quoted 2 lines
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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx