public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@intel.com>,
	Daniel Vetter <daniel.vetter@ffwll.ch>
Subject: Re: [PATCH 1/2] drm/i915: Comment userptr recursion on struct_mutex
Date: Wed, 14 Aug 2019 21:22:42 +0200	[thread overview]
Message-ID: <20190814192242.GV7444@phenom.ffwll.local> (raw)
In-Reply-To: <20190814124933.19056-1-daniel.vetter@ffwll.ch>

On Wed, Aug 14, 2019 at 02:49:32PM +0200, Daniel Vetter wrote:
> Discussed this a bit with Chris, I think a comment here is warranted
> that this will be bad once we have more than one i915 instance. And
> lockdep won't catch it.
> 
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> ---
>  drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c
> index 74da35611d7c..70dc506a5426 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c
> @@ -135,6 +135,12 @@ userptr_mn_invalidate_range_start(struct mmu_notifier *_mn,
>  			switch (mutex_trylock_recursive(unlock)) {
>  			default:
>  			case MUTEX_TRYLOCK_FAILED:
> +				/*
> +				 * NOTE: This only works because there's only
> +				 * ever one i915-style struct_mutex in the
> +				 * entire system. If we could have two i915
> +				 * instances, this would deadlock.
> +				 */

While fixing up annotations for the 2nd patch I though more about this,
and I'm not sold that "there's only one" makes sense. Scenario:

thread A:
get_pages
-> mutex_lock(obj->mm.lock)
-> fs_reclaim
-> mmu_notifier picks range of memory we're interested in
-> mutex_lock_killable(struct_mutex)

Why can this not deadlock against any other thread which does:

mutex_lock(struct_mutex)
-> get_pages
-> mutex_lock(obj->mm.lock)

They would both need to pick the same object, that's right now at a 0->1
transition for pages_pin_count. Plus a long list of other unhappy
circumstances ...

Note that this is different from the same annotation in shrinker_lock:
That one is only used if current_is_kswapd is, which guarantees we're not
holding a few unfortunate locks.
-Daniel

>  				if (mutex_lock_killable_nested(unlock, I915_MM_SHRINKER)) {
>  					i915_gem_object_put(obj);
>  					return -EINTR;
> -- 
> 2.22.0
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2019-08-14 19:22 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-14 12:49 [PATCH 1/2] drm/i915: Comment userptr recursion on struct_mutex Daniel Vetter
2019-08-14 12:49 ` [PATCH 2/2] RFC: drm/i915: Switch obj->mm.lock lockdep annotations on its head Daniel Vetter
2019-08-14 13:06   ` Chris Wilson
2019-08-14 14:48     ` Daniel Vetter
2019-08-14 18:49   ` [PATCH] " Daniel Vetter
2019-08-14 18:57     ` Chris Wilson
     [not found]       ` <20190815072301.GE7444@phenom.ffwll.local>
2019-08-15  7:28         ` Chris Wilson
2019-08-14 19:24   ` Daniel Vetter
2019-08-15 19:35     ` Tang, CQ
2019-08-16  7:28       ` Daniel Vetter
2019-08-14 14:36 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [1/2] drm/i915: Comment userptr recursion on struct_mutex Patchwork
2019-08-14 14:58 ` ✗ Fi.CI.BAT: failure " Patchwork
2019-08-14 19:22 ` Daniel Vetter [this message]
2019-08-14 19:31 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [1/2] drm/i915: Comment userptr recursion on struct_mutex (rev3) Patchwork
2019-08-14 20:06 ` ✓ Fi.CI.BAT: success " Patchwork
2019-08-15 11:55 ` ✓ Fi.CI.IGT: " Patchwork

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=20190814192242.GV7444@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniel.vetter@intel.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox