All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Sam Ravnborg <sam@ravnborg.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
	Intel Graphics Development <intel-gfx@lists.freedesktop.org>,
	DRI Development <dri-devel@lists.freedesktop.org>,
	Daniel Vetter <daniel.vetter@intel.com>
Subject: Re: [PATCH 5/5] drm: Nerv drm_global_mutex BKL for good drivers
Date: Wed, 29 Jan 2020 18:07:21 +0100	[thread overview]
Message-ID: <20200129170721.GN43062@phenom.ffwll.local> (raw)
In-Reply-To: <20200129164733.GB22331@ravnborg.org>

On Wed, Jan 29, 2020 at 05:47:33PM +0100, Sam Ravnborg wrote:
> Hi Daniel.
> 
> In the nit-pick department today - sorry.
> 
> Subject: [PATCH 5/5] drm: Nerv drm_global_mutex BKL for good drivers
> I did not understand this subject... - what is "Nerv"?

It's a typo, supposed to be nerf:

https://www.urbandictionary.com/define.php?term=nerf

Cheers, Daniel
> 
> 	Sam
> 
> On Wed, Jan 29, 2020 at 09:24:10AM +0100, Daniel Vetter wrote:
> > This catches the majority of drivers (unfortunately not if we take
> > users into account, because all the big drivers have at least a
> > lastclose hook).
> > 
> > With the prep patches out of the way all drm state is fully protected
> > and either prevents or can deal with the races from dropping the BKL
> > around open/close. The only thing left to audit are the various driver
> > hooks - by keeping the BKL around if any of them are set we have a
> > very simple cop-out!
> > 
> > Note that one of the biggest prep pieces to get here was making
> > dev->open_count atomic, which was done in
> > 
> > commit 7e13ad896484a0165a68197a2e64091ea28c9602
> > Author: Chris Wilson <chris@chris-wilson.co.uk>
> > Date:   Fri Jan 24 13:01:07 2020 +0000
> > 
> >     drm: Avoid drm_global_mutex for simple inc/dec of dev->open_count
> > 
> > Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
> > Cc: Chris Wilson <chris@chris-wilson.co.uk>
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > ---
> >  drivers/gpu/drm/drm_drv.c      |  6 +++--
> >  drivers/gpu/drm/drm_file.c     | 46 ++++++++++++++++++++++++++++++----
> >  drivers/gpu/drm/drm_internal.h |  1 +
> >  3 files changed, 46 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> > index 05bdf0b9d2b3..9fcd6ab3c154 100644
> > --- a/drivers/gpu/drm/drm_drv.c
> > +++ b/drivers/gpu/drm/drm_drv.c
> > @@ -946,7 +946,8 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
> >  	struct drm_driver *driver = dev->driver;
> >  	int ret;
> >  
> > -	mutex_lock(&drm_global_mutex);
> > +	if (drm_dev_needs_global_mutex(dev))
> > +		mutex_lock(&drm_global_mutex);
> >  
> >  	if (dev->driver->load) {
> >  		if (!drm_core_check_feature(dev, DRIVER_LEGACY))
> > @@ -992,7 +993,8 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
> >  	drm_minor_unregister(dev, DRM_MINOR_PRIMARY);
> >  	drm_minor_unregister(dev, DRM_MINOR_RENDER);
> >  out_unlock:
> > -	mutex_unlock(&drm_global_mutex);
> > +	if (drm_dev_needs_global_mutex(dev))
> > +		mutex_unlock(&drm_global_mutex);
> >  	return ret;
> >  }
> >  EXPORT_SYMBOL(drm_dev_register);
> > diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
> > index d36cb74ebe0c..efd6fe0b6b4f 100644
> > --- a/drivers/gpu/drm/drm_file.c
> > +++ b/drivers/gpu/drm/drm_file.c
> > @@ -51,6 +51,37 @@
> >  /* from BKL pushdown */
> >  DEFINE_MUTEX(drm_global_mutex);
> >  
> > +bool drm_dev_needs_global_mutex(struct drm_device *dev)
> > +{
> > +	/*
> > +	 * Legacy drivers rely on all kinds of BKL locking semantics, don't
> > +	 * bother. They also still need BKL locking for their ioctls, so better
> > +	 * safe than sorry.
> > +	 */
> > +	if (drm_core_check_feature(dev, DRIVER_LEGACY))
> > +		return true;
> > +
> > +	/*
> > +	 * The deprecated ->load callback must be called after the driver is
> > +	 * already registered. This means such drivers rely on the BKL to make
> > +	 * sure an open can't proceed until the driver is actually fully set up.
> > +	 * Similar hilarity holds for the unload callback.
> > +	 */
> > +	if (dev->driver->load || dev->driver->unload)
> > +		return true;
> > +
> > +	/*
> > +	 * Drivers with the lastclose callback assume that it's synchronized
> > +	 * against concurrent opens, which again needs the BKL. The proper fix
> > +	 * is to use the drm_client infrastructure with proper locking for each
> > +	 * client.
> > +	 */
> > +	if (dev->driver->lastclose)
> > +		return true;
> > +
> > +	return false;
> > +}
> > +
> >  /**
> >   * DOC: file operations
> >   *
> > @@ -378,9 +409,10 @@ int drm_open(struct inode *inode, struct file *filp)
> >  	if (IS_ERR(minor))
> >  		return PTR_ERR(minor);
> >  
> > -	mutex_unlock(&drm_global_mutex);
> > -
> >  	dev = minor->dev;
> > +	if (drm_dev_needs_global_mutex(dev))
> > +		mutex_unlock(&drm_global_mutex);
> > +
> >  	if (!atomic_fetch_inc(&dev->open_count))
> >  		need_setup = 1;
> >  
> > @@ -398,13 +430,15 @@ int drm_open(struct inode *inode, struct file *filp)
> >  		}
> >  	}
> >  
> > -	mutex_unlock(&drm_global_mutex);
> > +	if (drm_dev_needs_global_mutex(dev))
> > +		mutex_unlock(&drm_global_mutex);
> >  
> >  	return 0;
> >  
> >  err_undo:
> >  	atomic_dec(&dev->open_count);
> > -	mutex_unlock(&drm_global_mutex);
> > +	if (drm_dev_needs_global_mutex(dev))
> > +		mutex_unlock(&drm_global_mutex);
> >  	drm_minor_release(minor);
> >  	return retcode;
> >  }
> > @@ -444,6 +478,7 @@ int drm_release(struct inode *inode, struct file *filp)
> >  	struct drm_minor *minor = file_priv->minor;
> >  	struct drm_device *dev = minor->dev;
> >  
> > +	if (drm_dev_needs_global_mutex(dev))
> >  	mutex_lock(&drm_global_mutex);
> >  
> >  	DRM_DEBUG("open_count = %d\n", atomic_read(&dev->open_count));
> > @@ -453,7 +488,8 @@ int drm_release(struct inode *inode, struct file *filp)
> >  	if (atomic_dec_and_test(&dev->open_count))
> >  		drm_lastclose(dev);
> >  
> > -	mutex_unlock(&drm_global_mutex);
> > +	if (drm_dev_needs_global_mutex(dev))
> > +		mutex_unlock(&drm_global_mutex);
> >  
> >  	drm_minor_release(minor);
> >  
> > diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h
> > index 6937bf923f05..aeec2e68d772 100644
> > --- a/drivers/gpu/drm/drm_internal.h
> > +++ b/drivers/gpu/drm/drm_internal.h
> > @@ -41,6 +41,7 @@ struct drm_printer;
> >  
> >  /* drm_file.c */
> >  extern struct mutex drm_global_mutex;
> > +bool drm_dev_needs_global_mutex(struct drm_device *dev);
> >  struct drm_file *drm_file_alloc(struct drm_minor *minor);
> >  void drm_file_free(struct drm_file *file);
> >  void drm_lastclose(struct drm_device *dev);
> > -- 
> > 2.24.1
> > 
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

WARNING: multiple messages have this Message-ID (diff)
From: Daniel Vetter <daniel@ffwll.ch>
To: Sam Ravnborg <sam@ravnborg.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
	Intel Graphics Development <intel-gfx@lists.freedesktop.org>,
	DRI Development <dri-devel@lists.freedesktop.org>,
	Daniel Vetter <daniel.vetter@intel.com>
Subject: Re: [Intel-gfx] [PATCH 5/5] drm: Nerv drm_global_mutex BKL for good drivers
Date: Wed, 29 Jan 2020 18:07:21 +0100	[thread overview]
Message-ID: <20200129170721.GN43062@phenom.ffwll.local> (raw)
In-Reply-To: <20200129164733.GB22331@ravnborg.org>

On Wed, Jan 29, 2020 at 05:47:33PM +0100, Sam Ravnborg wrote:
> Hi Daniel.
> 
> In the nit-pick department today - sorry.
> 
> Subject: [PATCH 5/5] drm: Nerv drm_global_mutex BKL for good drivers
> I did not understand this subject... - what is "Nerv"?

It's a typo, supposed to be nerf:

https://www.urbandictionary.com/define.php?term=nerf

Cheers, Daniel
> 
> 	Sam
> 
> On Wed, Jan 29, 2020 at 09:24:10AM +0100, Daniel Vetter wrote:
> > This catches the majority of drivers (unfortunately not if we take
> > users into account, because all the big drivers have at least a
> > lastclose hook).
> > 
> > With the prep patches out of the way all drm state is fully protected
> > and either prevents or can deal with the races from dropping the BKL
> > around open/close. The only thing left to audit are the various driver
> > hooks - by keeping the BKL around if any of them are set we have a
> > very simple cop-out!
> > 
> > Note that one of the biggest prep pieces to get here was making
> > dev->open_count atomic, which was done in
> > 
> > commit 7e13ad896484a0165a68197a2e64091ea28c9602
> > Author: Chris Wilson <chris@chris-wilson.co.uk>
> > Date:   Fri Jan 24 13:01:07 2020 +0000
> > 
> >     drm: Avoid drm_global_mutex for simple inc/dec of dev->open_count
> > 
> > Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
> > Cc: Chris Wilson <chris@chris-wilson.co.uk>
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > ---
> >  drivers/gpu/drm/drm_drv.c      |  6 +++--
> >  drivers/gpu/drm/drm_file.c     | 46 ++++++++++++++++++++++++++++++----
> >  drivers/gpu/drm/drm_internal.h |  1 +
> >  3 files changed, 46 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> > index 05bdf0b9d2b3..9fcd6ab3c154 100644
> > --- a/drivers/gpu/drm/drm_drv.c
> > +++ b/drivers/gpu/drm/drm_drv.c
> > @@ -946,7 +946,8 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
> >  	struct drm_driver *driver = dev->driver;
> >  	int ret;
> >  
> > -	mutex_lock(&drm_global_mutex);
> > +	if (drm_dev_needs_global_mutex(dev))
> > +		mutex_lock(&drm_global_mutex);
> >  
> >  	if (dev->driver->load) {
> >  		if (!drm_core_check_feature(dev, DRIVER_LEGACY))
> > @@ -992,7 +993,8 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
> >  	drm_minor_unregister(dev, DRM_MINOR_PRIMARY);
> >  	drm_minor_unregister(dev, DRM_MINOR_RENDER);
> >  out_unlock:
> > -	mutex_unlock(&drm_global_mutex);
> > +	if (drm_dev_needs_global_mutex(dev))
> > +		mutex_unlock(&drm_global_mutex);
> >  	return ret;
> >  }
> >  EXPORT_SYMBOL(drm_dev_register);
> > diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
> > index d36cb74ebe0c..efd6fe0b6b4f 100644
> > --- a/drivers/gpu/drm/drm_file.c
> > +++ b/drivers/gpu/drm/drm_file.c
> > @@ -51,6 +51,37 @@
> >  /* from BKL pushdown */
> >  DEFINE_MUTEX(drm_global_mutex);
> >  
> > +bool drm_dev_needs_global_mutex(struct drm_device *dev)
> > +{
> > +	/*
> > +	 * Legacy drivers rely on all kinds of BKL locking semantics, don't
> > +	 * bother. They also still need BKL locking for their ioctls, so better
> > +	 * safe than sorry.
> > +	 */
> > +	if (drm_core_check_feature(dev, DRIVER_LEGACY))
> > +		return true;
> > +
> > +	/*
> > +	 * The deprecated ->load callback must be called after the driver is
> > +	 * already registered. This means such drivers rely on the BKL to make
> > +	 * sure an open can't proceed until the driver is actually fully set up.
> > +	 * Similar hilarity holds for the unload callback.
> > +	 */
> > +	if (dev->driver->load || dev->driver->unload)
> > +		return true;
> > +
> > +	/*
> > +	 * Drivers with the lastclose callback assume that it's synchronized
> > +	 * against concurrent opens, which again needs the BKL. The proper fix
> > +	 * is to use the drm_client infrastructure with proper locking for each
> > +	 * client.
> > +	 */
> > +	if (dev->driver->lastclose)
> > +		return true;
> > +
> > +	return false;
> > +}
> > +
> >  /**
> >   * DOC: file operations
> >   *
> > @@ -378,9 +409,10 @@ int drm_open(struct inode *inode, struct file *filp)
> >  	if (IS_ERR(minor))
> >  		return PTR_ERR(minor);
> >  
> > -	mutex_unlock(&drm_global_mutex);
> > -
> >  	dev = minor->dev;
> > +	if (drm_dev_needs_global_mutex(dev))
> > +		mutex_unlock(&drm_global_mutex);
> > +
> >  	if (!atomic_fetch_inc(&dev->open_count))
> >  		need_setup = 1;
> >  
> > @@ -398,13 +430,15 @@ int drm_open(struct inode *inode, struct file *filp)
> >  		}
> >  	}
> >  
> > -	mutex_unlock(&drm_global_mutex);
> > +	if (drm_dev_needs_global_mutex(dev))
> > +		mutex_unlock(&drm_global_mutex);
> >  
> >  	return 0;
> >  
> >  err_undo:
> >  	atomic_dec(&dev->open_count);
> > -	mutex_unlock(&drm_global_mutex);
> > +	if (drm_dev_needs_global_mutex(dev))
> > +		mutex_unlock(&drm_global_mutex);
> >  	drm_minor_release(minor);
> >  	return retcode;
> >  }
> > @@ -444,6 +478,7 @@ int drm_release(struct inode *inode, struct file *filp)
> >  	struct drm_minor *minor = file_priv->minor;
> >  	struct drm_device *dev = minor->dev;
> >  
> > +	if (drm_dev_needs_global_mutex(dev))
> >  	mutex_lock(&drm_global_mutex);
> >  
> >  	DRM_DEBUG("open_count = %d\n", atomic_read(&dev->open_count));
> > @@ -453,7 +488,8 @@ int drm_release(struct inode *inode, struct file *filp)
> >  	if (atomic_dec_and_test(&dev->open_count))
> >  		drm_lastclose(dev);
> >  
> > -	mutex_unlock(&drm_global_mutex);
> > +	if (drm_dev_needs_global_mutex(dev))
> > +		mutex_unlock(&drm_global_mutex);
> >  
> >  	drm_minor_release(minor);
> >  
> > diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h
> > index 6937bf923f05..aeec2e68d772 100644
> > --- a/drivers/gpu/drm/drm_internal.h
> > +++ b/drivers/gpu/drm/drm_internal.h
> > @@ -41,6 +41,7 @@ struct drm_printer;
> >  
> >  /* drm_file.c */
> >  extern struct mutex drm_global_mutex;
> > +bool drm_dev_needs_global_mutex(struct drm_device *dev);
> >  struct drm_file *drm_file_alloc(struct drm_minor *minor);
> >  void drm_file_free(struct drm_file *file);
> >  void drm_lastclose(struct drm_device *dev);
> > -- 
> > 2.24.1
> > 
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
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:[~2020-01-29 17:07 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-29  8:24 [PATCH 0/5] disable drm_global_mutex for most drivers Daniel Vetter
2020-01-29  8:24 ` [Intel-gfx] " Daniel Vetter
2020-01-29  8:24 ` [PATCH 1/5] drm: Complain if drivers still use the ->load callback Daniel Vetter
2020-01-29  8:24   ` [Intel-gfx] " Daniel Vetter
2020-01-29  8:24 ` [PATCH 2/5] drm/fbdev-helper: don't force restores Daniel Vetter
2020-01-29  8:24   ` [Intel-gfx] " Daniel Vetter
2020-01-29  8:24 ` [PATCH 3/5] drm/client: Rename _force to _locked Daniel Vetter
2020-01-29  8:24   ` [Intel-gfx] " Daniel Vetter
2020-01-29 13:16   ` Noralf Trønnes
2020-01-29 13:16     ` [Intel-gfx] " Noralf Trønnes
2020-01-29 14:06     ` Daniel Vetter
2020-01-29 14:06       ` [Intel-gfx] " Daniel Vetter
2020-01-29  8:24 ` [PATCH 4/5] drm: Push drm_global_mutex locking in drm_open Daniel Vetter
2020-01-29  8:24   ` [Intel-gfx] " Daniel Vetter
2020-01-29 16:45   ` Sam Ravnborg
2020-01-29 16:45     ` [Intel-gfx] " Sam Ravnborg
2020-01-29 17:05     ` Daniel Vetter
2020-01-29 17:05       ` [Intel-gfx] " Daniel Vetter
2020-01-31  5:59   ` [PATCH] " Daniel Vetter
2020-01-31  5:59     ` [Intel-gfx] " Daniel Vetter
2020-01-29  8:24 ` [PATCH 5/5] drm: Nerv drm_global_mutex BKL for good drivers Daniel Vetter
2020-01-29  8:24   ` [Intel-gfx] " Daniel Vetter
2020-01-29 16:47   ` Sam Ravnborg
2020-01-29 16:47     ` [Intel-gfx] " Sam Ravnborg
2020-01-29 17:07     ` Daniel Vetter [this message]
2020-01-29 17:07       ` Daniel Vetter
2020-01-29 17:59   ` Chris Wilson
2020-01-29 17:59     ` [Intel-gfx] " Chris Wilson
2020-01-31  5:58   ` [PATCH] drm: Nerf " Daniel Vetter
2020-01-31  5:58     ` [Intel-gfx] " Daniel Vetter
2020-01-29 17:37 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for disable drm_global_mutex for most drivers Patchwork
2020-01-29 17:50 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork
2020-01-31  6:19 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for disable drm_global_mutex for most drivers (rev3) Patchwork
2020-01-31  6:43 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork
2020-01-31 19:15 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for disable drm_global_mutex for most drivers (rev4) Patchwork
2020-01-31 20:08 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2020-02-04 14:26 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " 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=20200129170721.GN43062@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=sam@ravnborg.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.