From: Mika Kuoppala <mika.kuoppala@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/i915: Prevent lock-cycles between GPU waits and GPU resets
Date: Wed, 12 Jun 2019 14:00:07 +0300 [thread overview]
Message-ID: <878su79ih4.fsf@gaia.fi.intel.com> (raw)
In-Reply-To: <20190612085246.16374-1-chris@chris-wilson.co.uk>
Chris Wilson <chris@chris-wilson.co.uk> writes:
> We cannot allow ourselves to wait on the GPU while holding any lock we
s/we/as we?
My english parser is not strong.
> may need to reset the GPU. While there is not an explicit lock between
> the two operations, lockdep cannot detect the dependency. So let's tell
> lockdep about the wait/reset dependency with an explicit lockmap.
>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> ---
> This is *annoyingly* good at detecting lock cycles in GPU reset.
> -Chris
> ---
> drivers/gpu/drm/i915/gt/intel_reset.c | 5 ++++-
> drivers/gpu/drm/i915/i915_drv.h | 8 ++++++++
> drivers/gpu/drm/i915/i915_gem.c | 3 +++
> drivers/gpu/drm/i915/i915_request.c | 2 ++
> drivers/gpu/drm/i915/selftests/mock_gem_device.c | 2 ++
> 5 files changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/gt/intel_reset.c b/drivers/gpu/drm/i915/gt/intel_reset.c
> index 60d24110af80..6368b37f26d1 100644
> --- a/drivers/gpu/drm/i915/gt/intel_reset.c
> +++ b/drivers/gpu/drm/i915/gt/intel_reset.c
> @@ -978,10 +978,11 @@ void i915_reset(struct drm_i915_private *i915,
>
> might_sleep();
> GEM_BUG_ON(!test_bit(I915_RESET_BACKOFF, &error->flags));
> + lock_map_acquire(&i915->gt.reset_lockmap);
>
> /* Clear any previous failed attempts at recovery. Time to try again. */
> if (!__i915_gem_unset_wedged(i915))
> - return;
> + goto unlock;
>
> if (reason)
> dev_notice(i915->drm.dev, "Resetting chip for %s\n", reason);
> @@ -1029,6 +1030,8 @@ void i915_reset(struct drm_i915_private *i915,
>
> finish:
> reset_finish(i915);
> +unlock:
> + lock_map_release(&i915->gt.reset_lockmap);
> return;
The return patter in this function is rather unorthodox. Might be
even that I reviewed it. Very close that I fell into trap of thinking
that you return with lock held.
>
> taint:
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index 0ea7f78ae227..9cfa9500fcc4 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -1919,6 +1919,14 @@ struct drm_i915_private {
> ktime_t last_init_time;
>
> struct i915_vma *scratch;
> +
> + /*
> + * We must never wait on the GPU while holding a lock we may
My english parser still expected 'as' somewhere in there.
Regardless, a neat way to use lockdep to enforce our expectations.
Reviewed-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
> + * need to perform a GPU reset. So while we don't need to
> + * serialise wait/reset with an explicit lock, we do want
> + * lockdep to detect potential dependency cycles.
> + */
> + struct lockdep_map reset_lockmap;
> } gt;
>
> struct {
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index e980c1ee3dcf..24f0f3db1bfb 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -1782,6 +1782,7 @@ static void i915_gem_init__mm(struct drm_i915_private *i915)
>
> int i915_gem_init_early(struct drm_i915_private *dev_priv)
> {
> + static struct lock_class_key reset_key;
> int err;
>
> intel_gt_pm_init(dev_priv);
> @@ -1789,6 +1790,8 @@ int i915_gem_init_early(struct drm_i915_private *dev_priv)
> INIT_LIST_HEAD(&dev_priv->gt.active_rings);
> INIT_LIST_HEAD(&dev_priv->gt.closed_vma);
> spin_lock_init(&dev_priv->gt.closed_lock);
> + lockdep_init_map(&dev_priv->gt.reset_lockmap,
> + "i915.reset", &reset_key, 0);
>
> i915_gem_init__mm(dev_priv);
> i915_gem_init__pm(dev_priv);
> diff --git a/drivers/gpu/drm/i915/i915_request.c b/drivers/gpu/drm/i915/i915_request.c
> index 1a948471829d..cd4ce44dc4e5 100644
> --- a/drivers/gpu/drm/i915/i915_request.c
> +++ b/drivers/gpu/drm/i915/i915_request.c
> @@ -1444,6 +1444,7 @@ long i915_request_wait(struct i915_request *rq,
> return -ETIME;
>
> trace_i915_request_wait_begin(rq, flags);
> + lock_map_acquire(&rq->i915->gt.reset_lockmap);
>
> /*
> * Optimistic spin before touching IRQs.
> @@ -1517,6 +1518,7 @@ long i915_request_wait(struct i915_request *rq,
> dma_fence_remove_callback(&rq->fence, &wait.cb);
>
> out:
> + lock_map_release(&rq->i915->gt.reset_lockmap);
> trace_i915_request_wait_end(rq);
> return timeout;
> }
> diff --git a/drivers/gpu/drm/i915/selftests/mock_gem_device.c b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
> index b7f3fbb4ae89..1e9ffced78c1 100644
> --- a/drivers/gpu/drm/i915/selftests/mock_gem_device.c
> +++ b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
> @@ -130,6 +130,7 @@ static struct dev_pm_domain pm_domain = {
>
> struct drm_i915_private *mock_gem_device(void)
> {
> + static struct lock_class_key reset_key;
> struct drm_i915_private *i915;
> struct pci_dev *pdev;
> int err;
> @@ -204,6 +205,7 @@ struct drm_i915_private *mock_gem_device(void)
> INIT_LIST_HEAD(&i915->gt.active_rings);
> INIT_LIST_HEAD(&i915->gt.closed_vma);
> spin_lock_init(&i915->gt.closed_lock);
> + lockdep_init_map(&i915->gt.reset_lockmap, "i915.reset", &reset_key, 0);
>
> mutex_lock(&i915->drm.struct_mutex);
>
> --
> 2.20.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2019-06-12 11:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-12 8:52 [PATCH] drm/i915: Prevent lock-cycles between GPU waits and GPU resets Chris Wilson
2019-06-12 9:38 ` ✓ Fi.CI.BAT: success for drm/i915: Prevent lock-cycles between GPU waits and GPU resets (rev2) Patchwork
2019-06-12 11:00 ` Mika Kuoppala [this message]
2019-06-12 11:04 ` [PATCH] drm/i915: Prevent lock-cycles between GPU waits and GPU resets Chris Wilson
2019-06-13 5:21 ` ✗ Fi.CI.IGT: failure for drm/i915: Prevent lock-cycles between GPU waits and GPU resets (rev2) Patchwork
-- strict thread matches above, loose matches on Subject: below --
2019-06-11 14:27 [PATCH] drm/i915: Prevent lock-cycles between GPU waits and GPU resets Chris Wilson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878su79ih4.fsf@gaia.fi.intel.com \
--to=mika.kuoppala@linux.intel.com \
--cc=chris@chris-wilson.co.uk \
--cc=intel-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.