Skip to contentSkip to conversation

drm/vc4: Fix refcounting of runtime PM get if it errors out.

PATCH In review Eric Anholt 2 participants 3 messages Apr 17, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/vc4: Fix refcounting of runtime PM get if it errors out.

We were returning without decrementing if the error happened, meaning that at the next submit we wouldn't try to bring up the power domain.

---

I stumbled across this error when testing my CMA patch with a very low (64MB) CMA area -- we would oops on the submit after the one that failed.

 drivers/gpu/drm/vc4/vc4_gem.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/vc4/vc4_gem.c +8 -5
index 777a8d9afd60..735412e3725a 100644
@@ -1016,13 +1016,16 @@ vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
 	}
 
 	mutex_lock(&vc4->power_lock);
-	if (vc4->power_refcount++ == 0)
+	if (vc4->power_refcount++ == 0) {
 		ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
-	mutex_unlock(&vc4->power_lock);
-	if (ret < 0) {
-		kfree(exec);
-		return ret;
+		if (ret < 0) {
+			mutex_unlock(&vc4->power_lock);
+			vc4->power_refcount--;
+			kfree(exec);
+			return ret;
+		}
 	}
+	mutex_unlock(&vc4->power_lock);
 
 	exec->args = args;
 	INIT_LIST_HEAD(&exec->unref_list);
Signature · 6 lines
2.11.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Eric Anholt

We were returning without decrementing if the error happened, meaning that at the next submit we wouldn't try to bring up the power domain.

This change looks good to me. It seems a little odd to wrap pm_runtime which is already refcounted in another refcount, but I'm really not familiar with the driver, and I'm sure there's a good reason for it.

Quoted 37 lines

---

I stumbled across this error when testing my CMA patch with a very low (64MB) CMA area -- we would oops on the submit after the one that failed.

 drivers/gpu/drm/vc4/vc4_gem.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/vc4/vc4_gem.c +8 -5
index 777a8d9afd60..735412e3725a 100644
@@ -1016,13 +1016,16 @@ vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
 	}
 
 	mutex_lock(&vc4->power_lock);
-	if (vc4->power_refcount++ == 0)
+	if (vc4->power_refcount++ == 0) {
 		ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
-	mutex_unlock(&vc4->power_lock);
-	if (ret < 0) {
-		kfree(exec);
-		return ret;
+		if (ret < 0) {
+			mutex_unlock(&vc4->power_lock);
+			vc4->power_refcount--;
+			kfree(exec);
+			return ret;
+		}
 	}
+	mutex_unlock(&vc4->power_lock);
 
 	exec->args = args;
 	INIT_LIST_HEAD(&exec->unref_list);
Signature · 1 line
2.11.0
Signature · 5 lines
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw
Quoted 11 lines · Sean Paul
Quoted 4 lines · Eric Anholt

We were returning without decrementing if the error happened, meaning that at the next submit we wouldn't try to bring up the power domain.

This change looks good to me. It seems a little odd to wrap pm_runtime which is already refcounted in another refcount, but I'm really not familiar with the driver, and I'm sure there's a good reason for it.

Yeah, it's an unfortunate hack because the reset control is buried in the power domain driver on the RPi, so we have to get the power domain actually off (0 refcount) in order to reset the GPU.

Yay for building around closed-source firmware :(

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