All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: dri-devel@lists.freedesktop.org
Subject: [PATCH] drm: Use global_mutex to serialise open/lastclose
Date: Sun,  8 Aug 2010 09:37:24 +0100	[thread overview]
Message-ID: <1281256644-23138-1-git-send-email-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <AANLkTinMH7GT9OCGrrMuN7gCYBKCM_sBYSu5Sex+4q71@mail.gmail.com>

Dave Airlie:
  I might be missing something, but what stops the race with something
  reopening while we are in lastclose now?

The global_mutex which appears to fill this role is only taken inside
the drm_stub_open() and not drm_open() itself. As that mutex appears to
serve no other role, retask it to serialise open/lastclose.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/drm_fops.c |   35 ++++++++++++++++++-----------------
 1 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
index 6367961..71bcd1b 100644
--- a/drivers/gpu/drm/drm_fops.c
+++ b/drivers/gpu/drm/drm_fops.c
@@ -123,27 +123,30 @@ int drm_open(struct inode *inode, struct file *filp)
 	struct drm_device *dev = NULL;
 	int minor_id = iminor(inode);
 	struct drm_minor *minor;
-	int retcode = 0;
+	int retcode = -ENODEV;
 
+	mutex_lock(&drm_global_mutex);
 	minor = idr_find(&drm_minors_idr, minor_id);
 	if (!minor)
-		return -ENODEV;
+		goto err;
 
 	if (!(dev = minor->dev))
-		return -ENODEV;
+		goto err;
 
 	retcode = drm_open_helper(inode, filp, dev);
-	if (!retcode) {
-		atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
-		spin_lock(&dev->count_lock);
-		if (!dev->open_count++) {
-			spin_unlock(&dev->count_lock);
-			retcode = drm_setup(dev);
-			goto out;
-		}
+	if (retcode)
+		goto err;
+
+	atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
+	spin_lock(&dev->count_lock);
+	if (!dev->open_count++) {
 		spin_unlock(&dev->count_lock);
-	}
-out:
+		retcode = drm_setup(dev);
+	} else
+		spin_unlock(&dev->count_lock);
+err:
+	mutex_unlock(&drm_global_mutex);
+
 	if (!retcode) {
 		mutex_lock(&dev->struct_mutex);
 		if (minor->type == DRM_MINOR_LEGACY) {
@@ -178,7 +181,6 @@ int drm_stub_open(struct inode *inode, struct file *filp)
 
 	DRM_DEBUG("\n");
 
-	mutex_lock(&drm_global_mutex);
 	minor = idr_find(&drm_minors_idr, minor_id);
 	if (!minor)
 		goto out;
@@ -198,8 +200,8 @@ int drm_stub_open(struct inode *inode, struct file *filp)
 	}
 	fops_put(old_fops);
 
+	ret = 0;
 out:
-	mutex_unlock(&drm_global_mutex);
 	return err;
 }
 
@@ -474,8 +476,6 @@ int drm_release(struct inode *inode, struct file *filp)
 	struct drm_device *dev = file_priv->minor->dev;
 	int retcode = 0;
 
-	mutex_lock(&drm_global_mutex);
-
 	DRM_DEBUG("open_count = %d\n", dev->open_count);
 
 	if (dev->driver->preclose)
@@ -569,6 +569,7 @@ int drm_release(struct inode *inode, struct file *filp)
 	 * End inline drm_release
 	 */
 
+	mutex_lock(&drm_global_mutex);
 	atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
 	spin_lock(&dev->count_lock);
 	if (!--dev->open_count) {
-- 
1.7.1

  reply	other threads:[~2010-08-08  8:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-07 12:49 [PATCH] drm: Release spinlock for calling lastclose() after 58474713 Chris Wilson
2010-08-08  7:08 ` Dave Airlie
2010-08-08  8:37   ` Chris Wilson [this message]
2010-08-09 17:00     ` [PATCH] drm: Use global_mutex to serialise open/lastclose Chris Wilson
2010-08-11  9:09     ` Thomas Hellstrom
2010-08-11 13:41 ` [PATCH] drm: Remove count_lock for calling lastclose() after 58474713 (v2) 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=1281256644-23138-1-git-send-email-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=dri-devel@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.