Skip to content

Commit

Permalink
drm/nouveau: Fix race condition in channel refcount handling.
Browse files Browse the repository at this point in the history
nouveau_channel_put() can be executed after the 'refcount == 0' check
in nouveau_channel_get() and before the channel reference count is
incremented. In that case CPU0 will take the context down while CPU1
thinks it owns the channel and 'refcount == 1'.

Signed-off-by: Francisco Jerez <currojerez@riseup.net>
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
  • Loading branch information
Francisco Jerez authored and Ben Skeggs committed Dec 3, 2010
1 parent 3945e47 commit f175b74
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/gpu/drm/nouveau/nouveau_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,16 @@ nouveau_channel_get(struct drm_device *dev, struct drm_file *file_priv, int id)
spin_lock_irqsave(&dev_priv->channels.lock, flags);
chan = dev_priv->channels.ptr[id];

if (unlikely(!chan || atomic_read(&chan->refcount) == 0)) {
if (unlikely(!chan || (file_priv && chan->file_priv != file_priv))) {
spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
return ERR_PTR(-EINVAL);
}

if (unlikely(file_priv && chan->file_priv != file_priv)) {
if (unlikely(!atomic_inc_not_zero(&chan->refcount))) {
spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
return ERR_PTR(-EINVAL);
}

atomic_inc(&chan->refcount);
spin_unlock_irqrestore(&dev_priv->channels.lock, flags);

mutex_lock(&chan->mutex);
Expand Down

0 comments on commit f175b74

Please sign in to comment.