drm/i915: Fix recursive calls to unmap
Subsystems (2)
PATCH 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 make a somewhat generic flag to tell our code not to try to unmap objects from the GTT.
Kudos to Chris for tracking this one down.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42180
--- drivers/gpu/drm/i915/i915_drv.h | 9 +++++++++ drivers/gpu/drm/i915/i915_gem.c | 5 ++++- drivers/gpu/drm/i915/i915_gem_gtt.c | 6 +++++- 3 files changed, 18 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +9 -0
@@ -654,6 +654,15 @@ typedef struct drm_i915_private {*/ atomic_t wedged; +/** +* Flag if GTT ptes shouldn't be modified. +* +* This is set when graphics virtual address space +* should not be changed. It's currently only useful for +* a workaround which requires that we serialize unmaps. +*/ +bool freeze_ptes; +/** Bit 6 swizzling required for X tiling */ uint32_t bit_6_swizzle_x;/** Bit 6 swizzling required for Y tiling */
drivers/gpu/drm/i915/i915_gem.c +4 -1
@@ -2026,8 +2026,11 @@ i915_wait_request(struct intel_ring_buffer *ring,* to handle this, the waiter on a request often wants an associated * buffer to have made it to the inactive list, and we would need * a separate wait queue to handle that. +* +* The caller may have not wanted us to actually retire commands +* as that may lead to GTT modifications. */ -if (ret ==0 ) +if (ret ==0 && !dev_priv->mm.freeze_ptes)i915_gem_retire_requests_ring (ring);return ret;
drivers/gpu/drm/i915/i915_gem_gtt.c +5 -1
@@ -55,6 +55,8 @@ static bool do_idling(struct drm_i915_private *dev_priv)if (unlikely (dev_priv->mm.gtt->do_idle_maps)) { dev_priv->mm.interruptible = false; +WARN_ON (dev_priv->mm.freeze_ptes == true); + dev_priv->mm.freeze_ptes = true;if (i915_gpu_idle (dev_priv->dev)) {DRM_ERROR ("Couldn't idle GPU\n" );/* Wait a bit, in hopes it avoids the hang */
@@ -67,8 +69,10 @@ static bool do_idling(struct drm_i915_private *dev_priv)static void undo_idling (struct drm_i915_private *dev_priv,bool interruptible) { -if (unlikely (dev_priv->mm.gtt->do_idle_maps)) +if (unlikely (dev_priv->mm.gtt->do_idle_maps)) { + dev_priv->mm.freeze_ptes = false; dev_priv->mm.interruptible = interruptible; + } }void i915_gem_restore_gtt_mappings (struct drm_device *dev)
Signature · 1 line
1.7.7.1
drivers/gpu/drm/i915/i915_drv.h typedef struct drm_i915_private { · line 665
Quoted 9 lines · Ben Widawsky
drivers/gpu/drm/i915/i915_drv.h +9
-0+/** +* Flag if GTT ptes shouldn't be modified. +* +* This is set when graphics virtual address space +* should not be changed. It's currently only useful for +* a workaround which requires that we serialize unmaps. +*/ +bool freeze_ptes; +
Yucky. yucky. yucky.
What I expected was to see an extra argument passed down through the call chain instead of a global variable here.
Signature · 1 line
[email protected]
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 14 lines · On Sat, 29 Oct 2011 19:51:26 -0700 Keith Packard <[email protected]> wrote:
drivers/gpu/drm/i915/i915_drv.h typedef struct drm_i915_private { · line 665
Quoted 9 lines · Ben Widawsky
drivers/gpu/drm/i915/i915_drv.h +9
-0+/** +* Flag if GTT ptes shouldn't be modified. +* +* This is set when graphics virtual address space +* should not be changed. It's currently only useful for +* a workaround which requires that we serialize unmaps. +*/ +bool freeze_ptes; +Yucky. yucky. yucky.
Quoted 3 lines
What I expected was to see an extra argument passed down through the call chain instead of a global variable here.
Sigh. I started down that path, but it was becoming tedious with only one case where we actually want to not retire (I think), so I thought I'd see how this went down on the mailing list.
The other nice thing was it was really easy to detect if we recurse (with the added WARN_ON) when someone adds some similar code in the future.
I can do it the way you expected.
Quoted 3 lines · Ben Widawsky
Sigh. I started down that path, but it was becoming tedious with only one case where we actually want to not retire (I think), so I thought I'd see how this went down on the mailing list.
I don't even want to think about locking for this bug, and a global variable is just ripe with opportunities to mess that up.
Quoted 1 line
I can do it the way you expected.
Thanks. It will scare me a lot less that way.
Signature · 1 line
[email protected]
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx