drm/i915: Fix wait_req unreferencing.
Subsystems (2)
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
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
@@ -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
PATCH 2/2 drm/i915: Drop reference to current state wait req as soon as it goes unused
In reply to Maarten LankhorstThere 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.
--- drivers/gpu/drm/i915/intel_display.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_display.c +2 -2
@@ -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
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_fbis called beforedrm_atomic_helper_swap_state, so anywait_reqreference made inintel_prepare_plane_fbwill be inold_intel_state->wait_req.In the normal completion path,
wait_reqis 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
Signed-off-by Maarten Lankhorst <[email protected]>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@@ -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
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
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.
--- 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
@@ -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
@@ -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
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_requestis 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
Signed-off-by Maarten Lankhorst <[email protected]>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@@ -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@@ -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
Re: [PATCH 2/2] drm/i915: Drop reference to current state wait req as soon as it goes unused
In reply to Daniel VetterOp 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_fbis called beforedrm_atomic_helper_swap_state, so anywait_reqreference made inintel_prepare_plane_fbwill be inold_intel_state->wait_req.In the normal completion path,
wait_reqis 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
Signed-off-by Maarten Lankhorst <[email protected]>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
Patchwork
CI✗ 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