From: Thomas Hellstrom <thomas@shipmail.org>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm: Use global_mutex to serialise open/lastclose
Date: Wed, 11 Aug 2010 11:09:11 +0200 [thread overview]
Message-ID: <4C6268B7.5000602@shipmail.org> (raw)
In-Reply-To: <1281256644-23138-1-git-send-email-chris@chris-wilson.co.uk>
On 08/08/2010 10:37 AM, Chris Wilson wrote:
> 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.
>
Hmm.
But, if used this way, drm_global_mutex needs to protect *all* accesses
to dev::open_count, what is count_clock used for? Can't it be removed?
/Thomas
> 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) {
>
next prev parent reply other threads:[~2010-08-11 9:09 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 ` [PATCH] drm: Use global_mutex to serialise open/lastclose Chris Wilson
2010-08-09 17:00 ` Chris Wilson
2010-08-11 9:09 ` Thomas Hellstrom [this message]
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=4C6268B7.5000602@shipmail.org \
--to=thomas@shipmail.org \
--cc=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox