drm: Protect the master management with a drm_device::master_mutex v3
Subsystems (2)
PATCH 6/16 drm: Protect the master management with a drm_device::master_mutex v3
The master management was previously protected by the drm_device::struct_mutex. In order to avoid locking order violations in a reworked dropped master security check in the vmwgfx driver, break it out into a separate master_mutex. Locking order is master_mutex -> struct_mutex.
Also remove drm_master::blocked since it's not used.
v2: Add an inline comment about what drm_device::master_mutex is protecting.
v3: Remove unneeded struct_mutex locks. Fix error returns in
drm_setmaster_ioctl().
--- drivers/gpu/drm/drm_fops.c | 22 ++++++++++----------- drivers/gpu/drm/drm_stub.c | 43 ++++++++++++++++++++++++++--------------- include/drm/drmP.h | 46 ++++++++++++++++++++++++-------------------- 3 files changed, 64 insertions(+), 47 deletions(-)
drivers/gpu/drm/drm_fops.c +11 -11
@@ -231,12 +231,11 @@ static int drm_open_helper(struct inode *inode, struct file *filp,/* if there is no current master make this fd it, but do not create * any master object for render clients */ -mutex_lock (&dev->struct_mutex); +mutex_lock (&dev->master_mutex);if (drm_is_primary_client (priv) && !priv->minor->master) {/* create a new master */ priv->minor->master =drm_master_create (priv->minor);if (!priv->minor->master) { -mutex_unlock (&dev->struct_mutex); ret = -ENOMEM ; goto out_close; }
@@ -244,29 +243,23 @@ static int drm_open_helper(struct inode *inode, struct file *filp, priv->is_master =1 ;/* take another reference for the copy in the local file priv */ priv->master =drm_master_get (priv->minor->master); - priv->authenticated =1 ; -mutex_unlock (&dev->struct_mutex);if (dev->driver->master_create) { ret = dev->driver->master_create (dev, priv->master);if (ret) { -mutex_lock (&dev->struct_mutex);/* drop both references if this fails */ drm_master_put (&priv->minor->master);drm_master_put (&priv->master); -mutex_unlock (&dev->struct_mutex); goto out_close; } } -mutex_lock (&dev->struct_mutex);if (dev->driver->master_set) { ret = dev->driver->master_set (dev, priv, true);if (ret) {/* drop both references if this fails */ drm_master_put (&priv->minor->master);drm_master_put (&priv->master); -mutex_unlock (&dev->struct_mutex); goto out_close; } }
@@ -274,7 +267,7 @@ static int drm_open_helper(struct inode *inode, struct file *filp,/* get a reference to the master */ priv->master =drm_master_get (priv->minor->master); } -mutex_unlock (&dev->struct_mutex); +mutex_unlock (&dev->master_mutex);mutex_lock (&dev->struct_mutex);list_add (&priv->lhead, &dev->filelist);
@@ -302,6 +295,7 @@ static int drm_open_helper(struct inode *inode, struct file *filp,return 0 ; out_close: +mutex_unlock (&dev->master_mutex);if (dev->driver->postclose) dev->driver->postclose (dev, priv); out_prime_destroy:
@@ -489,11 +483,13 @@ int drm_release(struct inode *inode, struct file *filp) }mutex_unlock (&dev->ctxlist_mutex); -mutex_lock (&dev->struct_mutex); +mutex_lock (&dev->master_mutex);if (file_priv->is_master) {struct drm_master *master = file_priv->master;struct drm_file *temp; + +mutex_lock (&dev->struct_mutex);list_for_each_entry (temp, &dev->filelist, lhead) {if ((temp->master == file_priv->master) && (temp != file_priv))
@@ -512,6 +508,7 @@ int drm_release(struct inode *inode, struct file *filp) master->lock.file_priv =NULL ;wake_up_interruptible_all (&master->lock.lock_queue); } +mutex_unlock (&dev->struct_mutex);if (file_priv->minor->master == file_priv->master) {/* drop the reference held my the minor */
@@ -521,10 +518,13 @@ int drm_release(struct inode *inode, struct file *filp) } } -/* drop the reference held my the file priv */ +/* drop the master reference held by the file priv */ if (file_priv->master)drm_master_put (&file_priv->master); file_priv->is_master =0 ; +mutex_unlock (&dev->master_mutex); + +mutex_lock (&dev->struct_mutex);list_del (&file_priv->lhead);mutex_unlock (&dev->struct_mutex);
drivers/gpu/drm/drm_stub.c +28 -15
104 lines not on this page · raw message
include/drm/drmP.h +25 -21
73 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Hi
Quoted 10 lines · Thomas Hellstrom
The master management was previously protected by the
drm_device::struct_mutex. In order to avoid locking order violations in a reworked dropped master security check in the vmwgfx driver, break it out into a separatemaster_mutex. Locking order ismaster_mutex->struct_mutex.Also remove
drm_master::blockedsince it's not used.v2: Add an inline comment about what
drm_device::master_mutexis protecting.
v3: Remove unneededstruct_mutexlocks. Fix error returns in
drm_setmaster_ioctl().
Thanks, looks much better now. Tested on hsw, so I'm fine with pushing this into 3.15.
Thanks
David
Quoted 17 lines · David Herrmann
Hi
Quoted 10 lines · Thomas Hellstrom
The master management was previously protected by the
drm_device::struct_mutex. In order to avoid locking order violations in a reworked dropped master security check in the vmwgfx driver, break it out into a separatemaster_mutex. Locking order ismaster_mutex->struct_mutex.Also remove
drm_master::blockedsince it's not used.v2: Add an inline comment about what
drm_device::master_mutexis protecting.
v3: Remove unneededstruct_mutexlocks. Fix error returns in
drm_setmaster_ioctl().Thanks, looks much better now. Tested on hsw, so I'm fine with pushing this into 3.15.
Quoted 6 lines
Thanks
David
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Thanks. Want a Reviewed-By: or Acked-By: added?
/Thomas
David Herrmann
Reviewed-byHi
Quoted 1 line · Thomas Hellstrom
Thanks. Want a Reviewed-By: or Acked-By: added?
Oh, sure:
Thanks
David