Commit cd4f013f authored by Daniel Vetter's avatar Daniel Vetter Committed by Dave Airlie

drm/gem: switch dev->object_name_lock to a mutex

I want to wrap the creation of a dma-buf from a gem object in it,
so that the obj->export_dma_buf cache can be atomically filled in.

Instead of creating a new mutex just for that variable I've figured
I can reuse the existing dev->object_name_lock, especially since
the new semantics will exactly mirror the flink obj->name already
protected by that lock.

v2: idr_preload/idr_preload_end is now an atomic section, so need to
move the mutex locking outside.

[airlied: fix up conflict with patch to make debugfs use lock]
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent 84341c28
...@@ -93,7 +93,7 @@ drm_gem_init(struct drm_device *dev) ...@@ -93,7 +93,7 @@ drm_gem_init(struct drm_device *dev)
{ {
struct drm_gem_mm *mm; struct drm_gem_mm *mm;
spin_lock_init(&dev->object_name_lock); mutex_init(&dev->object_name_lock);
idr_init(&dev->object_name_idr); idr_init(&dev->object_name_idr);
mm = kzalloc(sizeof(struct drm_gem_mm), GFP_KERNEL); mm = kzalloc(sizeof(struct drm_gem_mm), GFP_KERNEL);
...@@ -243,10 +243,10 @@ drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj) ...@@ -243,10 +243,10 @@ drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj)
* checked for a name * checked for a name
*/ */
spin_lock(&obj->dev->object_name_lock); mutex_lock(&obj->dev->object_name_lock);
if (--obj->handle_count == 0) if (--obj->handle_count == 0)
drm_gem_object_handle_free(obj); drm_gem_object_handle_free(obj);
spin_unlock(&obj->dev->object_name_lock); mutex_unlock(&obj->dev->object_name_lock);
drm_gem_object_unreference_unlocked(obj); drm_gem_object_unreference_unlocked(obj);
} }
...@@ -324,16 +324,16 @@ drm_gem_handle_create(struct drm_file *file_priv, ...@@ -324,16 +324,16 @@ drm_gem_handle_create(struct drm_file *file_priv,
* Get the user-visible handle using idr. Preload and perform * Get the user-visible handle using idr. Preload and perform
* allocation under our spinlock. * allocation under our spinlock.
*/ */
mutex_lock(&dev->object_name_lock);
idr_preload(GFP_KERNEL); idr_preload(GFP_KERNEL);
spin_lock(&dev->object_name_lock);
spin_lock(&file_priv->table_lock); spin_lock(&file_priv->table_lock);
ret = idr_alloc(&file_priv->object_idr, obj, 1, 0, GFP_NOWAIT); ret = idr_alloc(&file_priv->object_idr, obj, 1, 0, GFP_NOWAIT);
drm_gem_object_reference(obj); drm_gem_object_reference(obj);
obj->handle_count++; obj->handle_count++;
spin_unlock(&file_priv->table_lock); spin_unlock(&file_priv->table_lock);
spin_unlock(&dev->object_name_lock);
idr_preload_end(); idr_preload_end();
mutex_unlock(&dev->object_name_lock);
if (ret < 0) { if (ret < 0) {
drm_gem_object_handle_unreference_unlocked(obj); drm_gem_object_handle_unreference_unlocked(obj);
return ret; return ret;
...@@ -578,8 +578,8 @@ drm_gem_flink_ioctl(struct drm_device *dev, void *data, ...@@ -578,8 +578,8 @@ drm_gem_flink_ioctl(struct drm_device *dev, void *data,
if (obj == NULL) if (obj == NULL)
return -ENOENT; return -ENOENT;
mutex_lock(&dev->object_name_lock);
idr_preload(GFP_KERNEL); idr_preload(GFP_KERNEL);
spin_lock(&dev->object_name_lock);
/* prevent races with concurrent gem_close. */ /* prevent races with concurrent gem_close. */
if (obj->handle_count == 0) { if (obj->handle_count == 0) {
ret = -ENOENT; ret = -ENOENT;
...@@ -601,8 +601,8 @@ drm_gem_flink_ioctl(struct drm_device *dev, void *data, ...@@ -601,8 +601,8 @@ drm_gem_flink_ioctl(struct drm_device *dev, void *data,
ret = 0; ret = 0;
err: err:
spin_unlock(&dev->object_name_lock);
idr_preload_end(); idr_preload_end();
mutex_unlock(&dev->object_name_lock);
drm_gem_object_unreference_unlocked(obj); drm_gem_object_unreference_unlocked(obj);
return ret; return ret;
} }
...@@ -625,11 +625,11 @@ drm_gem_open_ioctl(struct drm_device *dev, void *data, ...@@ -625,11 +625,11 @@ drm_gem_open_ioctl(struct drm_device *dev, void *data,
if (!(dev->driver->driver_features & DRIVER_GEM)) if (!(dev->driver->driver_features & DRIVER_GEM))
return -ENODEV; return -ENODEV;
spin_lock(&dev->object_name_lock); mutex_lock(&dev->object_name_lock);
obj = idr_find(&dev->object_name_idr, (int) args->name); obj = idr_find(&dev->object_name_idr, (int) args->name);
if (obj) if (obj)
drm_gem_object_reference(obj); drm_gem_object_reference(obj);
spin_unlock(&dev->object_name_lock); mutex_unlock(&dev->object_name_lock);
if (!obj) if (!obj)
return -ENOENT; return -ENOENT;
......
...@@ -219,9 +219,9 @@ int drm_gem_name_info(struct seq_file *m, void *data) ...@@ -219,9 +219,9 @@ int drm_gem_name_info(struct seq_file *m, void *data)
seq_printf(m, " name size handles refcount\n"); seq_printf(m, " name size handles refcount\n");
spin_lock(&dev->object_name_lock); mutex_lock(&dev->object_name_lock);
idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m); idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m);
spin_unlock(&dev->object_name_lock); mutex_unlock(&dev->object_name_lock);
return 0; return 0;
} }
......
...@@ -1196,7 +1196,7 @@ struct drm_device { ...@@ -1196,7 +1196,7 @@ struct drm_device {
/** \name GEM information */ /** \name GEM information */
/*@{ */ /*@{ */
spinlock_t object_name_lock; struct mutex object_name_lock;
struct idr object_name_idr; struct idr object_name_idr;
/*@} */ /*@} */
int switch_power_state; int switch_power_state;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment