public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 3/3] drm/i915: Remove superfluous locking around userfault_list
Date: Thu, 13 Oct 2016 16:47:56 +0200	[thread overview]
Message-ID: <20161013144756.GD20761@phenom.ffwll.local> (raw)
In-Reply-To: <20161011143759.28052-3-chris@chris-wilson.co.uk>

On Tue, Oct 11, 2016 at 03:37:59PM +0100, Chris Wilson wrote:
> Now that we have reduced the access to the list to either (a) under the
> struct_mutex whilst holding the RPM wakeref (so that concurrent writers to
> the list are serialised by struct_mutex) and (b) under the atomic
> runtime suspend (which cannot run concurrently with any other accessor due
> to the atomic nature of the runtime suspend) we can remove the extra
> locking around the list itself.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

So this is a bit a pet peeve of mine, but when changing locking schemes
I'm trying to make an as clear as possible distinction between locking
(which is just meant to protect the integrity of data structures, like
e.g. the userfault_list here). And anything else which manages lifetimes
and resources (all the get/put stuff we have) or ordering/sequence
(waiting, waking up other stuff and all that).

The reason for that is that with a BKL it is super easy to smash all these
things into one, but if you have locking that also keeps stuff alive and
guarantees ordering (or the other way round) it becomes nigh to impossible
to untangle.

Hence why I don't like this.
-Daniel

> ---
>  drivers/gpu/drm/i915/i915_drv.h |  3 ---
>  drivers/gpu/drm/i915/i915_gem.c | 21 ++++-----------------
>  2 files changed, 4 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index 72b3126c6c74..13ca968a760a 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -1359,9 +1359,6 @@ struct i915_gem_mm {
>  	 */
>  	struct list_head unbound_list;
>  
> -	/** Protects access to the userfault_list */
> -	spinlock_t userfault_lock;
> -
>  	/** List of all objects in gtt_space, currently mmaped by userspace.
>  	 * All objects within this list must also be on bound_list.
>  	 */
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index 587a91af5a3f..a268e804005c 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -1853,9 +1853,7 @@ int i915_gem_fault(struct vm_area_struct *area, struct vm_fault *vmf)
>  		goto err_unpin;
>  
>  	assert_rpm_wakelock_held(dev_priv);
> -	spin_lock(&dev_priv->mm.userfault_lock);
>  	list_add(&obj->userfault_link, &dev_priv->mm.userfault_list);
> -	spin_unlock(&dev_priv->mm.userfault_lock);
>  
>  err_unpin:
>  	__i915_vma_unpin(vma);
> @@ -1925,7 +1923,6 @@ void
>  i915_gem_release_mmap(struct drm_i915_gem_object *obj)
>  {
>  	struct drm_i915_private *i915 = to_i915(obj->base.dev);
> -	bool zap = false;
>  
>  	/* Serialisation between user GTT access and our code depends upon
>  	 * revoking the CPU's PTE whilst the mutex is held. The next user
> @@ -1937,15 +1934,10 @@ i915_gem_release_mmap(struct drm_i915_gem_object *obj)
>  	 */
>  	assert_rpm_wakelock_held(i915);
>  
> -	spin_lock(&i915->mm.userfault_lock);
> -	if (!list_empty(&obj->userfault_link)) {
> -		list_del_init(&obj->userfault_link);
> -		zap = true;
> -	}
> -	spin_unlock(&i915->mm.userfault_lock);
> -	if (!zap)
> +	if (list_empty(&obj->userfault_link))
>  		return;
>  
> +	list_del_init(&obj->userfault_link);
>  	drm_vma_node_unmap(&obj->base.vma_node,
>  			   obj->base.dev->anon_inode->i_mapping);
>  
> @@ -1963,13 +1955,9 @@ void
>  i915_gem_release_all_mmaps(struct drm_i915_private *dev_priv)
>  {
>  	struct drm_i915_gem_object *obj, *on;
> -	struct list_head userfault_list;
> -
> -	spin_lock(&dev_priv->mm.userfault_lock);
> -	list_replace_init(&dev_priv->mm.userfault_list, &userfault_list);
> -	spin_unlock(&dev_priv->mm.userfault_lock);
>  
> -	list_for_each_entry_safe(obj, on, &userfault_list, userfault_link)
> +	list_for_each_entry_safe(obj, on,
> +				 &dev_priv->mm.userfault_list, userfault_link)
>  		i915_gem_release_mmap(obj);
>  }
>  
> @@ -4457,7 +4445,6 @@ int i915_gem_init(struct drm_device *dev)
>  	int ret;
>  
>  	mutex_lock(&dev->struct_mutex);
> -	spin_lock_init(&dev_priv->mm.userfault_lock);
>  
>  	if (!i915.enable_execlists) {
>  		dev_priv->gt.resume = intel_legacy_submission_resume;
> -- 
> 2.9.3
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
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

  reply	other threads:[~2016-10-13 14:48 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-10 21:58 [PATCH 1/3] drm/i915: Use RPM as the barrier for controlling user mmap access Chris Wilson
2016-10-10 21:58 ` [PATCH 2/3] drm/i915: Remove RPM sequence checking Chris Wilson
2016-10-10 21:58 ` [PATCH 3/3] drm/i915: Use fence_write() from rpm resume Chris Wilson
2016-10-11  9:42   ` Joonas Lahtinen
2016-10-10 22:19 ` ✗ Fi.CI.BAT: warning for series starting with [1/3] drm/i915: Use RPM as the barrier for controlling user mmap access Patchwork
2016-10-11 13:25 ` [PATCH 1/3] " Daniel Vetter
2016-10-11 14:37   ` [PATCH 1/3] drm/i915: Move user fault tracking to a separate list Chris Wilson
2016-10-11 14:37     ` [PATCH 2/3] drm/i915: Use RPM as the barrier for controlling user mmap access Chris Wilson
2016-10-13 14:44       ` Daniel Vetter
2016-10-13 15:15         ` Chris Wilson
2016-10-13 15:25           ` Daniel Vetter
2016-10-11 14:37     ` [PATCH 3/3] drm/i915: Remove superfluous locking around userfault_list Chris Wilson
2016-10-13 14:47       ` Daniel Vetter [this message]
2016-10-13 14:40     ` [PATCH 1/3] drm/i915: Move user fault tracking to a separate list Daniel Vetter
2016-10-17  7:44 ` [lkp] [drm/i915] f23c074696: BUG: sleeping function called from invalid context at drivers/base/power/runtime.c:955 kernel test robot

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