* [PATCH] drm/i915: Fix recursive calls to unmap
@ 2011-10-30 2:07 Ben Widawsky
2011-10-30 2:51 ` Keith Packard
0 siblings, 1 reply; 4+ messages in thread
From: Ben Widawsky @ 2011-10-30 2:07 UTC (permalink / raw)
To: intel-gfx; +Cc: Ben Widawsky
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.
Cc: Keith Packard <keithp@keithp.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Reported-by: guang.a.yang@intel.com
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42180
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
---
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(-)
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 06a37f4..bddf19a 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -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 */
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 6651c36..b5cf0e3 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -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;
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 6042c5e..2f4b6c7 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -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)
--
1.7.7.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/i915: Fix recursive calls to unmap
2011-10-30 2:07 [PATCH] drm/i915: Fix recursive calls to unmap Ben Widawsky
@ 2011-10-30 2:51 ` Keith Packard
2011-10-30 2:56 ` Ben Widawsky
0 siblings, 1 reply; 4+ messages in thread
From: Keith Packard @ 2011-10-30 2:51 UTC (permalink / raw)
To: intel-gfx; +Cc: Ben Widawsky
[-- Attachment #1.1: Type: text/plain, Size: 543 bytes --]
On Sat, 29 Oct 2011 19:07:23 -0700, Ben Widawsky <ben@bwidawsk.net> wrote:
> + /**
> + * 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.
--
keith.packard@intel.com
[-- Attachment #1.2: Type: application/pgp-signature, Size: 827 bytes --]
[-- Attachment #2: Type: text/plain, Size: 159 bytes --]
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/i915: Fix recursive calls to unmap
2011-10-30 2:51 ` Keith Packard
@ 2011-10-30 2:56 ` Ben Widawsky
2011-10-30 4:10 ` Keith Packard
0 siblings, 1 reply; 4+ messages in thread
From: Ben Widawsky @ 2011-10-30 2:56 UTC (permalink / raw)
To: Keith Packard; +Cc: intel-gfx
On Sat, 29 Oct 2011 19:51:26 -0700
Keith Packard <keithp@keithp.com> wrote:
> On Sat, 29 Oct 2011 19:07:23 -0700, Ben Widawsky <ben@bwidawsk.net> wrote:
>
> > + /**
> > + * 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.
>
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/i915: Fix recursive calls to unmap
2011-10-30 2:56 ` Ben Widawsky
@ 2011-10-30 4:10 ` Keith Packard
0 siblings, 0 replies; 4+ messages in thread
From: Keith Packard @ 2011-10-30 4:10 UTC (permalink / raw)
To: Ben Widawsky; +Cc: intel-gfx
[-- Attachment #1.1: Type: text/plain, Size: 525 bytes --]
On Sat, 29 Oct 2011 19:56:43 -0700, Ben Widawsky <ben@bwidawsk.net> wrote:
> 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.
> I can do it the way you expected.
Thanks. It will scare me a lot less that way.
--
keith.packard@intel.com
[-- Attachment #1.2: Type: application/pgp-signature, Size: 827 bytes --]
[-- Attachment #2: Type: text/plain, Size: 159 bytes --]
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-10-30 4:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-30 2:07 [PATCH] drm/i915: Fix recursive calls to unmap Ben Widawsky
2011-10-30 2:51 ` Keith Packard
2011-10-30 2:56 ` Ben Widawsky
2011-10-30 4:10 ` Keith Packard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox