Skip to contentSkip to conversation

drm/prime: fix error path deadlock fail

PATCH In review Rob Clark 4 participants 6 messages Jun 9, 2016 – Jun 13, 2016

Subsystems (2)
lore
Share & tools
lore

Rob Clark

author
#0 lore raw

PATCH 1/1 drm/prime: fix error path deadlock fail

There were a couple messed up things about this fail path.
(1) it would drop object_name_lock twice
(2) drm_gem_handle_delete() (in drm_gem_remove_prime_handles()) needs to grab prime_lock

---
Untested, but I think this should fix the potential deadlock that Alex reported. Would be nice if someone with setup to reproduce could test this.

 drivers/gpu/drm/drm_prime.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_prime.c +6 -4
index aab0f3f..780589b 100644
@@ -593,7 +593,7 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 		get_dma_buf(dma_buf);
 	}
 
-	/* drm_gem_handle_create_tail unlocks dev->object_name_lock. */
+	/* _handle_create_tail unconditionally unlocks dev->object_name_lock. */
 	ret = drm_gem_handle_create_tail(file_priv, obj, handle);
 	drm_gem_object_unreference_unlocked(obj);
 	if (ret)
@@ -601,11 +601,10 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 
 	ret = drm_prime_add_buf_handle(&file_priv->prime,
 			dma_buf, *handle);
+	mutex_unlock(&file_priv->prime.lock);
 	if (ret)
 		goto fail;
 
-	mutex_unlock(&file_priv->prime.lock);
-
 	dma_buf_put(dma_buf);
 
 	return 0;
@@ -615,11 +614,14 @@ fail:
 	 * to detach.. which seems ok..
 	 */
 	drm_gem_handle_delete(file_priv, *handle);
+	dma_buf_put(dma_buf);
+	return ret;
+
 out_unlock:
 	mutex_unlock(&dev->object_name_lock);
 out_put:
-	dma_buf_put(dma_buf);
 	mutex_unlock(&file_priv->prime.lock);
+	dma_buf_put(dma_buf);
 	return ret;
 }
 EXPORT_SYMBOL(drm_gem_prime_fd_to_handle);
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

If you let me know how, I'll test it

Quoted 62 lines · On Thu, 9 Jun 2016 at 20:29 Rob Clark <[email protected]> wrote:

There were a couple messed up things about this fail path.
(1) it would drop object_name_lock twice
(2) drm_gem_handle_delete() (in drm_gem_remove_prime_handles()) needs to grab prime_lock

---
Untested, but I think this should fix the potential deadlock that Alex reported. Would be nice if someone with setup to reproduce could test this.

 drivers/gpu/drm/drm_prime.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_prime.c +1 -1
index aab0f3f..780589b 100644
@@ -593,7 +593,7 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
                get_dma_buf(dma_buf);
        }
 
-       /* drm_gem_handle_create_tail unlocks dev->object_name_lock. */
+       /* _handle_create_tail unconditionally unlocks

dev->object_name_lock. */

        ret = drm_gem_handle_create_tail(file_priv, obj, handle);
        drm_gem_object_unreference_unlocked(obj);
        if (ret)
drivers/gpu/drm/drm_prime.c +1 -2
@@ -601,11 +601,10 @@ int drm_gem_prime_fd_to_handle(struct drm_device
 *dev,
 
        ret = drm_prime_add_buf_handle(&file_priv->prime,
                        dma_buf, *handle);
+       mutex_unlock(&file_priv->prime.lock);
        if (ret)
                goto fail;
 
-       mutex_unlock(&file_priv->prime.lock);
-
        dma_buf_put(dma_buf);
 
        return 0;
drivers/gpu/drm/drm_prime.c +4 -2
@@ -615,11 +614,14 @@ fail:
         * to detach.. which seems ok..
         */
        drm_gem_handle_delete(file_priv, *handle);
+       dma_buf_put(dma_buf);
+       return ret;
+
 out_unlock:
        mutex_unlock(&dev->object_name_lock);
 out_put:
-       dma_buf_put(dma_buf);
        mutex_unlock(&file_priv->prime.lock);
+       dma_buf_put(dma_buf);
        return ret;
 }
 EXPORT_SYMBOL(drm_gem_prime_fd_to_handle);
--

2.5.5

Quoted 5 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author
#2 lore raw
In reply to Rob Clark
Quoted 7 lines · Rob Clark

There were a couple messed up things about this fail path.
(1) it would drop object_name_lock twice
(2) drm_gem_handle_delete() (in drm_gem_remove_prime_handles()) needs to grab prime_lock

fyi,

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=117861

Quoted 51 lines

---
Untested, but I think this should fix the potential deadlock that Alex reported. Would be nice if someone with setup to reproduce could test this.

 drivers/gpu/drm/drm_prime.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_prime.c +6 -5
index aab0f3f..780589b 100644
@@ -593,7 +593,7 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
                get_dma_buf(dma_buf);
        }
 
-       /* drm_gem_handle_create_tail unlocks dev->object_name_lock. */
+       /* _handle_create_tail unconditionally unlocks dev->object_name_lock. */
        ret = drm_gem_handle_create_tail(file_priv, obj, handle);
        drm_gem_object_unreference_unlocked(obj);
        if (ret)
@@ -601,11 +601,10 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 
        ret = drm_prime_add_buf_handle(&file_priv->prime,
                        dma_buf, *handle);
+       mutex_unlock(&file_priv->prime.lock);
        if (ret)
                goto fail;
 
-       mutex_unlock(&file_priv->prime.lock);
-
        dma_buf_put(dma_buf);
 
        return 0;
@@ -615,11 +614,14 @@ fail:
         * to detach.. which seems ok..
         */
        drm_gem_handle_delete(file_priv, *handle);
+       dma_buf_put(dma_buf);
+       return ret;
+
 out_unlock:
        mutex_unlock(&dev->object_name_lock);
 out_put:
-       dma_buf_put(dma_buf);
        mutex_unlock(&file_priv->prime.lock);
+       dma_buf_put(dma_buf);
        return ret;
 }
 EXPORT_SYMBOL(drm_gem_prime_fd_to_handle);
--
Quoted 2 lines

2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by on v1 1/1
#3 lore raw
In reply to Rob Clark
Quoted 11 lines · Rob Clark

There were a couple messed up things about this fail path.
(1) it would drop object_name_lock twice
(2) drm_gem_handle_delete() (in drm_gem_remove_prime_handles()) needs to grab prime_lock

---
Untested, but I think this should fix the potential deadlock that Alex reported. Would be nice if someone with setup to reproduce could test this.

Sorry for the confusion. There were actually two deadlocks. The
first one (https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1579610
fixed by https://github.com/torvalds/linux/commit/6984128d01cf935820a0563f3a00c6623ba58109)
was that one we hit in testing. This one was just one that Qiang
noticed by inspection while debugging the first. That said, the error
path is obviously wrong and the patch looks correct to me.

Quoted 47 lines
 drivers/gpu/drm/drm_prime.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_prime.c +6 -5
index aab0f3f..780589b 100644
@@ -593,7 +593,7 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
                get_dma_buf(dma_buf);
        }
 
-       /* drm_gem_handle_create_tail unlocks dev->object_name_lock. */
+       /* _handle_create_tail unconditionally unlocks dev->object_name_lock. */
        ret = drm_gem_handle_create_tail(file_priv, obj, handle);
        drm_gem_object_unreference_unlocked(obj);
        if (ret)
@@ -601,11 +601,10 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 
        ret = drm_prime_add_buf_handle(&file_priv->prime,
                        dma_buf, *handle);
+       mutex_unlock(&file_priv->prime.lock);
        if (ret)
                goto fail;
 
-       mutex_unlock(&file_priv->prime.lock);
-
        dma_buf_put(dma_buf);
 
        return 0;
@@ -615,11 +614,14 @@ fail:
         * to detach.. which seems ok..
         */
        drm_gem_handle_delete(file_priv, *handle);
+       dma_buf_put(dma_buf);
+       return ret;
+
 out_unlock:
        mutex_unlock(&dev->object_name_lock);
 out_put:
-       dma_buf_put(dma_buf);
        mutex_unlock(&file_priv->prime.lock);
+       dma_buf_put(dma_buf);
        return ret;
 }
 EXPORT_SYMBOL(drm_gem_prime_fd_to_handle);
--
Quoted 2 lines

2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw
Quoted 13 lines · Alex Deucher
Quoted 11 lines · Rob Clark

There were a couple messed up things about this fail path.
(1) it would drop object_name_lock twice
(2) drm_gem_handle_delete() (in drm_gem_remove_prime_handles()) needs to grab prime_lock

---
Untested, but I think this should fix the potential deadlock that Alex reported. Would be nice if someone with setup to reproduce could test this.

Quoted 8 lines

Sorry for the confusion. There were actually two deadlocks. The
first one (https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1579610
fixed by https://github.com/torvalds/linux/commit/6984128d01cf935820a0563f3a00c6623ba58109)
was that one we hit in testing. This one was just one that Qiang
noticed by inspection while debugging the first. That said, the error
path is obviously wrong and the patch looks correct to me.

Ok, I didn't add the bugzilla to this one. Applied to drm-misc, thanks. -Daniel

Quoted 50 lines
Quoted 50 lines

 drivers/gpu/drm/drm_prime.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_prime.c +6 -5
index aab0f3f..780589b 100644
@@ -593,7 +593,7 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
                get_dma_buf(dma_buf);
        }
 
-       /* drm_gem_handle_create_tail unlocks dev->object_name_lock. */
+       /* _handle_create_tail unconditionally unlocks dev->object_name_lock. */
        ret = drm_gem_handle_create_tail(file_priv, obj, handle);
        drm_gem_object_unreference_unlocked(obj);
        if (ret)
@@ -601,11 +601,10 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 
        ret = drm_prime_add_buf_handle(&file_priv->prime,
                        dma_buf, *handle);
+       mutex_unlock(&file_priv->prime.lock);
        if (ret)
                goto fail;
 
-       mutex_unlock(&file_priv->prime.lock);
-
        dma_buf_put(dma_buf);
 
        return 0;
@@ -615,11 +614,14 @@ fail:
         * to detach.. which seems ok..
         */
        drm_gem_handle_delete(file_priv, *handle);
+       dma_buf_put(dma_buf);
+       return ret;
+
 out_unlock:
        mutex_unlock(&dev->object_name_lock);
 out_put:
-       dma_buf_put(dma_buf);
        mutex_unlock(&file_priv->prime.lock);
+       dma_buf_put(dma_buf);
        return ret;
 }
 EXPORT_SYMBOL(drm_gem_prime_fd_to_handle);
--

2.5.5

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw
Quoted 21 lines · Daniel Vetter
Quoted 20 lines · Alex Deucher
Quoted 11 lines · Rob Clark

There were a couple messed up things about this fail path.
(1) it would drop object_name_lock twice
(2) drm_gem_handle_delete() (in drm_gem_remove_prime_handles()) needs to grab prime_lock

---
Untested, but I think this should fix the potential deadlock that Alex reported. Would be nice if someone with setup to reproduce could test this.

Sorry for the confusion. There were actually two deadlocks. The
first one (https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1579610
fixed by https://github.com/torvalds/linux/commit/6984128d01cf935820a0563f3a00c6623ba58109)
was that one we hit in testing. This one was just one that Qiang
noticed by inspection while debugging the first. That said, the error
path is obviously wrong and the patch looks correct to me.

Quoted 3 lines
Quoted 1 line

Ok, I didn't add the bugzilla to this one. Applied to drm-misc, thanks.

There actually is a bugzilla for the potential deadlock fixed by this patch:
https://bugzilla.kernel.org/show_bug.cgi?id=117861

Alex
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel