Skip to contentSkip to conversation

drm/i915: Fix missing unlock on error in i915_gem_init_hw()

PATCH Applied [email protected] 4 participants 8 messages Dec 5, 2014

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

PATCH 1/1 drm/i915: Fix missing unlock on error in i915_gem_init_hw()

From: Wei Yongjun <[email protected]>

Add the missing unlock before return from function i915_gem_init_hw() in the error handling case.

---
 drivers/gpu/drm/i915/i915_gem.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem.c +3 -1
index d2ba315..3eeb2d0 100644
@@ -4879,8 +4879,10 @@ i915_gem_init_hw(struct drm_device *dev)
 	i915_gem_init_swizzling(dev);
 
 	ret = dev_priv->gt.init_rings(dev);
-	if (ret)
+	if (ret) {
+		mutex_unlock(&dev->struct_mutex);
 		return ret;
+	}
 
 	for (i = 0; i < NUM_L3_SLICES(dev); i++)
 		i915_gem_l3_remap(&dev_priv->ring[RCS], i);
#1 lore raw

Wei Yongjun,

Quoted 15 lines · On Fri, Dec 05, 2014 at 08:55:59AM +0800, [email protected] wrote:

From: Wei Yongjun <[email protected]>

Add the missing unlock before return from function i915_gem_init_hw() in the error handling case.

---
 drivers/gpu/drm/i915/i915_gem.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem.c +0 -0
index d2ba315..3eeb2d0 100644

drivers/gpu/drm/i915/i915_gem.c i915_gem_init_hw(struct drm_device *dev) · line 4886

Quoted 9 lines
drivers/gpu/drm/i915/i915_gem.c +3 -1
@@ -4879,8 +4879,10 @@ i915_gem_init_hw(struct drm_device *dev)
 	i915_gem_init_swizzling(dev);
 
 	ret = dev_priv->gt.init_rings(dev);
-	if (ret)
+	if (ret) {
+		mutex_unlock(&dev->struct_mutex);
 		return ret;
+	}
 

There are other places in i915_gem_init_hw() where it returns without unlocking the mutex. Why is it only necessary here and not any of the other places?

Quoted 8 lines
drivers/gpu/drm/i915/i915_gem.c +0 -1
 	for (i = 0; i < NUM_L3_SLICES(dev); i++)
 		i915_gem_l3_remap(&dev_priv->ring[RCS], i);
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 1 line
- Jeremiah Mahler
#2 lore raw
Quoted 3 lines · Jeremiah Mahler

There are other places in i915_gem_init_hw() where it returns without unlocking the mutex. Why is it only necessary here and not any of the other places?

There's probably some rebase/merge confusion going on. The following patch is against drm-intel-next-queued where the problem is present. Thanks for reporting this.

BR,
Jani.

Jani Nikula (1):
drm/i915: release struct_mutex on the i915_gem_init_hw fail path

 drivers/gpu/drm/i915/i915_gem.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
Signature · 6 lines
2.1.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw
In reply to Jeremiah Mahler
Quoted 3 lines · Jeremiah Mahler

There are other places in i915_gem_init_hw() where it returns without unlocking the mutex. Why is it only necessary here and not any of the other places?

There's probably some rebase/merge confusion going on. The following patch is against drm-intel-next-queued where the problem is present. Thanks for reporting this.

BR,
Jani.

Jani Nikula (1):
drm/i915: release struct_mutex on the i915_gem_init_hw fail path

 drivers/gpu/drm/i915/i915_gem.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
Signature · 6 lines
2.1.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

PATCH 1/1 drm/i915: release struct_mutex on the i915_gem_init_hw fail path

Release struct_mutex if init_rings() fails.

This is a regression introduced in
commit 35a57ffbb10840af219eeaf64718434242bb7c76

Author: Daniel Vetter <[email protected]>
Date:   Thu Nov 20 00:33:07 2014 +0100

drm/i915: Only init engines once

---
 drivers/gpu/drm/i915/i915_gem.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +7 -9
index c1c11418231b..e3ce4bef22a3 100644
@@ -4860,22 +4860,18 @@ int i915_gem_init(struct drm_device *dev)
 	}
 
 	ret = i915_gem_init_userptr(dev);
-	if (ret) {
-		mutex_unlock(&dev->struct_mutex);
-		return ret;
-	}
+	if (ret)
+		goto out_unlock;
 
 	i915_gem_init_global_gtt(dev);
 
 	ret = i915_gem_context_init(dev);
-	if (ret) {
-		mutex_unlock(&dev->struct_mutex);
-		return ret;
-	}
+	if (ret)
+		goto out_unlock;
 
 	ret = dev_priv->gt.init_rings(dev);
 	if (ret)
-		return ret;
+		goto out_unlock;
 
 	ret = i915_gem_init_hw(dev);
 	if (ret == -EIO) {
@@ -4887,6 +4883,8 @@ int i915_gem_init(struct drm_device *dev)
 		atomic_set_mask(I915_WEDGED, &dev_priv->gpu_error.reset_counter);
 		ret = 0;
 	}
+
+out_unlock:
 	mutex_unlock(&dev->struct_mutex);
 
 	return ret;
Signature · 6 lines
2.1.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw

Re: [PATCH] drm/i915: release struct_mutex on the i915_gem_init_hw fail path

Jani,

Quoted 59 lines · Jani Nikula

Release struct_mutex if init_rings() fails.

This is a regression introduced in
commit 35a57ffbb10840af219eeaf64718434242bb7c76

Author: Daniel Vetter <[email protected]>
Date:   Thu Nov 20 00:33:07 2014 +0100

drm/i915: Only init engines once

---
 drivers/gpu/drm/i915/i915_gem.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +7 -9
index c1c11418231b..e3ce4bef22a3 100644
@@ -4860,22 +4860,18 @@ int i915_gem_init(struct drm_device *dev)
 	}
 
 	ret = i915_gem_init_userptr(dev);
-	if (ret) {
-		mutex_unlock(&dev->struct_mutex);
-		return ret;
-	}
+	if (ret)
+		goto out_unlock;
 
 	i915_gem_init_global_gtt(dev);
 
 	ret = i915_gem_context_init(dev);
-	if (ret) {
-		mutex_unlock(&dev->struct_mutex);
-		return ret;
-	}
+	if (ret)
+		goto out_unlock;
 
 	ret = dev_priv->gt.init_rings(dev);
 	if (ret)
-		return ret;
+		goto out_unlock;
 
 	ret = i915_gem_init_hw(dev);
 	if (ret == -EIO) {
@@ -4887,6 +4883,8 @@ int i915_gem_init(struct drm_device *dev)
 		atomic_set_mask(I915_WEDGED, &dev_priv->gpu_error.reset_counter);
 		ret = 0;
 	}
+
+out_unlock:
 	mutex_unlock(&dev->struct_mutex);
 
 	return ret;
Signature · 1 line
2.1.3

Yes, this looks much better.

Signature · 1 line
- Jeremiah Mahler
#6 lore raw

Re: [Intel-gfx] [PATCH] drm/i915: release struct_mutex on the i915_gem_init_hw fail path

Quoted 58 lines · Jeremiah Mahler

Jani,

Quoted 55 lines · Jani Nikula

Release struct_mutex if init_rings() fails.

This is a regression introduced in
commit 35a57ffbb10840af219eeaf64718434242bb7c76

Author: Daniel Vetter <[email protected]>
Date:   Thu Nov 20 00:33:07 2014 +0100

drm/i915: Only init engines once

---
 drivers/gpu/drm/i915/i915_gem.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +7 -9
index c1c11418231b..e3ce4bef22a3 100644
@@ -4860,22 +4860,18 @@ int i915_gem_init(struct drm_device *dev)
 	}
 
 	ret = i915_gem_init_userptr(dev);
-	if (ret) {
-		mutex_unlock(&dev->struct_mutex);
-		return ret;
-	}
+	if (ret)
+		goto out_unlock;
 
 	i915_gem_init_global_gtt(dev);
 
 	ret = i915_gem_context_init(dev);
-	if (ret) {
-		mutex_unlock(&dev->struct_mutex);
-		return ret;
-	}
+	if (ret)
+		goto out_unlock;
 
 	ret = dev_priv->gt.init_rings(dev);
 	if (ret)
-		return ret;
+		goto out_unlock;
 
 	ret = i915_gem_init_hw(dev);
 	if (ret == -EIO) {
@@ -4887,6 +4883,8 @@ int i915_gem_init(struct drm_device *dev)
 		atomic_set_mask(I915_WEDGED, &dev_priv->gpu_error.reset_counter);
 		ret = 0;
 	}
+
+out_unlock:
 	mutex_unlock(&dev->struct_mutex);
 
Quoted 6 lines
Quoted 4 lines
drivers/gpu/drm/i915/i915_gem.c +0 -0
 	return ret;
Signature · 1 line
2.1.3

Yes, this looks much better.

Oh well confusion in my mailbox. I've dropped Wei's patch and merged this one instead.

Thanks, Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw
In reply to [email protected]
Quoted 6 lines · On Fri, Dec 05, 2014 at 08:55:59AM +0800, [email protected] wrote:

From: Wei Yongjun <[email protected]>

Add the missing unlock before return from function i915_gem_init_hw() in the error handling case.

Applied, thanks for the patch. Two minor comments:
- Please mention the commit that introduced the issue next time around. I've added that while applying.

- The usual patter is

	if (ret)
		goto out;


	/* more code */

out:

	mutex_unlock();
	return ret;

This would work really well in i915_gem_init_hw and besides the code-cleanup also prevents such a fumble in the future. If you feel like please submit that patch to convert init_hw to this shared unlock code pattern, too.

Thanks, Daniel

Quoted 25 lines
---
 drivers/gpu/drm/i915/i915_gem.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem.c +3 -1
index d2ba315..3eeb2d0 100644
@@ -4879,8 +4879,10 @@ i915_gem_init_hw(struct drm_device *dev)
 	i915_gem_init_swizzling(dev);
 
 	ret = dev_priv->gt.init_rings(dev);
-	if (ret)
+	if (ret) {
+		mutex_unlock(&dev->struct_mutex);
 		return ret;
+	}
 
 	for (i = 0; i < NUM_L3_SLICES(dev); i++)
 		i915_gem_l3_remap(&dev_priv->ring[RCS], i);

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel