[PATCH] drm: idr_find (drm_gem_object_lookup) needs only rcu read locks

Chris Wilson chris at chris-wilson.co.uk
Thu Nov 4 03:09:53 PDT 2010


... other mutation of the handle idr is still serialised using spin
locks.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 drivers/gpu/drm/drm_gem.c |   20 ++++++++------------
 1 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index ea1c4b0..ce63a14 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -184,7 +184,6 @@ EXPORT_SYMBOL(drm_gem_object_alloc);
 static int
 drm_gem_handle_delete(struct drm_file *filp, u32 handle)
 {
-	struct drm_device *dev;
 	struct drm_gem_object *obj;
 
 	/* This is gross. The idr system doesn't let us try a delete and
@@ -204,12 +203,13 @@ drm_gem_handle_delete(struct drm_file *filp, u32 handle)
 		spin_unlock(&filp->table_lock);
 		return -EINVAL;
 	}
-	dev = obj->dev;
 
 	/* Release reference and decrement refcount. */
 	idr_remove(&filp->object_idr, handle);
 	spin_unlock(&filp->table_lock);
 
+	synchronize_rcu();
+
 	drm_gem_object_handle_unreference_unlocked(obj);
 
 	return 0;
@@ -257,18 +257,14 @@ drm_gem_object_lookup(struct drm_device *dev, struct drm_file *filp,
 {
 	struct drm_gem_object *obj;
 
-	spin_lock(&filp->table_lock);
+	rcu_read_lock();
 
 	/* Check if we currently have a reference on the object */
 	obj = idr_find(&filp->object_idr, handle);
-	if (obj == NULL) {
-		spin_unlock(&filp->table_lock);
-		return NULL;
-	}
-
-	drm_gem_object_reference(obj);
+	if (obj)
+		drm_gem_object_reference(obj);
 
-	spin_unlock(&filp->table_lock);
+	rcu_read_unlock();
 
 	return obj;
 }
@@ -363,11 +359,11 @@ drm_gem_open_ioctl(struct drm_device *dev, void *data,
 	if (!(dev->driver->driver_features & DRIVER_GEM))
 		return -ENODEV;
 
-	spin_lock(&dev->object_name_lock);
+	rcu_read_lock();
 	obj = idr_find(&dev->object_name_idr, (int) args->name);
 	if (obj)
 		drm_gem_object_reference(obj);
-	spin_unlock(&dev->object_name_lock);
+	rcu_read_unlock();
 	if (!obj)
 		return -ENOENT;
 
-- 
1.7.2.3



More information about the dri-devel mailing list