Skip to contentSkip to conversation

drm/atomic: Fix memleak on ERESTARTSYS during non-blocking commits

PATCH Applied [email protected] 5 participants 5 messages Jan 4, 2018 – Jan 10, 2018

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

PATCH 1/1 drm/atomic: Fix memleak on ERESTARTSYS during non-blocking commits

From: "Leo (Sunpeng) Li" <[email protected]>

During a non-blocking commit, it is possible to return before the commit_tail work is queued (-ERESTARTSYS, for example).

Since a reference on the crtc commit object is obtained for the pending vblank event when preparing the commit, the above situation will leave us with an extra reference.

Therefore, if the commit_tail worker has not consumed the event at the end of a commit, release it's reference.

---
 drivers/gpu/drm/drm_atomic_helper.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/drm_atomic_helper.c +9 -0
index ab40321..4253f57 100644
@@ -3421,6 +3421,15 @@ EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
 void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state)
 {
 	if (state->commit) {
+		/*
+		 * In the event that a non-blocking commit returns
+		 * -ERESTARTSYS before the commit_tail work is queued, we will
+		 * have an extra reference to the commit object. Release it, if
+		 * the event has not been consumed by the worker.
+		 */
+		if (state->event)
+			drm_crtc_commit_put(state->commit);
+
 		kfree(state->commit->event);
 		state->commit->event = NULL;
 		drm_crtc_commit_put(state->commit);
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · On 2018-01-04 02:47 PM, [email protected] wrote:

From: "Leo (Sunpeng) Li" <[email protected]>

During a non-blocking commit, it is possible to return before the commit_tail work is queued (-ERESTARTSYS, for example).

Quoted 8 lines

Since a reference on the crtc commit object is obtained for the pending vblank event when preparing the commit, the above situation will leave us with an extra reference.

Therefore, if the commit_tail worker has not consumed the event at the end of a commit, release it's reference.

No expert on this but looks sane to me.

Harry

Quoted 15 lines
---
 drivers/gpu/drm/drm_atomic_helper.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/drm_atomic_helper.c +2 -0
index ab40321..4253f57 100644
@@ -3421,6 +3421,15 @@ EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
 void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state)
 {
 	if (state->commit) {
+		/*
+		 * In the event that a non-blocking commit returns

drivers/gpu/drm/drm_atomic_helper.c EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state); · line 3435

Quoted 10 lines
drivers/gpu/drm/drm_atomic_helper.c +7 -0
+		 * -ERESTARTSYS before the commit_tail work is queued, we will
+		 * have an extra reference to the commit object. Release it, if
+		 * the event has not been consumed by the worker.
+		 */
+		if (state->event)
+			drm_crtc_commit_put(state->commit);
+
 		kfree(state->commit->event);
 		state->commit->event = NULL;
 		drm_crtc_commit_put(state->commit);

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

Applied
#2 lore raw
Quoted 10 lines · Harry Wentland
Quoted 9 lines · On 2018-01-04 02:47 PM, [email protected] wrote:

From: "Leo (Sunpeng) Li" <[email protected]>

During a non-blocking commit, it is possible to return before the commit_tail work is queued (-ERESTARTSYS, for example).

Since a reference on the crtc commit object is obtained for the pending vblank event when preparing the commit, the above situation will leave us with an extra reference.

Quoted 8 lines
Quoted 4 lines

Therefore, if the commit_tail worker has not consumed the event at the end of a commit, release it's reference.

No expert on this but looks sane to me.

Pushed to drm-misc-next.

Thanks,

Alex

Quoted 24 lines

Harry

Quoted 21 lines
---
 drivers/gpu/drm/drm_atomic_helper.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/drm_atomic_helper.c +9 -0
index ab40321..4253f57 100644
@@ -3421,6 +3421,15 @@ EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
 void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state)
 {
      if (state->commit) {
+             /*
+              * In the event that a non-blocking commit returns
+              * -ERESTARTSYS before the commit_tail work is queued, we will
+              * have an extra reference to the commit object. Release it, if
+              * the event has not been consumed by the worker.
+              */
+             if (state->event)
+                     drm_crtc_commit_put(state->commit);
+
Quoted 8 lines

drivers/gpu/drm/drm_atomic_helper.c EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state); · line 3435

Quoted 4 lines
drivers/gpu/drm/drm_atomic_helper.c +0 -0
              kfree(state->commit->event);
              state->commit->event = NULL;
              drm_crtc_commit_put(state->commit);

_______________________________________________
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

#3 lore raw
Quoted 14 lines · Alex Deucher
Quoted 13 lines · Harry Wentland
Quoted 12 lines · On 2018-01-04 02:47 PM, [email protected] wrote:

From: "Leo (Sunpeng) Li" <[email protected]>

During a non-blocking commit, it is possible to return before the commit_tail work is queued (-ERESTARTSYS, for example).

Since a reference on the crtc commit object is obtained for the pending vblank event when preparing the commit, the above situation will leave us with an extra reference.

Therefore, if the commit_tail worker has not consumed the event at the end of a commit, release it's reference.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

No expert on this but looks sane to me.

Pushed to drm-misc-next.

This blows up all over the place in our CI:

https://bugs.freedesktop.org/show_bug.cgi?id=104566

I think as a leak fix it should also be pushed to -fixes. And we didn't really figure out what's wrong, so we're going with the quick revert until you folks are all awake.

Cheers, Daniel

Quoted 41 lines

Thanks,

Alex

Quoted 24 lines

Harry

Quoted 21 lines
---
 drivers/gpu/drm/drm_atomic_helper.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/drm_atomic_helper.c +9 -0
index ab40321..4253f57 100644
@@ -3421,6 +3421,15 @@ EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
 void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state)
 {
      if (state->commit) {
+             /*
+              * In the event that a non-blocking commit returns
+              * -ERESTARTSYS before the commit_tail work is queued, we will
+              * have an extra reference to the commit object. Release it, if
+              * the event has not been consumed by the worker.
+              */
+             if (state->event)
+                     drm_crtc_commit_put(state->commit);
+
Quoted 8 lines

drivers/gpu/drm/drm_atomic_helper.c EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state); · line 3435

Quoted 4 lines
drivers/gpu/drm/drm_atomic_helper.c +0 -0
              kfree(state->commit->event);
              state->commit->event = NULL;
              drm_crtc_commit_put(state->commit);

_______________________________________________
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

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
#4 lore raw
In reply to Harry Wentland

Op 08-01-18 om 22:30 schreef Harry Wentland:

Quoted 13 lines · On 2018-01-04 02:47 PM, [email protected] wrote:
Quoted 12 lines

From: "Leo (Sunpeng) Li" <[email protected]>

During a non-blocking commit, it is possible to return before the commit_tail work is queued (-ERESTARTSYS, for example).

Since a reference on the crtc commit object is obtained for the pending vblank event when preparing the commit, the above situation will leave us with an extra reference.

Therefore, if the commit_tail worker has not consumed the event at the end of a commit, release it's reference.

Quoted 6 lines
Quoted 1 line

No expert on this but looks sane to me.

Harry

Hey,

I've reverted the patch for now. I planned to apply it to the drm-misc-fixes branch with the appropriate commits referenced, but it is causing crashes on the kms_flip testcase.

https://bugs.freedesktop.org/show_bug.cgi?id=104566

I'll investigate it some more then send out a fixed patch. :)

~Maarten

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