Skip to contentSkip to conversation

drm/i915: Fix wait_req unreferencing.

PATCH In review Maarten Lankhorst 4 participants 9 messages Aug 8, 2016 – Aug 9, 2016

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

cover drm/i915: Fix wait_req unreferencing.

Small cleanup plus a fix for the reference dropping. This removes a source of heisenbugs. :-)

Maarten Lankhorst (2):
drm/i915: Remove early return in prepare/cleanup plane drm/i915: Drop reference to current state wait req as soon as it goes
unused

 drivers/gpu/drm/i915/intel_display.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
Signature · 6 lines
2.7.4

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

PATCH 1/2 drm/i915: Remove early return in prepare/cleanup plane

This is a noop in prepare_plane, which already carefully handles this with if guards and early return.

cleanup_plane_fb has it as a noop too, it only unpins old_fb and unsets wait_req. The latter is a noop because prepare_plane won't set wait_req when obj == NULL. It's also dangerous to keep because plane->state may change before cleanup_plane_fb is called.

---
 drivers/gpu/drm/i915/intel_display.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/intel_display.c +2 -10
index b12c8302580f..f56707289615 100644
@@ -14117,9 +14117,6 @@ intel_prepare_plane_fb(struct drm_plane *plane,
 	struct reservation_object *resv;
 	int ret = 0;
 
-	if (!obj && !old_obj)
-		return 0;
-
 	if (old_obj) {
 		struct drm_crtc_state *crtc_state =
 			drm_atomic_get_existing_crtc_state(new_state->state, plane->state->crtc);
@@ -14193,15 +14190,10 @@ intel_cleanup_plane_fb(struct drm_plane *plane,
 		       const struct drm_plane_state *old_state)
 {
 	struct drm_device *dev = plane->dev;
-	struct intel_plane_state *old_intel_state;
 	struct intel_plane_state *intel_state = to_intel_plane_state(plane->state);
 	struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb);
-	struct drm_i915_gem_object *obj = intel_fb_obj(plane->state->fb);
-
-	old_intel_state = to_intel_plane_state(old_state);
-
-	if (!obj && !old_obj)
-		return;
+	struct intel_plane_state *old_intel_state =
+		to_intel_plane_state(old_state);
 
 	if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR ||
 	    !INTEL_INFO(dev)->cursor_needs_physical))
Signature · 6 lines
2.7.4

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

PATCH 2/2 drm/i915: Drop reference to current state wait req as soon as it goes unused

In reply to Maarten Lankhorst

There are two paths into intel_cleanup_plane_fb, the normal completion path and the failure path.

In the failure case, intel_cleanup_plane_fb is called before drm_atomic_helper_swap_state, so any wait_req reference made in intel_prepare_plane_fb will be in old_intel_state->wait_req.

In the normal completion path, wait_req is not freed until the next commit, which is no longer used after waiting.

Free it as soon as possible, so we don't hold on to it indefinitely.

Cc Keith Packard <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc David Airlie <[email protected]>
Fixes 849782575325 ("drm/i915: cleanup_plane_fb: also drop reference to current state wait_req")
---
 drivers/gpu/drm/i915/intel_display.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_display.c +2 -2
index f56707289615..e72ad97998a4 100644
@@ -13754,6 +13754,8 @@ static void intel_atomic_commit_tail(struct drm_atomic_state *state)
 		/* EIO should be eaten, and we can't get interrupted in the
 		 * worker, and blocking commits have waited already. */
 		WARN_ON(ret);
+
+		i915_gem_request_assign(&intel_plane_state->wait_req, NULL);
 	}
 
 	if (!state->legacy_cursor_update)
@@ -14190,7 +14192,6 @@ intel_cleanup_plane_fb(struct drm_plane *plane,
 		       const struct drm_plane_state *old_state)
 {
 	struct drm_device *dev = plane->dev;
-	struct intel_plane_state *intel_state = to_intel_plane_state(plane->state);
 	struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb);
 	struct intel_plane_state *old_intel_state =
 		to_intel_plane_state(old_state);
@@ -14199,7 +14200,6 @@ intel_cleanup_plane_fb(struct drm_plane *plane,
 	    !INTEL_INFO(dev)->cursor_needs_physical))
 		intel_unpin_fb_obj(old_state->fb, old_state->rotation);
 
-	i915_gem_request_assign(&intel_state->wait_req, NULL);
 	i915_gem_request_assign(&old_intel_state->wait_req, NULL);
 }
 
Signature · 6 lines
2.7.4

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

Re: [PATCH 2/2] drm/i915: Drop reference to current state wait req as soon as it goes unused

Quoted 12 lines · Maarten Lankhorst

There are two paths into intel_cleanup_plane_fb, the normal completion path and the failure path.

In the failure case, intel_cleanup_plane_fb is called before drm_atomic_helper_swap_state, so any wait_req reference made in intel_prepare_plane_fb will be in old_intel_state->wait_req.

In the normal completion path, wait_req is not freed until the next commit, which is no longer used after waiting.

Free it as soon as possible, so we don't hold on to it indefinitely.

Quoted 7 lines
Cc Keith Packard <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc David Airlie <[email protected]>
Fixes 849782575325 ("drm/i915: cleanup_plane_fb: also drop reference to current state wait_req")

We still need to clean up the reference in case of failure, which means latest in intel_plane_destroy_state(). Also hanging onto a request isn't that evil really, why can't we just only clean up in the destroy function?
-Daniel

Quoted 40 lines
---
 drivers/gpu/drm/i915/intel_display.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_display.c +2 -3
index f56707289615..e72ad97998a4 100644
@@ -13754,6 +13754,8 @@ static void intel_atomic_commit_tail(struct drm_atomic_state *state)
                /* EIO should be eaten, and we can't get interrupted in the
                 * worker, and blocking commits have waited already. */
                WARN_ON(ret);
+
+               i915_gem_request_assign(&intel_plane_state->wait_req, NULL);
        }
 
        if (!state->legacy_cursor_update)
@@ -14190,7 +14192,6 @@ intel_cleanup_plane_fb(struct drm_plane *plane,
                       const struct drm_plane_state *old_state)
 {
        struct drm_device *dev = plane->dev;
-       struct intel_plane_state *intel_state = to_intel_plane_state(plane->state);
        struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb);
        struct intel_plane_state *old_intel_state =
                to_intel_plane_state(old_state);
@@ -14199,7 +14200,6 @@ intel_cleanup_plane_fb(struct drm_plane *plane,
            !INTEL_INFO(dev)->cursor_needs_physical))
                intel_unpin_fb_obj(old_state->fb, old_state->rotation);
 
-       i915_gem_request_assign(&intel_state->wait_req, NULL);
        i915_gem_request_assign(&old_intel_state->wait_req, NULL);
 }
 
--

2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://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
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

Re: [PATCH 2/2] drm/i915: Drop reference to current state wait req as soon as it goes unused

Quoted 4 lines · Daniel Vetter

We still need to clean up the reference in case of failure, which means latest in intel_plane_destroy_state(). Also hanging onto a request isn't that evil really, why can't we just only clean up in the destroy function?

Sticking a cleanup there as well is good insurance, but it seems like a reasonable policy to drop references when values go 'out of scope' as they do in cleanup_plane_fb. But, you're right, we only *need* to drop the reference in the destroy function, it's just that the state hangs around until the next mode setting operation, which is likely to be days away.

Signature · 1 line
-keith

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

#5 lore raw

PATCH 2/2 drm/i915: Drop reference to plane state wait req in destructor.

With gem requests reworked to only keep some memory around after it's completed it's now mostly harmless to keep a reference to the request until the state is destroyed. This makes it easy to hang on to the request until the plane state is destroyed since it is just a bunch of memory now.

On my 64-bits system a i915_gem_request is 352 bytes. With all 3 crtc's, each 4 planes enabled the total is 4224 bytes, low enough not to optimize this case too much.

Cc Keith Packard <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc David Airlie <[email protected]>
Fixes 849782575325 ("drm/i915: cleanup_plane_fb: also drop reference to current state wait_req")
---
 drivers/gpu/drm/i915/intel_atomic_plane.c | 5 ++++-
 drivers/gpu/drm/i915/intel_display.c      | 6 ------
 2 files changed, 4 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/intel_atomic_plane.c +4 -1
index 7de7721f65bc..f98071a1dcc0 100644
@@ -101,7 +101,10 @@ void
 intel_plane_destroy_state(struct drm_plane *plane,
 			  struct drm_plane_state *state)
 {
-	WARN_ON(state && to_intel_plane_state(state)->wait_req);
+	struct intel_plane_state *intel_state = to_intel_plane_state(state);
+
+	i915_gem_request_assign(&intel_state->wait_req, NULL);
+
 	drm_atomic_helper_plane_destroy_state(plane, state);
 }
 
drivers/gpu/drm/i915/intel_display.c +0 -6
index af45ee206239..774895288bcc 100644
@@ -14063,17 +14063,11 @@ intel_cleanup_plane_fb(struct drm_plane *plane,
 		       const struct drm_plane_state *old_state)
 {
 	struct drm_device *dev = plane->dev;
-	struct intel_plane_state *intel_state = to_intel_plane_state(plane->state);
 	struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb);
-	struct intel_plane_state *old_intel_state =
-		to_intel_plane_state(old_state);
 
 	if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR ||
 	    !INTEL_INFO(dev)->cursor_needs_physical))
 		intel_unpin_fb_obj(old_state->fb, old_state->rotation);
-
-	i915_gem_request_assign(&intel_state->wait_req, NULL);
-	i915_gem_request_assign(&old_intel_state->wait_req, NULL);
 }
 
 int
Signature · 7 lines
2.7.4


_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] drm/i915: Drop reference to plane state wait req in destructor.

Quoted 10 lines · Maarten Lankhorst

With gem requests reworked to only keep some memory around after it's completed it's now mostly harmless to keep a reference to the request until the state is destroyed. This makes it easy to hang on to the request until the plane state is destroyed since it is just a bunch of memory now.

On my 64-bits system a i915_gem_request is 352 bytes. With all 3 crtc's, each 4 planes enabled the total is 4224 bytes, low enough not to optimize this case too much.

Quoted 7 lines
Cc Keith Packard <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc David Airlie <[email protected]>
Fixes 849782575325 ("drm/i915: cleanup_plane_fb: also drop reference to current state wait_req")

Yeah, I think hanging onto requests like that is perfectly fine, and it simplifies the gymnastics for tracking things if we always allocate drm_*_state resources in atomic_duplicate, update the refs in atomic_check (with the various set functions the core has, or our own) and then release references in atomic_state destroy.

Quoted 47 lines
---
 drivers/gpu/drm/i915/intel_atomic_plane.c | 5 ++++-
 drivers/gpu/drm/i915/intel_display.c      | 6 ------
 2 files changed, 4 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/intel_atomic_plane.c +4 -1
index 7de7721f65bc..f98071a1dcc0 100644
@@ -101,7 +101,10 @@ void
 intel_plane_destroy_state(struct drm_plane *plane,
 			  struct drm_plane_state *state)
 {
-	WARN_ON(state && to_intel_plane_state(state)->wait_req);
+	struct intel_plane_state *intel_state = to_intel_plane_state(state);
+
+	i915_gem_request_assign(&intel_state->wait_req, NULL);
+
 	drm_atomic_helper_plane_destroy_state(plane, state);
 }
 
drivers/gpu/drm/i915/intel_display.c +0 -6
index af45ee206239..774895288bcc 100644
@@ -14063,17 +14063,11 @@ intel_cleanup_plane_fb(struct drm_plane *plane,
 		       const struct drm_plane_state *old_state)
 {
 	struct drm_device *dev = plane->dev;
-	struct intel_plane_state *intel_state = to_intel_plane_state(plane->state);
 	struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb);
-	struct intel_plane_state *old_intel_state =
-		to_intel_plane_state(old_state);
 
 	if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR ||
 	    !INTEL_INFO(dev)->cursor_needs_physical))
 		intel_unpin_fb_obj(old_state->fb, old_state->rotation);
-
-	i915_gem_request_assign(&intel_state->wait_req, NULL);
-	i915_gem_request_assign(&old_intel_state->wait_req, NULL);
 }
 
 int
Signature · 1 line
2.7.4
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw

Re: [PATCH 2/2] drm/i915: Drop reference to current state wait req as soon as it goes unused

In reply to Daniel Vetter

Op 08-08-16 om 17:34 schreef Daniel Vetter:

Quoted 21 lines
Quoted 12 lines · Maarten Lankhorst

There are two paths into intel_cleanup_plane_fb, the normal completion path and the failure path.

In the failure case, intel_cleanup_plane_fb is called before drm_atomic_helper_swap_state, so any wait_req reference made in intel_prepare_plane_fb will be in old_intel_state->wait_req.

In the normal completion path, wait_req is not freed until the next commit, which is no longer used after waiting.

Free it as soon as possible, so we don't hold on to it indefinitely.

Quoted 7 lines
Cc Keith Packard <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc David Airlie <[email protected]>
Fixes 849782575325 ("drm/i915: cleanup_plane_fb: also drop reference to current state wait_req")
Quoted 4 lines

We still need to clean up the reference in case of failure, which means latest in intel_plane_destroy_state(). Also hanging onto a request isn't that evil really, why can't we just only clean up in the destroy function?

Hm true, we're still guaranteed to call cleanup_plane_fb in case of failure though, else the WARN in unref would trigger.

I think it's harmless to hang onto the request, worst case we keep an extra MAX_PLANES * MAX_CRTCS * sizeof(i915_gem_request) allocated, which is slightly more than 4k memory. (4 * 3 * 352)

If we unref the request in the destructor, it's also one step closer to constifying plane_state.

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

#8 lore raw

✗ Ro.CI.BAT: failure for drm/i915: Fix wait_req unreferencing.

In reply to Maarten Lankhorst
== Series Details ==

== Series Details ==

Series: drm/i915: Fix wait_req unreferencing.
URL : https://patchwork.freedesktop.org/series/10781/
State : failure

== Summary ==

Applying: drm/i915: Remove early return in prepare/cleanup plane
Applying: drm/i915: Drop reference to current state wait req as soon as it goes unused
fatal: sha1 information is lacking or useless (drivers/gpu/drm/i915/intel_display.c).
error: could not build fake ancestor
Patch failed at 0002 drm/i915: Drop reference to current state wait req as soon as it goes unused The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

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