drm/i915: Fix recursive calls to unmap
Subsystems (2)
PATCH v2 1/1 drm/i915: Fix recursive calls to unmap
After the ILK vt-d workaround patches it became clear that we had introduced a bug. Chris tracked down the issue to recursive calls to unmap. This happens because we try to optimize waiting on requests by calling retire requests after the wait, which may drop the last reference on an object and end up freeing the object (and then unmap the object from the gtt).
The solution here is to add a new flag to the call chain which gives the routines the information they need to possibly defer actions which may cause us to recurse.
Kudos to Chris for tracking this one down.
This fixes tests/gem_linear_blits in intel-gpu-tools.
v2: v1 used a global, v2 directly modified the call chain.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42180
--- drivers/gpu/drm/i915/i915_drv.h | 6 ++++-- drivers/gpu/drm/i915/i915_gem.c | 24 ++++++++++++++---------- drivers/gpu/drm/i915/i915_gem_gtt.c | 2 +- drivers/gpu/drm/i915/intel_overlay.c | 4 ++-- 4 files changed, 21 insertions(+), 15 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +4 -2
@@ -1180,13 +1180,15 @@ void i915_gem_do_init(struct drm_device *dev,unsigned long start, unsigned long mappable_end, unsigned long end); -int __must_check i915_gpu_idle (struct drm_device *dev); +int __must_check i915_gem_gpu_idle (struct drm_device *dev,bool strictly_idle); +#define i915_gpu_idle (dev) i915_gem_gpu_idle(dev, false)int __must_check i915_gem_idle (struct drm_device *dev);int __must_check i915_add_request (struct intel_ring_buffer *ring,struct drm_file *file,struct drm_i915_gem_request *request);int __must_check i915_wait_request (struct intel_ring_buffer *ring, -uint32_t seqno); +uint32_t seqno, +bool defer_retirement);int i915_gem_fault (struct vm_area_struct *vma,struct vm_fault *vmf); int __must_check i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj,
drivers/gpu/drm/i915/i915_gem.c +14 -10
@@ -1943,7 +1943,8 @@ i915_gem_retire_work_handler(struct work_struct *work)*/ int i915_wait_request (struct intel_ring_buffer *ring, -uint32_t seqno) +uint32_t seqno, +bool defer_retirement) {drm_i915_private_t *dev_priv = ring->dev->dev_private;u32 ier;
@@ -2027,7 +2028,7 @@ i915_wait_request(struct intel_ring_buffer *ring,* buffer to have made it to the inactive list, and we would need * a separate wait queue to handle that. */ -if (ret ==0 ) +if (ret ==0 && !defer_retirement)i915_gem_retire_requests_ring (ring);return ret;
@@ -2051,7 +2052,8 @@ i915_gem_object_wait_rendering(struct drm_i915_gem_object *obj)* it. */ if (obj->active) { - ret =i915_wait_request (obj->ring, obj->last_rendering_seqno); + ret =i915_wait_request (obj->ring, obj->last_rendering_seqno, + true);if (ret)return ret; }
@@ -2172,7 +2174,7 @@ i915_gem_flush_ring(struct intel_ring_buffer *ring,return 0 ; } -static int i915_ring_idle (struct intel_ring_buffer *ring) +static int i915_ring_idle (struct intel_ring_buffer *ring,bool defer_retirement) {int ret;
@@ -2186,18 +2188,18 @@ static int i915_ring_idle(struct intel_ring_buffer *ring)return ret; } -return i915_wait_request (ring,i915_gem_next_request_seqno (ring)); +return i915_wait_request (ring,i915_gem_next_request_seqno (ring), + defer_retirement); } -int -i915_gpu_idle (struct drm_device *dev) +int i915_gem_gpu_idle (struct drm_device *dev,bool strictly_idle) {drm_i915_private_t *dev_priv = dev->dev_private;int ret, i;/* Flush everything onto the inactive list. */ for (i =0 ; i <I915_NUM_RINGS ; i++) { - ret =i915_ring_idle (&dev_priv->ring[i]); + ret =i915_ring_idle (&dev_priv->ring[i], strictly_idle);if (ret)return ret; }
@@ -2400,7 +2402,8 @@ i915_gem_object_flush_fence(struct drm_i915_gem_object *obj,if (!ring_passed_seqno (obj->last_fenced_ring, obj->last_fenced_seqno)) { ret =i915_wait_request (obj->last_fenced_ring, - obj->last_fenced_seqno); + obj->last_fenced_seqno, + true);if (ret)return ret; }
@@ -2541,7 +2544,8 @@ i915_gem_object_get_fence(struct drm_i915_gem_object *obj,if (!ring_passed_seqno (obj->last_fenced_ring, reg->setup_seqno)) { ret =i915_wait_request (obj->last_fenced_ring, - reg->setup_seqno); + reg->setup_seqno, + true);if (ret)return ret; }
drivers/gpu/drm/i915/i915_gem_gtt.c +1 -1
@@ -55,7 +55,7 @@ static bool do_idling(struct drm_i915_private *dev_priv)if (unlikely (dev_priv->mm.gtt->do_idle_maps)) { dev_priv->mm.interruptible = false; -if (i915_gpu_idle (dev_priv->dev)) { +if (i915_gem_gpu_idle (dev_priv->dev, true)) {DRM_ERROR ("Couldn't idle GPU\n" );/* Wait a bit, in hopes it avoids the hang */ udelay (10 );
drivers/gpu/drm/i915/intel_overlay.c +2 -2
@@ -227,7 +227,7 @@ static int intel_overlay_do_wait_request(struct intel_overlay *overlay, } overlay->last_flip_req = request->seqno; overlay->flip_tail = tail; - ret =i915_wait_request (LP_RING (dev_priv), overlay->last_flip_req); + ret =i915_wait_request (LP_RING (dev_priv), overlay->last_flip_req, false);if (ret)return ret;
@@ -448,7 +448,7 @@ static int intel_overlay_recover_from_interrupt(struct intel_overlay *overlay)if (overlay->last_flip_req ==0 )return 0 ; - ret =i915_wait_request (LP_RING (dev_priv), overlay->last_flip_req); + ret =i915_wait_request (LP_RING (dev_priv), overlay->last_flip_req, false);if (ret)return ret;
Signature · 1 line
1.7.7.1
Quoted 4 lines · Ben Widawsky
The solution here is to add a new flag to the call chain which gives the routines the information they need to possibly defer actions which may cause us to recurse.
This looks a lot nicer; it's shorter than I feared too.
Quoted 19 lines
drivers/gpu/drm/i915/i915_gem.c +4
-2@@ -2051,7 +2052,8 @@ i915_gem_object_wait_rendering(struct drm_i915_gem_object *obj)* it. */ if (obj->active) { - ret =i915_wait_request (obj->ring, obj->last_rendering_seqno); + ret =i915_wait_request (obj->ring, obj->last_rendering_seqno, + true);@@ -2400,7 +2402,8 @@ i915_gem_object_flush_fence(struct drm_i915_gem_object *obj,if (!ring_passed_seqno (obj->last_fenced_ring, obj->last_fenced_seqno)) { ret =i915_wait_request (obj->last_fenced_ring, - obj->last_fenced_seqno); + obj->last_fenced_seqno, + true);if (ret)return ret; }
drivers/gpu/drm/i915/i915_gem.c i915_gem_object_get_fence(struct drm_i915_gem_object *obj, · line 2551
Quoted 9 lines
drivers/gpu/drm/i915/i915_gem.c +2
-1@@ -2541,7 +2544,8 @@ i915_gem_object_get_fence(struct drm_i915_gem_object *obj,if (!ring_passed_seqno (obj->last_fenced_ring, reg->setup_seqno)) { ret =i915_wait_request (obj->last_fenced_ring, - reg->setup_seqno); + reg->setup_seqno, + true);if (ret)return ret; }
Any reason you're changing behaviour outside of the area with the actual problem? If so, you should stick those in a separate patch instead of mixing them into this bug fix.
Signature · 1 line
[email protected]
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 32 lines · On Sun, 30 Oct 2011 18:36:23 -0700 Keith Packard <[email protected]> wrote:
Quoted 4 lines · Ben Widawsky
The solution here is to add a new flag to the call chain which gives the routines the information they need to possibly defer actions which may cause us to recurse.
This looks a lot nicer; it's shorter than I feared too.
Quoted 24 lines
drivers/gpu/drm/i915/i915_gem.c +5
-3@@ -2051,7 +2052,8 @@ i915_gem_object_wait_rendering(struct drm_i915_gem_object *obj)* it. */ if (obj->active) { - ret =i915_wait_request (obj->ring, obj->last_rendering_seqno); + ret =i915_wait_request (obj->ring, obj->last_rendering_seqno, + true);@@ -2400,7 +2402,8 @@ i915_gem_object_flush_fence(struct drm_i915_gem_object *obj,if (!ring_passed_seqno (obj->last_fenced_ring, obj->last_fenced_seqno)) { ret =i915_wait_request (obj->last_fenced_ring, - obj->last_fenced_seqno); + obj->last_fenced_seqno, + true);if (ret)return ret; }@@ -2541,7 +2544,8 @@ i915_gem_object_get_fence(struct drm_i915_gem_object *obj,if (!ring_passed_seqno (obj->last_fenced_ring, reg->setup_seqno)) { ret = i915_wait_request(obj->last_fenced_ring, - reg->setup_seqno); + reg->setup_seqno,
Quoted 9 lines
drivers/gpu/drm/i915/i915_gem.c i915_gem_object_wait_rendering(struct drm_i915_gem_object *obj) · line 2059
Quoted 4 lines
drivers/gpu/drm/i915/i915_gem.c +1
-0+ true);if (ret)return ret; }Any reason you're changing behaviour outside of the area with the actual problem? If so, you should stick those in a separate patch instead of mixing them into this bug fix.
Well, I had to pick one, and looking at the call chain, it seemed there wasn't much to gain by doing retiring at this point. If you want to take the patch, and modify those vales to false - I'm okay with it.
Ben
Quoted 2 lines · Ben Widawsky
Well, I had to pick one, and looking at the call chain, it seemed there wasn't much to gain by doing retiring at this point.
The point is that you're mixing the stuff the commit message talks about with other changes *which are not mentioned in the commit message* and which are *unrelated to the bug in question*.
Two changes get two patches, it's pretty simple. And, commit messages must tell the whole truth and nothing but the truth. I really hate having to be this careful in reviewing your patches.
Signature · 1 line
[email protected]
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx